123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233 |
- 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 static System.Runtime.InteropServices.JavaScript.JSType;
- 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>();
- taskSys.date = DateTime.Now.ToString().Replace("/","-").Replace(":","-").Replace(" ","-");
- //Console.WriteLine("date:" + taskSys.date);
- 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);
- //for (int i = 0; i < editorConfig.medicalTargetPoints.Count; i++)
- //{
- // for (int z = 0; z < editorConfig.medicalTargetPoints[i].TargetType.diseaseTypes.Length; z++)
- // {
- // Console.WriteLine("疾病类型:" + editorConfig.medicalTargetPoints[i].TargetType.diseaseTypes[z]);
- // }
- //}
- 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;
- }
- foreach (var item in editorConfig.targetPoints)
- {
- if (item.TargetType.Type == "遇险人员" || item.TargetType.Type == "车辆" || item.TargetType.Type == "航空器")
- {
- taskSys.isLand = true;
- }
- else if (item.TargetType.Type == "落水人员" || item.TargetType.Type == "救生筏" || item.TargetType.Type == "船舶" || item.TargetType.Type == "大规模落水人群")
- {
- taskSys.isSea = true;
- }
- //Console.WriteLine("taskSys.isLand:" + taskSys.isLand + "_" + "taskSys.isSea:" + taskSys.isSea);
- break;
- }
- //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)
- //{
- // taskSys.missionCount++;
- // //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 });
- // //break;
- //}
- //foreach (var landSXTask in taskConfig.LandSouXunTasks)
- //{
- // taskSys.missionCount++;
- // Game.EventSystem.Publish(new CreateLandSXTask
- // { EditorConfig = editorConfig, LandSXTask = landSXTask });
- // //break;
- //}
- ////创建空中吊运救援任务
- //foreach (var KZDYTask in taskConfig.KZDYTasks)
- //{
- // taskSys.missionCount++;
- // Game.EventSystem.Publish(new CreateKZDYTask
- // { EditorConfig = editorConfig, KZDYTask = KZDYTask });
- // //break;
- //}
- ////创建空投空送任务
- //foreach (var KTKSTask in taskConfig.KTKSTasks)
- //{
- // taskSys.missionCount++;
- // Game.EventSystem.Publish(new CreateKTKSTask
- // { EditorConfig = editorConfig, KTKSTask = KTKSTask });
- // //break;
- //}
- ////创建着水救援任务
- //foreach (var ZSJYTask in taskConfig.ZSJYTasks)
- //{
- // taskSys.missionCount++;
- // Game.EventSystem.Publish(new CreateZSJYTask
- // { EditorConfig = editorConfig, ZSJYTask = ZSJYTask });
- // //break;
- //}
- ////创建机降救援任务
- //foreach (var JJJYTask in taskConfig.JJJYTasks)
- //{
- // taskSys.missionCount++;
- // Game.EventSystem.Publish(new CreateJJJYTask
- // { EditorConfig = editorConfig, JJJYTask = JJJYTask });
- // //break;
- //}
- ////创建索滑降救援任务
- //foreach (var SHJTask in taskConfig.SHJTasks)
- //{
- // taskSys.missionCount++;
- // Game.EventSystem.Publish(new CreateSHJTask
- // { EditorConfig = editorConfig, SHJTask = SHJTask });
- // //break;
- //}
- //创建现场急救任务
- foreach (var XCJJTask in taskConfig.XCJJTasks)
- {
- taskSys.missionCount++;
- Game.EventSystem.Publish(new CreateXCJJTask
- { EditorConfig = editorConfig, XCJJTask = XCJJTask });
- //break;
- }
- //医疗转运任务
- foreach (var YLZYTask in taskConfig.YLZYTasks)
- {
- taskSys.missionCount++;
- Game.EventSystem.Publish(new CreateYLZYTask
- { EditorConfig = editorConfig, YLZYTask = YLZYTask });
- //break;
- }
- //医疗物品运送
- foreach (var YLWPYSTask in taskConfig.YLWPYSTasks)
- {
- taskSys.missionCount++;
- Game.EventSystem.Publish(new CreateYLWPYSTask
- { EditorConfig = editorConfig, YLWPYSTask = YLWPYSTask });
- //break;
- }
- //绞车吊载转运任务
- foreach (var JCDZZYTask in taskConfig.JCDZZYTasks)
- {
- taskSys.missionCount++;
- Game.EventSystem.Publish(new CreateJCDZZYTask
- { EditorConfig = editorConfig, JCDZZYTask = JCDZZYTask });
- //break;
- }
- taskSys.ExecutionContext = editorConfig.runCounts;
- taskSys.Start();
- return UniTask.CompletedTask;
- }
- }
|