113 lines
2.9 KiB
C#
113 lines
2.9 KiB
C#
using System;
|
||
using System.Collections.Generic;
|
||
|
||
namespace ET
|
||
{
|
||
public class StarSoulBagAwakeSystem: AwakeSystem<StarSoulBag>
|
||
{
|
||
public override void Awake(StarSoulBag self)
|
||
{
|
||
self.InitData();
|
||
}
|
||
}
|
||
|
||
public class StarSoulBagDeserializeSystem: DeserializeSystem<StarSoulBag>
|
||
{
|
||
public override void Deserialize(StarSoulBag self)
|
||
{
|
||
}
|
||
}
|
||
|
||
public class StarSoulBagDestroySystem: DestroySystem<StarSoulBag>
|
||
{
|
||
public override void Destroy(StarSoulBag self)
|
||
{
|
||
self.ItemCount = 0;
|
||
self.itemDic.Clear();
|
||
}
|
||
}
|
||
|
||
public static class StarSoulBagSystem
|
||
{
|
||
public static void InitData(this StarSoulBag self)
|
||
{
|
||
#if UNITY
|
||
GetDataFromServer(self);
|
||
|
||
#endif
|
||
}
|
||
|
||
public static bool CanAdd(this StarSoulBag self)
|
||
{
|
||
return self.ItemCount < StarSoulBag.MaxCount;
|
||
}
|
||
|
||
public static string Add(this StarSoulBag self, StarSoulItem item)
|
||
{
|
||
if (!self.CanAdd()) return "星魂背包已满";
|
||
if (!self.itemDic.TryAdd(item.Id, item))
|
||
{
|
||
Log.Error($"{self.Id.GetPlayerFormatName()} serverId 重复 :{item.Id}");
|
||
return "系统错误";
|
||
}
|
||
|
||
self.ItemCount++;
|
||
self.Sync(item.Id, item);
|
||
return null;
|
||
}
|
||
|
||
public static bool Remove(this StarSoulBag self, long Id)
|
||
{
|
||
if (!self.itemDic.Remove(Id))
|
||
{
|
||
return false;
|
||
}
|
||
|
||
self.ItemCount--;
|
||
self.Sync(Id, null);
|
||
return true;
|
||
}
|
||
|
||
public static StarSoulItem Get(this StarSoulBag self, long Id)
|
||
{
|
||
if (!self.itemDic.TryGetValue(Id, out var itemBase))
|
||
{
|
||
return null;
|
||
}
|
||
|
||
return itemBase;
|
||
}
|
||
|
||
private static void Sync(this StarSoulBag self, long Id, StarSoulItem item)
|
||
{
|
||
M2C_SyncStarSoulBag proto = new();
|
||
StarSoulNetItem netItem = new StarSoulNetItem();
|
||
if (item == null)
|
||
{
|
||
netItem.Id = 0;
|
||
}
|
||
|
||
netItem.Id = item.Id;
|
||
netItem.level = item.level;
|
||
netItem.exp = item.exp;
|
||
netItem.quality = (int) item.quality;
|
||
netItem.posType = (int) item.posType;
|
||
netItem.typeId = item.typeId;
|
||
netItem.isUsed = item.isUsed;
|
||
netItem.main = item.mainId;
|
||
foreach (int id in item.viceIds)
|
||
{
|
||
netItem.vice.Add(id);
|
||
}
|
||
|
||
foreach (float id in item.viceAdd)
|
||
{
|
||
netItem.viceAdd.Add(id);
|
||
}
|
||
|
||
proto.Id = Id;
|
||
proto.item = netItem;
|
||
MessageHelper.SendActor(self.GetParent<Unit>(), proto);
|
||
}
|
||
}
|
||
} |