|
|
|
using System;
|
|
|
|
using System.Collections.Generic;
|
|
|
|
using ET.EventType;
|
|
|
|
|
|
|
|
namespace ET
|
|
|
|
{
|
|
|
|
[FriendClass(typeof(Unit))]
|
|
|
|
public static class UnitHelper
|
|
|
|
{
|
|
|
|
public static Unit GetMyUnitFromZoneScene(Scene zoneScene)
|
|
|
|
{
|
|
|
|
// PlayerComponent playerComponent = zoneScene.GetComponent<PlayerComponent>();
|
|
|
|
Scene currentScene = zoneScene.GetComponent<CurrentScenesComponent>().Scene;
|
|
|
|
// return currentScene.GetComponent<UnitComponent>().Get(playerComponent.MyId);
|
|
|
|
return currentScene.GetComponent<UnitComponent>().GetUnit();
|
|
|
|
}
|
|
|
|
|
|
|
|
public static Unit GetMyUnitFromCurrentScene(Scene currentScene)
|
|
|
|
{
|
|
|
|
PlayerComponent playerComponent = currentScene.Parent.Parent.GetComponent<PlayerComponent>();
|
|
|
|
return currentScene.GetComponent<UnitComponent>().Get(playerComponent.MyId);
|
|
|
|
}
|
|
|
|
|
|
|
|
public static async ETTask<int> GetUnitGameTime(Unit unit)
|
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
|
|
|
M2C_GameTime resp = await unit.ZoneScene().GetComponent<SessionComponent>().Session.Call(new C2M_GameTime()) as M2C_GameTime;
|
|
|
|
if (resp.Error != ErrorCode.ERR_Success)
|
|
|
|
{
|
|
|
|
Log.Error(resp.Error.ToString());
|
|
|
|
return resp.Error;
|
|
|
|
}
|
|
|
|
|
|
|
|
unit.GameTime = resp.GameTime;
|
|
|
|
Game.EventSystem.Publish(new EventType.SyncTime(){Unit = unit, Time = resp.GameTime});
|
|
|
|
}
|
|
|
|
catch (Exception e)
|
|
|
|
{
|
|
|
|
Log.Error(e);
|
|
|
|
throw;
|
|
|
|
}
|
|
|
|
await ETTask.CompletedTask;
|
|
|
|
return ErrorCode.ERR_Success;
|
|
|
|
}
|
|
|
|
|
|
|
|
public static async ETTask<int> UpgradeScale(Unit unit)
|
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
|
|
|
M2C_UpgradeScale resp = await unit.ZoneScene().GetComponent<SessionComponent>().Session.Call(new C2M_UpgradeScale()) as M2C_UpgradeScale;
|
|
|
|
if (resp.Error != ErrorCode.ERR_Success)
|
|
|
|
{
|
|
|
|
Log.Error(resp.Error.ToString());
|
|
|
|
return resp.Error;
|
|
|
|
}
|
|
|
|
unit.Scale = resp.Scale;
|
|
|
|
// Game.EventSystem.Publish(new EventType.SyncTime(){Unit = unit, Scale = resp.Scale});
|
|
|
|
}
|
|
|
|
catch (Exception e)
|
|
|
|
{
|
|
|
|
Log.Error(e);
|
|
|
|
throw;
|
|
|
|
}
|
|
|
|
await ETTask.CompletedTask;
|
|
|
|
return ErrorCode.ERR_Success;
|
|
|
|
}
|
|
|
|
|
|
|
|
public static async ETTask<int> GetNightEvent(Unit unit)
|
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
|
|
|
List<NightEvent> nightEvents = null;
|
|
|
|
if (unit.EventSeed > 0)
|
|
|
|
{
|
|
|
|
SeasonConfig lastSeasonConfig = UnitOperate.GetSeasonConfigByDay(unit.Day-1, unit.Season);
|
|
|
|
int nightTime = UnitOperate.CheckMoonNightTime(unit.Day-1, lastSeasonConfig.DayTime[1]);
|
|
|
|
nightEvents = UnitOperate.NightEvent(unit, nightTime, unit.SeasonConfig.DayTime[0]);
|
|
|
|
|
|
|
|
Game.EventSystem.Publish(new EventType.ShowNightEvent() { Unit = unit, Events = nightEvents, ShowAni = false });
|
|
|
|
}
|
|
|
|
}
|
|
|
|
catch (Exception e)
|
|
|
|
{
|
|
|
|
Log.Error(e);
|
|
|
|
throw;
|
|
|
|
}
|
|
|
|
await ETTask.CompletedTask;
|
|
|
|
return ErrorCode.ERR_Success;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|