namespace Cthangover.Mods.BattleFormulas
{
using System.Linq;
using Cthangover.Core.Battle;
using Cthangover.Core.Events;
using Cthangover.Mods.Stats;
///
/// The moment a battle starts: formula actions are (re)registered, the party's bound
/// stats are synced (a member may have joined in the same dialog that started the
/// fight), and enemies whose templates carry stats data (Stats,
/// Archetype or Traits) get their battle attributes from their sheets. An
/// enemy without stats data keeps its template's numbers, so old content fights as before.
///
public static class BattleStatsBridge
{
///
/// The battle route is about to load: the battle scene builds its sides and HUD from
/// the attributes right after this, so they get their stats now.
///
public static void OnRouteActivating(SceneRouteActivatingEvent evt)
{
if (evt?.LogicalName == "Battle")
OnBattleStarted(null);
}
///
/// Handler of (also run on the route activation);
/// every step is idempotent, so running twice changes nothing.
///
public static void OnBattleStarted(BattleStartedEvent evt)
{
FormulaActions.Refresh();
StatSync.SyncRoster();
foreach (var enemy in BattleRequest.Current?.EnemiesCards?.Where(e => e != null) ?? Enumerable.Empty())
{
if (StatsService.Participates(enemy.ID))
StatBindings.Apply(StatsService.Sheet(enemy.ID), enemy.Attributes);
}
}
}
}