Skip to content

Battler

namespace Griff.Modules.Battles;
public sealed class Battler : Component, IActionReady, ITurnReady, IPlaytestReport

A fighter in a turn-based battle, as in an RPG, with no code: on its turn it attacks its Foe, casts its Spell (paid for in Mana) or uses one of its Items, a potion that heals or a bomb that hurts. Attacks are softened by the foe’s Armor; spells and items aren’t. Each move uses an action of its TurnTaker, so the turns pass by themselves. The player’s fighter moves when its actions are done (by buttons whose Action is Do, by a Trigger, or by its own keys); one on a team the TurnOrder’s computer plays picks its own moves: it heals when hurt, casts while it has the mana and the spell hits harder, throws an item that hits harder still, and otherwise attacks.

Its numbers are made to come from a table: a TableValues beside it sets them from a class’s or an enemy’s row (Health.Max = Health, Battler.Damage = Damage, Battler.Spell = Spell…), dice columns rolled for each hit, so a balance simulation plays the fight by the same numbers. Without a turn order it moves whenever its actions are done, and the computer moves nobody. In a network game the host carries out the moves.

This is a component: its saved properties are on its component page.

public float Armor { get; set; }

Taken off each attack that hits it (never below 1). Spells and items go through it.

public string? AttackAction { get; set; }

The input action that attacks on its turn, e.g. “Attack” (X); empty for none.

public string? AttackSound { get; set; }

Played as it attacks, e.g. “Sounds/swing.wav”.

public string Called { get; }

The name it goes by in what it says: its Title, or its entity’s name.

public bool CanAct { get; }

True while it can move: it’s its turn (if it takes turns) and it hasn’t moved yet. The game keeps it up to date.

public bool CanCast { get; }

True if it has a spell and the mana for it.

public bool CanUseItem { get; }

True if it has an item left to use.

public bool Controllable { get; set; }

Whether it takes the player’s keys (AttackAction, SpellAction, ItemAction). Its actions are done either way.

public float Damage { get; set; }

Hit points an attack takes away, before the foe’s Armor.

public string? DamageRoll { get; set; }

Dice rolled for each attack in place of Damage, e.g. “1d8+2”; empty hits for Damage every time.

public string? Effect { get; set; }

A prefab spawned on what each move lands on, e.g. “Sparkle”.

public string? FailSound { get; set; }

Played when a move can’t be made: not enough mana, nothing left to use.

public string? Foe { get; set; }

What it fights, by name, e.g. “Enemy” (or “Knight, Mage” for a party): it goes for the first still standing. Its attacks, damaging spells and damaging items hit it. Empty fights the first battler standing on another team (its turn taker’s, or a Team’s; see Teams).

public float HealBelow { get; set; }

For the computer: the share of its health below which it heals (with an item, or a spell that heals), e.g. 0.4 for under 40%.

public string? Item { get; set; }

The item it carries, e.g. “Potion”, said when it’s used; empty for none. Read as the “Item” output.

public string? ItemAction { get; set; }

The input action that uses an item on its turn; empty for none (buttons do it).

public float ItemDamage { get; set; }

Hit points one takes from the foe (armor or not), as a bomb does.

public string? ItemDamageRoll { get; set; }

Dice rolled for each use’s damage in place of ItemDamage, e.g. “3d6”.

public float ItemHeal { get; set; }

Hit points one gives back to it.

public string? ItemHealRoll { get; set; }

Dice rolled for each use’s healing in place of ItemHeal, e.g. “2d4+4”.

public float ItemMana { get; set; }

Mana one gives back to it.

public string? ItemSound { get; set; }

Played as it uses an item.

public int Items { get; set; }

How many of its Item it has left; each use takes one.

public float Mana { get; set; }

Mana it has now, which spells cost. It starts full.

public float ManaPerTurn { get; set; }

Mana it gets back as each of its turns starts, never past MaxMana.

public float MaxMana { get; set; }

The most mana it can have. Changing it while full keeps it full.

public string? Said { get; set; }

What it last did, e.g. “Elf Mage casts Fireball on Ogre: 14 damage.” The game sets it. Read as the “Said” output.

public string? Spell { get; set; }

Its spell’s name, e.g. “Fireball”, said when it’s cast; empty for none. Read as the “Spell” output.

public string? SpellAction { get; set; }

The input action that casts its spell on its turn; empty for none (buttons do it).

public float SpellCost { get; set; }

Mana a cast costs.

public float SpellDamage { get; set; }

Hit points the spell takes from the foe (armor or not); 0 for a spell that only heals.

public string? SpellDamageRoll { get; set; }

Dice rolled for each cast’s damage in place of SpellDamage, e.g. “3d6”.

public float SpellHeal { get; set; }

Hit points the spell gives back to its caster; 0 for a spell that only hurts.

public string? SpellHealRoll { get; set; }

Dice rolled for each cast’s healing in place of SpellHeal, e.g. “2d6+2”.

public string? SpellSound { get; set; }

Played as it casts.

public float ThinkTime { get; set; }

For the computer: seconds it waits on its turn before it moves, so the player sees it coming. 0 moves at once.

public string? Title { get; set; }

What it’s called in what it says, e.g. “Elf Mage”; empty uses its entity’s name. Read as the “Title” output.

public void Attack()

Attacks its foe on its turn, as its Attack Action does.

public void CastSpell()

Casts its spell on its turn, if it has the mana.

public void UseItem()

Uses one of its items on its turn, if it has any left.

public event Action<Battler, string>? Moved

Raised as it makes a move, with what it said.