zxl
/
CTT
forked from Cal/CTT
1
0
Fork 0
CTT/Server/Hotfix/Game/System/Map/MapSceneComponentSystem.cs

149 lines
5.1 KiB
C#
Raw Normal View History

2021-04-08 20:09:59 +08:00
using Cal.DataTable;
using ET.EventType;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ET
{
2021-05-01 11:27:41 +08:00
public class MapSceneComponentAwakeSystem: AwakeSystem<MapSceneComponent>
2021-04-08 20:09:59 +08:00
{
public override void Awake(MapSceneComponent self)
{
MapSceneComponent.Instance = self;
self.Load();
self.AddComponent<BattleEventComponent>();
self.AddComponent<BattleMgrCompnent>();
self.AddComponent<MainStoryMap>();
self.AddComponent<TrialCopyMap>();
self.AddComponent<BossComponent>();
self.AddComponent<BattleIdleMap>();
self.AddComponent<PvpMap>();
self.AddComponent<ManulEquipMap>();
self.AddComponent<MapCoinComponent>();
}
}
public static class MapSceneComponentSystem
{
2021-05-01 11:27:41 +08:00
class CheckPerMinute: AEvent<ET.EventType.UpdatePer1MinuteOfDay>
2021-04-08 20:09:59 +08:00
{
public override async ETTask Run(UpdatePer1MinuteOfDay args)
{
2021-04-11 19:50:39 +08:00
foreach (MapScene map in MapSceneComponent.Instance.GetAllMap())
2021-04-08 20:09:59 +08:00
{
try
{
2021-04-11 19:50:39 +08:00
foreach (Tier tier in map.tierDic.Values)
2021-04-08 20:09:59 +08:00
{
try
{
2021-04-11 19:50:39 +08:00
using ListComponent<long> listComponent = ListComponent<long>.Create();
2021-04-08 20:09:59 +08:00
listComponent.List.AddRange(tier.unitDic.Keys);
2021-04-11 19:50:39 +08:00
foreach (long id in listComponent.List)
2021-04-08 20:09:59 +08:00
{
if (!tier.Get(id))
{
Log.Error($"unitId:{id}");
tier.Remove(id);
}
}
}
catch (Exception e)
{
Log.Error(e);
}
}
2021-05-01 11:27:41 +08:00
if (AppConfig.inst.isTest)
2021-04-08 20:09:59 +08:00
{
if (map.GetAll().ToArray().Length != 0)
{
Log.Info($"{map.GetAll().ToCustomString()}");
}
}
}
catch (Exception e)
{
Log.Error(e);
}
}
await ETTask.CompletedTask;
}
}
2021-05-01 11:27:41 +08:00
2021-04-08 20:09:59 +08:00
public static void Load(this MapSceneComponent self)
{
2021-04-11 19:50:39 +08:00
foreach (KeyValuePair<int, MapScene> item in self.m_MapSceneDic)
2021-04-08 20:09:59 +08:00
{
item.Value.Dispose();
}
2021-05-01 11:27:41 +08:00
2021-04-08 20:09:59 +08:00
self.m_MapSceneDic.Clear();
2021-04-11 19:50:39 +08:00
IEnumerable<Sys_Scene> list = DataTableHelper.GetAll<Sys_Scene>();
2021-04-08 20:09:59 +08:00
foreach (Sys_Scene item in list)
{
for (int i = 0; i < item.Layers; i++)
{
2021-04-11 19:50:39 +08:00
MapScene map = EntityFactory.CreateWithParent<MapScene>(self);
2021-05-01 11:27:41 +08:00
int id = (int) (item.Id * 100 + i + 1);
2021-04-08 20:09:59 +08:00
self.m_MapSceneDic.Add(id, map);
map.mapId = id;
}
}
}
2021-05-01 11:27:41 +08:00
2021-04-08 20:09:59 +08:00
public static Sys_Scene GetMapInfo(this MapSceneComponent self, int id)
{
Sys_Scene sys_Scene = Sys_SceneCategory.Instance.Get(id);
return sys_Scene;
}
2021-05-01 11:27:41 +08:00
2021-04-08 20:09:59 +08:00
public static IEnumerable<MapScene> GetAllMap(this MapSceneComponent self)
{
return self.m_MapSceneDic.Values;
}
2021-05-01 11:27:41 +08:00
2021-04-08 20:09:59 +08:00
public static IEnumerable<int> GetAllMapId(this MapSceneComponent self)
{
return self.m_MapSceneDic.Keys;
}
2021-05-01 11:27:41 +08:00
2021-04-08 20:09:59 +08:00
public static MapScene GetMap(this MapSceneComponent self, int mapId)
{
2021-04-11 19:50:39 +08:00
self.m_MapSceneDic.TryGetValue(mapId, out MapScene map);
2021-04-08 20:09:59 +08:00
return map;
}
2021-05-01 11:27:41 +08:00
2021-04-08 20:09:59 +08:00
public static MapScene GetMap(this MapSceneComponent self, Unit unit)
{
2021-04-11 19:50:39 +08:00
UnitScene unitScene = unit.GetComponent<UnitScene>();
2021-04-08 20:09:59 +08:00
return self.GetMap(unitScene.MapId);
2021-05-01 11:27:41 +08:00
}
public static async ETTask ChangeMap(this MapSceneComponent self, UnitScene unitScene, int mapId)
2021-04-08 20:09:59 +08:00
{
Unit unit = unitScene.GetParent<Unit>();
2021-05-01 11:27:41 +08:00
MapScene mapScene = MapSceneComponent.Instance.GetMap(unitScene.MapId) ??
MapSceneComponent.Instance.GetMap(Sys_SceneId.Scene_MainCity * 100 + 1);
2021-04-08 20:09:59 +08:00
mapScene.Leave(unit);
unitScene.MapId = mapId;
2021-05-01 11:27:41 +08:00
mapScene = MapSceneComponent.Instance.GetMap(unitScene.MapId) ?? MapSceneComponent.Instance.GetMap(Sys_SceneId.Scene_MainCity * 100 + 1);
2021-04-08 20:09:59 +08:00
await mapScene.Enter(unit);
}
2021-05-01 11:27:41 +08:00
2021-04-08 20:09:59 +08:00
public static void RemoveUnit(this MapSceneComponent self, Unit unit)
{
2021-04-11 19:50:39 +08:00
UnitScene unitScene = unit.GetComponent<UnitScene>();
2021-04-08 20:09:59 +08:00
if (unitScene)
{
2021-04-11 19:50:39 +08:00
MapScene map = self.GetMap(unitScene.MapId);
2021-04-08 20:09:59 +08:00
map?.Leave(unit, true);
}
}
2021-05-01 11:27:41 +08:00
2021-04-08 20:09:59 +08:00
}
2021-05-01 11:27:41 +08:00
}