123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249 |
- using Cysharp.Threading.Tasks;
- using KYFramework;
- using Model;
- using MongoDB.Bson;
- using Newtonsoft.Json;
- using SimulationServer.Utils;
- namespace SimulationServer;
- [Event]
- public class ServerStartEventHandler : AEvent<ServerStart>
- {
- protected override UniTask Run(ServerStart a)
- {
- Log.Info("服务器启动完成!");
- var taskSys = Game.Scene.GetComponent<TaskComponent>();
- // 读取任务配置文件
- string ec_path = "Missions/editor_config.json";
- string tc_path = "Missions/task_config.json";
- if (!File.Exists(ec_path))
- {
- Log.Error("editor_config.json文件不存在!");
- return UniTask.CompletedTask;
- }
-
- if (!File.Exists(tc_path))
- {
- Log.Error("task_config.json文件不存在!");
- return UniTask.CompletedTask;
- }
-
- string ec_str = File.ReadAllText("Missions/editor_config.json");
- string tc_str = File.ReadAllText("Missions/task_config.json");
-
- EditorConfig? editorConfig = JsonConvert.DeserializeObject<EditorConfig>(ec_str);
- TaskConfig? taskConfig = JsonConvert.DeserializeObject<TaskConfig>(tc_str);
- if(editorConfig == null || taskConfig == null)
- {
- Log.Error("配置文件解析失败!");
- return UniTask.CompletedTask;
- }
-
- //Weather weather = Util.GetWeather("内蒙古", "根河", DateTime.Now.ToString("2024-05-10"));
- Weather weather = new Weather();
- foreach (MHTaskConfig mHTaskConfig in taskConfig.mHTaskConfigs)
- {
- RescueMission mission = ComponentFactory.Create<RescueMission>();
- mission.AddComponent<TotalTaskPerformanceComponent>();
- mission.AddComponent<TotalEconomicalComponent>();
- mission.AddComponent<EquipmentComponent>();
- taskSys.RescueMissions.Add(mission);
- mission.MissionId = $"灭火任务 {mHTaskConfig.TotalMHId}";
- mission.MissionType = "灭火";
- Log.Info($"创建任务 : {mHTaskConfig.TotalMHId}");
- double slope = Util.GetSlope(editorConfig.firePoints[mHTaskConfig.FirePointId - 1].FirePointLongitude,
- editorConfig.firePoints[mHTaskConfig.FirePointId - 1].FirePointLatitude, 30);
- FireGround fireGround = ComponentFactory.Create<FireGround>();
- mission.FireGround = fireGround;
- mission.InitArea = editorConfig.firePoints[mHTaskConfig.FirePointId - 1].InitialArea;
- Log.Info("初始火场面积:" + fireGround.countArea.burnarea);
- fireGround.FirePoint = new DVector { Latitude = editorConfig.firePoints[mHTaskConfig.FirePointId - 1].FirePointLatitude,
- Longitude = editorConfig.firePoints[mHTaskConfig.FirePointId - 1].FirePointLongitude,Altitude = editorConfig.firePoints[mHTaskConfig.FirePointId - 1].FirePointHeight};
-
-
- foreach (MHTask mhTask in mHTaskConfig.mHTask)
- {
- Log.Info($"创建灭火任务 : {mhTask.missionInformation.MissionName}");
- if(mhTask.missionInformation.AircraftInfos == null) continue;
- for (int i = 0; i < mhTask.missionInformation.AircraftInfos.Length; i++)
- {
- FlightPlanEditor? flightPlanEditor = new FlightPlanEditor();
-
- flightPlanEditor.aircraftparameter = editorConfig.aircraftParameters.Find( a => a.AircraftID == mhTask.missionInformation.AircraftInfos[i]);
- flightPlanEditor.firepoint = new FirePoint[1];
- flightPlanEditor.firepoint[0] = editorConfig.firePoints[mHTaskConfig.FirePointId - 1];
- flightPlanEditor.missionpoint = mhTask.MissionPoints[0];
- flightPlanEditor.originbase = editorConfig.bases.Find(b => b.BaseId == flightPlanEditor.aircraftparameter.AirportId);
- flightPlanEditor.climbsegment = editorConfig.climbSegment;
- flightPlanEditor.descentsegment = editorConfig.descentSegment;
- flightPlanEditor.cruisesegment = editorConfig.cruiseSegment;
- flightPlanEditor.cityweather = editorConfig.cityWeather;
-
- AircraftMH aircraft = ComponentFactory.Create<AircraftMH, FlightPlanEditor>( flightPlanEditor);
- aircraft.Name = mhTask.missionInformation.AircraftInfos[i];
- aircraft.NextMissionId = mhTask.NextTaskId;
- mission.Aircrafts.Add(aircraft);
- aircraft.aircraftparameter = flightPlanEditor.aircraftparameter;
- aircraft.Airport = flightPlanEditor.originbase.BaseName;
- aircraft.Weather = weather;
- aircraft.TaskName = mhTask.missionInformation.MissionName;
- aircraft.slope = slope;
- mission.End += aircraft.End;
- aircraft.AddComponent<StaticCapacityComponent>();
- aircraft.AddComponent<TaskPerformanceComponent>();
- aircraft.AddComponent<EconomicalComponent>();
-
- Log.Info($"创建机型 : {flightPlanEditor.aircraftparameter.AircraftID}");
- }
- }
- foreach (DMMHTask dmmhTask in mHTaskConfig.dMMHTask)
- {
- Log.Info($"创建地面灭火任务 : {dmmhTask.missionInformation.MissionName}");
- if(dmmhTask.missionInformation.AircraftInfos == null) continue;
- for (int i = 0; i < dmmhTask.missionInformation.AircraftInfos.Length; i++)
- {
- FlightPlanEditor? flightPlanEditor = new FlightPlanEditor();
-
- flightPlanEditor.aircraftparameter = editorConfig.aircraftParameters.Find( a => a.AircraftID == dmmhTask.missionInformation.AircraftInfos[i]);
- flightPlanEditor.firepoint = new FirePoint[1];
- flightPlanEditor.firepoint[0] = editorConfig.firePoints[mHTaskConfig.FirePointId - 1];
- flightPlanEditor.missionpoint = dmmhTask.MissionPoints[0];
- flightPlanEditor.originbase = editorConfig.bases.Find(b => b.BaseId == flightPlanEditor.aircraftparameter.AirportId);
- flightPlanEditor.climbsegment = editorConfig.climbSegment;
- flightPlanEditor.descentsegment = editorConfig.descentSegment;
- flightPlanEditor.cruisesegment = editorConfig.cruiseSegment;
- flightPlanEditor.cityweather = editorConfig.cityWeather;
-
- AircraftMHWithPersion aircraftWithPerson = ComponentFactory.Create<AircraftMHWithPersion, FlightPlanEditor>( flightPlanEditor);
- aircraftWithPerson.Weather = weather;
- mission.End += aircraftWithPerson.End;
- aircraftWithPerson.GroundPersonnel = (int)dmmhTask.GroundPersonnel;
- aircraftWithPerson.LandingPersonnel = (int)dmmhTask.LandingPersonnel;
- aircraftWithPerson.NextMissionId = dmmhTask.NextTaskId;
- aircraftWithPerson.TaskName = dmmhTask.missionInformation.MissionName;
- mission.AircraftWithPersions.Add(aircraftWithPerson);
-
- Log.Info($"创建机型 : {flightPlanEditor.aircraftparameter.AircraftID}");
- }
- }
- foreach (SHJTask shjTask in mHTaskConfig.sHJTask)
- {
- if(shjTask.missionInformation.AircraftInfos == null) continue;
- for (int i = 0; i < shjTask.missionInformation.AircraftInfos.Length; i++)
- {
- FlightPlanEditor? flightPlanEditor = new FlightPlanEditor();
- flightPlanEditor.aircraftparameter = editorConfig.aircraftParameters.Find(a =>
- a.AircraftID == shjTask.missionInformation.AircraftInfos[i]);
- flightPlanEditor.firepoint = new FirePoint[1];
- flightPlanEditor.firepoint[0] = editorConfig.firePoints[mHTaskConfig.FirePointId - 1];
- flightPlanEditor.missionpoint = shjTask.MissionPoints[0];
- flightPlanEditor.originbase =
- editorConfig.bases.Find(b => b.BaseId == flightPlanEditor.aircraftparameter.AirportId);
- flightPlanEditor.climbsegment = editorConfig.climbSegment;
- flightPlanEditor.descentsegment = editorConfig.descentSegment;
- flightPlanEditor.cruisesegment = editorConfig.cruiseSegment;
- flightPlanEditor.cityweather = editorConfig.cityWeather;
- AircraftSHJ aircraftSHJ = ComponentFactory.Create<AircraftSHJ, FlightPlanEditor,SHJTask>( flightPlanEditor, shjTask);
- mission.End += aircraftSHJ.End;
- mission.AircraftSHJs.Add(aircraftSHJ);
- }
- }
- }
- foreach (ZCTask zcTask in taskConfig.zCTask)
- {
- RescueMission mission = ComponentFactory.Create<RescueMission>();
- taskSys.RescueMissions.Add(mission);
- //mission.MissionId = zcTask.TotalZCId;
- mission.MissionId = $"侦擦任务 {zcTask.missionInformation.MissionId}";
- FireGround fireGround = ComponentFactory.Create<FireGround>();
- fireGround.countArea.burnarea = editorConfig.firePoints[zcTask.FirePointId - 1].InitialArea;
- fireGround.FirePoint = new DVector
- {
- Latitude = editorConfig.firePoints[zcTask.FirePointId - 1].FirePointLatitude,
- Longitude = editorConfig.firePoints[zcTask.FirePointId - 1].FirePointLongitude,
- Altitude = editorConfig.firePoints[zcTask.FirePointId - 1].FirePointHeight
- };
- mission.InitArea = editorConfig.firePoints[zcTask.FirePointId - 1].InitialArea;
- if(zcTask.missionInformation.AircraftInfos == null) continue;
- for (int i = 0; i < zcTask.missionInformation.AircraftInfos.Length; i++)
- {
- FlightPlanEditor? flightPlanEditor = new FlightPlanEditor();
- flightPlanEditor.aircraftparameter =
- editorConfig.aircraftParameters.Find(
- a => a.AircraftID == zcTask.missionInformation.AircraftInfos[i]);
- flightPlanEditor.firepoint = new FirePoint[1];
- flightPlanEditor.firepoint[0] = editorConfig.firePoints[zcTask.FirePointId - 1];
- flightPlanEditor.missionpoint = zcTask.MissionPoints[0];
- flightPlanEditor.originbase =
- editorConfig.bases.Find(b => b.BaseId == flightPlanEditor.aircraftparameter.AirportId);
- flightPlanEditor.climbsegment = editorConfig.climbSegment;
- flightPlanEditor.descentsegment = editorConfig.descentSegment;
- flightPlanEditor.cruisesegment = editorConfig.cruiseSegment;
- flightPlanEditor.cityweather = editorConfig.cityWeather;
- AircraftZC aircraft = ComponentFactory.Create<AircraftZC, FlightPlanEditor,ZCTask>( flightPlanEditor, zcTask);
- //aircraft.Name = zcTask.missionInformation.AircraftInfos[i];
- //aircraft.NextMissionId = zcTask.NextTaskId;
- mission.End += aircraft.End;
- mission.AircraftZCs.Add(aircraft);
- }
- }
- foreach (XHTask xhTask in taskConfig.xHTask)
- {
- if(xhTask.MissionPoints == null) continue;
- RescueMission mission = ComponentFactory.Create<RescueMission>();
- mission.AddComponent<XHEconomicalComponent>();
- mission.AddComponent<XHTotalTaskPerformanceComponent>();
- mission.MissionId = $"巡护任务 {xhTask.missionInformation.MissionId}";
- taskSys.RescueMissions.Add(mission);
- FireGround fireGround = ComponentFactory.Create<FireGround>();
- mission.FireGround = fireGround;
- mission.InitArea = editorConfig.firePoints[xhTask.FirePointId - 1].InitialArea;
- fireGround.FirePoint = new DVector
- {
- Latitude = editorConfig.firePoints[xhTask.FirePointId - 1].FirePointLatitude,
- Longitude = editorConfig.firePoints[xhTask.FirePointId - 1].FirePointLongitude,
- Altitude = editorConfig.firePoints[xhTask.FirePointId - 1].FirePointHeight
- };
- if(xhTask.missionInformation.AircraftInfos == null) continue;
- for (int i = 0; i < xhTask.missionInformation.AircraftInfos.Length; i++)
- {
-
- FlightPlanEditor? flightPlanEditor = new FlightPlanEditor();
- flightPlanEditor.aircraftparameter = editorConfig.aircraftParameters.Find(a =>
- a.AircraftID == xhTask.missionInformation.AircraftInfos[i]);
- flightPlanEditor.firepoint = new FirePoint[1];
- flightPlanEditor.firepoint[0] = editorConfig.firePoints[xhTask.FirePointId - 1];
- flightPlanEditor.missionpoint = xhTask.MissionPoints[0];
- flightPlanEditor.originbase =
- editorConfig.bases.Find(b => b.BaseId == flightPlanEditor.aircraftparameter.AirportId);
- flightPlanEditor.climbsegment = editorConfig.climbSegment;
- flightPlanEditor.descentsegment = editorConfig.descentSegment;
- flightPlanEditor.cruisesegment = editorConfig.cruiseSegment;
- flightPlanEditor.cityweather = editorConfig.cityWeather;
- AircraftXH aircraft = ComponentFactory.Create<AircraftXH, FlightPlanEditor>( flightPlanEditor);
- //aircraft.Name = zcTask.missionInformation.AircraftInfos[i];
- //aircraft.NextMissionId = zcTask.NextTaskId;
- mission.AircraftXHs.Add(aircraft);
- mission.End += aircraft.End;
- aircraft.Weather = weather;
- aircraft.AddComponent<XHStaticCapacityComponent>();
- aircraft.AddComponent<XHEconomicalComponent>();
- }
- }
- taskSys.Start();
- return UniTask.CompletedTask;
- }
- }
|