ServerStartEventHandler.cs 3.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  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(tc_str);
  35. EditorConfig? editorConfig = JsonConvert.DeserializeObject<EditorConfig>(ec_str);
  36. TaskConfig? taskConfig = JsonConvert.DeserializeObject<TaskConfig>(tc_str);
  37. if (editorConfig == null || taskConfig == null)
  38. {
  39. Log.Error("配置文件解析失败!");
  40. return UniTask.CompletedTask;
  41. }
  42. //Weather weather = Util.GetWeather("内蒙古", "根河", DateTime.Now.ToString("2024-05-10"));
  43. TaskComponent.Weather = new Weather();
  44. var temp = TaskComponent.Weather.day_temp.Replace("°C", "");
  45. Define.TEMPERATURE = double.Parse(temp);
  46. var wind_temp = TaskComponent.Weather.day_wind_comp.Replace("级", "").Split('-');
  47. Define.WIND = double.Parse(wind_temp[0]);
  48. // 创建灭火
  49. foreach (var mhTask in taskConfig.mHTaskConfigs)
  50. {
  51. Game.EventSystem.Publish(new CreateMHTask
  52. { EditorConfig = editorConfig, MHTaskConfig = mhTask });
  53. }
  54. // 创建侦察
  55. foreach (var zcTask in taskConfig.zCTask)
  56. {
  57. Game.EventSystem.Publish(new CreateZCTask
  58. { EditorConfig = editorConfig, ZCTask = zcTask });
  59. }
  60. // 创建巡护
  61. foreach (var xhTask in taskConfig.xHTask)
  62. {
  63. Game.EventSystem.Publish(new CreateXHTask
  64. { EditorConfig = editorConfig, XHTask = xhTask });
  65. }
  66. //Console.WriteLine("taskConfig.seaSouJiuTasks.Count:" + taskConfig.seaSouJiuTasks.Count);
  67. //创建搜救
  68. foreach (var seaSJTask in taskConfig.seaSouJiuTasks)
  69. {
  70. //Console.WriteLine("seaSJTask.missionInformation.MissionName:" + seaSJTask.missionInformation.MissionName);
  71. //Console.WriteLine("TargetPointId:" + seaSJTask.TargetPointId);
  72. //Console.WriteLine("SearchPayload:" + seaSJTask.SearchPayload);
  73. //Console.WriteLine("SearchMode:" + seaSJTask.SearchMode);
  74. //Console.WriteLine("RadarTransmitterPower:" + seaSJTask.RadarTransmitterPower);
  75. //Console.WriteLine("仿真次数:" + editorConfig.runCounts);
  76. Game.EventSystem.Publish(new CreateSeaSJTask
  77. { EditorConfig = editorConfig, SeaSJTask = seaSJTask });
  78. }
  79. taskSys.ExecutionContext = editorConfig.runCounts;
  80. taskSys.Start();
  81. return UniTask.CompletedTask;
  82. }
  83. }