ServerStartEventHandler.cs 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  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 Define = SimulationServer.Utils.Define;
  9. namespace SimulationServer;
  10. [Event]
  11. public class ServerStartEventHandler : AEvent<ServerStart>
  12. {
  13. protected override UniTask Run(ServerStart a)
  14. {
  15. Log.Info("读取配置文件!");
  16. var taskSys = Game.Scene.GetComponent<TaskComponent>();
  17. HttpInterface.serverIp = File.ReadAllText("dbIp.txt");
  18. SimulationCommon.Util.serverIp = HttpInterface.serverIp;
  19. // 读取任务配置文件
  20. string ec_path = "Missions/editor_config.json";
  21. string tc_path = "Missions/task_config.json";
  22. if (!File.Exists(ec_path))
  23. {
  24. Log.Error("editor_config.json文件不存在!");
  25. return UniTask.CompletedTask;
  26. }
  27. if (!File.Exists(tc_path))
  28. {
  29. Log.Error("task_config.json文件不存在!");
  30. return UniTask.CompletedTask;
  31. }
  32. string ec_str = File.ReadAllText("Missions/editor_config.json");
  33. string tc_str = File.ReadAllText("Missions/task_config.json");
  34. //Console.WriteLine(ec_str);
  35. //Console.WriteLine(tc_str);
  36. EditorConfig? editorConfig = JsonConvert.DeserializeObject<EditorConfig>(ec_str);
  37. TaskConfig? taskConfig = JsonConvert.DeserializeObject<TaskConfig>(tc_str);
  38. //int index = 0;
  39. //foreach (var item in taskConfig.LandSouJiuTasks)
  40. //{
  41. // index++;
  42. // foreach (var item1 in item.missionInformation.aircraftInfos)
  43. // {
  44. // Console.WriteLine("应用机型" + index + ":" + item1.AircraftType);
  45. // }
  46. // if (item.SearchMode.poly != null)
  47. // foreach (var item1 in item.SearchMode.poly)
  48. // {
  49. // foreach (var item2 in item1)
  50. // {
  51. // Console.WriteLine("多边形边界" + index + ":" + item2);
  52. // }
  53. // }
  54. //}
  55. //foreach (var item in editorConfig.bases)
  56. //{
  57. // Console.WriteLine("位置信息:" + item.BasePositionInfo);
  58. //}
  59. if (editorConfig == null || taskConfig == null)
  60. {
  61. Log.Error("配置文件解析失败!");
  62. return UniTask.CompletedTask;
  63. }
  64. //Weather weather = Util.GetWeather("内蒙古", "根河", DateTime.Now.ToString("2024-05-10"));
  65. TaskComponent.Weather = new Weather();
  66. var temp = TaskComponent.Weather.day_temp.Replace("°C", "");
  67. Define.TEMPERATURE = double.Parse(temp);
  68. var wind_temp = TaskComponent.Weather.day_wind_comp.Replace("级", "").Split('-');
  69. Define.WIND = double.Parse(wind_temp[0]);
  70. // 创建灭火
  71. foreach (var mhTask in taskConfig.mHTaskConfigs)
  72. {
  73. Game.EventSystem.Publish(new CreateMHTask
  74. { EditorConfig = editorConfig, MHTaskConfig = mhTask });
  75. }
  76. // 创建侦察
  77. foreach (var zcTask in taskConfig.zCTask)
  78. {
  79. Game.EventSystem.Publish(new CreateZCTask
  80. { EditorConfig = editorConfig, ZCTask = zcTask });
  81. }
  82. // 创建巡护
  83. foreach (var xhTask in taskConfig.xHTask)
  84. {
  85. Game.EventSystem.Publish(new CreateXHTask
  86. { EditorConfig = editorConfig, XHTask = xhTask });
  87. }
  88. //Console.WriteLine("taskConfig.seaSouJiuTasks.Count:" + taskConfig.seaSouJiuTasks.Count);
  89. //创建搜救
  90. foreach (var seaSJTask in taskConfig.seaSouJiuTasks)
  91. {
  92. //Console.WriteLine("seaSJTask.missionInformation.MissionName:" + seaSJTask.missionInformation.MissionName);
  93. //Console.WriteLine("TargetPointId:" + seaSJTask.TargetPointId);
  94. //Console.WriteLine("SearchPayload:" + seaSJTask.SearchPayload);
  95. //Console.WriteLine("SearchMode:" + seaSJTask.SearchMode);
  96. //Console.WriteLine("RadarTransmitterPower:" + seaSJTask.RadarTransmitterPower);
  97. //Console.WriteLine("仿真次数:" + editorConfig.runCounts);
  98. Game.EventSystem.Publish(new CreateSeaSJTask
  99. { EditorConfig = editorConfig, SeaSJTask = seaSJTask });
  100. }
  101. //foreach (var landSJTask in taskConfig.LandSouJiuTasks)
  102. //{
  103. // Game.EventSystem.Publish(new CreateLandSJTask
  104. // { EditorConfig = editorConfig, LandSJTask = landSJTask });
  105. //}
  106. taskSys.ExecutionContext = editorConfig.runCounts;
  107. taskSys.Start();
  108. return UniTask.CompletedTask;
  109. }
  110. }