using KYFramework;
using KYFramework.Network;
using Model;
using MongoDB.Bson;
namespace SimulationServer;
public static class MHRescueMissionSystem
{
///
/// 开始同步信息到客户端
///
///
public static void StartAsyncMH(this MHRescueMission self)
{
for (int i = 0; i < self.aircrafts.Count; i++)
{
if(self.aircrafts[i].SyncOver) continue;
var location = FXJHGenerate.GetAllCurrentLocation(self.aircrafts[i].TurningPoints, self.SimulationTime);
if (self.aircrafts[i] is AircraftMH aircraftMh && aircraftMh.FireGrids.Count > 0 )
{
Fire.FireGrid fireGrid = aircraftMh.FireGrids.First();
// 发送火焰数据
if (self.SimulationTime > fireGrid.Time)
{
//洒水了
S2C_FireSpread fireSpread = new S2C_FireSpread();
fireSpread.AircraftId = aircraftMh.AircraftId;
fireSpread.FirePointId = self.FireGround.FirePointName;
fireSpread.FireGrids = fireGrid.FireGrids;
fireSpread.FiredGrids = fireGrid.FiredGrids;
SessionComponent.Instance.Session.Send(fireSpread);
aircraftMh.FireGrids.RemoveAt(0);
}
}
// 同步信息到客户端
self.SyncLocation(location.Item1, self.aircrafts[i]);
if (location.Item2) // 判断飞机飞到终点
{
self.aircrafts[i].SyncOver = true;
Log.Info(self.aircrafts[i].AircraftId + "飞机到终点");
}
}
// 如果 aircraft.SyncOver 为 true ,从列表一处当前aircraft
//self.aircrafts.RemoveAll(a => a.SyncOver);
bool over = true;
foreach (var aircraft in self.aircrafts)
{
if (aircraft.SyncOver == false)
over = false;
}
if (over)
{
// 任务结束
Game.EventSystem.Publish(new MHSimulationOver {Mission = self});
return;
}
self.SimulationTime += Init.SimulationSpeed;
Task.Delay(TimeSpan.FromSeconds(1f)).ContinueWith(t => self.StartAsyncMH());
}
public static void SyncLocation(this MHRescueMission self,CurrentLocation location,AircraftEntity aircraft)
{
// 同步信息到客户端
if (location != null && aircraft != 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()}");
}
}
}