108 lines
3.9 KiB
C#
108 lines
3.9 KiB
C#
using Cal.DataTable;
|
|
using ET.EventType;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
|
|
namespace ET
|
|
{
|
|
public class UnitOnlineTimeEvent : AEvent<EventType.UpdatePer1MinuteOfDay>
|
|
{
|
|
public override async ETTask Run(UpdatePer1MinuteOfDay args)
|
|
{
|
|
long now = args.now;
|
|
foreach (Unit unit in MapUnitComponent.Instance.GetAll())
|
|
{
|
|
try
|
|
{
|
|
if (!unit) continue;
|
|
if (unit.UnitType != UnitType.Player)
|
|
continue;
|
|
if (unit.IsOffline)
|
|
{
|
|
if(AppConfig.inst.isTest)
|
|
Log.Warning($"离线:{unit.Id.GetPlayerFormatName()}");
|
|
continue;
|
|
}
|
|
PlayerData data = unit.GetComponent<PlayerData>();
|
|
if (!data)
|
|
{
|
|
Log.Error($"data is invalid isNull = {data == null}");
|
|
continue;
|
|
}
|
|
data.UpdateOnlineTime(now);
|
|
|
|
UnitScene unitScene = unit.GetComponent<UnitScene>();
|
|
if (unitScene == null) continue;
|
|
if (unitScene.MapId/100 == Sys_SceneId.Scene_MainCity)
|
|
{
|
|
int maxSceneId = data.MainStoryRecordId;
|
|
MainStoryExp mainStoryExp = MainStoryExpCategory.Instance.Get(maxSceneId);
|
|
CharacterHelper.AddExp(unit, MathHelper.RoundToLong(mainStoryExp.Exp/10f));
|
|
}
|
|
|
|
TimeSpan time = TimeSpan.FromMilliseconds(data.OnlineTime);
|
|
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
Log.Error(e);
|
|
}
|
|
}
|
|
await ETTask.CompletedTask;
|
|
}
|
|
}
|
|
public class UnitSaveEvent : AEvent<EventType.UpdatePer1MinuteOfDay>
|
|
{
|
|
public override async ETTask Run(UpdatePer1MinuteOfDay args)
|
|
{
|
|
long now = args.now;
|
|
//!dTime =59s
|
|
//long dTime = TimeSpan.TicksPerMinute / 10000 - 1000;
|
|
Unit[] arr = MapUnitComponent.Instance.GetAll().ToArray();
|
|
for (int i = 0; i < arr.Length; i++)
|
|
{
|
|
try
|
|
{
|
|
Unit unit = arr[i];
|
|
if (!unit) continue;
|
|
if (unit.UnitType != UnitType.Player)
|
|
continue;
|
|
Team team = TeamComponent.Instance.Get(unit.Id);
|
|
if (team?.TeamState != TeamState.Fight)
|
|
{
|
|
await UnitHelper.Save<PlayerData>(unit);
|
|
await UnitHelper.Save<NumericComponent>(unit);
|
|
await UnitHelper.Save<Character>(unit);
|
|
await UnitHelper.Save<Bag>(unit);
|
|
await UnitHelper.Save<StarSoulBag>(unit);
|
|
await UnitHelper.Save<UnitTask>(unit);
|
|
await UnitHelper.Save<UnitScene>(unit);
|
|
await UnitHelper.Save<UserSetting>(unit);
|
|
await UnitHelper.Save<UnitSkillComponent>(unit);
|
|
await UnitHelper.Save<Pet>(unit);
|
|
}
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
Log.Error(e);
|
|
}
|
|
}
|
|
User[] userArr = UserComponent.Instance.GetAll().ToArray();
|
|
for (int i = 0; i < userArr.Length; i++)
|
|
{
|
|
try
|
|
{
|
|
User user = userArr[i];
|
|
await DBComponent.Instance.Save(user);
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
Log.Error(e);
|
|
}
|
|
}
|
|
await ETTask.CompletedTask;
|
|
}
|
|
}
|
|
}
|