83 lines
3.0 KiB
C#
83 lines
3.0 KiB
C#
using System;
|
||
|
||
namespace ET
|
||
{
|
||
[ActorMessageHandler]
|
||
public class C2M_UseMainUIGoodsHandler : AMActorLocationRpcHandler<Unit, C2M_UseMainUIGoods, M2C_UseMainUIGoods>
|
||
{
|
||
protected override async ETTask Run(Unit unit, C2M_UseMainUIGoods request, M2C_UseMainUIGoods response, Action reply)
|
||
{
|
||
if (!unit.IsAlive)
|
||
{
|
||
response.Message = "您已经死亡!";
|
||
reply();
|
||
return;
|
||
}
|
||
UserSetting userSetting = unit.GetComponent<UserSetting>();
|
||
if (userSetting == null)
|
||
{
|
||
Log.Error("userSetting == null");
|
||
reply();
|
||
return;
|
||
}
|
||
if (!userSetting.canUse)
|
||
{
|
||
response.Message = "公共冷却中!";
|
||
reply();
|
||
return;
|
||
}
|
||
MainUISlot[] arr = userSetting.GetMainUISlots();
|
||
if (request.SlotId < 0 || request.SlotId >= arr.Length)
|
||
{
|
||
Log.Error(new Exception($"*************************************" +
|
||
$"[等级1]:" +
|
||
$" 格子index错误,作弊嫌疑!\n" +
|
||
$" 【玩家unitId = {unit.Id}】,\n" +
|
||
$"*************************************"));
|
||
response.Message = "请求信息错误,请注意您的行为!";
|
||
reply();
|
||
return;
|
||
}
|
||
MainUISlot mainUISlot = arr[request.SlotId];
|
||
if (mainUISlot == null)
|
||
{
|
||
response.Message = "点击了空格子,请拖入技能或者物品!";
|
||
reply();
|
||
return;
|
||
}
|
||
int itemId = mainUISlot.RealId;
|
||
if (itemId == 0)
|
||
{
|
||
response.Message = "点击了空格子,请拖入技能或者物品!";
|
||
reply();
|
||
return;
|
||
}
|
||
|
||
string ret = (await ItemComponent.Instance.UseGoods(unit, itemId: itemId)).Item1;
|
||
if (ret==null)
|
||
{
|
||
foreach (MainUISlot __mainUISlot in userSetting.GetMainUISlots())
|
||
{
|
||
if (__mainUISlot?.RealId == itemId)
|
||
{
|
||
__mainUISlot.Count--;
|
||
if (__mainUISlot.Count <= 0)
|
||
{
|
||
__mainUISlot.RealId = 0;
|
||
__mainUISlot.MainUIType = MainUIType.NoneSlot;
|
||
}
|
||
}
|
||
}
|
||
BagHelper.GetBagInfo(unit, response.BagMapList);
|
||
MainUIHelper.GetMainUISlotInfo(userSetting, response.MainUISlotList);
|
||
userSetting.StartCD(MainUIType.ItemSlot, itemId, Bag.UseTimeInterval);
|
||
}
|
||
else
|
||
{
|
||
response.Message = ret;
|
||
}
|
||
reply();
|
||
await ETTask.CompletedTask;
|
||
}
|
||
}
|
||
} |