using System; using System.Collections.Generic; using System.IO; 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 { public static async ETTask Query(this MaintainRewardComponent self) { MaintainRewardComponent maintainRewardComponent = await DBComponent.Instance.Query(0); return maintainRewardComponent; } } }