using Cal.DataTable; using ET.EventType; using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace ET { public class MapSceneComponentAwakeSystem : AwakeSystem { public override void Awake(MapSceneComponent self) { MapSceneComponent.Instance = self; self.Load(); self.AddComponent(); self.AddComponent(); self.AddComponent(); self.AddComponent(); self.AddComponent(); self.AddComponent(); self.AddComponent(); self.AddComponent(); self.AddComponent(); } } public static class MapSceneComponentSystem { class CheckPerMinute : AEvent { public override async ETTask Run(UpdatePer1MinuteOfDay args) { foreach (MapScene map in MapSceneComponent.Instance.GetAllMap()) { try { foreach (Tier tier in map.tierDic.Values) { try { using ListComponent listComponent = ListComponent.Create(); listComponent.List.AddRange(tier.unitDic.Keys); foreach (long id in listComponent.List) { if (!tier.Get(id)) { Log.Error($"unitId:{id}"); tier.Remove(id); } } } catch (Exception e) { Log.Error(e); } } if(AppConfig.inst.isTest) { if (map.GetAll().ToArray().Length != 0) { Log.Info($"{map.GetAll().ToCustomString()}"); } } } catch (Exception e) { Log.Error(e); } } await ETTask.CompletedTask; } } public static void Load(this MapSceneComponent self) { foreach (KeyValuePair item in self.m_MapSceneDic) { item.Value.Dispose(); } self.m_MapSceneDic.Clear(); IEnumerable list = DataTableHelper.GetAll(); foreach (Sys_Scene item in list) { for (int i = 0; i < item.Layers; i++) { MapScene map = EntityFactory.CreateWithParent(self); int id = (int)(item.Id * 100 + i + 1); self.m_MapSceneDic.Add(id, map); map.mapId = id; } } } public static Sys_Scene GetMapInfo(this MapSceneComponent self, int id) { Sys_Scene sys_Scene = Sys_SceneCategory.Instance.Get(id); return sys_Scene; } public static IEnumerable GetAllMap(this MapSceneComponent self) { return self.m_MapSceneDic.Values; } public static IEnumerable GetAllMapId(this MapSceneComponent self) { return self.m_MapSceneDic.Keys; } public static MapScene GetMap(this MapSceneComponent self, int mapId) { self.m_MapSceneDic.TryGetValue(mapId, out MapScene map); return map; } public static MapScene GetMap(this MapSceneComponent self, Unit unit) { UnitScene unitScene = unit.GetComponent(); return self.GetMap(unitScene.MapId); } public static async ETTask ChangeMap(this MapSceneComponent self, UnitScene unitScene,int mapId) { Unit unit = unitScene.GetParent(); MapScene mapScene = MapSceneComponent.Instance.GetMap(unitScene.MapId); if (mapScene == null) mapScene = MapSceneComponent.Instance.GetMap(Sys_SceneId.Scene_MainCity * 100 + 1); mapScene.Leave(unit); unitScene.MapId = mapId; mapScene = MapSceneComponent.Instance.GetMap(unitScene.MapId); if (mapScene == null) mapScene = MapSceneComponent.Instance.GetMap(Sys_SceneId.Scene_MainCity * 100 + 1); await mapScene.Enter(unit); } public static void RemoveUnit(this MapSceneComponent self, Unit unit) { UnitScene unitScene = unit.GetComponent(); if (unitScene) { MapScene map = self.GetMap(unitScene.MapId); map?.Leave(unit, true); } } public static UnitSceneType GetUnitSceneType(this MapSceneComponent self, int sceneId) => sceneId switch { int id when id >= Sys_SceneId.Scene_MainStory1 && id <= Sys_SceneId.Scene_MainStory16 => UnitSceneType.MainStory, int id when id == Sys_SceneId.Scene_Beach => UnitSceneType.Beach, int id when id == Sys_SceneId.Scene_Challenge || id == Sys_SceneId.Scene_Challenge_Middle || id == Sys_SceneId.Scene_Challenge_Hard|| id == Sys_SceneId.Scene_PersonalBoss => UnitSceneType.Trial, int id when id == Sys_SceneId.Scene_Boss => UnitSceneType.Boss, int id when id == Sys_SceneId.Scene_PersonalPvp1 || id == Sys_SceneId.Scene_PersonalPvp2 || id == Sys_SceneId.Scene_PersonalPvp3 => UnitSceneType.PersonalPvp, int id when id == Sys_SceneId.Scene_ManulEquip1 || id == Sys_SceneId.Scene_ManulEquip2 || id == Sys_SceneId.Scene_ManulEquip3 => UnitSceneType.ManulEquip, _ => UnitSceneType.Common, }; } }