123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355 |
- using Cysharp.Threading.Tasks;
- using KYFramework;
- using Model;
- using SimulationServer.Utils;
- using SimulationSingleServer.Utils;
- using Unity.Mathematics;
- namespace SimulationServer;
- [Event]
- public class CreateMHTaskEventHandler : AEvent<CreateMHTask>
- {
- protected override UniTask Run(CreateMHTask config)
- {
- // TODO 创建灭火任务
- var taskSys = Game.Scene.GetComponent<TaskComponent>();
- FirePoint point = config.EditorConfig.firePoints.Find(fire => fire.FirePointId == config.MHTaskConfig.FirePointId);
- // 创建火点
- var fireGround = ComponentFactory.Create<FireGround, FirePoint>(point);
- fireGround.FirePointName = point.FirePointId;
- // 创建灭火任务
- var mission = ComponentFactory.Create<MHRescueMission, FireGround, double>(fireGround, point.InitialArea);
- mission.AddComponent<TotalEconomicalComponent>();
- mission.AddComponent<TotalTaskPerformanceComponent>();
- mission.AddComponent<EquipmentComponent>();
- mission.MissionId = "灭火任务 " + config.MHTaskConfig.TotalMHId;
- taskSys.MHRescueMissions.Add(mission);
- //查询坡度
- mission.slope = Util.GetSlope(point.FirePointLongitude,
- point.FirePointLatitude, 30);
- Log.Info($"创建任务 : {config.MHTaskConfig.TotalMHId}");
- //创建吊桶灭火任务
- foreach (MHTask mhTask in config.MHTaskConfig.mHTask)
- {
- Log.Info($"创建灭火任务 : {mhTask.missionInformation.MissionName}");
- if (mhTask.aircraftInfos == null) continue;
- for (int i = 0; i < mhTask.aircraftInfos.Length; i++)
- {
- //飞机参数
- var aircraftParameter = config.EditorConfig.aircraftParameters.Find(
- a => a.AircraftID == mhTask.aircraftInfos[i].AircraftType);
- //基地
- var originBase = config.EditorConfig.bases.Find(b => b.BaseId == aircraftParameter.AirportId);
- //创建飞行计划编辑器
- var flightPlanEditor = FlightPlanEditor.Create(aircraftParameter, config.EditorConfig.cityWeather, originBase, mhTask.MissionPoints[0], new[] { point });
- AircraftMH aircraft = ComponentFactory.Create<AircraftMH, FlightPlanEditor>(flightPlanEditor);
- aircraft.Name = mhTask.aircraftInfos[i].AircraftType;
- aircraft.AircraftId = mhTask.aircraftInfos[i].AircraftId;
- aircraft.fireGround = fireGround;
- aircraft.mhRescueMission = mission;
- mission.aircrafts.Add(aircraft);
- aircraft.Airport = flightPlanEditor.originbase.BaseName;
- aircraft.TaskName = mhTask.missionInformation.MissionName;
- mission.End += aircraft.End;
- aircraft.AddComponent<StaticCapacityComponent>();
- aircraft.AddComponent<TaskPerformanceComponent>();
- aircraft.AddComponent<EconomicalComponent>();
- aircraft.TaskReadyTime = mhTask.missionInformation.TakeoffPreparationTime;
- Log.Info($"创建机型 : {flightPlanEditor.aircraftparameter.AircraftID}");
- }
- }
- //创建机降灭火任务
- foreach (DMMHTask dmmhTask in config.MHTaskConfig.dMMHTask)
- {
- Log.Info($"创建地面灭火任务 : {dmmhTask.missionInformation.MissionName}");
- if (dmmhTask.aircraftInfos == null) continue;
- for (int i = 0; i < dmmhTask.aircraftInfos.Length; i++)
- {
- //飞机参数
- var aircraftParameter = config.EditorConfig.aircraftParameters.Find(
- a => a.AircraftID == dmmhTask.aircraftInfos[i].AircraftType);
- //基地
- var originBase = config.EditorConfig.bases.Find(b => b.BaseId == aircraftParameter.AirportId);
- //创建飞行计划编辑器
- var flightPlanEditor = FlightPlanEditor.Create(aircraftParameter, config.EditorConfig.cityWeather, originBase, dmmhTask.MissionPoints[0], new[] { point });
- AircraftMHWithPersion aircraftWithPerson = ComponentFactory.Create<AircraftMHWithPersion, FlightPlanEditor>(flightPlanEditor);
- mission.End += aircraftWithPerson.End;
- aircraftWithPerson.Name = dmmhTask.aircraftInfos[i].AircraftType;
- aircraftWithPerson.fireGround = fireGround;
- aircraftWithPerson.mhRescueMission = mission;
- aircraftWithPerson.GroundPersonnel = (int)dmmhTask.GroundPersonnel;
- aircraftWithPerson.LandingPersonnel = (int)dmmhTask.LandingPersonnel;
- aircraftWithPerson.NextMissionId = dmmhTask.NextTaskId;
- aircraftWithPerson.TaskName = dmmhTask.missionInformation.MissionName;
- aircraftWithPerson.TaskReadyTime = dmmhTask.missionInformation.TakeoffPreparationTime;
- aircraftWithPerson.AircraftId = dmmhTask.aircraftInfos[i].AircraftId;
- mission.aircrafts.Add(aircraftWithPerson);
- Log.Info($"创建机型 : {flightPlanEditor.aircraftparameter.AircraftID}");
- }
- }
- //创建索滑降任务
- foreach (SHJTask shjTask in config.MHTaskConfig.sHJTask)
- {
- Log.Info($"创建索滑降任务 : {shjTask.missionInformation.MissionName}");
- if (shjTask.aircraftInfos == null) continue;
- for (int i = 0; i < shjTask.aircraftInfos.Length; i++)
- {
- //飞机参数
- var aircraftParameter = config.EditorConfig.aircraftParameters.Find(
- a => a.AircraftID == shjTask.aircraftInfos[i].AircraftType);
- //基地
- var originBase = config.EditorConfig.bases.Find(b => b.BaseId == aircraftParameter.AirportId);
- MissionPoint missionPoint = null;
- foreach (var item in shjTask.SHJParameters)
- {
- if (aircraftParameter.Id == item.AircraftId)
- missionPoint = item.MissionPoints[0];
- }
- //创建飞行计划编辑器
- var flightPlanEditor = FlightPlanEditor.Create(aircraftParameter, config.EditorConfig.cityWeather, originBase, missionPoint, new[] { point });
- AircraftSHJ aircraftSHJ = ComponentFactory.Create<AircraftSHJ, FlightPlanEditor, SHJTask>(flightPlanEditor, shjTask);
- mission.End += aircraftSHJ.End;
- aircraftSHJ.AircraftId = shjTask.aircraftInfos[i].AircraftId;
- aircraftSHJ.TaskReadyTime = shjTask.missionInformation.TakeoffPreparationTime;
- foreach (var item in config.MHTaskConfig.sHJTask)
- {
- foreach (var item1 in item.SHJParameters)
- {
- if (aircraftSHJ.AircraftId == item1.AircraftId)
- {
- aircraftSHJ.SHJParameter = item1;
- }
- }
- }
- mission.aircrafts.Add(aircraftSHJ);
- Log.Info($"创建机型 : {flightPlanEditor.aircraftparameter.AircraftID}");
- }
- }
- return UniTask.CompletedTask;
- }
- }
- [Event]
- public class CreateZCTaskEventHandler : AEvent<CreateZCTask>
- {
- protected override UniTask Run(CreateZCTask config)
- {
- var taskSys = Game.Scene.GetComponent<TaskComponent>();
- ZCRescueMission mission = ComponentFactory.Create<ZCRescueMission>();
- taskSys.ZCRescueMissions.Add(mission);
- mission.MissionId = $"侦擦任务 {config.ZCTask.missionInformation.MissionName}";
- FirePoint point = config.EditorConfig.firePoints.Find(f => f.FirePointId == config.ZCTask.FirePointId);
- for (int i = 0; i < config.ZCTask.aircraftInfos.Length; i++)
- {
- //飞机参数
- var aircraftParameter = config.EditorConfig.aircraftParameters.Find(
- a => a.AircraftID == config.ZCTask.aircraftInfos[i].AircraftType);
- //基地
- var originBase = config.EditorConfig.bases.Find(b => b.BaseId == aircraftParameter.AirportId);
- //创建飞行计划编辑器
- var flightPlanEditor = FlightPlanEditor.Create(aircraftParameter, config.EditorConfig.cityWeather, originBase, config.ZCTask.MissionPoints[0], new[] { point });
- //创建飞机
- int index = i;
- AircraftZC aircraft = ComponentFactory.Create<AircraftZC, FlightPlanEditor, ZCTask, int>(flightPlanEditor, config.ZCTask, index);
- aircraft.AddComponent<StaticCapacityComponent>();
- aircraft.AddComponent<TaskPerformanceComponent>();
- aircraft.AddComponent<EconomicalComponent>();
- aircraft.TaskReadyTime = config.ZCTask.missionInformation.TakeoffPreparationTime;
- aircraft.AircraftId = config.ZCTask.aircraftInfos[i].AircraftId;
- foreach (var item in config.ZCTask.ZCMethods)
- {
- if(aircraft.AircraftId == item.AircraftId)
- {
- aircraft.ZCMethod = item;
- }
- }
- Log.Info($"创建机型 : {flightPlanEditor.aircraftparameter.AircraftID}");
- mission.AircraftZCs.Add(aircraft);
- }
- return UniTask.CompletedTask;
- }
- }
- [Event]
- public class CreateXHTaskEventHandler : AEvent<CreateXHTask>
- {
- protected override UniTask Run(CreateXHTask config)
- {
- // TODO 创建巡护任务
- var taskSys = Game.Scene.GetComponent<TaskComponent>();
- XHRescueMission mission = ComponentFactory.Create<XHRescueMission>();
- mission.AddComponent<XHTotalTaskPerformanceComponent>();
- mission.AddComponent<EquipmentComponent>();
- mission.MissionId = $"巡护任务 {config.XHTask.missionInformation.MissionId}";
- taskSys.XHRescueMissions.Add(mission);
- FirePoint point = config.EditorConfig.firePoints.Find(f => f.FirePointId == config.XHTask.FirePointId);
- mission.FireGround = ComponentFactory.Create<FireGround, FirePoint>(point);
- for (int i = 0; i < config.XHTask.aircraftInfos.Length; i++)
- {
- //飞机参数
- var aircraftParameter = config.EditorConfig.aircraftParameters.Find(
- a => a.AircraftID == config.XHTask.aircraftInfos[i].AircraftType);
- //基地
- var originBase = config.EditorConfig.bases.Find(b => b.BaseId == aircraftParameter.AirportId);
- string content = HttpManager.Get(HttpInterface.routes, new List<string>
- {
- "fName"
- }, new List<string>
- {
- config.XHTask.airroute[0].AirRouteName
- });
- var routes = JsonHelper.FromJson<RouteDB>(content);
- //routes.data.lstPoints => AirRoute[]
- AirRoute[] airRoutes = new AirRoute[routes.data[0].lstPoints.Count];
- for (int j = 0; j < routes.data[0].lstPoints.Count; j++)
- {
- airRoutes[j] = new AirRoute
- {
- AirRouteLongitude = routes.data[0].lstPoints[j].lon,
- AirRouteLatitude = routes.data[0].lstPoints[j].lat,
- AirRouteHeight = routes.data[0].lstPoints[j].dem
- };
- }
- //创建飞行计划编辑器
- var flightPlanEditor = FlightPlanEditor.Create(aircraftParameter, config.EditorConfig.cityWeather, originBase, airRoutes, config.XHTask.MissionPoints[0], new[] { point });
- AircraftXH aircraft = ComponentFactory.Create<AircraftXH, FlightPlanEditor, string, string>(flightPlanEditor,
- config.XHTask.aircraftInfos[i].AircraftType, config.XHTask.aircraftInfos[i].AircraftId);
- aircraft.TaskReadyTime = config.XHTask.missionInformation.TakeoffPreparationTime;
- Log.Info($"Name:{config.XHTask.missionInformation.MissionName} AircraftId:{config.XHTask.aircraftInfos[i].AircraftId}");
- mission.AircraftXHs.Add(aircraft);
- mission.End += aircraft.End;
- aircraft.AddComponent<XHStaticCapacityComponent>();
- aircraft.AddComponent<XHEconomicalComponent>();
- Log.Info($"创建机型 : {flightPlanEditor.aircraftparameter.AircraftID}");
- }
- return UniTask.CompletedTask;
- }
- }
- [Event]
- public class CreateSeaSJEventHandler : AEvent<CreateSeaSJTask>
- {
- protected override UniTask Run(CreateSeaSJTask config)
- {
- var taskSys = Game.Scene.GetComponent<TaskComponent>();
- SeaSJRescueMission mission = ComponentFactory.Create<SeaSJRescueMission>();
- taskSys.SeaSJRescueMissions.Add(mission);
- mission.MissionId = $"海上搜索救援任务 {config.SeaSJTask.missionInformation.MissionName}";
- mission.ExecutionContext = config.EditorConfig.runCounts;
- mission.AddComponent<SJTotalTaskPerformanceComponent>();
- for (int i = 0; i < config.SeaSJTask.aircraftInfos.Length; i++)
- {
- //飞机参数
- var aircraftParameter = config.EditorConfig.aircraftParameters.Find(
- a => a.AircraftID == config.SeaSJTask.aircraftInfos[i].AircraftType);
- //基地
- var originBase = config.EditorConfig.bases.Find(b => b.BaseId == aircraftParameter.AirportId);
- TargetPoint targetPoint = config.EditorConfig.targetPoints.Find(t => t.TargetPointId == config.SeaSJTask.missionInformation.TargetPointId);
- //创建飞行计划编辑器
- var flightPlanEditor = FlightPlanEditor.Create(aircraftParameter, config.EditorConfig.cityWeather, originBase, new TargetPoint[] { targetPoint });
- AircraftSJ aircraft = ComponentFactory.Create<AircraftSJ, FlightPlanEditor>(flightPlanEditor);
- aircraft.Name = config.SeaSJTask.aircraftInfos[i].AircraftType;
- aircraft.TaskReadyTime = config.SeaSJTask.missionInformation.TakeoffPreparationTime;
- mission.aircrafts.Add(aircraft);
- aircraft.taskContent = config.SeaSJTask;
- aircraft.AircraftId = config.SeaSJTask.aircraftInfos[i].AircraftId;
- foreach (var item in config.SeaSJTask.SearchModes)
- {
- if (aircraft.AircraftId == item.AircraftId)
- aircraft.SearchMode = item;
- }
- aircraft.AddComponent<SJStaticCapacityComponent>();
- Log.Info($"创建机型 : {flightPlanEditor.aircraftparameter.AircraftID}");
- }
- return UniTask.CompletedTask;
- }
- }
- [Event]
- public class CreateLandSJEventHandler : AEvent<CreateLandSXTask>
- {
- protected override UniTask Run(CreateLandSXTask config)
- {
- var taskSys = Game.Scene.GetComponent<TaskComponent>();
- LandSJRescueMission mission = ComponentFactory.Create<LandSJRescueMission>();
- taskSys.LandSJRescueMissions.Add(mission);
- mission.MissionId = $"陆上搜索救援任务 {config.LandSXTask.missionInformation.MissionName}";
- mission.ExecutionContext = config.EditorConfig.runCounts;
- //mission.AddComponent<SJTotalTaskPerformanceComponent>();
- for (int i = 0; i < config.LandSXTask.aircraftInfos.Length; i++)
- {
- //飞机参数
- var aircraftParameter = config.EditorConfig.aircraftParameters.Find(
- a => a.AircraftID == config.LandSXTask.aircraftInfos[i].AircraftType);
- //基地
- var originBase = config.EditorConfig.bases.Find(b => b.BaseId == aircraftParameter.AirportId);
- TargetPoint targetPoint = config.EditorConfig.targetPoints.Find(t => t.TargetPointId == config.LandSXTask.missionInformation.TargetPointId);
- //创建飞行计划编辑器
- var flightPlanEditor = FlightPlanEditor.Create(aircraftParameter, config.EditorConfig.cityWeather, originBase, new TargetPoint[] { targetPoint });
- AircraftLandSJ aircraft = ComponentFactory.Create<AircraftLandSJ, FlightPlanEditor>(flightPlanEditor);
- aircraft.Name = config.LandSXTask.aircraftInfos[i].AircraftType;
- aircraft.TaskReadyTime = config.LandSXTask.missionInformation.TakeoffPreparationTime;
- mission.aircrafts.Add(aircraft);
- aircraft.taskContent = config.LandSXTask;
- aircraft.AircraftId = config.LandSXTask.aircraftInfos[i].AircraftId;
- aircraft.MissionEndPoint = new MissionEndPoint
- {
- MissionEndPointLongitude = targetPoint.TargetPointLongitude,
- MissionEndPointLatitude = targetPoint.TargetPointLatitude,
- MissionEndPointHeight = targetPoint.TargetPointHeight
- };
- foreach (var item in config.LandSXTask.SearchModes)
- {
- if (item.AircraftId == aircraft.AircraftId)
- aircraft.SearchMissionMode = item;
- }
- aircraft.AddComponent<SJStaticCapacityComponent>(); // 陆上搜救是否需要新建SJStaticCapacityComponent?
- Log.Info($"创建机型 : {flightPlanEditor.aircraftparameter.AircraftID}");
- }
- return UniTask.CompletedTask;
- }
- }
|