ServerStartEventHandler.cs 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  1. using Cysharp.Threading.Tasks;
  2. using KYFramework;
  3. using Model;
  4. using Newtonsoft.Json;
  5. using SimulationServer.Utils;
  6. using SimulationSingleServer.Utils;
  7. using static Org.BouncyCastle.Math.EC.ECCurve;
  8. using static System.Runtime.InteropServices.JavaScript.JSType;
  9. using Define = SimulationServer.Utils.Define;
  10. namespace SimulationServer;
  11. [Event]
  12. public class ServerStartEventHandler : AEvent<ServerStart>
  13. {
  14. protected override UniTask Run(ServerStart a)
  15. {
  16. Log.Info("读取配置文件!");
  17. var taskSys = Game.Scene.GetComponent<TaskComponent>();
  18. taskSys.date = DateTime.Now.ToString().Replace("/","-").Replace(":","-").Replace(" ","-");
  19. //Console.WriteLine("date:" + taskSys.date);
  20. HttpInterface.serverIp = File.ReadAllText("dbIp.txt");
  21. SimulationCommon.Util.serverIp = HttpInterface.serverIp;
  22. // 读取任务配置文件
  23. string ec_path = "Missions/editor_config.json";
  24. string tc_path = "Missions/task_config.json";
  25. if (!File.Exists(ec_path))
  26. {
  27. Log.Error("editor_config.json文件不存在!");
  28. return UniTask.CompletedTask;
  29. }
  30. if (!File.Exists(tc_path))
  31. {
  32. Log.Error("task_config.json文件不存在!");
  33. return UniTask.CompletedTask;
  34. }
  35. string ec_str = File.ReadAllText("Missions/editor_config.json");
  36. string tc_str = File.ReadAllText("Missions/task_config.json");
  37. //Console.WriteLine(ec_str);
  38. //Console.WriteLine(tc_str);
  39. EditorConfig? editorConfig = JsonConvert.DeserializeObject<EditorConfig>(ec_str);
  40. TaskConfig? taskConfig = JsonConvert.DeserializeObject<TaskConfig>(tc_str);
  41. //int index = 0;
  42. //foreach (var item in taskConfig.LandSouJiuTasks)
  43. //{
  44. // index++;
  45. // foreach (var item1 in item.missionInformation.aircraftInfos)
  46. // {
  47. // Console.WriteLine("应用机型" + index + ":" + item1.AircraftType);
  48. // }
  49. // if (item.SearchMode.poly != null)
  50. // foreach (var item1 in item.SearchMode.poly)
  51. // {
  52. // foreach (var item2 in item1)
  53. // {
  54. // Console.WriteLine("多边形边界" + index + ":" + item2);
  55. // }
  56. // }
  57. //}
  58. //foreach (var item in editorConfig.bases)
  59. //{
  60. // Console.WriteLine("位置信息:" + item.BasePositionInfo);
  61. //}
  62. if (editorConfig == null || taskConfig == null)
  63. {
  64. Log.Error("配置文件解析失败!");
  65. return UniTask.CompletedTask;
  66. }
  67. foreach (var item in editorConfig.targetPoints)
  68. {
  69. if (item.TargetType.Type == "遇险人员" || item.TargetType.Type == "车辆" || item.TargetType.Type == "航空器")
  70. {
  71. taskSys.isLand = true;
  72. }
  73. else if (item.TargetType.Type == "落水人员" || item.TargetType.Type == "救生筏" || item.TargetType.Type == "船舶" || item.TargetType.Type == "大规模落水人群")
  74. {
  75. taskSys.isSea = true;
  76. }
  77. //Console.WriteLine("taskSys.isLand:" + taskSys.isLand + "_" + "taskSys.isSea:" + taskSys.isSea);
  78. break;
  79. }
  80. //Weather weather = Util.GetWeather("内蒙古", "根河", DateTime.Now.ToString("2024-05-10"));
  81. TaskComponent.Weather = new Weather();
  82. var temp = TaskComponent.Weather.day_temp.Replace("°C", "");
  83. Define.TEMPERATURE = double.Parse(temp);
  84. var wind_temp = TaskComponent.Weather.day_wind_comp.Replace("级", "").Split('-');
  85. Define.WIND = double.Parse(wind_temp[0]);
  86. //// 创建灭火
  87. //foreach (var mhTask in taskConfig.mHTaskConfigs)
  88. //{
  89. // Game.EventSystem.Publish(new CreateMHTask
  90. // { EditorConfig = editorConfig, MHTaskConfig = mhTask });
  91. //}
  92. //// 创建侦察
  93. //foreach (var zcTask in taskConfig.zCTask)
  94. //{
  95. // Game.EventSystem.Publish(new CreateZCTask
  96. // { EditorConfig = editorConfig, ZCTask = zcTask });
  97. //}
  98. //// 创建巡护
  99. //foreach (var xhTask in taskConfig.xHTask)
  100. //{
  101. // Game.EventSystem.Publish(new CreateXHTask
  102. // { EditorConfig = editorConfig, XHTask = xhTask });
  103. //}
  104. //Console.WriteLine("taskConfig.seaSouJiuTasks.Count:" + taskConfig.seaSouJiuTasks.Count);
  105. //创建搜救
  106. foreach (var seaSJTask in taskConfig.seaSouJiuTasks)
  107. {
  108. //Console.WriteLine("seaSJTask.missionInformation.MissionName:" + seaSJTask.missionInformation.MissionName);
  109. //Console.WriteLine("TargetPointId:" + seaSJTask.TargetPointId);
  110. //Console.WriteLine("SearchPayload:" + seaSJTask.SearchPayload);
  111. //Console.WriteLine("SearchMode:" + seaSJTask.SearchMode);
  112. //Console.WriteLine("RadarTransmitterPower:" + seaSJTask.RadarTransmitterPower);
  113. //Console.WriteLine("仿真次数:" + editorConfig.runCounts);
  114. Game.EventSystem.Publish(new CreateSeaSJTask
  115. { EditorConfig = editorConfig, SeaSJTask = seaSJTask });
  116. //break;
  117. }
  118. //foreach (var landSXTask in taskConfig.LandSouXunTasks)
  119. //{
  120. // Game.EventSystem.Publish(new CreateLandSXTask
  121. // { EditorConfig = editorConfig, LandSXTask = landSXTask });
  122. // //break;
  123. //}
  124. //创建空中吊运救援任务
  125. foreach (var KZDYTask in taskConfig.KZDYTasks)
  126. {
  127. Game.EventSystem.Publish(new CreateKZDYTask
  128. { EditorConfig = editorConfig, KZDYTask = KZDYTask });
  129. //break;
  130. }
  131. ////创建空投空送任务
  132. //foreach (var KTKSTask in taskConfig.KTKSTasks)
  133. //{
  134. // Game.EventSystem.Publish(new CreateKTKSTask
  135. // { EditorConfig = editorConfig, KTKSTask = KTKSTask });
  136. // //break;
  137. //}
  138. ////创建着水救援任务
  139. //foreach (var ZSJYTask in taskConfig.ZSJYTasks)
  140. //{
  141. // Game.EventSystem.Publish(new CreateZSJYTask
  142. // { EditorConfig = editorConfig, ZSJYTask = ZSJYTask });
  143. // //break;
  144. //}
  145. ////创建机降救援任务
  146. //foreach (var JJJYTask in taskConfig.JJJYTasks)
  147. //{
  148. // Game.EventSystem.Publish(new CreateJJJYTask
  149. // { EditorConfig = editorConfig, JJJYTask = JJJYTask });
  150. // //break;
  151. //}
  152. ////创建索滑降救援任务
  153. //foreach (var SHJTask in taskConfig.SHJTasks)
  154. //{
  155. // Game.EventSystem.Publish(new CreateSHJTask
  156. // { EditorConfig = editorConfig, SHJTask = SHJTask });
  157. // //break;
  158. //}
  159. taskSys.ExecutionContext = editorConfig.runCounts;
  160. taskSys.Start();
  161. return UniTask.CompletedTask;
  162. }
  163. }