using KYFramework; using KYFramework.Network; using Model; using MongoDB.Bson; namespace SimulationServer; public static class XHRescueMissionSystem { /// /// 开始同步信息到客户端 /// /// public static void StartAsyncXH(this XHRescueMission self) { foreach (var aircraft in self.AircraftXHs) { var location = FXJHGenerate.GetAllCurrentLocation(aircraft.turningPoints, self.SimulationTime); // 同步信息到客户端 self.SyncLocation(location.Item1, aircraft); if (location.Item2) // 判断飞机飞到终点 { aircraft.SyncOver = true; } } // 如果 aircraft.SyncOver 为 true ,从列表一处当前aircraft self.AircraftXHs.RemoveAll(a => a.SyncOver); if (self.AircraftXHs.Count == 0) { // 任务结束 Game.EventSystem.Publish(new XHSimulationOver{ Mission = self}); return; } self.SimulationTime += Init.SimulationSpeed; Task.Delay(TimeSpan.FromSeconds(1f)).ContinueWith(t => self.StartAsyncXH()); } public static void SyncLocation(this XHRescueMission self,CurrentLocation location,AircraftXH aircraft) { // 同步信息到客户端 if (location != null) { // 同步信息到客户端 S2C_TurningPointOutput s2CTurningPointOutput = new S2C_TurningPointOutput(); s2CTurningPointOutput.AircraftID = aircraft.AircraftId; //s2CTurningPointOutput.TurningPointName = fly.TurningPointName; s2CTurningPointOutput.PresentMission = location.PresentMission; s2CTurningPointOutput.PresentLocation = new Point { Altitude = location.CurrentHei, Latitude = location.CurrentLat, Longitude = location.CurrentLon }; s2CTurningPointOutput.PresentVelocity = location.Currentvelo; SessionComponent.Instance.Session.Send(s2CTurningPointOutput); Log.Info($"飞机{aircraft.Name} 当前位置: {location.ToJson()}"); } } }