336 lines
13 KiB
C#
336 lines
13 KiB
C#
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
|
|
|
|
using ServerCore; using ServerBase;
|
|
using ServerCommon;
|
|
|
|
|
|
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 ItemTattooAction : EntityActionBase
|
|
{
|
|
public ItemTattooAction(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> tryRegisterItemTattoo(ITEM_GUID itemGuid, Int32 toEquipSlotIndex)
|
|
{
|
|
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()}");
|
|
|
|
(result, _) = await tryUnequipTattooByTattooSlotType((TattooSlotType)toEquipSlotIndex, false);
|
|
if(result.isFail())
|
|
{
|
|
return result;
|
|
}
|
|
|
|
var found_item = inventory_action.tryGetItemByItemGuid(itemGuid);
|
|
if(null == found_item)
|
|
{
|
|
err_msg = $"Failed to tryGetItemByItemGuid !!! : itemGuid:{itemGuid} : {owner.toBasicString()}";
|
|
result.setFail(ServerErrorCode.ItemNotFound, err_msg);
|
|
Log.getLogger().error(result.toBasicString());
|
|
|
|
return result;
|
|
}
|
|
|
|
result = await inventory_action.tryTakableToEquip(found_item, (Int16)toEquipSlotIndex);
|
|
if(result.isFail())
|
|
{
|
|
return result;
|
|
}
|
|
|
|
return result;
|
|
}
|
|
|
|
public async Task<(Result, Item?)> tryUnequipTattooByTattooSlotType( TattooSlotType tattooSlotType
|
|
, bool isFailOnItemNotFound = true )
|
|
{
|
|
var result = new Result();
|
|
var err_msg = string.Empty;
|
|
|
|
var owner = getOwner();
|
|
NullReferenceCheckHelper.throwIfNull(owner, () => $"owner is null !!!");
|
|
|
|
if (false == InvenEquipType.Tattoo.isEquipableTattooSlotType(tattooSlotType, owner.getEntityType()))
|
|
{
|
|
err_msg = $"Not found TattooSlotType !!! : slotType:{tattooSlotType} - {owner.toBasicString()}";
|
|
result.setFail(ServerErrorCode.TattooEquipRuleTattooSlotTypeNotFound, err_msg);
|
|
Log.getLogger().error(result.toBasicString());
|
|
|
|
return (result, 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<TattooSlotType>( InvenEquipType.Tattoo, tattooSlotType
|
|
, 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, updated_item);
|
|
}
|
|
|
|
public async Task<Result> tryUnregisterItemTattoo(Int16 toUnequipSlotIndex, ITEM_GUID itemGuid)
|
|
{
|
|
var owner = getOwner();
|
|
NullReferenceCheckHelper.throwIfNull(owner, () => $"owner is null !!!");
|
|
|
|
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 found_item = inventory_action.tryGetItemByItemGuid(itemGuid);
|
|
if(null == found_item)
|
|
{
|
|
err_msg = $"Failed to tryGetItemByItemGuid !!! : itemGuid:{itemGuid} : {owner.toBasicString()}";
|
|
result.setFail(ServerErrorCode.ItemNotFound, err_msg);
|
|
Log.getLogger().error(result.toBasicString());
|
|
|
|
return result;
|
|
}
|
|
|
|
var item_attribute = found_item.getEntityAttribute<ItemAttributeBase>();
|
|
NullReferenceCheckHelper.throwIfNull(item_attribute, () => $"item_attribute is null !!! - {owner.toBasicString()}");
|
|
|
|
if (item_attribute.EquipedPos != toUnequipSlotIndex)
|
|
{
|
|
err_msg = $"Not match ItemTattoo quiped slot pos !!! : currPos:{item_attribute.EquipedPos} == reqUnequipPos:{toUnequipSlotIndex}, {found_item.toBasicString()} : {owner.toBasicString()}";
|
|
result.setFail(ServerErrorCode.EquipSlotNotMatch, err_msg);
|
|
Log.getLogger().error(result.toBasicString());
|
|
|
|
return result;
|
|
}
|
|
|
|
(result, var updated_item) = await inventory_action.tryTakableOutFromEquip(found_item);
|
|
if(result.isFail())
|
|
{
|
|
return result;
|
|
}
|
|
|
|
return result;
|
|
}
|
|
|
|
public async Task<(Result, bool, List<Item>?)> tryLevelUpItemTattoo(ITEM_GUID itemGuid)
|
|
{
|
|
await Task.CompletedTask;
|
|
|
|
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 = $"Failed to tryGetItemByItemGuid !!! : itemGuid:{itemGuid} : {owner.toBasicString()}";
|
|
result.setFail(ServerErrorCode.ItemTattooNotFound, err_msg);
|
|
Log.getLogger().error(result.toBasicString());
|
|
|
|
return (result, false, null);
|
|
}
|
|
|
|
var item_action = found_item.getEntityAction<ItemAction>();
|
|
NullReferenceCheckHelper.throwIfNull(item_action, () => $"item_action is null !!! - {owner.toBasicString()}");
|
|
|
|
(result, var is_level_up, var updated_items) = await item_action.tryLevelUpByTattoo();
|
|
if (result.isFail())
|
|
{
|
|
return (result, false, null);
|
|
}
|
|
|
|
return (result, is_level_up, updated_items);
|
|
}
|
|
|
|
public async Task<(Result, List<Item>?)> tryChangeAttriubte(ITEM_GUID itemGuid, Int16 targetAttributeId)
|
|
{
|
|
await Task.CompletedTask;
|
|
|
|
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 = $"Failed to tryGetItemByItemGuid !!! : itemGuid:{itemGuid} : {owner.toBasicString()}";
|
|
result.setFail(ServerErrorCode.ItemTattooNotFound, err_msg);
|
|
Log.getLogger().error(result.toBasicString());
|
|
|
|
return (result, null);
|
|
}
|
|
|
|
var item_action = found_item.getEntityAction<ItemAction>();
|
|
NullReferenceCheckHelper.throwIfNull(item_action, () => $"item_action is null !!! - {owner.toBasicString()}");
|
|
|
|
var item_attribute = found_item.getEntityAttribute<ItemAttributeBase>();
|
|
NullReferenceCheckHelper.throwIfNull(item_attribute, () => $"item_attribute is null !!! - {owner.toBasicString()}");
|
|
|
|
if(targetAttributeId < 0 || item_attribute.Attributes.Count <= targetAttributeId)
|
|
{
|
|
err_msg = $"Invalid ItemAttributeIdType : 0 <= targetAttributeId:{targetAttributeId} < {item_attribute.Attributes.Count} , {found_item.toBasicString()} : {owner.toBasicString()}";
|
|
result.setFail(ServerErrorCode.ItemAttributeIdTypeInvalid, err_msg);
|
|
Log.getLogger().error(result.toBasicString());
|
|
|
|
return (result, null);
|
|
}
|
|
|
|
(result, var updated_items) = await item_action.tryChangeAttributeByTattoo(targetAttributeId);
|
|
if (result.isFail())
|
|
{
|
|
return (result, null);
|
|
}
|
|
|
|
return (result, updated_items);
|
|
}
|
|
|
|
public async Task<Result> trySaveVisibleTattooSlot(Int16 slotIndex, bool isVisible)
|
|
{
|
|
await Task.CompletedTask;
|
|
|
|
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()}");
|
|
|
|
if(false == InvenEquipType.Tattoo.isEquipableTattooSlotType((TattooSlotType)slotIndex, owner.getEntityType()))
|
|
{
|
|
err_msg = $"Not found TattooSlotType !!! : slotType:{slotIndex} - {owner.toBasicString()}";
|
|
result.setFail(ServerErrorCode.TattooEquipRuleTattooSlotTypeNotFound, err_msg);
|
|
Log.getLogger().error(result.toBasicString());
|
|
|
|
return result;
|
|
}
|
|
|
|
var custom_defined_ui_action = owner.getEntityAction<CustomDefinedUiAction>();
|
|
NullReferenceCheckHelper.throwIfNull(custom_defined_ui_action, () => $"custom_defined_ui_action is null !!! - {owner.toBasicString()}");
|
|
|
|
var tattoo_slot = (TattooSlotType)slotIndex;
|
|
result = await custom_defined_ui_action.setTattooVisible(tattoo_slot, isVisible);
|
|
if(result.isFail())
|
|
{
|
|
return result;
|
|
}
|
|
|
|
return result;
|
|
}
|
|
|
|
public void fillupTattooSlotInfo(TattooSlotType slotType, Item tattooItem, ref TattooSlotInfo slotInfo)
|
|
{
|
|
var owner = getOwner();
|
|
NullReferenceCheckHelper.throwIfNull(owner, () => $"owner is null !!!");
|
|
|
|
var item_attribute = tattooItem.getOriginEntityAttribute<ItemAttributeBase>();
|
|
NullReferenceCheckHelper.throwIfNull(item_attribute, () => $"item_attribute is null !!! - {owner.toBasicString()}");
|
|
|
|
slotInfo.ItemInfo.ItemId = (Int32)(item_attribute.ItemMetaId);
|
|
slotInfo.ItemInfo.Level = item_attribute.Level;
|
|
slotInfo.ItemInfo.Attributeids.AddRange(item_attribute.Attributes.ConvertAll(x => x.castTo<Int32>()));
|
|
}
|
|
|
|
public Result send_S2C_NTF_ITEM_TATTOOS()
|
|
{
|
|
var owner = getOwner();
|
|
NullReferenceCheckHelper.throwIfNull(owner, () => $"owner is null !!!");
|
|
var parent = owner.getRootParent() as Player;
|
|
NullReferenceCheckHelper.throwIfNull(parent, () => $"parent is null !!! - {owner.toBasicString()}");
|
|
|
|
var result = new Result();
|
|
var err_msg = string.Empty;
|
|
|
|
var game_zone_action = owner.getEntityAction<GameZoneAction>();
|
|
NullReferenceCheckHelper.throwIfNull(game_zone_action, () => $"game_zone_action is null !!! - {owner.toBasicString()}");
|
|
|
|
var curr_join_map = game_zone_action.getLinkedToMap();
|
|
if (null == curr_join_map)
|
|
{
|
|
err_msg = $"Not in GameZone !!! : {owner.toBasicString()}";
|
|
result.setFail(ServerErrorCode.GameZoneNotJoin, err_msg);
|
|
Log.getLogger().error(result.toBasicString());
|
|
|
|
return result;
|
|
}
|
|
|
|
ClientToGame clientToGameNoti = new();
|
|
clientToGameNoti.Message = new();
|
|
clientToGameNoti.Message.ChangeTattooNoti = new();
|
|
|
|
var inventory_action = owner.getEntityAction<InventoryActionBase>();
|
|
NullReferenceCheckHelper.throwIfNull(inventory_action, () => $"inventory_action is null !!! - {owner.toBasicString()}");
|
|
|
|
clientToGameNoti.Message.ChangeTattooNoti.AccountGuid = owner.onGetGuidOfOwnerEntityType();
|
|
clientToGameNoti.Message.ChangeTattooNoti.TattooInfoList.AddRange(inventory_action.toTattooInven4Client());
|
|
|
|
curr_join_map.Broadcast(parent, clientToGameNoti);
|
|
|
|
return result;
|
|
}
|
|
}
|
|
}
|