CTT/Server/Hotfix/Game/System/Bag/ServerItemLimitComponentSys...

100 lines
3.0 KiB
C#

using Cal.DataTable;
using ET.EventType;
namespace ET
{
class ServerItemLimitComponentUpdatePerDay: AEvent<ET.EventType.UpdatePer1DayOfMonth>
{
public override async ETTask Run(UpdatePer1DayOfMonth args)
{
int zone = args.zone;
var now = args.now;
var domain = args.domain;
ServerItemLimitComponent serverItemLimitComponent = domain.GetComponent<ServerItemLimitComponent>();
serverItemLimitComponent.Refresh();
await ETTask.CompletedTask;
}
}
class ServerItemLimitComponentAwakeSystem: AwakeSystem<ServerItemLimitComponent>
{
public override void Awake(ServerItemLimitComponent self)
{
self.Id = 0;
self.Awake().Coroutine();
}
}
class ServerItemLimitComponentStartSystem: StartSystem<ServerItemLimitComponent>
{
public override void Start(ServerItemLimitComponent self)
{
self.AddComponent<FixedTimeSaveComponent>().Init(2 * 60 * 1000, self.Save);
}
}
class ServerItemLimitComponentLoadSystem: LoadSystem<ServerItemLimitComponent>
{
public override void Load(ServerItemLimitComponent self)
{
self.Load();
}
}
public static class ServerItemLimitComponentSystem
{
public static async ETVoid Awake(this ServerItemLimitComponent self)
{
using ServerItemLimitComponent serverItemLimitComponent = await UnitHelper.Query<ServerItemLimitComponent>(self.DomainZone(), 0);
if (serverItemLimitComponent == null)
self.Refresh();
else
{
self.currentItemCountDic = serverItemLimitComponent.currentItemCountDic;
}
}
public static void Save(this ServerItemLimitComponent self)
{
ServerItemLimitComponent serverItemLimitComponent = self.Domain.GetComponent<ServerItemLimitComponent>();
UnitHelper.SaveComponenet(self.DomainZone(), serverItemLimitComponent);
}
public static void Refresh(this ServerItemLimitComponent self)
{
ServerItemLimitCategory.Instance.FillDic(self.currentItemCountDic);
}
public static void Load(this ServerItemLimitComponent self)
{
ServerItemLimitCategory.Instance.ReFillDic(self.currentItemCountDic);
}
public static bool DropItem(this ServerItemLimitComponent self, int id, ref int _count)
{
if (!self.currentItemCountDic.TryGetValue(id, out int count))
{
return true;
}
if (count <= 0)
{
return false;
}
if (count >= _count)
{
count -= _count;
self.currentItemCountDic[id] = count;
return true;
}
_count = count;
count = 0;
self.currentItemCountDic[id] = count;
return true;
}
}
}