169 lines
6.4 KiB
C#
169 lines
6.4 KiB
C#
|
using Cal.DataTable;
|
|||
|
using ET.EventType;
|
|||
|
using System;
|
|||
|
using System.Collections.Generic;
|
|||
|
using System.Linq;
|
|||
|
using System.Text;
|
|||
|
|
|||
|
namespace ET
|
|||
|
{
|
|||
|
|
|||
|
public class MapSceneComponentAwakeSystem : AwakeSystem<MapSceneComponent>
|
|||
|
{
|
|||
|
|
|||
|
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
|
|||
|
{
|
|||
|
class CheckPerMinute : AEvent<ET.EventType.UpdatePer1MinuteOfDay>
|
|||
|
{
|
|||
|
public override async ETTask Run(UpdatePer1MinuteOfDay args)
|
|||
|
{
|
|||
|
foreach (var map in MapSceneComponent.Instance.GetAllMap())
|
|||
|
{
|
|||
|
try
|
|||
|
{
|
|||
|
foreach (var tier in map.tierDic.Values)
|
|||
|
{
|
|||
|
try
|
|||
|
{
|
|||
|
using var listComponent = ListComponent<long>.Create();
|
|||
|
listComponent.List.AddRange(tier.unitDic.Keys);
|
|||
|
foreach (var 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 (var item in self.m_MapSceneDic)
|
|||
|
{
|
|||
|
item.Value.Dispose();
|
|||
|
}
|
|||
|
self.m_MapSceneDic.Clear();
|
|||
|
var list = DataTableHelper.GetAll<Sys_Scene>();
|
|||
|
foreach (Sys_Scene item in list)
|
|||
|
{
|
|||
|
for (int i = 0; i < item.Layers; i++)
|
|||
|
{
|
|||
|
var map = EntityFactory.CreateWithParent<MapScene>(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<MapScene> GetAllMap(this MapSceneComponent self)
|
|||
|
{
|
|||
|
return self.m_MapSceneDic.Values;
|
|||
|
}
|
|||
|
public static IEnumerable<int> GetAllMapId(this MapSceneComponent self)
|
|||
|
{
|
|||
|
return self.m_MapSceneDic.Keys;
|
|||
|
}
|
|||
|
public static MapScene GetMap(this MapSceneComponent self, int mapId)
|
|||
|
{
|
|||
|
self.m_MapSceneDic.TryGetValue(mapId, out var map);
|
|||
|
return map;
|
|||
|
}
|
|||
|
public static MapScene GetMap(this MapSceneComponent self, Unit unit)
|
|||
|
{
|
|||
|
var unitScene = unit.GetComponent<UnitScene>();
|
|||
|
return self.GetMap(unitScene.MapId);
|
|||
|
}
|
|||
|
public static async ETTask ChangeMap(this MapSceneComponent self, UnitScene unitScene,int mapId)
|
|||
|
{
|
|||
|
Unit unit = unitScene.GetParent<Unit>();
|
|||
|
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)
|
|||
|
{
|
|||
|
var unitScene = unit.GetComponent<UnitScene>();
|
|||
|
if (unitScene)
|
|||
|
{
|
|||
|
var 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,
|
|||
|
};
|
|||
|
}
|
|||
|
}
|