internal void Update()
{
var state = FleetSituation.Empty;
var ready = true;
var ships = this.source.SelectMany(x => x.Ships).ToArray();
if (ships.Length == 0)
{
ready = false;
}
else
{
var first = this.source[0];
if (this.source.Length == 1)
{
if (first.IsInSortie)
{
state |= FleetSituation.Sortie;
ready = false;
}
else if (first.Expedition.IsInExecution)
{
state |= FleetSituation.Expedition;
ready = false;
}
else
{
state |= FleetSituation.Homeport;
}
}
else
{
state |= FleetSituation.Combined;
if (first.IsInSortie)
{
state |= FleetSituation.Sortie;
ready = false;
}
else
{
state |= FleetSituation.Homeport;
}
}
}
this.Condition.Update(ships);
this.Condition.IsEnabled = state.HasFlag(FleetSituation.Homeport); // 疲労回復通知は母港待機中の艦隊でのみ行う
if (state.HasFlag(FleetSituation.Homeport))
{
var repairing = ships.Any(x => this.homeport.Repairyard.CheckRepairing(x.Id));
if (repairing)
{
state |= FleetSituation.Repairing;
ready = false;
}
var inShortSupply = ships.Any(s => s.Fuel.Current < s.Fuel.Maximum || s.Bull.Current < s.Bull.Maximum);
if (inShortSupply)
{
state |= FleetSituation.InShortSupply;
ready = false;
}
if (this.Condition.IsRejuvenating)
{
ready = false;
}
}
var heavilyDamaged = ships
.Where(s => !this.homeport.Repairyard.CheckRepairing(s.Id))
.Where(s => !s.Situation.HasFlag(ShipSituation.Evacuation) && !s.Situation.HasFlag(ShipSituation.Tow))
.Where(s => !(state.HasFlag(FleetSituation.Sortie) && s.Situation.HasFlag(ShipSituation.DamageControlled)))
.Any(s => s.HP.IsHeavilyDamage());
if (heavilyDamaged)
{
state |= FleetSituation.HeavilyDamaged;
ready = false;
}
this.Situation = state;
this.IsReady = ready;
if (this.Updated != null)
{
this.Updated(this, new EventArgs());
}
}