517 lines
21 KiB
C#
517 lines
21 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
|
|
|
|
using Nettention.Proud;
|
|
|
|
|
|
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 ItemToolAction : EntityActionBase
|
|
{
|
|
private ToolAction? m_curr_tool_action_nullable = null;
|
|
|
|
public ItemToolAction(Player 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> tryLoadToolActionFromDoc(ToolActionDoc doc)
|
|
{
|
|
await Task.CompletedTask;
|
|
|
|
var result = new Result();
|
|
var err_msg = string.Empty;
|
|
|
|
var owner = getOwner() as Player;
|
|
NullReferenceCheckHelper.throwIfNull(owner, () => $"owner is null !!!");
|
|
ArgumentNullReferenceCheckHelper.throwIfNull(doc, () => $"m_new_tool_action_nullable is null !!! - {owner.toBasicString()}");
|
|
|
|
var tool_action = new ToolAction(owner);
|
|
result = await tool_action.onInit();
|
|
if(result.isFail())
|
|
{
|
|
return result;
|
|
}
|
|
|
|
var tool_action_attribute = tool_action.getEntityAttribute<ToolActionAttribute>();
|
|
NullReferenceCheckHelper.throwIfNull(tool_action_attribute, () => $"tool_action_attribute is null !!! - {owner.toBasicString()}");
|
|
|
|
var is_success = tool_action_attribute.copyEntityAttributeFromDoc(doc);
|
|
if(false == is_success)
|
|
{
|
|
err_msg = $"Failed to copyEntityAttributeFromDoc() !!!, to:{typeof(ToolActionAttribute).Name}, from:{doc.getTypeName()}";
|
|
result.setFail(ServerErrorCode.DynamoDbDocCopyToEntityAttributeFailed, err_msg);
|
|
Log.getLogger().error(result.toBasicString());
|
|
|
|
return result;
|
|
}
|
|
|
|
m_curr_tool_action_nullable = tool_action;
|
|
|
|
return result;
|
|
}
|
|
|
|
public void applyNewOrCurrToolAction(ToolAction toolAction)
|
|
{
|
|
var owner = getOwner() as Player;
|
|
NullReferenceCheckHelper.throwIfNull(owner, () => $"owner is null !!!");
|
|
|
|
m_curr_tool_action_nullable = toolAction;
|
|
}
|
|
|
|
public void applyCloseToolAction()
|
|
{
|
|
m_curr_tool_action_nullable = null;
|
|
}
|
|
|
|
public async Task<Result> tryRegisterItemTool(ITEM_GUID itemGuid, Int32 toEquipSlotIndex)
|
|
{
|
|
var result = new Result();
|
|
var err_msg = string.Empty;
|
|
|
|
var owner = getOwner() as Player;
|
|
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.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> tryUnregisterItemTool(Int16 toUnequipSlotIndex, ITEM_GUID itemGuid)
|
|
{
|
|
var result = new Result();
|
|
var err_msg = string.Empty;
|
|
|
|
var owner = getOwner() as Player;
|
|
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.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 ItemTool 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;
|
|
}
|
|
|
|
if( null != m_curr_tool_action_nullable
|
|
&& true == m_curr_tool_action_nullable.isActivateToolAction(itemGuid) )
|
|
{
|
|
result = await m_curr_tool_action_nullable.tryUnactivateToolAction();
|
|
if (result.isFail())
|
|
{
|
|
return result;
|
|
}
|
|
|
|
m_curr_tool_action_nullable = null;
|
|
}
|
|
|
|
return result;
|
|
}
|
|
|
|
public async Task<(Result, ToolAction?, Item?)> tryActivateItemTool(Int16 itemToolSlotIndex)
|
|
{
|
|
await Task.CompletedTask;
|
|
|
|
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()}");
|
|
|
|
inventory_action.getEquipInvens().TryGetValue(InvenEquipType.Tool, out var found_equip_inven);
|
|
NullReferenceCheckHelper.throwIfNull(found_equip_inven, () => $"found_equip_inven is null !!! - {owner.toBasicString()}");
|
|
|
|
var tool_inven = found_equip_inven as ToolEquipInven;
|
|
NullReferenceCheckHelper.throwIfNull(tool_inven, () => $"tool_inven is null !!! - {owner.toBasicString()}");
|
|
|
|
var tool_inven_data = tool_inven.getData();
|
|
NullReferenceCheckHelper.throwIfNull(tool_inven_data, () => $"tool_inven_data is null !!! - {owner.toBasicString()}");
|
|
|
|
var tool_slot_type = (ToolSlotType)itemToolSlotIndex;
|
|
var found_item_tool = tool_inven_data.onFindEntityBase(tool_slot_type) as Item;
|
|
if (null == found_item_tool)
|
|
{
|
|
err_msg = $"Not found Item Tool !!! : ToolSlotType:{tool_slot_type} - {owner.toBasicString()}";
|
|
result.setFail(ServerErrorCode.ItemToolNotFound, err_msg);
|
|
Log.getLogger().error(result.toBasicString());
|
|
|
|
return (result, null, null);
|
|
}
|
|
|
|
if(null != m_curr_tool_action_nullable)
|
|
{
|
|
var item_attribute = found_item_tool.getOriginEntityAttribute<ItemAttributeBase>();
|
|
NullReferenceCheckHelper.throwIfNull(item_attribute, () => $"item_attribute is null !!! - {owner.toBasicString()}");
|
|
|
|
// 동일한 도구가 활성화 상태인 경우
|
|
if (true == m_curr_tool_action_nullable.isActivateToolAction(item_attribute.ItemGuid))
|
|
{
|
|
err_msg = $"Already activated ToolAction of Item !!! : ToolSlotType:{tool_slot_type}, ItemGuid:{item_attribute.ItemGuid} - {owner.toBasicString()}";
|
|
result.setFail(ServerErrorCode.ToolActionAlreadyActivateState, err_msg);
|
|
Log.getLogger().error(result.toBasicString());
|
|
|
|
return (result, null, null);
|
|
}
|
|
// 동일한 도구가 아닌 경우
|
|
else
|
|
{
|
|
result = await m_curr_tool_action_nullable.tryUnactivateToolAction();
|
|
if (result.isFail())
|
|
{
|
|
return (result, null, null);
|
|
}
|
|
}
|
|
}
|
|
|
|
var new_tool_action_nullable = new ToolAction(owner);
|
|
result = await new_tool_action_nullable.onInit();
|
|
if (result.isFail())
|
|
{
|
|
return (result, null, null);
|
|
}
|
|
|
|
result = await new_tool_action_nullable.tryAactivateToolAction(found_item_tool, itemToolSlotIndex);
|
|
if (result.isFail())
|
|
{
|
|
return (result, null, null);
|
|
}
|
|
|
|
return (result, new_tool_action_nullable, found_item_tool);
|
|
}
|
|
|
|
public Result send_NTF_ITEM_TOOL_ACTIVITY(Item activatedItemTool)
|
|
{
|
|
var owner = getOwner() as Player;
|
|
NullReferenceCheckHelper.throwIfNull(owner, () => $"owner is null !!!");
|
|
ArgumentNullReferenceCheckHelper.throwIfNull(activatedItemTool, () => $"activatedItemTool is null !!! - {owner.toBasicString()}");
|
|
|
|
var result = new Result();
|
|
var err_msg = string.Empty;
|
|
|
|
var item_meta = activatedItemTool.getItemMeta();
|
|
NullReferenceCheckHelper.throwIfNull(item_meta, () => $"item_meta is null !!! - {owner.toBasicString()}");
|
|
|
|
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.ActivateToolItemNoti = new();
|
|
clientToGameNoti.Message.ActivateToolItemNoti.ActorGuid = owner.getUserGuid();
|
|
clientToGameNoti.Message.ActivateToolItemNoti.ToolItemId = item_meta.ItemId;
|
|
|
|
curr_join_map.Broadcast(owner, clientToGameNoti);
|
|
|
|
return result;
|
|
}
|
|
|
|
public async Task<Result> tryUnactivateItemTool()
|
|
{
|
|
await Task.CompletedTask;
|
|
|
|
var owner = getOwner() as Player;
|
|
NullReferenceCheckHelper.throwIfNull(owner, () => $"owner is null !!!");
|
|
|
|
var result = new Result();
|
|
var err_msg = string.Empty;
|
|
|
|
if(null == m_curr_tool_action_nullable)
|
|
{
|
|
err_msg = $"Already unactivated ToolAction !!!, m_curr_tool_action_nullable is null - {owner.toBasicString()}";
|
|
result.setFail(ServerErrorCode.ToolActionAlreadyUnactivateState, err_msg);
|
|
Log.getLogger().error(result.toBasicString());
|
|
|
|
return result;
|
|
}
|
|
|
|
var tool_action_attribute = m_curr_tool_action_nullable.getEntityAttribute<ToolActionAttribute>();
|
|
NullReferenceCheckHelper.throwIfNull(tool_action_attribute, () => $"tool_action_attribute is null !!! - {owner.toBasicString()}");
|
|
|
|
var item_tool_meta_id = tool_action_attribute.ItemMetaId;
|
|
if(0 == item_tool_meta_id)
|
|
{
|
|
err_msg = $"Item Tool not activate state !!! : itemToolMetaId:{item_tool_meta_id} - {owner.toBasicString()}";
|
|
result.setFail(ServerErrorCode.ItemToolNotActivateState, err_msg);
|
|
Log.getLogger().error(result.toBasicString());
|
|
|
|
return result;
|
|
}
|
|
|
|
if (false == MetaData.Instance._ToolMetaTable.TryGetValue((Int32)item_tool_meta_id, out var curr_tool_data))
|
|
{
|
|
err_msg = $"Not found Item Tool Meta !!! : itemToolMetaId:{item_tool_meta_id} - {owner.toBasicString()}";
|
|
result.setFail(ServerErrorCode.ItemToolMetaDataNotFound, err_msg);
|
|
Log.getLogger().error(result.toBasicString());
|
|
|
|
return result;
|
|
}
|
|
|
|
return await m_curr_tool_action_nullable.tryUnactivateToolAction();
|
|
}
|
|
|
|
public Result send_NTF_ITEM_TOOL_UNACTIVITY()
|
|
{
|
|
var owner = getOwner() as Player;
|
|
NullReferenceCheckHelper.throwIfNull(owner, () => $"owner is null !!!");
|
|
|
|
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.DeactivateToolItemNoti = new();
|
|
clientToGameNoti.Message.DeactivateToolItemNoti.ActorGuid = owner.getUserGuid();
|
|
|
|
curr_join_map.Broadcast(owner, clientToGameNoti);
|
|
|
|
return result;
|
|
}
|
|
|
|
public async Task<Result> tryUseItemTool(Int32 equipedToolItemStep, Int32 equipedToolItemRandomState, Int64 actionStartTime)
|
|
{
|
|
await Task.CompletedTask;
|
|
|
|
var owner = getOwner() as Player;
|
|
NullReferenceCheckHelper.throwIfNull(owner, () => $"owner is null !!!");
|
|
|
|
var result = new Result();
|
|
var err_msg = string.Empty;
|
|
|
|
if (null == m_curr_tool_action_nullable)
|
|
{
|
|
err_msg = $"Already unactivated ToolAction !!!, m_curr_tool_action_nullable is null - {owner.toBasicString()}";
|
|
result.setFail(ServerErrorCode.ToolActionAlreadyUnactivateState, err_msg);
|
|
Log.getLogger().error(result.toBasicString());
|
|
|
|
return result;
|
|
}
|
|
|
|
var tool_action_attribute = m_curr_tool_action_nullable.getEntityAttribute<ToolActionAttribute>();
|
|
NullReferenceCheckHelper.throwIfNull(tool_action_attribute, () => $"tool_action_attribute is null !!! - {owner.toBasicString()}");
|
|
|
|
var item_tool_meta_id = tool_action_attribute.ItemMetaId;
|
|
if(0 == item_tool_meta_id)
|
|
{
|
|
err_msg = $"Item Tool not activate state !!! : itemToolMetaId:{item_tool_meta_id} - {owner.toBasicString()}";
|
|
result.setFail(ServerErrorCode.ItemToolNotActivateState, err_msg);
|
|
Log.getLogger().error(result.toBasicString());
|
|
|
|
return result;
|
|
}
|
|
|
|
if (false == MetaData.Instance._ToolMetaTable.TryGetValue((Int32)item_tool_meta_id, out var curr_tool_data))
|
|
{
|
|
err_msg = $"Not found Item Tool Meta !!! : itemToolMetaId:{item_tool_meta_id} - {owner.toBasicString()}";
|
|
result.setFail(ServerErrorCode.ItemToolMetaDataNotFound, err_msg);
|
|
Log.getLogger().error(result.toBasicString());
|
|
|
|
return result;
|
|
}
|
|
|
|
var action_buff_meta_id = curr_tool_data.ActionBuffID;
|
|
if (action_buff_meta_id != 0)
|
|
{
|
|
var buff_action = owner.getEntityAction<BuffAction>();
|
|
NullReferenceCheckHelper.throwIfNull(buff_action, () => $"buff_action is null !!! - {owner.toBasicString()}");
|
|
|
|
(result, var add_buff_attribute, var del_buff_attribute) = buff_action.AddBuffProcess((META_ID)action_buff_meta_id);
|
|
if (result.isFail())
|
|
{
|
|
return result;
|
|
}
|
|
|
|
BuffNotifyHelper.send_S2C_NTF_DELETE_BUFF(owner, del_buff_attribute);
|
|
BuffNotifyHelper.send_S2C_NTF_START_BUFF(owner, add_buff_attribute);
|
|
}
|
|
|
|
tool_action_attribute.Step = equipedToolItemStep;
|
|
tool_action_attribute.RandomState = equipedToolItemRandomState;
|
|
tool_action_attribute.ActionStartDateTime = actionStartTime;
|
|
|
|
tool_action_attribute.modifiedEntityAttribute();
|
|
|
|
return result;
|
|
}
|
|
|
|
public Result send_S2C_NTF_ITEM_TOOL_USE()
|
|
{
|
|
var owner = getOwner() as Player;
|
|
NullReferenceCheckHelper.throwIfNull(owner, () => $"owner is null !!!");
|
|
|
|
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;
|
|
}
|
|
|
|
if (null == m_curr_tool_action_nullable)
|
|
{
|
|
err_msg = $"Already unactivated ToolAction !!!, m_curr_tool_action_nullable is null - {owner.toBasicString()}";
|
|
result.setFail(ServerErrorCode.ToolActionAlreadyUnactivateState, err_msg);
|
|
Log.getLogger().error(result.toBasicString());
|
|
|
|
return result;
|
|
}
|
|
|
|
var tool_action_attribute = m_curr_tool_action_nullable.getOriginEntityAttribute<ToolActionAttribute>();
|
|
NullReferenceCheckHelper.throwIfNull(tool_action_attribute, () => $"tool_action_attribute is null !!! - {owner.toBasicString()}");
|
|
|
|
ClientToGame clientToGameNoti = new();
|
|
clientToGameNoti.Message = new();
|
|
clientToGameNoti.Message.UseToolItemNoti = new();
|
|
|
|
clientToGameNoti.Message.UseToolItemNoti.ActorGuid = owner.getUserGuid();
|
|
clientToGameNoti.Message.UseToolItemNoti.ToolItemId = (Int32)tool_action_attribute.ItemMetaId;
|
|
clientToGameNoti.Message.UseToolItemNoti.ToolItemStep = tool_action_attribute.Step;
|
|
clientToGameNoti.Message.UseToolItemNoti.ToolItemRandomState = tool_action_attribute.RandomState;
|
|
clientToGameNoti.Message.UseToolItemNoti.ActionStartTime = tool_action_attribute.ActionStartDateTime;
|
|
|
|
curr_join_map.Broadcast(owner, clientToGameNoti);
|
|
|
|
return result;
|
|
}
|
|
|
|
public EquipInfo toToolAction4Client()
|
|
{
|
|
var owner = getOwner() as Player;
|
|
NullReferenceCheckHelper.throwIfNull(owner, () => $"owner is null !!!");
|
|
|
|
var equip_info = new EquipInfo();
|
|
|
|
if(null != m_curr_tool_action_nullable)
|
|
{
|
|
var tool_action_attribute = m_curr_tool_action_nullable.getEntityAttribute<ToolActionAttribute>();
|
|
NullReferenceCheckHelper.throwIfNull(tool_action_attribute, () => $"tool_action_attribute is null !!! - {owner.toBasicString()}");
|
|
|
|
equip_info.ToolItemGuid = tool_action_attribute.ItemGuid;
|
|
equip_info.ToolItemId = (int)tool_action_attribute.ItemMetaId;
|
|
equip_info.ToolItemStep = tool_action_attribute.Step;
|
|
equip_info.ToolItemRandomState = tool_action_attribute.RandomState;
|
|
equip_info.ActionStartTime = tool_action_attribute.ActionStartDateTime;
|
|
}
|
|
|
|
return equip_info;
|
|
}
|
|
|
|
public int getCurrentToolItemMetaId()
|
|
{
|
|
if (m_curr_tool_action_nullable == null)
|
|
return 0;
|
|
|
|
var tool_action_attribute = m_curr_tool_action_nullable.getEntityAttribute<ToolActionAttribute>();
|
|
NullReferenceCheckHelper.throwIfNull(tool_action_attribute, () => $"tool_action_attribute is null !!! - {getOwner().toBasicString()}");
|
|
|
|
return (int)tool_action_attribute.ItemMetaId;
|
|
}
|
|
}
|
|
} |