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) { Unit uu = tier.Get(id); if (uu==null || uu.IsDisposed) { 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) ?? MapSceneComponent.Instance.GetMap(Sys_SceneId.Scene_MainCity * 100 + 1); mapScene.Leave(unit); unitScene.MapId = mapId; mapScene = MapSceneComponent.Instance.GetMap(unitScene.MapId) ?? 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); } } } }