CTT/Server/Hotfix/Game/System/Account/MaintainRewardComponentSyst...

90 lines
3.7 KiB
C#
Raw Normal View History

2021-04-08 20:09:59 +08:00
using System;
using System.Collections.Generic;
using System.IO;
namespace ET
{
public class MaintainRewardComponentAwakeSystem : AwakeSystem<MaintainRewardComponent>
{
public override void Awake(MaintainRewardComponent self)
{
AwakeAsync(self).Coroutine();
}
private async ETVoid AwakeAsync(MaintainRewardComponent self)
{
string path = @"../Config\MaintainReward.txt";
2021-04-11 19:50:39 +08:00
string str = await File.ReadAllTextAsync(path);
2021-04-08 20:09:59 +08:00
self.maintainReward = MongoHelper.FromJson<MaintainReward>(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);
//!给奖励
2021-04-11 19:50:39 +08:00
long now = TimeHelper.ClientNow();
MaintainReward.MaintainRewardItem[][] arr = self.maintainReward.rewardArr;
List<User> list = await DBComponent.Instance.Query<User>(u => u.Level >= 100);
2021-04-08 20:09:59 +08:00
int count = 0;
for (int i = 0; i < arr.Length; i++)
{
try
{
count = 0;
2021-04-11 19:50:39 +08:00
MaintainReward.MaintainRewardItem[] interArr = arr[i];
2021-04-08 20:09:59 +08:00
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++)
{
2021-04-11 19:50:39 +08:00
MaintainReward.MaintainRewardItem item = interArr[j];
2021-04-08 20:09:59 +08:00
mail.RewordArr.Add(new MailItem
{
ItemId = item.itemId,
Count = item.itemCount,
IsLock = true
});
}
if (list == null || list.Count == 0) return;
2021-04-11 19:50:39 +08:00
foreach (User u in list)
2021-04-08 20:09:59 +08:00
{
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<MaintainRewardComponent> Query(this MaintainRewardComponent self)
{
MaintainRewardComponent maintainRewardComponent = await DBComponent.Instance.Query<MaintainRewardComponent>(0);
return maintainRewardComponent;
}
}
}