namespace Cthangover.Mods.BattleFormulas
{
using System;
using System.Collections.Generic;
using System.Linq;
using Cthangover.Core.Battle;
using Cthangover.Core.Characters;
using Cthangover.Core.Events;
using Cthangover.Mods.Stats;
///
/// The pool stats ("Pool": true, like mana) of party members who take part in
/// the stats, as bars of the battle cores: current = what is left after spending, max =
/// the sheet value. Hidden stats and enemies (they never pay costs) get none.
///
public class PoolGauge : IBattleUnitGauge
{
///
public int Order => 100;
///
public IEnumerable Read(Character unit)
{
if (unit?.ID == null || StatsService.RosterEntry(unit.ID) == null || !StatsService.Participates(unit.ID))
yield break;
var sheet = StatsService.Sheet(unit.ID);
foreach (var def in StatsService.Definitions.Where(d => d.Pool && !d.Hidden && sheet.Has(d.ID)))
{
yield return new BattleGauge
{
Id = def.ID,
Label = string.IsNullOrWhiteSpace(def.Short) ? def.Name ?? def.ID : def.Short,
Current = (int)Math.Round(StatPools.Current(unit.ID, def.ID), MidpointRounding.AwayFromZero),
Max = sheet.Rounded(def.ID),
};
}
}
/// Stats changed (mana spent or refilled): the cores redraw that unit's bars.
public static void OnStatsChanged(StatsChangedEvent evt) => BattleUnitGauges.NotifyChanged(evt?.CharacterId);
}
}