초기커밋
This commit is contained in:
609
GameServer/Contents/ItemCloth/Action/ItemClothAction.cs
Normal file
609
GameServer/Contents/ItemCloth/Action/ItemClothAction.cs
Normal file
@@ -0,0 +1,609 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
|
||||
using Grpc.Core;
|
||||
|
||||
|
||||
using ServerCore; using ServerBase;
|
||||
using ServerCommon;
|
||||
using ServerCommon.BusinessLogDomain;
|
||||
using MetaAssets;
|
||||
|
||||
|
||||
using SESSION_ID = System.Int32;
|
||||
using WORLD_META_ID = System.UInt32;
|
||||
using META_ID = System.UInt32;
|
||||
using ENTITY_GUID = System.String;
|
||||
using ACCOUNT_ID = System.String;
|
||||
using OWNER_GUID = System.String;
|
||||
using USER_GUID = System.String;
|
||||
using CHARACTER_GUID = System.String;
|
||||
using ITEM_GUID = System.String;
|
||||
|
||||
|
||||
|
||||
|
||||
namespace GameServer
|
||||
{
|
||||
public class ItemClothAction : EntityActionBase
|
||||
{
|
||||
public ItemClothAction(EntityBase owner)
|
||||
: base(owner)
|
||||
{
|
||||
}
|
||||
|
||||
public override async Task<Result> onInit()
|
||||
{
|
||||
await Task.CompletedTask;
|
||||
|
||||
var result = new Result();
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
public override void onClear()
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
public async Task<Result> tryApplyClothsByMetaId(ClothInfo? clothInfo)
|
||||
{
|
||||
var result = new Result();
|
||||
var err_msg = string.Empty;
|
||||
|
||||
var owner = getOwner();
|
||||
NullReferenceCheckHelper.throwIfNull(owner, () => toBasicString());
|
||||
|
||||
if (null == clothInfo)
|
||||
{
|
||||
err_msg = $"ClothInfo is null !!! - {owner.toBasicString()}";
|
||||
Log.getLogger().info(err_msg);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
ITEM_GUID equiped_item_guid = string.Empty;
|
||||
|
||||
if (clothInfo.ClothAvatar > 0)
|
||||
{
|
||||
(result, equiped_item_guid) = await fillupItemAfterEquipedClothByMetaId(clothInfo.ClothAvatar);
|
||||
if (result.isFail())
|
||||
{
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
if (clothInfo.ClothHeadwear > 0)
|
||||
{
|
||||
(result, equiped_item_guid) = await fillupItemAfterEquipedClothByMetaId(clothInfo.ClothHeadwear);
|
||||
if (result.isFail())
|
||||
{
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
if (clothInfo.ClothMask > 0)
|
||||
{
|
||||
(result, equiped_item_guid) = await fillupItemAfterEquipedClothByMetaId(clothInfo.ClothMask);
|
||||
if (result.isFail())
|
||||
{
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
if (clothInfo.ClothBag > 0)
|
||||
{
|
||||
(result, equiped_item_guid) = await fillupItemAfterEquipedClothByMetaId(clothInfo.ClothBag);
|
||||
if (result.isFail())
|
||||
{
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
if (clothInfo.ClothShoes > 0)
|
||||
{
|
||||
(result, equiped_item_guid) = await fillupItemAfterEquipedClothByMetaId(clothInfo.ClothShoes);
|
||||
if (result.isFail())
|
||||
{
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
if (clothInfo.ClothOuter > 0)
|
||||
{
|
||||
(result, equiped_item_guid) = await fillupItemAfterEquipedClothByMetaId(clothInfo.ClothOuter);
|
||||
if (result.isFail())
|
||||
{
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
if (clothInfo.ClothTops > 0)
|
||||
{
|
||||
(result, equiped_item_guid) = await fillupItemAfterEquipedClothByMetaId(clothInfo.ClothTops);
|
||||
if (result.isFail())
|
||||
{
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
if (clothInfo.ClothBottoms > 0)
|
||||
{
|
||||
(result, equiped_item_guid) = await fillupItemAfterEquipedClothByMetaId(clothInfo.ClothBottoms);
|
||||
if (result.isFail())
|
||||
{
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
if (clothInfo.ClothGloves > 0)
|
||||
{
|
||||
(result, equiped_item_guid) = await fillupItemAfterEquipedClothByMetaId(clothInfo.ClothGloves);
|
||||
if (result.isFail())
|
||||
{
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
if (clothInfo.ClothEarrings > 0)
|
||||
{
|
||||
(result, equiped_item_guid) = await fillupItemAfterEquipedClothByMetaId(clothInfo.ClothEarrings);
|
||||
if (result.isFail())
|
||||
{
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
if (clothInfo.ClothNeckless > 0)
|
||||
{
|
||||
(result, equiped_item_guid) = await fillupItemAfterEquipedClothByMetaId(clothInfo.ClothNeckless);
|
||||
if (result.isFail())
|
||||
{
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
if (clothInfo.ClothSocks > 0)
|
||||
{
|
||||
(result, equiped_item_guid) = await fillupItemAfterEquipedClothByMetaId(clothInfo.ClothSocks);
|
||||
if (result.isFail())
|
||||
{
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
private async Task<(Result result, ITEM_GUID equipedItemGuid)> fillupItemAfterEquipedClothByMetaId(META_ID metaId)
|
||||
{
|
||||
var result = new Result();
|
||||
|
||||
var owner = getOwner();
|
||||
NullReferenceCheckHelper.throwIfNull(owner, () => $"owner is null !!!");
|
||||
|
||||
var inventory_action = owner.getEntityAction<InventoryActionBase>();
|
||||
NullReferenceCheckHelper.throwIfNull(inventory_action, () => toBasicString());
|
||||
|
||||
(result, var take_in_items) = await inventory_action.tryTakableToBagWithEquip(metaId, 1);
|
||||
if (result.isFail())
|
||||
{
|
||||
return (result, string.Empty);
|
||||
}
|
||||
NullReferenceCheckHelper.throwIfNull(take_in_items, () => toBasicString());
|
||||
|
||||
var item_attribute = take_in_items[0].getEntityAttribute<ItemAttributeBase>();
|
||||
NullReferenceCheckHelper.throwIfNull(item_attribute, () => toBasicString());
|
||||
|
||||
return (result, item_attribute.ItemGuid);
|
||||
}
|
||||
|
||||
public async Task tryApplyClothsByClothInfo(ClothInfo clothInfo)
|
||||
{
|
||||
var result = new Result();
|
||||
var err_msg = string.Empty;
|
||||
|
||||
var owner = getOwner();
|
||||
NullReferenceCheckHelper.throwIfNull(owner, () => $"owner is null !!!");
|
||||
NullReferenceCheckHelper.throwIfNull(clothInfo, () => $"clothInfo is null !!! - {owner.toBasicString()}");
|
||||
|
||||
if (clothInfo.ClothAvatarItemGuid.isNullOrWhiteSpace())
|
||||
{
|
||||
(result, _) = await tryUnequipClothByClothType(ClothSlotType.Avatar);
|
||||
if (result.isFail()) { Log.getLogger().error(result.toBasicString()); }
|
||||
}
|
||||
else
|
||||
{
|
||||
(result, _) = await tryEquipClothByItemGuid(clothInfo.ClothAvatarItemGuid);
|
||||
if (result.isFail() && result.getErrorCode() != ServerErrorCode.SlotsAlreadyEquiped) { Log.getLogger().error(result.toBasicString()); }
|
||||
}
|
||||
|
||||
if (clothInfo.ClothHeadwearItemGuid.isNullOrWhiteSpace())
|
||||
{
|
||||
(result, _) = await tryUnequipClothByClothType(ClothSlotType.Headwear);
|
||||
if (result.isFail()) { Log.getLogger().error(result.toBasicString()); }
|
||||
}
|
||||
else
|
||||
{
|
||||
(result, _) = await tryEquipClothByItemGuid(clothInfo.ClothHeadwearItemGuid);
|
||||
if (result.isFail() && result.getErrorCode() != ServerErrorCode.SlotsAlreadyEquiped) { Log.getLogger().error(result.toBasicString()); }
|
||||
}
|
||||
|
||||
if (clothInfo.ClothMaskItemGuid.isNullOrWhiteSpace())
|
||||
{
|
||||
(result, _) = await tryUnequipClothByClothType(ClothSlotType.Mask);
|
||||
if (result.isFail()) { Log.getLogger().error(result.toBasicString()); }
|
||||
}
|
||||
else
|
||||
{
|
||||
(result, _) = await tryEquipClothByItemGuid(clothInfo.ClothMaskItemGuid);
|
||||
if (result.isFail() && result.getErrorCode() != ServerErrorCode.SlotsAlreadyEquiped) { Log.getLogger().error(result.toBasicString()); }
|
||||
}
|
||||
|
||||
if (clothInfo.ClothBagItemGuid.isNullOrWhiteSpace())
|
||||
{
|
||||
(result, _) = await tryUnequipClothByClothType(ClothSlotType.Bag);
|
||||
if (result.isFail()) { Log.getLogger().error(result.toBasicString()); }
|
||||
}
|
||||
else
|
||||
{
|
||||
(result, _) = await tryEquipClothByItemGuid(clothInfo.ClothBagItemGuid);
|
||||
if (result.isFail() && result.getErrorCode() != ServerErrorCode.SlotsAlreadyEquiped) { Log.getLogger().error(result.toBasicString()); }
|
||||
}
|
||||
|
||||
if (clothInfo.ClothShoesItemGuid.isNullOrWhiteSpace())
|
||||
{
|
||||
(result, _) = await tryUnequipClothByClothType(ClothSlotType.Shoes);
|
||||
if (result.isFail()) { Log.getLogger().error(result.toBasicString()); }
|
||||
}
|
||||
else
|
||||
{
|
||||
(result, _) = await tryEquipClothByItemGuid(clothInfo.ClothShoesItemGuid);
|
||||
if (result.isFail() && result.getErrorCode() != ServerErrorCode.SlotsAlreadyEquiped) { Log.getLogger().error(result.toBasicString()); }
|
||||
}
|
||||
|
||||
if (clothInfo.ClothOuterItemGuid.isNullOrWhiteSpace())
|
||||
{
|
||||
(result, _) = await tryUnequipClothByClothType(ClothSlotType.Outer);
|
||||
if (result.isFail()) { Log.getLogger().error(result.toBasicString()); }
|
||||
}
|
||||
else
|
||||
{
|
||||
(result, _) = await tryEquipClothByItemGuid(clothInfo.ClothOuterItemGuid);
|
||||
if (result.isFail() && result.getErrorCode() != ServerErrorCode.SlotsAlreadyEquiped) { Log.getLogger().error(result.toBasicString()); }
|
||||
}
|
||||
|
||||
if (clothInfo.ClothTopsItemGuid.isNullOrWhiteSpace())
|
||||
{
|
||||
(result, _) = await tryUnequipClothByClothType(ClothSlotType.Tops);
|
||||
if (result.isFail()) { Log.getLogger().error(result.toBasicString()); }
|
||||
}
|
||||
else
|
||||
{
|
||||
(result, _) = await tryEquipClothByItemGuid(clothInfo.ClothTopsItemGuid);
|
||||
if (result.isFail() && result.getErrorCode() != ServerErrorCode.SlotsAlreadyEquiped) { Log.getLogger().error(result.toBasicString()); }
|
||||
}
|
||||
|
||||
if (clothInfo.ClothBottomsItemGuid.isNullOrWhiteSpace())
|
||||
{
|
||||
(result, _) = await tryUnequipClothByClothType(ClothSlotType.Bottoms);
|
||||
if (result.isFail()) { Log.getLogger().error(result.toBasicString()); }
|
||||
}
|
||||
else
|
||||
{
|
||||
(result, _) = await tryEquipClothByItemGuid(clothInfo.ClothBottomsItemGuid);
|
||||
if (result.isFail() && result.getErrorCode() != ServerErrorCode.SlotsAlreadyEquiped) { Log.getLogger().error(result.toBasicString()); }
|
||||
}
|
||||
|
||||
if (clothInfo.ClothGlovesItemGuid.isNullOrWhiteSpace())
|
||||
{
|
||||
(result, _) = await tryUnequipClothByClothType(ClothSlotType.Gloves);
|
||||
if (result.isFail()) { Log.getLogger().error(result.toBasicString()); }
|
||||
}
|
||||
else
|
||||
{
|
||||
(result, _) = await tryEquipClothByItemGuid(clothInfo.ClothGlovesItemGuid);
|
||||
if (result.isFail() && result.getErrorCode() != ServerErrorCode.SlotsAlreadyEquiped) { Log.getLogger().error(result.toBasicString()); }
|
||||
}
|
||||
|
||||
if (clothInfo.ClothEarringsItemGuid.isNullOrWhiteSpace())
|
||||
{
|
||||
(result, _) = await tryUnequipClothByClothType(ClothSlotType.Earrings);
|
||||
if (result.isFail()) { Log.getLogger().error(result.toBasicString()); }
|
||||
}
|
||||
else
|
||||
{
|
||||
(result, _) = await tryEquipClothByItemGuid(clothInfo.ClothEarringsItemGuid);
|
||||
if (result.isFail() && result.getErrorCode() != ServerErrorCode.SlotsAlreadyEquiped) { Log.getLogger().error(result.toBasicString()); }
|
||||
}
|
||||
|
||||
if (clothInfo.ClothNecklessItemGuid.isNullOrWhiteSpace())
|
||||
{
|
||||
(result, _) = await tryUnequipClothByClothType(ClothSlotType.Neckless);
|
||||
if (result.isFail()) { Log.getLogger().error(result.toBasicString()); }
|
||||
}
|
||||
else
|
||||
{
|
||||
(result, _) = await tryEquipClothByItemGuid(clothInfo.ClothNecklessItemGuid);
|
||||
if (result.isFail() && result.getErrorCode() != ServerErrorCode.SlotsAlreadyEquiped) { Log.getLogger().error(result.toBasicString()); }
|
||||
}
|
||||
|
||||
if (clothInfo.ClothSocksItemGuid.isNullOrWhiteSpace())
|
||||
{
|
||||
(result, _) = await tryUnequipClothByClothType(ClothSlotType.Socks);
|
||||
if (result.isFail()) { Log.getLogger().error(result.toBasicString()); }
|
||||
}
|
||||
else
|
||||
{
|
||||
(result, _) = await tryEquipClothByItemGuid(clothInfo.ClothSocksItemGuid);
|
||||
if (result.isFail() && result.getErrorCode() != ServerErrorCode.SlotsAlreadyEquiped) { Log.getLogger().error(result.toBasicString()); }
|
||||
}
|
||||
}
|
||||
|
||||
private async Task<(Result, Item?)> tryEquipClothByItemGuid(ITEM_GUID itemGuid)
|
||||
{
|
||||
var result = new Result();
|
||||
var err_msg = string.Empty;
|
||||
|
||||
var owner = getOwner();
|
||||
NullReferenceCheckHelper.throwIfNull(owner, () => $"owner is null !!!");
|
||||
|
||||
var inventory_action = owner.getEntityAction<InventoryActionBase>();
|
||||
NullReferenceCheckHelper.throwIfNull(inventory_action, () => $"inventory_action is null !!! - {owner.toBasicString()}");
|
||||
|
||||
var found_item = inventory_action.tryGetItemByItemGuid(itemGuid);
|
||||
if (null == found_item)
|
||||
{
|
||||
err_msg = $"Not found Item in Bag !!! : itemGuid:{itemGuid} - {owner.toBasicString()}";
|
||||
result.setFail(ServerErrorCode.BagItemNotFound, err_msg);
|
||||
Log.getLogger().error(result.toBasicString());
|
||||
|
||||
return (result, null);
|
||||
}
|
||||
|
||||
var item_meta = found_item.getItemMeta();
|
||||
NullReferenceCheckHelper.throwIfNull(item_meta, () => $"item_meta is null !!! - {owner.toBasicString()}");
|
||||
|
||||
if (false == item_meta.TypeLarge.isClothType())
|
||||
{
|
||||
err_msg = $"Not EItemLargeType of Cloth !!! : EItemLargeType.Cloth == {item_meta.TypeLarge}, ItemMetaId:{item_meta.ItemId} - {owner.toBasicString()}";
|
||||
result.setFail(ServerErrorCode.ItemClothInvalidLargeType, err_msg);
|
||||
Log.getLogger().error(result.toBasicString());
|
||||
|
||||
return (result, null);
|
||||
}
|
||||
|
||||
if (false == item_meta.TypeSmall.isClothType())
|
||||
{
|
||||
err_msg = $"Not EItemSmallType of Cloth !!! : {item_meta.TypeSmall}, ItemMetaId:{item_meta.ItemId} - {owner.toBasicString()}";
|
||||
result.setFail(ServerErrorCode.ItemClothInvalidSmallType, err_msg);
|
||||
Log.getLogger().error(result.toBasicString());
|
||||
|
||||
return (result, null);
|
||||
}
|
||||
|
||||
var item_attribute = found_item.getOriginEntityAttribute<ItemAttributeBase>();
|
||||
NullReferenceCheckHelper.throwIfNull(item_attribute, () => $"item_attribute is null !!! - {owner.toBasicString()}");
|
||||
|
||||
var equiped_inven_type = item_attribute.EquipedIvenType;
|
||||
var equiped_pos = item_attribute.EquipedPos;
|
||||
if ( InvenEquipType.None != equiped_inven_type )
|
||||
{
|
||||
err_msg = $"Already equiped Cloth Item !!! : InvenEquipType.None == equipedInvenType{equiped_inven_type}, equipedPos:{equiped_pos}"
|
||||
+ $" - ItemMetaId:{item_meta.ItemId}, ItemGuid:{item_attribute.ItemGuid}, {owner.toBasicString()}";
|
||||
result.setFail(ServerErrorCode.SlotsAlreadyEquiped, err_msg);
|
||||
Log.getLogger().warn(result.toBasicString());
|
||||
|
||||
return (result, found_item);
|
||||
}
|
||||
|
||||
(result, _) = await tryUnequipClothByItemMeta(item_meta, false);
|
||||
if(result.isFail())
|
||||
{
|
||||
return (result, null);
|
||||
}
|
||||
|
||||
result = await inventory_action.tryTakableToEquip(found_item);
|
||||
if (result.isFail())
|
||||
{
|
||||
return (result, null);
|
||||
}
|
||||
|
||||
return (result, null);
|
||||
}
|
||||
|
||||
private async Task<(Result, Item?)> tryUnequipClothByItemMeta(ItemMetaData itemMeta, bool isFailOnItemNotFound = true)
|
||||
{
|
||||
var owner = getOwner();
|
||||
NullReferenceCheckHelper.throwIfNull(owner, () => $"owner is null !!!");
|
||||
ArgumentNullReferenceCheckHelper.throwIfNull(itemMeta, () => $"itemMeta is null !!! - {owner.toBasicString()}");
|
||||
|
||||
var result = new Result();
|
||||
var err_msg = string.Empty;
|
||||
|
||||
var inventory_action = owner.getEntityAction<InventoryActionBase>();
|
||||
NullReferenceCheckHelper.throwIfNull(inventory_action, () => $"inventory_action is null !!! - {owner.toBasicString()}");
|
||||
|
||||
var inven_rule = GameServerApp.getServerLogic().findRule<InventoryRule>();
|
||||
if (null == inven_rule)
|
||||
{
|
||||
err_msg = $"Not found InventoryRule !!! - {owner.toBasicString()}";
|
||||
result.setFail(ServerErrorCode.InventoryRuleNotFound, err_msg);
|
||||
Log.getLogger().error(result.toBasicString());
|
||||
|
||||
return (result, null);
|
||||
}
|
||||
|
||||
inventory_action.getEquipInvens().TryGetValue(InvenEquipType.Cloth, out var found_equip_inven);
|
||||
NullReferenceCheckHelper.throwIfNull(found_equip_inven, () => $"found_equip_inven is null !!! - {owner.toBasicString()}");
|
||||
|
||||
var cloth_inven = found_equip_inven as ClothEquipInven;
|
||||
NullReferenceCheckHelper.throwIfNull(inventory_action, () => $"cloth_inven is null !!! - {owner.toBasicString()}");
|
||||
|
||||
var equip_rule_bases = inven_rule.getEquipRuleBasesByItemLargeType(itemMeta.TypeLarge);
|
||||
if (null == equip_rule_bases)
|
||||
{
|
||||
err_msg = $"Not found EquipRuleBase !!! - {owner.toBasicString()}";
|
||||
Log.getLogger().warn(err_msg);
|
||||
|
||||
return (result, null);
|
||||
}
|
||||
else
|
||||
{
|
||||
foreach (var equip_rule in equip_rule_bases)
|
||||
{
|
||||
var cloth_equip_rule = equip_rule as ClothEquipRule;
|
||||
NullReferenceCheckHelper.throwIfNull(cloth_equip_rule, () => $"cloth_equip_rule is null !!! - {owner.toBasicString()}");
|
||||
|
||||
if (false == cloth_equip_rule.m_slots_by_item_type.TryGetValue(itemMeta.TypeSmall, out var found_cloth_slot_types))
|
||||
{
|
||||
err_msg = $"Not found ClothSlotType !!! : itemSmallType:{itemMeta.TypeSmall} - {owner.toBasicString()}";
|
||||
result.setFail(ServerErrorCode.ClothEquipRuleClothSlotTypeNotFound, err_msg);
|
||||
Log.getLogger().error(result.toBasicString());
|
||||
|
||||
return (result, null);
|
||||
}
|
||||
NullReferenceCheckHelper.throwIfNull(found_cloth_slot_types, () => $"found_cloth_slot_types is null !!! - {owner.toBasicString()}");
|
||||
|
||||
foreach (var cloth_slot_type in found_cloth_slot_types)
|
||||
{
|
||||
(var unequip_result, var unequiped_item) = await tryUnequipClothByClothType(cloth_slot_type, isFailOnItemNotFound);
|
||||
if(unequip_result.isFail())
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
return (unequip_result, unequiped_item);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return (result, null);
|
||||
}
|
||||
|
||||
private async Task<(Result, Item?)> tryUnequipClothByClothType( ClothSlotType clothSlotType
|
||||
, bool isFailOnItemNotFound = true )
|
||||
{
|
||||
var result = new Result();
|
||||
var err_msg = string.Empty;
|
||||
|
||||
var owner = getOwner();
|
||||
NullReferenceCheckHelper.throwIfNull(owner, () => $"owner is null !!!");
|
||||
|
||||
var inventory_action = owner.getEntityAction<InventoryActionBase>();
|
||||
NullReferenceCheckHelper.throwIfNull(inventory_action, () => $"inventory_action is null !!! - {owner.toBasicString()}");
|
||||
|
||||
(var get_item_result, var found_item) = await inventory_action.tryGetEquipItemByInvenEquipType<ClothSlotType>( InvenEquipType.Cloth, clothSlotType
|
||||
, isFailOnItemNotFound );
|
||||
if (null == found_item)
|
||||
{
|
||||
if (get_item_result.isFail())
|
||||
{
|
||||
return (get_item_result, null);
|
||||
}
|
||||
|
||||
return (result, null);
|
||||
}
|
||||
|
||||
(result, var updated_item) = await inventory_action.tryTakableOutFromEquip(found_item);
|
||||
if (result.isFail())
|
||||
{
|
||||
return (result, null);
|
||||
}
|
||||
|
||||
return (result, null);
|
||||
}
|
||||
|
||||
public Result fillupCloth(ClothSlotType clothSlotType, Item item, ref ClothInfo clothInfo)
|
||||
{
|
||||
var owner = getOwner();
|
||||
NullReferenceCheckHelper.throwIfNull(owner, () => $"owner is null !!!");
|
||||
ArgumentNullReferenceCheckHelper.throwIfNull(item, () => $"item is null !!! - {owner.toBasicString()}");
|
||||
ArgumentNullReferenceCheckHelper.throwIfNull(clothInfo, () => $"item is null !!! - {owner.toBasicString()}");
|
||||
|
||||
var result = new Result();
|
||||
var err_msg = string.Empty;
|
||||
|
||||
var item_meta = item.getItemMeta();
|
||||
NullReferenceCheckHelper.throwIfNull(item_meta, () => $"item_meta is null !!! - {owner.toBasicString()}");
|
||||
var item_attribute = item.getOriginEntityAttribute<ItemAttributeBase>();
|
||||
NullReferenceCheckHelper.throwIfNull(item_attribute, () => $"item_attribute is null !!! - {owner.toBasicString()}");
|
||||
|
||||
switch (clothSlotType)
|
||||
{
|
||||
case ClothSlotType.Avatar:
|
||||
clothInfo.ClothAvatar = (UInt32)item_meta.ItemId;
|
||||
clothInfo.ClothAvatarItemGuid = item_attribute.ItemGuid;
|
||||
break;
|
||||
|
||||
case ClothSlotType.Headwear:
|
||||
clothInfo.ClothHeadwear = (UInt32)item_meta.ItemId;
|
||||
clothInfo.ClothHeadwearItemGuid = item_attribute.ItemGuid;
|
||||
break;
|
||||
|
||||
case ClothSlotType.Mask:
|
||||
clothInfo.ClothMask = (UInt32)item_meta.ItemId;
|
||||
clothInfo.ClothMaskItemGuid = item_attribute.ItemGuid;
|
||||
break;
|
||||
|
||||
case ClothSlotType.Bag:
|
||||
clothInfo.ClothBag = (UInt32)item_meta.ItemId;
|
||||
clothInfo.ClothBagItemGuid = item_attribute.ItemGuid;
|
||||
break;
|
||||
|
||||
case ClothSlotType.Shoes:
|
||||
clothInfo.ClothShoes = (UInt32)item_meta.ItemId;
|
||||
clothInfo.ClothShoesItemGuid = item_attribute.ItemGuid;
|
||||
break;
|
||||
|
||||
case ClothSlotType.Outer:
|
||||
clothInfo.ClothOuter = (UInt32)item_meta.ItemId;
|
||||
clothInfo.ClothOuterItemGuid = item_attribute.ItemGuid;
|
||||
break;
|
||||
|
||||
case ClothSlotType.Tops:
|
||||
clothInfo.ClothTops = (UInt32)item_meta.ItemId;
|
||||
clothInfo.ClothTopsItemGuid = item_attribute.ItemGuid;
|
||||
break;
|
||||
|
||||
case ClothSlotType.Bottoms:
|
||||
clothInfo.ClothBottoms = (UInt32)item_meta.ItemId;
|
||||
clothInfo.ClothBottomsItemGuid = item_attribute.ItemGuid;
|
||||
break;
|
||||
|
||||
case ClothSlotType.Gloves:
|
||||
clothInfo.ClothGloves = (UInt32)item_meta.ItemId;
|
||||
clothInfo.ClothGlovesItemGuid = item_attribute.ItemGuid;
|
||||
break;
|
||||
|
||||
case ClothSlotType.Earrings:
|
||||
clothInfo.ClothEarrings = (UInt32)item_meta.ItemId;
|
||||
clothInfo.ClothEarringsItemGuid = item_attribute.ItemGuid;
|
||||
break;
|
||||
|
||||
case ClothSlotType.Neckless:
|
||||
clothInfo.ClothNeckless = (UInt32)item_meta.ItemId;
|
||||
clothInfo.ClothNecklessItemGuid = item_attribute.ItemGuid;
|
||||
break;
|
||||
|
||||
case ClothSlotType.Socks:
|
||||
clothInfo.ClothSocks = (UInt32)item_meta.ItemId;
|
||||
clothInfo.ClothSocksItemGuid = item_attribute.ItemGuid;
|
||||
break;
|
||||
|
||||
default:
|
||||
err_msg = $"Invalid ClothSlotType !!! : {clothSlotType} - {owner.toBasicString()}";
|
||||
result.setFail(ServerErrorCode.ClothSlotTypeInvalid, err_msg);
|
||||
Log.getLogger().warn(err_msg);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
}
|
||||
}
|
||||
33
GameServer/Contents/ItemCloth/Helper/ItemClothHelper.cs
Normal file
33
GameServer/Contents/ItemCloth/Helper/ItemClothHelper.cs
Normal file
@@ -0,0 +1,33 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
|
||||
|
||||
namespace GameServer
|
||||
{
|
||||
public static class ItemClothHelper
|
||||
{
|
||||
public static ClothInfoOfAnotherUser toClothInfoOfAnotherUser(this ClothInfo src)
|
||||
{
|
||||
var cloth_info_of_another_user = new ClothInfoOfAnotherUser();
|
||||
|
||||
cloth_info_of_another_user.ClothAvatar = src.ClothAvatar;
|
||||
cloth_info_of_another_user.ClothHeadwear = src.ClothHeadwear;
|
||||
cloth_info_of_another_user.ClothMask = src.ClothMask;
|
||||
cloth_info_of_another_user.ClothBag = src.ClothBag;
|
||||
cloth_info_of_another_user.ClothShoes = src.ClothShoes;
|
||||
cloth_info_of_another_user.ClothOuter = src.ClothOuter;
|
||||
cloth_info_of_another_user.ClothTops = src.ClothTops;
|
||||
cloth_info_of_another_user.ClothBottoms = src.ClothBottoms;
|
||||
cloth_info_of_another_user.ClothGloves = src.ClothGloves;
|
||||
cloth_info_of_another_user.ClothEarrings = src.ClothEarrings;
|
||||
cloth_info_of_another_user.ClothNeckless = src.ClothNeckless;
|
||||
cloth_info_of_another_user.ClothSocks = src.ClothSocks;
|
||||
|
||||
return cloth_info_of_another_user;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,114 @@
|
||||
using Google.Protobuf;
|
||||
using Google.Protobuf.WellKnownTypes;
|
||||
|
||||
|
||||
using ServerCore;
|
||||
using ServerBase;
|
||||
using ServerCommon;
|
||||
using ServerCommon.BusinessLogDomain;
|
||||
using MetaAssets;
|
||||
|
||||
|
||||
using static ClientToGameReq.Types;
|
||||
using static ClientToGameRes.Types;
|
||||
|
||||
|
||||
namespace GameServer.PacketHandler;
|
||||
|
||||
[PacketHandler(typeof(ClientToGameReq), typeof(ClothInfoSaveReq), typeof(ItemClothSavePacketHandler), typeof(GameLoginListener))]
|
||||
public class ItemClothSavePacketHandler : PacketRecvHandler
|
||||
{
|
||||
public static bool send_S2C_ACK_ITEM_CLOTH_SAVE(Player owner, Result result, ClothInfo? savedClothInfo)
|
||||
{
|
||||
var ack_packet = new ClientToGame();
|
||||
ack_packet.Response = new ClientToGameRes();
|
||||
|
||||
ack_packet.Response.ErrorCode = result.ErrorCode;
|
||||
ack_packet.Response.ClothInfoSaveRes = new ClothInfoSaveRes();
|
||||
|
||||
if (result.isSuccess())
|
||||
{
|
||||
ack_packet.Response.ClothInfoSaveRes.ClothInfo = savedClothInfo;
|
||||
}
|
||||
|
||||
if (false == GameServerApp.getServerLogic().onSendPacket(owner, ack_packet))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
public override async Task<Result> onProcessPacket(ISession entityWithSession, Google.Protobuf.IMessage recvMessage)
|
||||
{
|
||||
var result = new Result();
|
||||
var err_msg = string.Empty;
|
||||
|
||||
var entity_player = entityWithSession as Player;
|
||||
NullReferenceCheckHelper.throwIfNull(entity_player, () => "player is null !!!");
|
||||
|
||||
var recv_msg = recvMessage as ClientToGame;
|
||||
ArgumentNullReferenceCheckHelper.throwIfNull(recv_msg, () => $"recv_msg is null !!! - {entity_player.toBasicString()}");
|
||||
var request = recv_msg.Request.ClothInfoSaveReq;
|
||||
ArgumentNullReferenceCheckHelper.throwIfNull(request, () => $"recv_msg is null !!! - {entity_player.toBasicString()}");
|
||||
|
||||
var player_action = entity_player.getEntityAction<PlayerAction>();
|
||||
NullReferenceCheckHelper.throwIfNull(player_action, () => $"player action is null !!! - {entity_player.toBasicString()}");
|
||||
|
||||
var selected_character = player_action.getSelectedCharacter();
|
||||
if(null == selected_character)
|
||||
{
|
||||
err_msg = $"Not selected Character !!! - {entity_player.toBasicString()}";
|
||||
result.setFail(ServerErrorCode.CharacterNotSelected, err_msg);
|
||||
Log.getLogger().error(result.toBasicString());
|
||||
|
||||
send_S2C_ACK_ITEM_CLOTH_SAVE(entity_player, result, null);
|
||||
return result;
|
||||
}
|
||||
|
||||
var server_logic = GameServerApp.getServerLogic();
|
||||
|
||||
var fn_item_cloth_save = async delegate ()
|
||||
{
|
||||
var result = new Result();
|
||||
|
||||
var item_cloth_action = entity_player.getEntityAction<ItemClothAction>();
|
||||
NullReferenceCheckHelper.throwIfNull(item_cloth_action, () => $"item_cloth_action is null !!! - {entity_player.toBasicString()}");
|
||||
|
||||
await item_cloth_action.tryApplyClothsByClothInfo(request.ClothInfo);
|
||||
|
||||
var batch = new QueryBatchEx<QueryRunnerWithDocument>( entity_player, LogActionType.ItemUse
|
||||
, server_logic.getDynamoDbClient() );;
|
||||
{
|
||||
batch.addQuery(new DBQWriteToAttributeAllWithTransactionRunner());
|
||||
}
|
||||
|
||||
result = await QueryHelper.sendQueryAndBusinessLog(batch);
|
||||
if (result.isFail())
|
||||
{
|
||||
send_S2C_ACK_ITEM_CLOTH_SAVE(entity_player, result, null);
|
||||
return result;
|
||||
}
|
||||
|
||||
var inventory_action = entity_player.getEntityAction<InventoryActionBase>();
|
||||
NullReferenceCheckHelper.throwIfNull(inventory_action, () => $"inventory_action is null !!! - {entity_player.toBasicString()}");
|
||||
|
||||
send_S2C_ACK_ITEM_CLOTH_SAVE(entity_player, result, inventory_action.toClothInven4Client());
|
||||
|
||||
return result;
|
||||
};
|
||||
|
||||
result = await entity_player.runTransactionRunnerSafely(TransactionIdType.PrivateContents, "ItemClothSave", fn_item_cloth_save);
|
||||
if (result.isFail())
|
||||
{
|
||||
err_msg = $"Failed to runTransactionRunnerSafely() !!! : {result.toBasicString()} - {entity_player.toBasicString()}";
|
||||
Log.getLogger().error(err_msg);
|
||||
}
|
||||
|
||||
await QuestManager.It.QuestCheck(entity_player, new QuestCostume(EQuestEventTargetType.COSTUME, EQuestEventNameType.EQUIPED, request.ClothInfo));
|
||||
|
||||
|
||||
return result;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user