ZCRescueMission.cs 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. using KYFramework;
  2. using KYFramework.Network;
  3. using Model;
  4. using MongoDB.Bson;
  5. namespace SimulationServer;
  6. public class ZCRescueMission : Entity
  7. {
  8. public string MissionId; // 任务ID
  9. public bool Success; // 任务是否成功
  10. public double InitArea;
  11. public double SimulationTime;
  12. public List<AircraftZC> AircraftZCs = new List<AircraftZC>();
  13. public void Start()
  14. {
  15. AircraftZCs?.ForEach(a => a.Start());
  16. var readyTime = AircraftZCs.First().TaskReadyTime;
  17. Log.Info("侦察时间延迟" + readyTime);
  18. Task.Delay(TimeSpan.FromSeconds(readyTime)).ContinueWith(t => this.StartAsyncZC());
  19. }
  20. }
  21. public static class ZCRescueMissionSystem
  22. {
  23. /// <summary>
  24. /// 开始同步信息到客户端
  25. /// </summary>
  26. /// <param name="self"></param>
  27. public static void StartAsyncZC(this ZCRescueMission self)
  28. {
  29. foreach (var aircraft in self.AircraftZCs)
  30. {
  31. var location = FXJHGenerate.GetAllCurrentLocation(aircraft.TurningPoints, self.SimulationTime);
  32. // 同步信息到客户端
  33. self.SyncLocation(location.Item1, aircraft);
  34. if (location.Item2) // 判断飞机飞到终点
  35. {
  36. aircraft.SyncOver = true;
  37. }
  38. }
  39. // 如果 aircraft.SyncOver 为 true ,从列表一处当前aircraft
  40. self.AircraftZCs.RemoveAll(a => a.SyncOver);
  41. if (self.AircraftZCs.Count == 0)
  42. {
  43. // 任务结束
  44. S2C_StmulationEnd end = new S2C_StmulationEnd();
  45. SessionComponent.Instance.Session.Send(end);
  46. return;
  47. }
  48. self.SimulationTime += Init.SimulationSpeed;
  49. Task.Delay(TimeSpan.FromSeconds(1f)).ContinueWith(t => self.StartAsyncZC());
  50. }
  51. public static void SyncLocation(this ZCRescueMission self,CurrentLocation location,AircraftEntity aircraft)
  52. {
  53. // 同步信息到客户端
  54. if (location != null)
  55. {
  56. // 同步信息到客户端
  57. S2C_TurningPointOutput s2CTurningPointOutput = new S2C_TurningPointOutput();
  58. s2CTurningPointOutput.AircraftID = aircraft.AircraftId;
  59. //s2CTurningPointOutput.TurningPointName = fly.TurningPointName;
  60. s2CTurningPointOutput.PresentMission = location.PresentMission;
  61. s2CTurningPointOutput.PresentLocation = new Point
  62. {
  63. Altitude = location.CurrentHei,
  64. Latitude = location.CurrentLat,
  65. Longitude = location.CurrentLon
  66. };
  67. s2CTurningPointOutput.PresentVelocity = location.Currentvelo;
  68. SessionComponent.Instance.Session.Send(s2CTurningPointOutput);
  69. Log.Info($"飞机{aircraft.Name} 当前位置: {location.ToJson()}");
  70. }
  71. }
  72. }