namespace Aeshnidae.Bank;
///
/// The bank panel for the HUD feed: what /bank prints, as a window.
///
/// The feed itself - the /hud switch, who is listening, the wire contract - is
/// Aeshnidae.Hud; this mod is one provider. HudFeed.cs is the verbatim copy of that
/// mod's Feed.cs (cross-mod types are unsafe, ACE's are not), and /hud-bank is the
/// command the Hud mod invokes when a session turns the feed on or asks for a sync.
///
/// Every button is a /b command the player could have typed, with the selected row's
/// short name and the two text boxes filled in. So the panel adds nothing the bank
/// does not already do; it just puts the balances where the player can see them and
/// saves the typing. Nothing here touches a balance.
///
public static class Hud
{
/// Re-send the bank panel, if the session is listening. Safe to call from anywhere.
public static void Refresh(Player? player)
{
try
{
if (player?.Session is null || player.Account is null || !BankDb.Ready || !HudFeed.IsOn(player))
return;
HudFeed.Send(player.Session, BankPanel(player));
}
catch (Exception ex)
{
ModManager.Log($"[{Mod.Name}] hud refresh failed: {ex}", ModManager.LogLevel.Warn);
}
}
///
/// One row per currency: banked (including earnings not yet flushed, exactly as the
/// statement does), and carried, so "is there anything to deposit" is visible
/// without opening the pack. Rows with something carried are coloured. The earned
/// currencies have no carried form and say so.
///
public static object BankPanel(Player player)
{
var accountId = player.Account.AccountId;
var balances = BankDb.GetAllBalances(accountId);
foreach (var (kind, pending) in Earning.PendingFor(accountId))
balances[kind] = balances.GetValueOrDefault(kind) + pending;
var rows = new List