CreateTaskEventHandler.cs 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355
  1. using Cysharp.Threading.Tasks;
  2. using KYFramework;
  3. using Model;
  4. using SimulationServer.Utils;
  5. using SimulationSingleServer.Utils;
  6. using Unity.Mathematics;
  7. namespace SimulationServer;
  8. [Event]
  9. public class CreateMHTaskEventHandler : AEvent<CreateMHTask>
  10. {
  11. protected override UniTask Run(CreateMHTask config)
  12. {
  13. // TODO 创建灭火任务
  14. var taskSys = Game.Scene.GetComponent<TaskComponent>();
  15. FirePoint point = config.EditorConfig.firePoints.Find(fire => fire.FirePointId == config.MHTaskConfig.FirePointId);
  16. // 创建火点
  17. var fireGround = ComponentFactory.Create<FireGround, FirePoint>(point);
  18. fireGround.FirePointName = point.FirePointId;
  19. // 创建灭火任务
  20. var mission = ComponentFactory.Create<MHRescueMission, FireGround, double>(fireGround, point.InitialArea);
  21. mission.AddComponent<TotalEconomicalComponent>();
  22. mission.AddComponent<TotalTaskPerformanceComponent>();
  23. mission.AddComponent<EquipmentComponent>();
  24. mission.MissionId = "灭火任务 " + config.MHTaskConfig.TotalMHId;
  25. taskSys.MHRescueMissions.Add(mission);
  26. //查询坡度
  27. mission.slope = Util.GetSlope(point.FirePointLongitude,
  28. point.FirePointLatitude, 30);
  29. Log.Info($"创建任务 : {config.MHTaskConfig.TotalMHId}");
  30. //创建吊桶灭火任务
  31. foreach (MHTask mhTask in config.MHTaskConfig.mHTask)
  32. {
  33. Log.Info($"创建灭火任务 : {mhTask.missionInformation.MissionName}");
  34. if (mhTask.aircraftInfos == null) continue;
  35. for (int i = 0; i < mhTask.aircraftInfos.Length; i++)
  36. {
  37. //飞机参数
  38. var aircraftParameter = config.EditorConfig.aircraftParameters.Find(
  39. a => a.AircraftID == mhTask.aircraftInfos[i].AircraftType);
  40. //基地
  41. var originBase = config.EditorConfig.bases.Find(b => b.BaseId == aircraftParameter.AirportId);
  42. //创建飞行计划编辑器
  43. var flightPlanEditor = FlightPlanEditor.Create(aircraftParameter, config.EditorConfig.cityWeather, originBase, mhTask.MissionPoints[0], new[] { point });
  44. AircraftMH aircraft = ComponentFactory.Create<AircraftMH, FlightPlanEditor>(flightPlanEditor);
  45. aircraft.Name = mhTask.aircraftInfos[i].AircraftType;
  46. aircraft.AircraftId = mhTask.aircraftInfos[i].AircraftId;
  47. aircraft.fireGround = fireGround;
  48. aircraft.mhRescueMission = mission;
  49. mission.aircrafts.Add(aircraft);
  50. aircraft.Airport = flightPlanEditor.originbase.BaseName;
  51. aircraft.TaskName = mhTask.missionInformation.MissionName;
  52. mission.End += aircraft.End;
  53. aircraft.AddComponent<StaticCapacityComponent>();
  54. aircraft.AddComponent<TaskPerformanceComponent>();
  55. aircraft.AddComponent<EconomicalComponent>();
  56. aircraft.TaskReadyTime = mhTask.missionInformation.TakeoffPreparationTime;
  57. Log.Info($"创建机型 : {flightPlanEditor.aircraftparameter.AircraftID}");
  58. }
  59. }
  60. //创建机降灭火任务
  61. foreach (DMMHTask dmmhTask in config.MHTaskConfig.dMMHTask)
  62. {
  63. Log.Info($"创建地面灭火任务 : {dmmhTask.missionInformation.MissionName}");
  64. if (dmmhTask.aircraftInfos == null) continue;
  65. for (int i = 0; i < dmmhTask.aircraftInfos.Length; i++)
  66. {
  67. //飞机参数
  68. var aircraftParameter = config.EditorConfig.aircraftParameters.Find(
  69. a => a.AircraftID == dmmhTask.aircraftInfos[i].AircraftType);
  70. //基地
  71. var originBase = config.EditorConfig.bases.Find(b => b.BaseId == aircraftParameter.AirportId);
  72. //创建飞行计划编辑器
  73. var flightPlanEditor = FlightPlanEditor.Create(aircraftParameter, config.EditorConfig.cityWeather, originBase, dmmhTask.MissionPoints[0], new[] { point });
  74. AircraftMHWithPersion aircraftWithPerson = ComponentFactory.Create<AircraftMHWithPersion, FlightPlanEditor>(flightPlanEditor);
  75. mission.End += aircraftWithPerson.End;
  76. aircraftWithPerson.Name = dmmhTask.aircraftInfos[i].AircraftType;
  77. aircraftWithPerson.fireGround = fireGround;
  78. aircraftWithPerson.mhRescueMission = mission;
  79. aircraftWithPerson.GroundPersonnel = (int)dmmhTask.GroundPersonnel;
  80. aircraftWithPerson.LandingPersonnel = (int)dmmhTask.LandingPersonnel;
  81. aircraftWithPerson.NextMissionId = dmmhTask.NextTaskId;
  82. aircraftWithPerson.TaskName = dmmhTask.missionInformation.MissionName;
  83. aircraftWithPerson.TaskReadyTime = dmmhTask.missionInformation.TakeoffPreparationTime;
  84. aircraftWithPerson.AircraftId = dmmhTask.aircraftInfos[i].AircraftId;
  85. mission.aircrafts.Add(aircraftWithPerson);
  86. Log.Info($"创建机型 : {flightPlanEditor.aircraftparameter.AircraftID}");
  87. }
  88. }
  89. //创建索滑降任务
  90. foreach (SHJTask shjTask in config.MHTaskConfig.sHJTask)
  91. {
  92. Log.Info($"创建索滑降任务 : {shjTask.missionInformation.MissionName}");
  93. if (shjTask.aircraftInfos == null) continue;
  94. for (int i = 0; i < shjTask.aircraftInfos.Length; i++)
  95. {
  96. //飞机参数
  97. var aircraftParameter = config.EditorConfig.aircraftParameters.Find(
  98. a => a.AircraftID == shjTask.aircraftInfos[i].AircraftType);
  99. //基地
  100. var originBase = config.EditorConfig.bases.Find(b => b.BaseId == aircraftParameter.AirportId);
  101. MissionPoint missionPoint = null;
  102. foreach (var item in shjTask.SHJParameters)
  103. {
  104. if (aircraftParameter.Id == item.AircraftId)
  105. missionPoint = item.MissionPoints[0];
  106. }
  107. //创建飞行计划编辑器
  108. var flightPlanEditor = FlightPlanEditor.Create(aircraftParameter, config.EditorConfig.cityWeather, originBase, missionPoint, new[] { point });
  109. AircraftSHJ aircraftSHJ = ComponentFactory.Create<AircraftSHJ, FlightPlanEditor, SHJTask>(flightPlanEditor, shjTask);
  110. mission.End += aircraftSHJ.End;
  111. aircraftSHJ.AircraftId = shjTask.aircraftInfos[i].AircraftId;
  112. aircraftSHJ.TaskReadyTime = shjTask.missionInformation.TakeoffPreparationTime;
  113. foreach (var item in config.MHTaskConfig.sHJTask)
  114. {
  115. foreach (var item1 in item.SHJParameters)
  116. {
  117. if (aircraftSHJ.AircraftId == item1.AircraftId)
  118. {
  119. aircraftSHJ.SHJParameter = item1;
  120. }
  121. }
  122. }
  123. mission.aircrafts.Add(aircraftSHJ);
  124. Log.Info($"创建机型 : {flightPlanEditor.aircraftparameter.AircraftID}");
  125. }
  126. }
  127. return UniTask.CompletedTask;
  128. }
  129. }
  130. [Event]
  131. public class CreateZCTaskEventHandler : AEvent<CreateZCTask>
  132. {
  133. protected override UniTask Run(CreateZCTask config)
  134. {
  135. var taskSys = Game.Scene.GetComponent<TaskComponent>();
  136. ZCRescueMission mission = ComponentFactory.Create<ZCRescueMission>();
  137. taskSys.ZCRescueMissions.Add(mission);
  138. mission.MissionId = $"侦擦任务 {config.ZCTask.missionInformation.MissionName}";
  139. FirePoint point = config.EditorConfig.firePoints.Find(f => f.FirePointId == config.ZCTask.FirePointId);
  140. for (int i = 0; i < config.ZCTask.aircraftInfos.Length; i++)
  141. {
  142. //飞机参数
  143. var aircraftParameter = config.EditorConfig.aircraftParameters.Find(
  144. a => a.AircraftID == config.ZCTask.aircraftInfos[i].AircraftType);
  145. //基地
  146. var originBase = config.EditorConfig.bases.Find(b => b.BaseId == aircraftParameter.AirportId);
  147. //创建飞行计划编辑器
  148. var flightPlanEditor = FlightPlanEditor.Create(aircraftParameter, config.EditorConfig.cityWeather, originBase, config.ZCTask.MissionPoints[0], new[] { point });
  149. //创建飞机
  150. int index = i;
  151. AircraftZC aircraft = ComponentFactory.Create<AircraftZC, FlightPlanEditor, ZCTask, int>(flightPlanEditor, config.ZCTask, index);
  152. aircraft.AddComponent<StaticCapacityComponent>();
  153. aircraft.AddComponent<TaskPerformanceComponent>();
  154. aircraft.AddComponent<EconomicalComponent>();
  155. aircraft.TaskReadyTime = config.ZCTask.missionInformation.TakeoffPreparationTime;
  156. aircraft.AircraftId = config.ZCTask.aircraftInfos[i].AircraftId;
  157. foreach (var item in config.ZCTask.ZCMethods)
  158. {
  159. if(aircraft.AircraftId == item.AircraftId)
  160. {
  161. aircraft.ZCMethod = item;
  162. }
  163. }
  164. Log.Info($"创建机型 : {flightPlanEditor.aircraftparameter.AircraftID}");
  165. mission.AircraftZCs.Add(aircraft);
  166. }
  167. return UniTask.CompletedTask;
  168. }
  169. }
  170. [Event]
  171. public class CreateXHTaskEventHandler : AEvent<CreateXHTask>
  172. {
  173. protected override UniTask Run(CreateXHTask config)
  174. {
  175. // TODO 创建巡护任务
  176. var taskSys = Game.Scene.GetComponent<TaskComponent>();
  177. XHRescueMission mission = ComponentFactory.Create<XHRescueMission>();
  178. mission.AddComponent<XHTotalTaskPerformanceComponent>();
  179. mission.AddComponent<EquipmentComponent>();
  180. mission.MissionId = $"巡护任务 {config.XHTask.missionInformation.MissionId}";
  181. taskSys.XHRescueMissions.Add(mission);
  182. FirePoint point = config.EditorConfig.firePoints.Find(f => f.FirePointId == config.XHTask.FirePointId);
  183. mission.FireGround = ComponentFactory.Create<FireGround, FirePoint>(point);
  184. for (int i = 0; i < config.XHTask.aircraftInfos.Length; i++)
  185. {
  186. //飞机参数
  187. var aircraftParameter = config.EditorConfig.aircraftParameters.Find(
  188. a => a.AircraftID == config.XHTask.aircraftInfos[i].AircraftType);
  189. //基地
  190. var originBase = config.EditorConfig.bases.Find(b => b.BaseId == aircraftParameter.AirportId);
  191. string content = HttpManager.Get(HttpInterface.routes, new List<string>
  192. {
  193. "fName"
  194. }, new List<string>
  195. {
  196. config.XHTask.airroute[0].AirRouteName
  197. });
  198. var routes = JsonHelper.FromJson<RouteDB>(content);
  199. //routes.data.lstPoints => AirRoute[]
  200. AirRoute[] airRoutes = new AirRoute[routes.data[0].lstPoints.Count];
  201. for (int j = 0; j < routes.data[0].lstPoints.Count; j++)
  202. {
  203. airRoutes[j] = new AirRoute
  204. {
  205. AirRouteLongitude = routes.data[0].lstPoints[j].lon,
  206. AirRouteLatitude = routes.data[0].lstPoints[j].lat,
  207. AirRouteHeight = routes.data[0].lstPoints[j].dem
  208. };
  209. }
  210. //创建飞行计划编辑器
  211. var flightPlanEditor = FlightPlanEditor.Create(aircraftParameter, config.EditorConfig.cityWeather, originBase, airRoutes, config.XHTask.MissionPoints[0], new[] { point });
  212. AircraftXH aircraft = ComponentFactory.Create<AircraftXH, FlightPlanEditor, string, string>(flightPlanEditor,
  213. config.XHTask.aircraftInfos[i].AircraftType, config.XHTask.aircraftInfos[i].AircraftId);
  214. aircraft.TaskReadyTime = config.XHTask.missionInformation.TakeoffPreparationTime;
  215. Log.Info($"Name:{config.XHTask.missionInformation.MissionName} AircraftId:{config.XHTask.aircraftInfos[i].AircraftId}");
  216. mission.AircraftXHs.Add(aircraft);
  217. mission.End += aircraft.End;
  218. aircraft.AddComponent<XHStaticCapacityComponent>();
  219. aircraft.AddComponent<XHEconomicalComponent>();
  220. Log.Info($"创建机型 : {flightPlanEditor.aircraftparameter.AircraftID}");
  221. }
  222. return UniTask.CompletedTask;
  223. }
  224. }
  225. [Event]
  226. public class CreateSeaSJEventHandler : AEvent<CreateSeaSJTask>
  227. {
  228. protected override UniTask Run(CreateSeaSJTask config)
  229. {
  230. var taskSys = Game.Scene.GetComponent<TaskComponent>();
  231. SeaSJRescueMission mission = ComponentFactory.Create<SeaSJRescueMission>();
  232. taskSys.SeaSJRescueMissions.Add(mission);
  233. mission.MissionId = $"海上搜索救援任务 {config.SeaSJTask.missionInformation.MissionName}";
  234. mission.ExecutionContext = config.EditorConfig.runCounts;
  235. mission.AddComponent<SJTotalTaskPerformanceComponent>();
  236. for (int i = 0; i < config.SeaSJTask.aircraftInfos.Length; i++)
  237. {
  238. //飞机参数
  239. var aircraftParameter = config.EditorConfig.aircraftParameters.Find(
  240. a => a.AircraftID == config.SeaSJTask.aircraftInfos[i].AircraftType);
  241. //基地
  242. var originBase = config.EditorConfig.bases.Find(b => b.BaseId == aircraftParameter.AirportId);
  243. TargetPoint targetPoint = config.EditorConfig.targetPoints.Find(t => t.TargetPointId == config.SeaSJTask.missionInformation.TargetPointId);
  244. //创建飞行计划编辑器
  245. var flightPlanEditor = FlightPlanEditor.Create(aircraftParameter, config.EditorConfig.cityWeather, originBase, new TargetPoint[] { targetPoint });
  246. AircraftSJ aircraft = ComponentFactory.Create<AircraftSJ, FlightPlanEditor>(flightPlanEditor);
  247. aircraft.Name = config.SeaSJTask.aircraftInfos[i].AircraftType;
  248. aircraft.TaskReadyTime = config.SeaSJTask.missionInformation.TakeoffPreparationTime;
  249. mission.aircrafts.Add(aircraft);
  250. aircraft.taskContent = config.SeaSJTask;
  251. aircraft.AircraftId = config.SeaSJTask.aircraftInfos[i].AircraftId;
  252. foreach (var item in config.SeaSJTask.SearchModes)
  253. {
  254. if (aircraft.AircraftId == item.AircraftId)
  255. aircraft.SearchMode = item;
  256. }
  257. aircraft.AddComponent<SJStaticCapacityComponent>();
  258. Log.Info($"创建机型 : {flightPlanEditor.aircraftparameter.AircraftID}");
  259. }
  260. return UniTask.CompletedTask;
  261. }
  262. }
  263. [Event]
  264. public class CreateLandSJEventHandler : AEvent<CreateLandSXTask>
  265. {
  266. protected override UniTask Run(CreateLandSXTask config)
  267. {
  268. var taskSys = Game.Scene.GetComponent<TaskComponent>();
  269. LandSJRescueMission mission = ComponentFactory.Create<LandSJRescueMission>();
  270. taskSys.LandSJRescueMissions.Add(mission);
  271. mission.MissionId = $"陆上搜索救援任务 {config.LandSXTask.missionInformation.MissionName}";
  272. mission.ExecutionContext = config.EditorConfig.runCounts;
  273. //mission.AddComponent<SJTotalTaskPerformanceComponent>();
  274. for (int i = 0; i < config.LandSXTask.aircraftInfos.Length; i++)
  275. {
  276. //飞机参数
  277. var aircraftParameter = config.EditorConfig.aircraftParameters.Find(
  278. a => a.AircraftID == config.LandSXTask.aircraftInfos[i].AircraftType);
  279. //基地
  280. var originBase = config.EditorConfig.bases.Find(b => b.BaseId == aircraftParameter.AirportId);
  281. TargetPoint targetPoint = config.EditorConfig.targetPoints.Find(t => t.TargetPointId == config.LandSXTask.missionInformation.TargetPointId);
  282. //创建飞行计划编辑器
  283. var flightPlanEditor = FlightPlanEditor.Create(aircraftParameter, config.EditorConfig.cityWeather, originBase, new TargetPoint[] { targetPoint });
  284. AircraftLandSJ aircraft = ComponentFactory.Create<AircraftLandSJ, FlightPlanEditor>(flightPlanEditor);
  285. aircraft.Name = config.LandSXTask.aircraftInfos[i].AircraftType;
  286. aircraft.TaskReadyTime = config.LandSXTask.missionInformation.TakeoffPreparationTime;
  287. mission.aircrafts.Add(aircraft);
  288. aircraft.taskContent = config.LandSXTask;
  289. aircraft.AircraftId = config.LandSXTask.aircraftInfos[i].AircraftId;
  290. aircraft.MissionEndPoint = new MissionEndPoint
  291. {
  292. MissionEndPointLongitude = targetPoint.TargetPointLongitude,
  293. MissionEndPointLatitude = targetPoint.TargetPointLatitude,
  294. MissionEndPointHeight = targetPoint.TargetPointHeight
  295. };
  296. foreach (var item in config.LandSXTask.SearchModes)
  297. {
  298. if (item.AircraftId == aircraft.AircraftId)
  299. aircraft.SearchMissionMode = item;
  300. }
  301. aircraft.AddComponent<SJStaticCapacityComponent>(); // 陆上搜救是否需要新建SJStaticCapacityComponent?
  302. Log.Info($"创建机型 : {flightPlanEditor.aircraftparameter.AircraftID}");
  303. }
  304. return UniTask.CompletedTask;
  305. }
  306. }