Seven steps in one commit, 1.15.0 to 1.21.0. They change the same files and were not saved apart, so they go in together. - The battle at a glance (1.15). A strip across the top of an encounter lists everyone in turn order and stays in view; a click goes to that card. On a wide screen the stat block of whoever is on turn stays beside the cards, and Pin keeps anyone else's there. Saving throws, every skill and passive Perception, Investigation and Insight are on encounter cards and in the character panel, which "Sheet" on a card and a button on the party overview open. For the DM, N is Next Turn and S opens the sheet of whoever is on turn. The party overview shows passive scores and spell save DC. - Subclasses (1.16). Three per class, picked in the level-up checklist at level 2 (cleric, druid, wizard) or 3, shown beside the class everywhere, and changed by the DM from the sheet: the old one's lines come out of Special Abilities and the new one's go in. Characters already at that level keep the path they were on. - Character state (1.17). Inspiration, exhaustion and conditions on the sheet and in the panel, and counters for what a class does a set number of times (Rage, Ki, Channel Divinity...), which the player spends and a rest gives back. A long rest takes a level of exhaustion off. A character's conditions are their own now: they stay from one encounter to the next. - Faster battles (1.18). Up to 20 of a monster added at once, numbered. One button rolls initiative for the monsters and NPCs. A condition can be given a number of rounds and then comes off by itself. Hovering over a condition shows its rule, and damaging someone who is Concentrating shows the save to call for. - Rolls from the sheet (1.19). A number with a dotted underline rolls when clicked, with its bonus: skills, saves, ability checks, attacks, damage, spell dice, and a monster's attack, damage and abilities. The dice roller has advantage and disadvantage. "Call for a roll" rolls one check or save for the whole party. Rolls stay in the browser. - XP and difficulty (1.20). An encounter shows the DM how hard it is, Trivial to Deadly, from the monsters' challenge ratings against the characters in it, and what it is worth in XP; one button shares that out, once. The sheet and the party overview show XP and when a level is due. Levelling up stays the DM's decision. - Subclasses are optional per campaign (1.21). With "Characters choose a subclass" unticked in the campaign's Settings nobody is asked, each class follows its first subclass, and none is named. - Conditions, exhaustion, counters and subclass features are reminders for the table: none of them changes a number on the sheet. - The docs cover all of it, with generated tables of what each subclass adds. - New migrations: a character's subclass; inspiration, exhaustion, conditions and spent counters on a character; the rounds left on a combatant's conditions; the XP awarded for an encounter; the campaign's subclass setting. - All packages at version 1.21.0. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
176 lines
6.5 KiB
TypeScript
176 lines
6.5 KiB
TypeScript
import { useState } from 'react';
|
||
import { Modal } from './Modal';
|
||
import { NumberInput } from './NumberInput';
|
||
import { ABILITY_LABELS, SKILL_LABELS, fmtMod } from '../lib/format';
|
||
import { rollD20, type RollMode } from '../lib/diceRoller';
|
||
import type { Ability, AbilityDetail, SaveBonuses, SkillBonuses } from '../api/types';
|
||
|
||
const ABILITIES: Ability[] = ['STR', 'DEX', 'CON', 'INT', 'WIS', 'CHA'];
|
||
|
||
// What the modal needs to know about each character who might roll.
|
||
export interface Checker {
|
||
id: string;
|
||
name: string;
|
||
abilities: Record<Ability, AbilityDetail>;
|
||
saves: SaveBonuses;
|
||
skills: SkillBonuses;
|
||
}
|
||
|
||
interface Result {
|
||
id: string;
|
||
name: string;
|
||
dice: number[];
|
||
kept: number;
|
||
bonus: number;
|
||
total: number;
|
||
}
|
||
|
||
// A check is "SKILL:STEALTH", "SAVE:DEX" or "ABILITY:STR".
|
||
function describe(check: string): string {
|
||
const [kind, key] = check.split(':');
|
||
if (kind === 'SKILL') return SKILL_LABELS[key];
|
||
return `${ABILITY_LABELS[key]} ${kind === 'SAVE' ? 'save' : 'check'}`;
|
||
}
|
||
|
||
function bonusFor(c: Checker, check: string): number {
|
||
const [kind, key] = check.split(':');
|
||
if (kind === 'SKILL') return c.skills[key].bonus;
|
||
if (kind === 'SAVE') return c.saves[key as Ability].bonus;
|
||
return c.abilities[key as Ability].modifier;
|
||
}
|
||
|
||
// The DM calling for a roll from several characters at once: everyone makes
|
||
// a Stealth check, or a Dexterity save against a fireball. Pick the roll and
|
||
// who makes it; each gets their own d20 with their own bonus, and with a DC
|
||
// the list says who made it. Rolled in the browser, like every table roll.
|
||
export function GroupCheckModal({ characters, onClose }: { characters: Checker[]; onClose: () => void }) {
|
||
const [check, setCheck] = useState('SKILL:PERCEPTION');
|
||
const [dc, setDc] = useState('');
|
||
const [mode, setMode] = useState<RollMode>('NORMAL');
|
||
const [left, setLeft] = useState<Set<string>>(new Set()); // who sits this one out
|
||
const [results, setResults] = useState<{ check: string; dc: number | null; rows: Result[] } | null>(null);
|
||
|
||
const rolling = characters.filter((c) => !left.has(c.id));
|
||
const target = dc === '' ? null : Number(dc);
|
||
|
||
function roll() {
|
||
setResults({
|
||
check,
|
||
dc: target,
|
||
rows: rolling.map((c) => {
|
||
const { kept, dice } = rollD20(mode);
|
||
const bonus = bonusFor(c, check);
|
||
return { id: c.id, name: c.name, dice, kept, bonus, total: kept + bonus };
|
||
}),
|
||
});
|
||
}
|
||
|
||
const passed = results && results.dc != null ? results.rows.filter((r) => r.total >= results.dc!).length : 0;
|
||
|
||
return (
|
||
<Modal title="Call for a roll" subtitle="One d20 each, with each character's own bonus" onClose={onClose}>
|
||
<div className="flex-row flex-wrap gap-sm">
|
||
<select aria-label="What to roll" value={check} onChange={(e) => setCheck(e.target.value)} style={{ flex: 1, minWidth: 180 }}>
|
||
<optgroup label="Skills">
|
||
{Object.keys(SKILL_LABELS).map((skill) => (
|
||
<option key={skill} value={`SKILL:${skill}`}>
|
||
{SKILL_LABELS[skill]}
|
||
</option>
|
||
))}
|
||
</optgroup>
|
||
<optgroup label="Saving throws">
|
||
{ABILITIES.map((a) => (
|
||
<option key={a} value={`SAVE:${a}`}>
|
||
{ABILITY_LABELS[a]} save
|
||
</option>
|
||
))}
|
||
</optgroup>
|
||
<optgroup label="Ability checks">
|
||
{ABILITIES.map((a) => (
|
||
<option key={a} value={`ABILITY:${a}`}>
|
||
{ABILITY_LABELS[a]} check
|
||
</option>
|
||
))}
|
||
</optgroup>
|
||
</select>
|
||
<NumberInput
|
||
min={1}
|
||
max={40}
|
||
placeholder="DC"
|
||
title="The number to reach. Leave empty to just see the totals."
|
||
aria-label="Difficulty class"
|
||
value={dc}
|
||
onChange={(e) => setDc(e.target.value)}
|
||
style={{ width: 70 }}
|
||
/>
|
||
<select aria-label="How the d20s are rolled" value={mode} onChange={(e) => setMode(e.target.value as RollMode)} style={{ width: 'auto' }}>
|
||
<option value="NORMAL">Normal</option>
|
||
<option value="ADVANTAGE">Advantage</option>
|
||
<option value="DISADVANTAGE">Disadvantage</option>
|
||
</select>
|
||
</div>
|
||
|
||
<div className="level-spells mt-sm">
|
||
{characters.map((c) => (
|
||
<label key={c.id} className="checkbox-row level-choice">
|
||
<input
|
||
type="checkbox"
|
||
checked={!left.has(c.id)}
|
||
onChange={(e) => {
|
||
const next = new Set(left);
|
||
if (e.target.checked) next.delete(c.id);
|
||
else next.add(c.id);
|
||
setLeft(next);
|
||
}}
|
||
/>
|
||
<span>
|
||
{c.name} <span className="combatant-sub mono">{fmtMod(bonusFor(c, check))}</span>
|
||
</span>
|
||
</label>
|
||
))}
|
||
</div>
|
||
|
||
<button className="btn btn-primary btn-block mt-sm" onClick={roll} disabled={rolling.length === 0}>
|
||
🎲 Roll {describe(check)} for {rolling.length}
|
||
</button>
|
||
|
||
{results && (
|
||
<div className="mt-md" aria-live="polite">
|
||
<div className="section-label">
|
||
{describe(results.check)}
|
||
{results.dc != null && ` · DC ${results.dc} · ${passed} of ${results.rows.length} made it`}
|
||
</div>
|
||
{results.rows.map((r) => {
|
||
const made = results.dc == null ? null : r.total >= results.dc;
|
||
return (
|
||
<div key={r.id} className="detail-row">
|
||
<span>
|
||
{r.name}{' '}
|
||
<span className="combatant-sub mono">
|
||
{r.dice.length > 1 ? `${r.dice.join(' / ')} → ${r.kept}` : r.kept} {r.bonus >= 0 ? '+' : '−'} {Math.abs(r.bonus)}
|
||
{r.kept === 20 && ' · natural 20'}
|
||
{r.kept === 1 && ' · natural 1'}
|
||
</span>
|
||
</span>
|
||
<span>
|
||
<strong className="mono">{r.total}</strong>
|
||
{made != null && (
|
||
<span className={`badge ${made ? 'badge-live' : 'badge-hostile'}`} style={{ marginLeft: 6 }}>
|
||
{made ? 'made it' : 'failed'}
|
||
</span>
|
||
)}
|
||
</span>
|
||
</div>
|
||
);
|
||
})}
|
||
{results.dc != null && (
|
||
<p className="combatant-sub" style={{ margin: '0.4rem 0 0' }}>
|
||
A group check succeeds when at least half make it{passed * 2 >= results.rows.length ? ': this one does.' : ': this one does not.'}
|
||
</p>
|
||
)}
|
||
</div>
|
||
)}
|
||
</Modal>
|
||
);
|
||
}
|