Skip to content

Battler

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.

Part of the Battles module: Turn-based battles, as in an RPG: fighters that attack, cast spells paid for in mana and use items on their turn, by the numbers of a class’s or an enemy’s table row (Battler), the computer playing a team, and the RPG Stats template, whose races, classes, items, spells and levels are tables and whose balance simulations show which class is too strong at which level.

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.

Requires: Health (what it has left; at 0 it’s beaten)

Works with: TurnTaker (takes its turns: each move uses an action); TableValues (its numbers from a class’s or an enemy’s row)

Takes the player’s input only while it has focus (its Controllable): its Focus action hands it the input and takes it from everything else the same player plays.

Each is listed as its key in the scene file and the MCP tools, then its kind of value, its default and what it does.

  • foe: text = “Enemy”. 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). (Names entities: their names, separated by commas.) (Field: an entity’s name.)
  • title: text = null. What it’s called in what it says, e.g. “Elf Mage”; empty uses its entity’s name. Read as the “Title” output. (Plain text: what it’s called in what it says, its own words.) (Field: text.)
  • damage: a number = 2. Hit points an attack takes away, before the foe’s Armor. (Field: a number.)
  • damageRoll: text = null. Dice rolled for each attack in place of Damage, e.g. “1d8+2”; empty hits for Damage every time. (Dice: how many, “d”, their sides, then anything added or taken away, e.g. “2d6+3”, “d20”, “1d8+1d6-1” or a plain number; empty for none. The Inspector builds them and shows the lowest, highest and average roll.) (Field: its own editor: Dice.)
  • armor: a number = 0. Taken off each attack that hits it (never below 1). Spells and items go through it. (Field: a number.)
  • maxMana: a number = 0. The most mana it can have. Changing it while full keeps it full. (Field: a number.)
  • mana: a number = 0. Mana it has now, which spells cost. It starts full. (Field: a number.)
  • manaPerTurn: a number = 0. Mana it gets back as each of its turns starts, never past MaxMana. (Field: a number.)
  • spell: text = null. Its spell’s name, e.g. “Fireball”, said when it’s cast; empty for none. Read as the “Spell” output. (Plain text: its spell’s name as it says it, named nowhere else.) (Field: text.)
  • spellCost: a number = 0. Mana a cast costs. (Field: a number.)
  • spellDamage: a number = 0. Hit points the spell takes from the foe (armor or not); 0 for a spell that only heals. (Field: a number.)
  • spellDamageRoll: text = null. Dice rolled for each cast’s damage in place of SpellDamage, e.g. “3d6”. (Dice: how many, “d”, their sides, then anything added or taken away, e.g. “2d6+3”, “d20”, “1d8+1d6-1” or a plain number; empty for none. The Inspector builds them and shows the lowest, highest and average roll.) (Field: its own editor: Dice.)
  • spellHeal: a number = 0. Hit points the spell gives back to its caster; 0 for a spell that only hurts. (Field: a number.)
  • spellHealRoll: text = null. Dice rolled for each cast’s healing in place of SpellHeal, e.g. “2d6+2”. (Dice: how many, “d”, their sides, then anything added or taken away, e.g. “2d6+3”, “d20”, “1d8+1d6-1” or a plain number; empty for none. The Inspector builds them and shows the lowest, highest and average roll.) (Field: its own editor: Dice.)
  • item: text = null. The item it carries, e.g. “Potion”, said when it’s used; empty for none. Read as the “Item” output. (Plain text: its item’s name as it says it, named nowhere else.) (Field: text.)
  • items: a whole number = 0. How many of its Item it has left; each use takes one. (Field: a number.)
  • itemHeal: a number = 0. Hit points one gives back to it. (Field: a number.)
  • itemHealRoll: text = null. Dice rolled for each use’s healing in place of ItemHeal, e.g. “2d4+4”. (Dice: how many, “d”, their sides, then anything added or taken away, e.g. “2d6+3”, “d20”, “1d8+1d6-1” or a plain number; empty for none. The Inspector builds them and shows the lowest, highest and average roll.) (Field: its own editor: Dice.)
  • itemMana: a number = 0. Mana one gives back to it. (Field: a number.)
  • itemDamage: a number = 0. Hit points one takes from the foe (armor or not), as a bomb does. (Field: a number.)
  • itemDamageRoll: text = null. Dice rolled for each use’s damage in place of ItemDamage, e.g. “3d6”. (Dice: how many, “d”, their sides, then anything added or taken away, e.g. “2d6+3”, “d20”, “1d8+1d6-1” or a plain number; empty for none. The Inspector builds them and shows the lowest, highest and average roll.) (Field: its own editor: Dice.)
  • healBelow: a number = 0.4. 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%. (Field: a number.)
  • thinkTime: a number = 0.6. For the computer: seconds it waits on its turn before it moves, so the player sees it coming. 0 moves at once. (Field: a number.)
  • controllable: true or false = true. Whether it takes the player’s keys (AttackAction, SpellAction, ItemAction). Its actions are done either way. (Field: on or off.)
  • attackAction: text = “Attack”. The input action that attacks on its turn, e.g. “Attack” (X); empty for none. (Names an input action.) (Field: a name.)
  • spellAction: text = null. The input action that casts its spell on its turn; empty for none (buttons do it). (Names an input action.) (Field: a name.)
  • itemAction: text = null. The input action that uses an item on its turn; empty for none (buttons do it). (Names an input action.) (Field: a name.)
  • attackSound: text = null. Played as it attacks, e.g. “Sounds/swing.wav”. (A sound in Assets, e.g. “Sounds/hit.wav”.) (Field: a sound.)
  • spellSound: text = null. Played as it casts. (A sound in Assets, e.g. “Sounds/hit.wav”.) (Field: a sound.)
  • itemSound: text = null. Played as it uses an item. (A sound in Assets, e.g. “Sounds/hit.wav”.) (Field: a sound.)
  • failSound: text = null. Played when a move can’t be made: not enough mana, nothing left to use. (A sound in Assets, e.g. “Sounds/hit.wav”.) (Field: a sound.)
  • effect: text = null. A prefab spawned on what each move lands on, e.g. “Sparkle”. (Names a prefab.) (Field: a name.)
  • said: text = null. What it last did, e.g. “Elf Mage casts Fireball on Ogre: 14 damage.” The game sets it. Read as the “Said” output. (Plain text: what it last did: the game writes it.) (Field: text.)

