42 lines
1.4 KiB
C#
Executable File
42 lines
1.4 KiB
C#
Executable File
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)
|
|
{
|
|
List<User> list = await DBComponent.Instance.Query<User>(u => u.Level >= 500);
|
|
if (list == null || list.Count == 0) return;
|
|
foreach (User user in list)
|
|
{
|
|
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);
|
|
UnitHelper.SaveComponenet(num);
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
Log.Error(e);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
}
|