XHRescueMissionSystem.cs 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. using KYFramework;
  2. using KYFramework.Network;
  3. using Model;
  4. using MongoDB.Bson;
  5. namespace SimulationServer;
  6. public static class XHRescueMissionSystem
  7. {
  8. /// <summary>
  9. /// 开始同步信息到客户端
  10. /// </summary>
  11. /// <param name="self"></param>
  12. public static void StartAsyncXH(this XHRescueMission self)
  13. {
  14. foreach (var aircraft in self.AircraftXHs)
  15. {
  16. var location = FXJHGenerate.GetAllCurrentLocation(aircraft.turningPoints, self.SimulationTime);
  17. // 同步信息到客户端
  18. self.SyncLocation(location.Item1, aircraft);
  19. if (location.Item2) // 判断飞机飞到终点
  20. {
  21. aircraft.SyncOver = true;
  22. }
  23. }
  24. // 如果 aircraft.SyncOver 为 true ,从列表一处当前aircraft
  25. self.AircraftXHs.RemoveAll(a => a.SyncOver);
  26. if (self.AircraftXHs.Count == 0)
  27. {
  28. // 任务结束
  29. Game.EventSystem.Publish(new XHSimulationOver{ Mission = self});
  30. return;
  31. }
  32. self.SimulationTime += Init.SimulationSpeed;
  33. Task.Delay(TimeSpan.FromSeconds(1f)).ContinueWith(t => self.StartAsyncXH());
  34. }
  35. public static void SyncLocation(this XHRescueMission self,CurrentLocation location,AircraftXH aircraft)
  36. {
  37. // 同步信息到客户端
  38. if (location != null)
  39. {
  40. // 同步信息到客户端
  41. S2C_TurningPointOutput s2CTurningPointOutput = new S2C_TurningPointOutput();
  42. s2CTurningPointOutput.AircraftID = aircraft.AircraftId;
  43. //s2CTurningPointOutput.TurningPointName = fly.TurningPointName;
  44. s2CTurningPointOutput.PresentMission = location.PresentMission;
  45. s2CTurningPointOutput.PresentLocation = new Point
  46. {
  47. Altitude = location.CurrentHei,
  48. Latitude = location.CurrentLat,
  49. Longitude = location.CurrentLon
  50. };
  51. s2CTurningPointOutput.PresentVelocity = location.Currentvelo;
  52. SessionComponent.Instance.Session.Send(s2CTurningPointOutput);
  53. Log.Info($"飞机{aircraft.Name} 当前位置: {location.ToJson()}");
  54. }
  55. }
  56. }