What anything can make it do with no code: a Trigger’s do when its message arrives, a Contraptions Wire’s input as its signal comes on, a script’s Game.Do(entity, “Name”).

  • Attack. Attacks its foe on its turn, as its Attack Action does.
  • CastSpell. Casts its spell on its turn, if it has the mana.
  • UseItem. Uses one of its items on its turn, if it has any left.
  • Focus. Gives its entity the player’s input: whatever there and inside it has focus, and everything else the same player plays loses it (a platformer’s player stops on the arrow keys while a board takes them).

What anything can read with no code: a Counter’s, Bar’s or Text’s output, a Contraptions Wire’s output as its signal; Text shows names too, the rest read numbers, true as 1.

  • Title (a name). What it’s called in what it says, e.g. “Elf Mage”; empty uses its entity’s name. Read as the “Title” output.
  • Mana (a number, out of its maxMana). Mana it has now, which spells cost. It starts full.
  • Spell (a name). Its spell’s name, e.g. “Fireball”, said when it’s cast; empty for none. Read as the “Spell” output.
  • SpellCost (a number). Mana a cast costs.
  • Item (a name). The item it carries, e.g. “Potion”, said when it’s used; empty for none. Read as the “Item” output.
  • Items (a whole number). How many of its Item it has left; each use takes one.
  • Said (a name). What it last did, e.g. “Elf Mage casts Fireball on Ogre: 14 damage.” The game sets it. Read as the “Said” output.

Not saved with the scene; scripts read them, and entity_get shows them as live while the game plays.

  • canAct: true or false. 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.
  • called: text. The name it goes by in what it says: its Title, or its entity’s name.
  • canCast: true or false. True if it has a spell and the mana for it.
  • canUseItem: true or false. True if it has an item left to use.

Scripts use it as Battler: its methods, events and values that aren’t saved with the scene.