using System; using System.Collections.Generic; using System.IO; using Cal.DataTable; using ET.EventType; namespace ET { public class MaintainRewardComponentAwakeSystem: AwakeSystem { public override void Awake(MaintainRewardComponent self) { AwakeAsync(self).Coroutine(); } private async ETVoid AwakeAsync(MaintainRewardComponent self) { // string path = @"../Config/MaintainReward.txt"; // string str = await File.ReadAllTextAsync(path); // self.maintainReward = MongoHelper.FromJson(str); // self.version = self.maintainReward.version; // MaintainRewardComponent maintainRewardComponent = await self.Query(); // if (maintainRewardComponent == null) // maintainRewardComponent = (MaintainRewardComponent)Entity.Create(typeof(MaintainRewardComponent), false); // if (maintainRewardComponent.version < self.version) // { // maintainRewardComponent.version++; // await DBComponent.Instance.Save(maintainRewardComponent); // //!给奖励 // long now = TimeHelper.ClientNow(); // MaintainReward.MaintainRewardItem[][] arr = self.maintainReward.rewardArr; // List list = await DBComponent.Instance.Query(u => u.Level >= 100); // int count = 0; // for (int i = 0; i < arr.Length; i++) // { // try // { // count = 0; // MaintainReward.MaintainRewardItem[] interArr = arr[i]; // Mail mail = new Mail // { // Id = Game.IdGenerater.GenerateId(), // Title = "维护奖励", // Content = self.maintainReward.notice, // SenderName = "系统", // State = MailState.UnReceive, // RemainTime = now + (long)TimeSpan.FromDays(7).TotalMilliseconds, // }; // for (int j = 0; j < interArr.Length; j++) // { // MaintainReward.MaintainRewardItem item = interArr[j]; // mail.RewordArr.Add(new MailItem // { // ItemId = item.itemId, // Count = item.itemCount, // IsLock = true // }); // } // if (list == null || list.Count == 0) return; // foreach (User u in list) // { // try // { // count++; // await MailComponent.Instance.AddMail(u.Id, mail); // } // catch (Exception e) // { // Log.Error(e); // } // } // Log.Info($"第{i}个奖励人数:{count}"); // } // catch (Exception e) // { // Log.Error(e); // } // // } // } } } public static class MaintainRewardComponentSystem { class MaintainRewardUpdatePerHour: AEvent { public override async ETTask Run(UpdatePer1HourOfDay args) { var now = args.now; MaintainRewardComponent maintainRewardComponent = await DBComponent.Instance.Query(0); if (maintainRewardComponent == null) maintainRewardComponent = (MaintainRewardComponent) Entity.Create(typeof (MaintainRewardComponent), false); MaintainRewardConfig config = MaintainRewardConfigCategory.Instance.Get(1001); int version = config.Y * 100_0000 + config.M * 10000 + config.D * 100 + config.Version; if (maintainRewardComponent.version < version) { maintainRewardComponent.version=version; await DBComponent.Instance.Save(maintainRewardComponent); //!给奖励 List list = await DBComponent.Instance.Query(u => u.Level >= 2000); int count = 0; for (int i = 0; i < config.RewardArr.Length; i += 2) { try { count = 0; Mail mail = new Mail { Id = Game.IdGenerater.GenerateId(), Title = "维护奖励", Content = config.Notice, SenderName = "系统", State = MailState.UnReceive, RemainTime = now + (long) TimeSpan.FromDays(7).TotalMilliseconds, }; int itemCount = 0; itemCount = i == config.RewardArr.Length - 1? 1 : 2; for (int j = 0; j < itemCount; j++) { var item = config.RewardArr[i + j]; mail.RewordArr.Add(new MailItem { ItemId = item._Id, Count = item.Count, IsLock = true }); } if (list == null || list.Count == 0) return; using var listComponent = ListComponent.Create(); foreach (User u in list) { try { count++; listComponent.List.Add(MailComponent.Instance.AddMail(u.Id, mail)); } catch (Exception e) { Log.Error(e); } } await ETTaskHelper.WaitAll(listComponent.List); Log.Info($"第{i}个奖励人数:{count}"); } catch (Exception e) { Log.Error(e); } } } } } } }