183 lines
7.5 KiB
C#
183 lines
7.5 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 META_ID = System.UInt32;
|
|
|
|
|
|
namespace GameServer
|
|
{
|
|
public class ToolAction : EntityBase
|
|
{
|
|
public ToolAction(EntityBase parent)
|
|
: base(EntityType.ToolAction, parent)
|
|
{
|
|
}
|
|
|
|
public override async Task<Result> onInit()
|
|
{
|
|
var direct_parent = getDirectParent();
|
|
NullReferenceCheckHelper.throwIfNull(direct_parent, () => $"direct_parent is null !!!");
|
|
|
|
addEntityAttribute(new ToolActionAttribute(this, direct_parent));
|
|
|
|
return await base.onInit();
|
|
}
|
|
|
|
public async Task<Result> tryUnactivateToolAction()
|
|
{
|
|
await Task.CompletedTask;
|
|
|
|
var direct_parent = getDirectParent();
|
|
NullReferenceCheckHelper.throwIfNull(direct_parent, () => $"direct_parent is null !!!");
|
|
var root_parent = getRootParent();
|
|
NullReferenceCheckHelper.throwIfNull(root_parent, () => $"root_parent is null !!!");
|
|
|
|
var result = new Result();
|
|
var err_msg = string.Empty;
|
|
|
|
var tool_action_attribute = getEntityAttribute<ToolActionAttribute>();
|
|
NullReferenceCheckHelper.throwIfNull(tool_action_attribute, () => $"tool_action_attribute is null !!! - {root_parent.toBasicString()}");
|
|
|
|
var item_tool_meta_id = tool_action_attribute.ItemMetaId;
|
|
if (0 != tool_action_attribute.ItemMetaId)
|
|
{
|
|
if (false == MetaData.Instance._ToolMetaTable.TryGetValue((Int32)item_tool_meta_id, out var old_tool_data))
|
|
{
|
|
err_msg = $"Not found Item Tool Meta !!! : itemToolMetaId:{item_tool_meta_id} - {root_parent.toBasicString()}";
|
|
result.setFail(ServerErrorCode.ItemToolMetaDataNotFound, err_msg);
|
|
Log.getLogger().error(result.toBasicString());
|
|
|
|
return result;
|
|
}
|
|
|
|
var old_buff_meta_id = old_tool_data.ActivateBuffID;
|
|
if (old_buff_meta_id != 0)
|
|
{
|
|
if (MetaData.Instance._BuffTable.TryGetValue(old_buff_meta_id, out var BuffData) == false)
|
|
{
|
|
err_msg = $"Not found Buff Meta !!! : BuffMetaId:{old_buff_meta_id} - {root_parent.toBasicString()}";
|
|
result.setFail(ServerErrorCode.NotFoundBuffTableId, err_msg);
|
|
Log.getLogger().error(result.toBasicString());
|
|
|
|
return result;
|
|
}
|
|
|
|
if (BuffData.DurationTime == 0)
|
|
{
|
|
var buff_action = root_parent.getEntityAction<BuffAction>();
|
|
NullReferenceCheckHelper.throwIfNull(buff_action, () => $"buff_action is null !!! - {root_parent.toBasicString()}");
|
|
|
|
(result, var buff_attribute) = buff_action.DelBuffProcess((META_ID)old_buff_meta_id);
|
|
if (result.isFail())
|
|
{
|
|
return result;
|
|
}
|
|
|
|
NullReferenceCheckHelper.throwIfNull(tool_action_attribute, () => $"tool_action_attribute is null !!! - {root_parent.toBasicString()}");
|
|
}
|
|
}
|
|
|
|
tool_action_attribute.deleteEntityAttribute();
|
|
}
|
|
|
|
return result;
|
|
}
|
|
|
|
public async Task<Result> tryAactivateToolAction(Item foundItemTool, Int16 itemToolSlotIndex)
|
|
{
|
|
await Task.CompletedTask;
|
|
|
|
var root_parent = getRootParent() as Player;
|
|
NullReferenceCheckHelper.throwIfNull(root_parent, () => $"root_parent is null !!!");
|
|
ArgumentNullReferenceCheckHelper.throwIfNull(foundItemTool, () => $"foundItemTool is null !!! - {root_parent.toBasicString()}");
|
|
|
|
var result = new Result();
|
|
var err_msg = string.Empty;
|
|
|
|
var new_item_tool_meta = foundItemTool.getItemMeta();
|
|
NullReferenceCheckHelper.throwIfNull(new_item_tool_meta, () => $"new_item_tool_meta is null !!! - {root_parent.toBasicString()}");
|
|
|
|
var new_item_tool_meta_id = new_item_tool_meta.ItemId;
|
|
if (false == MetaData.Instance._ToolMetaTable.TryGetValue(new_item_tool_meta_id, out var new_tool_data))
|
|
{
|
|
err_msg = $"Not found new Item Tool Meta !!! : itemToolMetaId:{new_item_tool_meta_id} - {root_parent.toBasicString()}";
|
|
result.setFail(ServerErrorCode.ItemToolMetaDataNotFound, err_msg);
|
|
Log.getLogger().error(result.toBasicString());
|
|
|
|
return result;
|
|
}
|
|
|
|
var new_buff_meta_id = new_tool_data.ActivateBuffID;
|
|
if (new_buff_meta_id == 0)
|
|
{
|
|
err_msg = $"ActivateBuffID 0 setup !!! : toolMetaId:{new_item_tool_meta_id} - {root_parent.toBasicString()}";
|
|
Log.getLogger().warn(err_msg);
|
|
}
|
|
else
|
|
{
|
|
var buff_action = root_parent.getEntityAction<BuffAction>();
|
|
NullReferenceCheckHelper.throwIfNull(buff_action, () => $"buff_action is null !!! - {root_parent.toBasicString()}");
|
|
|
|
(result, var add_buff_attribute, var del_buff_attribute) = buff_action.AddBuffProcess((META_ID)new_buff_meta_id);
|
|
if (result.isFail())
|
|
{
|
|
return result;
|
|
}
|
|
|
|
BuffNotifyHelper.send_S2C_NTF_DELETE_BUFF(root_parent, del_buff_attribute);
|
|
BuffNotifyHelper.send_S2C_NTF_START_BUFF(root_parent, add_buff_attribute);
|
|
}
|
|
|
|
var item_attribute = foundItemTool.getEntityAttribute<ItemAttributeBase>();
|
|
NullReferenceCheckHelper.throwIfNull(item_attribute, () => $"item_attribute is null !!! - {root_parent.toBasicString()}");
|
|
|
|
var tool_action_attribute = getEntityAttribute<ToolActionAttribute>();
|
|
NullReferenceCheckHelper.throwIfNull(tool_action_attribute, () => $"tool_action_attribute is null !!! - {root_parent.toBasicString()}");
|
|
|
|
tool_action_attribute.ItemGuid = item_attribute.ItemGuid;
|
|
tool_action_attribute.ItemMetaId = item_attribute.ItemMetaId;
|
|
tool_action_attribute.Step = 0;
|
|
tool_action_attribute.newEntityAttribute();
|
|
|
|
return result;
|
|
}
|
|
|
|
public bool isActivateToolAction(string itemGuid)
|
|
{
|
|
var root_parent = getRootParent();
|
|
NullReferenceCheckHelper.throwIfNull(root_parent, () => $"root_parent is null !!!");
|
|
|
|
var result = new Result();
|
|
var err_msg = string.Empty;
|
|
|
|
var tool_action_attribute = getEntityAttribute<ToolActionAttribute>();
|
|
NullReferenceCheckHelper.throwIfNull(tool_action_attribute, () => $"tool_action_attribute is null !!! - {root_parent.toBasicString()}");
|
|
|
|
if(tool_action_attribute.ItemGuid == itemGuid)
|
|
{
|
|
return true;
|
|
}
|
|
|
|
return false;
|
|
}
|
|
|
|
public override string toBasicString()
|
|
{
|
|
return $"{this.getTypeName()}, ItemGuid:{getOriginEntityAttribute<ToolActionAttribute>()?.ItemGuid}, ItemMetaId:{getOriginEntityAttribute<ToolActionAttribute>()?.ItemMetaId}";
|
|
}
|
|
|
|
public override string toSummaryString()
|
|
{
|
|
return $"{this.getTypeName()}, {getOriginEntityAttribute<ToolActionAttribute>()?.toSummaryString()}";
|
|
}
|
|
}
|
|
}
|