123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122 |
- using Cysharp.Threading.Tasks;
- using KYFramework;
- using Model;
- using Newtonsoft.Json;
- using SimulationServer.Utils;
- using SimulationSingleServer.Utils;
- using static Org.BouncyCastle.Math.EC.ECCurve;
- using Define = SimulationServer.Utils.Define;
- namespace SimulationServer;
- [Event]
- public class ServerStartEventHandler : AEvent<ServerStart>
- {
- protected override UniTask Run(ServerStart a)
- {
- Log.Info("读取配置文件!");
- var taskSys = Game.Scene.GetComponent<TaskComponent>();
- HttpInterface.serverIp = File.ReadAllText("dbIp.txt");
- SimulationCommon.Util.serverIp = HttpInterface.serverIp;
- // 读取任务配置文件
- 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");
- //Console.WriteLine(ec_str);
- //Console.WriteLine(tc_str);
- EditorConfig? editorConfig = JsonConvert.DeserializeObject<EditorConfig>(ec_str);
- TaskConfig? taskConfig = JsonConvert.DeserializeObject<TaskConfig>(tc_str);
- //int index = 0;
- //foreach (var item in taskConfig.LandSouJiuTasks)
- //{
- // index++;
- // foreach (var item1 in item.missionInformation.aircraftInfos)
- // {
- // Console.WriteLine("应用机型" + index + ":" + item1.AircraftType);
- // }
- // if (item.SearchMode.poly != null)
- // foreach (var item1 in item.SearchMode.poly)
- // {
- // foreach (var item2 in item1)
- // {
- // Console.WriteLine("多边形边界" + index + ":" + item2);
- // }
- // }
- //}
- //foreach (var item in editorConfig.bases)
- //{
- // Console.WriteLine("位置信息:" + item.BasePositionInfo);
- //}
- if (editorConfig == null || taskConfig == null)
- {
- Log.Error("配置文件解析失败!");
- return UniTask.CompletedTask;
- }
- //Weather weather = Util.GetWeather("内蒙古", "根河", DateTime.Now.ToString("2024-05-10"));
- TaskComponent.Weather = new Weather();
- var temp = TaskComponent.Weather.day_temp.Replace("°C", "");
- Define.TEMPERATURE = double.Parse(temp);
- var wind_temp = TaskComponent.Weather.day_wind_comp.Replace("级", "").Split('-');
- Define.WIND = double.Parse(wind_temp[0]);
- // 创建灭火
- foreach (var mhTask in taskConfig.mHTaskConfigs)
- {
- Game.EventSystem.Publish(new CreateMHTask
- { EditorConfig = editorConfig, MHTaskConfig = mhTask });
- }
- // 创建侦察
- foreach (var zcTask in taskConfig.zCTask)
- {
- Game.EventSystem.Publish(new CreateZCTask
- { EditorConfig = editorConfig, ZCTask = zcTask });
- }
- // 创建巡护
- foreach (var xhTask in taskConfig.xHTask)
- {
- Game.EventSystem.Publish(new CreateXHTask
- { EditorConfig = editorConfig, XHTask = xhTask });
- }
- //Console.WriteLine("taskConfig.seaSouJiuTasks.Count:" + taskConfig.seaSouJiuTasks.Count);
- //创建搜救
- foreach (var seaSJTask in taskConfig.seaSouJiuTasks)
- {
- //Console.WriteLine("seaSJTask.missionInformation.MissionName:" + seaSJTask.missionInformation.MissionName);
- //Console.WriteLine("TargetPointId:" + seaSJTask.TargetPointId);
- //Console.WriteLine("SearchPayload:" + seaSJTask.SearchPayload);
- //Console.WriteLine("SearchMode:" + seaSJTask.SearchMode);
- //Console.WriteLine("RadarTransmitterPower:" + seaSJTask.RadarTransmitterPower);
- //Console.WriteLine("仿真次数:" + editorConfig.runCounts);
- Game.EventSystem.Publish(new CreateSeaSJTask
- { EditorConfig = editorConfig, SeaSJTask = seaSJTask });
- }
- //foreach (var landSJTask in taskConfig.LandSouJiuTasks)
- //{
- // Game.EventSystem.Publish(new CreateLandSJTask
- // { EditorConfig = editorConfig, LandSJTask = landSJTask });
- //}
- taskSys.ExecutionContext = editorConfig.runCounts;
- taskSys.Start();
- return UniTask.CompletedTask;
- }
- }
|