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(); Scene currentScene = zoneScene.GetComponent().Scene; // return currentScene.GetComponent().Get(playerComponent.MyId); return currentScene.GetComponent().GetUnit(); } public static Unit GetMyUnitFromCurrentScene(Scene currentScene) { PlayerComponent playerComponent = currentScene.Parent.Parent.GetComponent(); return currentScene.GetComponent().Get(playerComponent.MyId); } public static async ETTask GetUnitGameTime(Unit unit) { try { M2C_GameTime resp = await unit.ZoneScene().GetComponent().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 UpgradeScale(Unit unit) { try { M2C_UpgradeScale resp = await unit.ZoneScene().GetComponent().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 GetNightEvent(Unit unit) { try { List 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; } } }