2021-04-08 20:09:59 +08:00
|
|
|
|
using ET.EventType;
|
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
|
|
|
|
|
namespace ET
|
|
|
|
|
{
|
|
|
|
|
public class UnitOffLineEvent : AEvent<EventType.UnitOffline>
|
|
|
|
|
{
|
|
|
|
|
public override async ETTask Run(UnitOffline args)
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
2021-04-11 19:50:39 +08:00
|
|
|
|
Unit unit = args.unit;
|
2021-04-08 20:09:59 +08:00
|
|
|
|
Log.Debug($"玩家Id=【{unit.Id}】下线开始");
|
|
|
|
|
User user = UserComponent.Instance.Get(unit.Id);
|
|
|
|
|
//保存玩家单位
|
|
|
|
|
await SaveUnit(unit);
|
|
|
|
|
if (user == null)
|
|
|
|
|
{
|
2021-04-20 00:25:04 +08:00
|
|
|
|
Log.ErrorDetail($"user == null where id = {unit.Id}");
|
2021-04-08 20:09:59 +08:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
user.lastLoginTime = TimeHelper.ClientNow();
|
|
|
|
|
UserComponent.Instance.Save(user).Coroutine();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//移除本地Actor
|
|
|
|
|
await unit.RemoveLocation();
|
|
|
|
|
//退出队伍
|
|
|
|
|
TeamComponent.Instance.DestroyTeam(unit);
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
//销毁之前保存buff
|
2021-04-11 19:50:39 +08:00
|
|
|
|
BuffLib lib = await BuffLibComponent.Instance.Query(unit.Id);
|
|
|
|
|
IEnumerable<GoodsEffect> goodsBuffList = GoodsEffectComponent.Instance.GetAllEffect(unit.Id);
|
2021-04-08 20:09:59 +08:00
|
|
|
|
if (goodsBuffList != null)
|
2021-04-11 19:50:39 +08:00
|
|
|
|
foreach (GoodsEffect item in goodsBuffList)
|
2021-04-08 20:09:59 +08:00
|
|
|
|
{
|
|
|
|
|
//!排除非时间性goodsBuff效果
|
|
|
|
|
if (item.BuffEndTime != 0)
|
|
|
|
|
lib.goodsEffectBuffDic[(int)item.GoodsBase.Id] = item.BuffEndTime;
|
|
|
|
|
}
|
|
|
|
|
BuffLibComponent.Instance.Save(lib).Coroutine();
|
|
|
|
|
}
|
|
|
|
|
catch (Exception e)
|
|
|
|
|
{
|
|
|
|
|
Log.Error(e);
|
|
|
|
|
}
|
2021-04-20 00:25:04 +08:00
|
|
|
|
//从地图中移除
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
unit.GetMap()?.Leave(unit);
|
|
|
|
|
}
|
|
|
|
|
catch (Exception e)
|
|
|
|
|
{
|
|
|
|
|
Log.Error(e);
|
|
|
|
|
}
|
2021-04-08 20:09:59 +08:00
|
|
|
|
//单元管理器移除
|
|
|
|
|
UserComponent.Instance.Remove(unit.Id);
|
|
|
|
|
unit.Dispose();
|
|
|
|
|
Log.Debug($"玩家Id=【{unit.Id}】下线完成");
|
|
|
|
|
}
|
|
|
|
|
catch (Exception e)
|
|
|
|
|
{
|
|
|
|
|
Log.Error(e);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private async ETTask SaveUnit(Unit unit)
|
|
|
|
|
{
|
|
|
|
|
if (!unit) return;
|
|
|
|
|
if (unit.UnitType != UnitType.Player)
|
|
|
|
|
return;
|
|
|
|
|
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<UnitTask>(unit);
|
|
|
|
|
await UnitHelper.Save<UnitScene>(unit);
|
|
|
|
|
await UnitHelper.Save<UserSetting>(unit);
|
|
|
|
|
await UnitHelper.Save<UnitSkillComponent>(unit);
|
|
|
|
|
await UnitHelper.Save<Pet>(unit);
|
2021-05-01 22:06:12 +08:00
|
|
|
|
await UnitHelper.Save<StarSoulBag>(unit);
|
2021-04-08 20:09:59 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|