V1.27.0: battles that run themselves: track, targets, hit or miss, saves, auto-rolls

- Turn-order track: names coloured by PC, NPC or monster, this round, a flag
  where it ends, and the next round
- Target by clicking a name on the track, the card, or keys 1-9; whoever is
  on turn and every target show what they have in hand
- Attacks and spells are declared, rolled and applied: type or roll the d20
  and the app says hit, miss or critical; a save spell asks each target for
  its save against the caster's DC; the DM overrules anything and applies
- Critical damage by the campaign's rule; a spell spends its slot; a
  concentration save is called for
- Auto-rolled monster and NPC attacks: aimed (weighted), rolled, and offered
  to the DM to accept, edit or discard; hidden from players until accepted
- Monsters can have named attacks and multiattacks; spells say how they land
- A "What now" line tells the DM (and each player) what the scene waits on

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-10-12 09:14:04 +02:00
co-authored by Claude Opus 5.5
parent 8811f14732
commit 9b3637576d
29 changed files with 2693 additions and 38 deletions
@@ -0,0 +1,51 @@
-- Battle actions: an attack or spell from being declared to its damage
-- landing; named attacks for monsters; and how each spell lands (a spell
-- attack, or a saving throw). Spells already in campaigns that came from
-- the library are marked by name.
-- AlterTable
ALTER TABLE "monsters" ADD COLUMN "attacks" JSONB NOT NULL DEFAULT '[]';
-- AlterTable
ALTER TABLE "spells" ADD COLUMN "attackRoll" BOOLEAN NOT NULL DEFAULT false,
ADD COLUMN "halfOnSave" BOOLEAN NOT NULL DEFAULT false,
ADD COLUMN "saveAbility" "Ability";
-- CreateTable
CREATE TABLE "encounter_actions" (
"id" TEXT NOT NULL,
"encounterId" TEXT NOT NULL,
"round" INTEGER NOT NULL,
"actorParticipantId" TEXT,
"actorName" TEXT NOT NULL,
"kind" TEXT NOT NULL,
"name" TEXT NOT NULL,
"detail" JSONB NOT NULL,
"targets" JSONB NOT NULL,
"damage" JSONB,
"status" TEXT NOT NULL DEFAULT 'PENDING',
"auto" BOOLEAN NOT NULL DEFAULT false,
"hidden" BOOLEAN NOT NULL DEFAULT false,
"createdById" TEXT,
"createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
"appliedAt" TIMESTAMP(3),
CONSTRAINT "encounter_actions_pkey" PRIMARY KEY ("id")
);
-- CreateIndex
CREATE INDEX "encounter_actions_encounterId_status_idx" ON "encounter_actions"("encounterId", "status");
-- AddForeignKey
ALTER TABLE "encounter_actions" ADD CONSTRAINT "encounter_actions_encounterId_fkey" FOREIGN KEY ("encounterId") REFERENCES "encounters"("id") ON DELETE CASCADE ON UPDATE CASCADE;
-- How the library's spells land, for copies already in campaigns.
UPDATE "spells" SET "attackRoll" = true WHERE lower("name") IN ('chill touch', 'eldritch blast', 'fire bolt', 'produce flame', 'ray of frost', 'shocking grasp', 'thorn whip', 'guiding bolt', 'witch bolt', 'scorching ray', 'spiritual weapon', 'contagion');
UPDATE "spells" SET "saveAbility" = 'STR', "halfOnSave" = false WHERE lower("name") IN ('entangle', 'gust of wind');
UPDATE "spells" SET "saveAbility" = 'DEX', "halfOnSave" = true WHERE lower("name") IN ('burning hands', 'flaming sphere', 'call lightning', 'fireball', 'lightning bolt', 'guardian of faith', 'ice storm', 'wall of fire', 'flame strike');
UPDATE "spells" SET "saveAbility" = 'DEX', "halfOnSave" = false WHERE lower("name") IN ('acid splash', 'sacred flame', 'faerie fire', 'web', 'sleet storm');
UPDATE "spells" SET "saveAbility" = 'CON', "halfOnSave" = true WHERE lower("name") IN ('thunderwave', 'moonbeam', 'shatter', 'blight', 'cloudkill', 'cone of cold', 'insect plague');
UPDATE "spells" SET "saveAbility" = 'CON', "halfOnSave" = false WHERE lower("name") IN ('poison spray', 'blindness/deafness', 'levitate', 'stinking cloud');
UPDATE "spells" SET "saveAbility" = 'WIS', "halfOnSave" = true WHERE lower("name") IN ('spirit guardians');
UPDATE "spells" SET "saveAbility" = 'WIS', "halfOnSave" = false WHERE lower("name") IN ('vicious mockery', 'animal friendship', 'charm person', 'command', 'hold person', 'suggestion', 'fear', 'slow', 'confusion', 'polymorph', 'dominate person', 'hold monster');
UPDATE "spells" SET "saveAbility" = 'CHA', "halfOnSave" = false WHERE lower("name") IN ('bane', 'zone of truth', 'banishment');
+50
View File
@@ -656,6 +656,13 @@ model Spell {
// Brings back the dead: a character who can cast it may revive a dead ally
// on their turn in a battle (encounters.routes.js).
revives Boolean @default(false)
// How it lands in a battle (game/combat.js). attackRoll: the caster rolls a
// spell attack against AC. saveAbility: each target saves against the
// caster's spell DC with this ability, taking half on a success when
// halfOnSave. Neither: it simply takes effect.
attackRoll Boolean @default(false)
saveAbility Ability?
halfOnSave Boolean @default(false)
campaign Campaign @relation(fields: [campaignId], references: [id], onDelete: Cascade)
known CharacterSpell[]
@@ -699,6 +706,11 @@ model Monster {
challengeRating String?
specialTrait String?
notes String?
// Named attacks, for a monster with more than the one above: a list of
// { name, attackBonus, damageDice, damageType?, count? }. `count` is how
// many times it is made each turn (a multiattack). Empty: the single
// attackBonus/damageDice above is its attack.
attacks Json @default("[]")
campaign Campaign @relation(fields: [campaignId], references: [id], onDelete: Cascade)
encounterAppearances EncounterParticipant[]
@@ -769,11 +781,49 @@ model Encounter {
participants EncounterParticipant[]
rewards EncounterReward[]
wares SaleOffer[]
actions EncounterAction[]
@@index([campaignId])
@@map("encounters")
}
// An attack or a spell in a battle, from the moment it is declared to the
// moment its damage lands (game/combat.js). A player declares their own on
// their turn; the DM declares anyone's; and with the campaign's auto-roll
// settings the server declares a monster's or NPC's, already rolled. While
// PENDING it gathers what it needs (a d20 against each target's AC, or each
// target's saving throw, and the damage); the DM then applies it, changed as
// they see fit, or discards it. `hidden` keeps it from the players until it
// is applied.
model EncounterAction {
id String @id @default(cuid())
encounterId String
round Int
actorParticipantId String?
actorName String
kind String // ATTACK (a d20 against AC) | SAVE (targets save against a DC) | AUTO (it just lands)
name String // "Longsword", "Fireball", "Bite"
// What it rolls with: { attackBonus?, saveAbility?, saveDC?, halfOnSave?,
// damageDice?, damageBonus, damageType?, characterId?, slotLevel? }.
detail Json
// One entry per target: { participantId, name, kind, ac, penalty, saveBonus,
// d20, outcome (set by the DM to overrule the dice), damage (likewise) }.
targets Json
// The damage once rolled or entered: { total, dice?, modifier?, crit? }.
damage Json?
status String @default("PENDING") // PENDING | APPLIED | DISCARDED
auto Boolean @default(false) // declared and rolled by the server
hidden Boolean @default(false)
createdById String?
createdAt DateTime @default(now())
appliedAt DateTime?
encounter Encounter @relation(fields: [encounterId], references: [id], onDelete: Cascade)
@@index([encounterId, status])
@@map("encounter_actions")
}
// Loot the DM lines up for an encounter and later hands to a character. Until
// it is awarded it is the DM's secret; awarding it is what actually changes
// the character (gold ledger entry, or the weapon/item added to what they hold).