zxl
/
CTT
forked from Cal/CTT
1
0
Fork 0
CTT/Server/Hotfix/Game/Event/TimerSendEnergyEvent.cs

42 lines
1.4 KiB
C#
Raw Normal View History

2021-04-08 20:09:59 +08:00
using System;
using System.Collections.Generic;
using System.Text;
namespace ET
{
public class TimerSendEnergyEvent : AEvent<EventType.UpdatePer30MinuteOfDay>
{
public override async ETTask Run(EventType.UpdatePer30MinuteOfDay args)
{
2021-04-11 19:50:39 +08:00
List<User> list = await DBComponent.Instance.Query<User>(u => u.Level >= 500);
2021-04-08 20:09:59 +08:00
if (list == null || list.Count == 0) return;
2021-04-11 19:50:39 +08:00
foreach (User user in list)
2021-04-08 20:09:59 +08:00
{
try
{
NumericComponent num = null;
Unit unit = MapUnitComponent.Instance.Get(user.Id);
if (unit != null)
{
num = unit.GetComponent<NumericComponent>();
}
if (num == null)
{
num = await DBComponent.Instance.Query<NumericComponent>(user.Id);
}
if (num == null) continue;
int energy = num.GetAsInt(NumericType.Energy);
if (energy >= ConstDefine.AutoEnergyMax) continue;
num.AddSet(NumericType.Energy, ConstDefine.EnergyPer30Minute);
await UnitHelper.SaveComponenet(num);
}
catch (Exception e)
{
Log.Error(e);
}
}
}
}
}