zxl
/
CTT
forked from Cal/CTT
1
0
Fork 0
CTT/Server/Hotfix/Game/Handler/UI/Bag/C2M_DropItemHandler.cs

62 lines
2.3 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

using System;
namespace ET
{
[ActorMessageHandler]
public class C2M_DropItemHandler : AMActorLocationRpcHandler<Unit, C2M_DropItem, M2C_DropItem>
{
protected override async ETTask Run(Unit unit, C2M_DropItem request, M2C_DropItem response, Action reply)
{
if (unit.teamState == TeamState.Fight)
{
response.Message = "战斗中...";
reply();
return;
}
UserSetting setting = unit.GetComponent<UserSetting>();
if (setting == null)
{
Log.Error("setting == null");
response.Message = "系统错误";
reply();
return;
}
int slotIndex = request.SlotId;
int bagIndex = request.BagIndex;
if (!(setting.GetMainUISlot(slotIndex) is MainUISlot mainUISlot))
{
mainUISlot = EntityFactory.CreateWithParent<MainUISlot>(setting);
setting.UpdateMainUISlot(slotIndex, mainUISlot);
}
if (bagIndex == -1)
{
mainUISlot.MainUIType = MainUIType.NoneSlot;
MainUIHelper.GetMainUISlotInfo(setting, response.MainUISlotList);
reply();
return;
}
Bag bag = unit.GetComponent<Bag>();
if (!bag.ItemDic.TryGetValueByKey1(bagIndex, out Item item))
{
Log.Error($"玩家Id={unit.Id}想要获取Index={bagIndex}的背包信息,存在错误");
response.Message = "系统错误!";
reply();
return;
}
if (item.ItemType != ItemType.GoodsItem)
{
Log.Error($"玩家Id={unit.Id}想要将Index={bagIndex}的背包物品ItemId = {item.ItemId}类型={item.ItemType}拖入主UI存在错误");
response.Message = "系统错误!";
reply();
return;
}
mainUISlot.RealId = item.ItemId;
//mainUISlot.BagIndex = bagIndex;
mainUISlot.Count = item.Count;
mainUISlot.MainUIType = MainUIType.ItemSlot;
MainUIHelper.GetMainUISlotInfo(setting, response.MainUISlotList);
reply();
await ETTask.CompletedTask;
}
}
}