zxl
/
CTT
forked from Cal/CTT
1
0
Fork 0
CTT/Server/Hotfix/Game/System/Log/YuanBaoLogComponentSystem.cs

42 lines
1.5 KiB
C#
Executable File

using ET.EventType;
using System;
using System.Collections.Generic;
namespace ET
{
public class YuanBaoLogComponentAwakeSystem : AwakeSystem<YuanBaoLogComponent>
{
public override void Awake(YuanBaoLogComponent self)
{
YuanBaoLogComponent.instance = self;
}
}
public static class YuanBaoLogComponentSystem
{
class SavePer5Minute : AEvent<EventType.UpdatePer1MinuteOfDay>
{
public override async ETTask Run(UpdatePer1MinuteOfDay args)
{
using ListComponent<ETTask> listComponent = ListComponent<ETTask>.Create();
foreach (KeyValuePair<long, YuanBaoLog> kv in YuanBaoLogComponent.instance.YuanBaoLogDic)
{
listComponent.List.Add(DBComponent.Instance.Save(kv.Value));
}
ETTaskHelper.WaitAll(listComponent.List).Coroutine();
await ETTask.CompletedTask;
}
}
public static void AddInfo(this YuanBaoLogComponent self, long id, string info)
{
if (!self.YuanBaoLogDic.TryGetValue(id, out YuanBaoLog yuanBaoLog))
{
self.YuanBaoLogDic[id] = yuanBaoLog = EntityFactory.CreateWithId<YuanBaoLog>(self.DomainScene(),id);
}
DateTime now = DateTime.UtcNow;
int day = now.Year * 10000 + now.Month * 100 + now.Day;
yuanBaoLog.logDic.TryGetValue(day, out string info_);
yuanBaoLog.logDic[day] = $"{info_}{now:HH:mm:ss}: {info}\r\n";
}
}
}