12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394 |
- 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(tc_str);
- EditorConfig? editorConfig = JsonConvert.DeserializeObject<EditorConfig>(ec_str);
- TaskConfig? taskConfig = JsonConvert.DeserializeObject<TaskConfig>(tc_str);
- 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 });
- }
- taskSys.ExecutionContext = editorConfig.runCounts;
- taskSys.Start();
- return UniTask.CompletedTask;
- }
- }
|