using Cal.DataTable; using ET.EventType; namespace ET { class ServerItemLimitComponentUpdatePerDay: AEvent { public override async ETTask Run(UpdatePer1DayOfMonth args) { int zone = args.zone; var now = args.now; var domain = args.domain; ServerItemLimitComponent serverItemLimitComponent = domain.GetComponent(); serverItemLimitComponent.Refresh(); await ETTask.CompletedTask; } } class ServerItemLimitComponentAwakeSystem: AwakeSystem { public override void Awake(ServerItemLimitComponent self) { self.Id = 0; self.Awake().Coroutine(); } } class ServerItemLimitComponentStartSystem: StartSystem { public override void Start(ServerItemLimitComponent self) { self.AddComponent().Init(2 * 60 * 1000, self.Save); } } class ServerItemLimitComponentLoadSystem: LoadSystem { 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(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(); 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; } } }