Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
67 changes: 3 additions & 64 deletions scripts/roll-record-sites.json
Original file line number Diff line number Diff line change
@@ -1,32 +1,19 @@
{
"_about": "Every file that still puts a roll on record by hand, outside the one door for it (src/lib/dm/roll-record.ts recordRoll): how many times it stores one (insertRoll), sends one (a publish of \"roll_result\") and adds one to a turn's cards (a push or other write onto rollIds, or joinStoredTurn), and the family of sites it moves onto the door with. A site moved is struck off, so the counts only go down; `total` is their sum. A send through a file's own wrapper is counted once, where the wrapper is written; a new site in such a file still shows, because it has to store its roll. Held by scripts/test-roll-record-sites.mjs; `node scripts/test-roll-record-sites.mjs --counts` prints what the source holds now.",
"total": { "store": 20, "send": 19, "join": 2 },
"total": { "store": 4, "send": 5, "join": 2 },
"families": {
"opportunity": "An opportunity attack's swing and damage, made on a stand-in turn that nothing draws its cards from.",
"clock": "Dice rolled as time passes or a rest is taken, with no GM call around them: death saves and the stable timer, hit dice, an item's charges. Death saves post a line of their own, which is their card's home.",
"initiative": "The dice that open a fight. Creatures' initiative and stealth are stored for the GM and handed no turn; by the ruling on issue #915 they join the turn as a creature's saves do.",
"requests": "A roll a person asked for outright (the dice tray, the GM's roll table), a parked roll put on record as it lands, and a secret roll sent again once it comes out."
},
"sites": {
"app/api/campaigns/[campaignId]/dm/roll-tables/[tableId]/roll/route.ts": { "store": 1, "send": 1, "family": "requests" },
"app/api/campaigns/[campaignId]/rolls/route.ts": { "store": 1, "send": 1, "family": "requests" },
"lib/dm/death.ts": { "store": 2, "send": 2, "family": "clock" },
"lib/dm/encounter-open.ts": { "store": 2, "send": 1, "family": "initiative" },
"lib/dm/encounter-tools.ts": { "store": 1, "send": 1, "family": "initiative" },
"lib/dm/held-call.ts": { "store": 1, "send": 1, "family": "requests" },
"lib/dm/hit-dice.ts": { "store": 1, "send": 1, "family": "clock" },
"lib/dm/item-charges.ts": { "store": 1, "send": 1, "family": "clock" },
"lib/dm/opportunity-pets.ts": { "store": 2, "send": 2, "family": "opportunity" },
"lib/dm/opportunity-sides.ts": { "store": 2, "send": 2, "family": "opportunity" },
"lib/dm/opportunity-strike.ts": { "store": 2, "send": 1, "family": "opportunity" },
"lib/dm/opportunity.ts": { "store": 2, "send": 2, "family": "opportunity" },
"lib/dm/pending-roll-land.ts": { "store": 1, "send": 1, "family": "requests" },
"lib/dm/regeneration-ring.ts": { "store": 1, "send": 1, "family": "clock" },
"lib/dm/retry-turn.ts": { "join": 1, "family": "requests" },
"lib/dm/roll-card.ts": { "send": 1, "family": "requests" },
"lib/dm/turn.ts": { "join": 1, "family": "requests" }
},
"_rows": "The rows of scripts/test-enforce-sweep-dice-sites.mjs whose call stores a roll that fails a check of its record, and which checks: home (the roll is on no turn and no line, so the chronicle never shows its card), sent (dice the seat entered are on record and sent as the server's, so the stage throws them again), roller (an attack or damage roll names nobody, so it reads as the roll of the character it lands on). Each is a site in `sites` above that has not moved onto recordRoll yet. A row is struck off when it passes; `ODM_SWEEP_ROWS=print node scripts/test-enforce-sweep-dice-sites.mjs` prints the list as it stands.",
"_rows": "The rows of scripts/test-enforce-sweep-dice-sites.mjs whose call stores a roll that fails a check of its record, and which checks: home (the roll is on no turn and no line, so the chronicle never shows its card), sent (dice the seat entered are on record and sent as the server's, so the stage throws them again), roller (an attack or damage roll names nobody, so it reads as the roll of the character it lands on; or a roll nobody made names a source that does not say what it is, says that source a second time, or does not name the character it lands on). Each is a site in `sites` above that has not moved onto recordRoll yet. A row is struck off when it passes; `ODM_SWEEP_ROWS=print node scripts/test-enforce-sweep-dice-sites.mjs` prints the list as it stands.",
"rows": {
"request_roll.skill_check.public@console": ["home"],
"request_roll.skill_check.blind@console": ["home"],
Expand Down Expand Up @@ -61,55 +48,7 @@
"request_roll.save.in_fight@console": ["home"],
"pc_attack.weapon@console": ["home"],
"pc_attack.spell@console": ["home"],
"opportunity.enemy_walks_off@console": ["home", "sent"],
"opportunity.enemy_flees@console": ["home", "sent"],
"cast_at_player.hazard@console": ["roller"],
"cast_at_player.hazard@ai": ["roller"],
"apply_hazard.falling@console": ["roller"],
"apply_hazard.falling@ai": ["roller"],
"apply_hazard.trap@console": ["roller"],
"apply_hazard.trap@ai": ["roller"],
"apply_hazard.generic@console": ["roller"],
"apply_hazard.generic@ai": ["roller"],
"apply_hazard.trap.Hunting Trap@console": ["roller"],
"apply_hazard.trap.Hunting Trap@ai": ["roller"],
"apply_hazard.trap.Collapsing Roof@console": ["roller"],
"apply_hazard.trap.Collapsing Roof@ai": ["roller"],
"apply_hazard.trap.Fire-Breathing Statue@console": ["roller"],
"apply_hazard.trap.Fire-Breathing Statue@ai": ["roller"],
"apply_hazard.trap.Simple Pit@console": ["roller"],
"apply_hazard.trap.Simple Pit@ai": ["roller"],
"apply_hazard.trap.Hidden Pit@console": ["roller"],
"apply_hazard.trap.Hidden Pit@ai": ["roller"],
"apply_hazard.trap.Locking Pit@console": ["roller"],
"apply_hazard.trap.Locking Pit@ai": ["roller"],
"apply_hazard.trap.Spiked Pit@console": ["roller"],
"apply_hazard.trap.Spiked Pit@ai": ["roller"],
"apply_hazard.trap.Spiked Pit (poisoned)@console": ["roller"],
"apply_hazard.trap.Spiked Pit (poisoned)@ai": ["roller"],
"apply_hazard.trap.Poison Darts@console": ["roller"],
"apply_hazard.trap.Poison Darts@ai": ["roller"],
"apply_hazard.trap.Poison Needle@console": ["roller"],
"apply_hazard.trap.Poison Needle@ai": ["roller"],
"apply_hazard.trap.Sphere of Annihilation@console": ["roller"],
"apply_hazard.trap.Sphere of Annihilation@ai": ["roller"],
"apply_hazard.trap.Rolling Sphere@console": ["roller"],
"apply_hazard.trap.Rolling Sphere@ai": ["roller"],
"death_save.turn_pass@console": ["home", "sent"],
"death_save.turn_pass@ai": ["home", "sent"],
"concentration.damage@console": ["roller"],
"concentration.damage@ai": ["roller"],
"stabilize.check@console": ["home"],
"stabilize.check@ai": ["home"],
"stabilize.kit@console": ["home"],
"stabilize.kit@ai": ["home"],
"take_rest.hit_dice@console": ["home"],
"take_rest.hit_dice@ai": ["home"],
"start_encounter.plain@console": ["home"],
"start_encounter.plain@ai": ["home"],
"start_encounter.party_ambush@console": ["home", "sent"],
"start_encounter.party_ambush@ai": ["home", "sent"],
"start_encounter.enemies_ambush@console": ["home"],
"start_encounter.enemies_ambush@ai": ["home"]
"start_encounter.enemies_ambush@console": ["home"]
}
}
19 changes: 19 additions & 0 deletions scripts/test-enforce-ai-gates.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,25 @@ await test("Dice the AI sends are rolled by the server: 2d6 of 3 and 4 is 7.", a
assert.equal(hp(), 33);
});

await test("Dice the AI sends for harm are on record as the roll of the words it gave for the harm, with the character as its target; healing dice name no roller.", async () => {
await stage();
const { listRecentRolls } = await import("../src/lib/db/rolls.ts");
const call = aiTurn();
const harm = await call("apply_damage", { characterId: hero.id, dice: "2d6", type: "bludgeoning", reason: "falling rubble" });
assert.equal(harm.ok, true, harm.error);
const [rubble] = listRecentRolls(world.campaignId, 1);
assert.equal(rubble.kind, "damage");
assert.deepEqual(rubble.attacker, { kind: "hazard", id: null, name: "falling rubble", hazard: "named" });
assert.equal(rubble.characterId, hero.id);
assert.equal(rubble.detail, `2d6 bludgeoning on ${world.sheet(hero.id).name}`);
// Healing is no attack and no damage: it names no roller, as before.
const mend = await call("heal", { characterId: hero.id, dice: "2d4+2" });
assert.equal(mend.ok, true, mend.error);
const [healed] = listRecentRolls(world.campaignId, 1);
assert.equal(healed.kind, "custom");
assert.equal(healed.attacker, null);
});

await test("A damage total the server rolled this turn is accepted once, and only once.", async () => {
await stage();
const call = aiTurn();
Expand Down
24 changes: 14 additions & 10 deletions scripts/test-enforce-damage-cards.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ await test("Bestow Curse: the extra necrotic when the curser's spell harms the c

// ---- costs paid in the caster's own hit points ----

await test("Overchannel's second use: the necrotic it costs is the wizard's card, with no attacker.", async () => {
await test("Overchannel's second use: the necrotic it costs is the wizard's own roll.", async () => {
const { world, sheets: [wizard], enemies: [goblin] } = await table([caster("wizard", "int", ["Fireball"], [], 14)]);
world.patch(wizard.id, { features: [...world.sheet(wizard.id).features, { name: "Overchannel", source: "test" }] });
world.dice(1);
Expand All @@ -175,53 +175,57 @@ await test("Overchannel's second use: the necrotic it costs is the wizard's card
world.clearDice();
const cost = cardsSince(world, before).find((card) => card.detail === "Overchannel");
assert.ok(cost, "no Overchannel card");
assert.equal(cost.attacker, null);
assert.deepEqual(cost.attacker, { kind: "sheet", id: wizard.id, name: world.sheet(wizard.id).name });
assert.equal(cost.characterId, wizard.id);
assert.equal(cost.total, 6);
});

await test("Contact Other Plane: the psychic backlash of a failed save is the caster's card, with no attacker.", async () => {
await test("Contact Other Plane: the psychic backlash of a failed save is the caster's own roll.", async () => {
const world = await openWorld();
const wizard = world.addHero(caster("wizard", "int", ["Contact Other Plane"], [], 9));
const before = snapshot(world);
world.dice(1, 1, 1, 1, 1, 1, 1);
const cast = await world.invoke("use_spell_slot", { characterId: wizard.id, spell: "Contact Other Plane", level: 5 });
world.clearDice();
assert.equal(cast.ok, true, cast.error);
expectCard(world, before, { attacker: null, detail: "Contact Other Plane", characterId: wizard.id, total: 6 });
expectCard(world, before, { attacker: { kind: "sheet", id: wizard.id, name: world.sheet(wizard.id).name }, detail: "Contact Other Plane", characterId: wizard.id, total: 6 });
world.close();
});

// ---- hazards and objects ----
// A roll nobody at the table made names its source (issue 915, ruling 2): the
// source is its attacker, a "hazard" with no id and a field that says what it
// is, and the character it lands on is its target. Named in front of the
// card, the source is not said again in the detail.

await test("A character's fall is a card with no attacker that names who fell, as an enemy's fall is.", async () => {
await test("A character's fall is the fall's roll, and names who fell as its target, as an enemy's fall does.", async () => {
const { world, sheets: [fighter] } = await table([{ ...FIGHTER, name: "Aria" }]);
const before = snapshot(world);
world.dice(2, 2, 2);
const out = await world.invoke("apply_hazard", { type: "falling", characterIds: [fighter.id], feet: 30 });
world.clearDice();
assert.equal(out.ok, true, out.error);
expectCard(world, before, { attacker: null, detail: "30 ft fall (3d6 bludgeoning) on Aria", characterId: fighter.id, total: 6 });
expectCard(world, before, { attacker: { kind: "hazard", id: null, name: "the fall", hazard: "fall" }, detail: "30 ft, 3d6 bludgeoning on Aria", characterId: fighter.id, total: 6 });
});

await test("A potion of poison's damage is a card about the drinker, with no attacker.", async () => {
await test("A potion of poison's damage is the potion's roll, with the drinker as its target.", async () => {
const { world, sheets: [fighter] } = await table([{ ...FIGHTER, name: "Aria", equipment: [...FIGHTER.equipment, { name: "Potion of Poison", qty: 1 }] }]);
const before = snapshot(world);
world.dice(2, 2, 2, 20);
const out = await world.invoke("use_item", { characterId: fighter.id, item: "Potion of Poison" });
world.clearDice();
assert.equal(out.ok, true, out.error);
expectCard(world, before, { attacker: null, detail: "Potion of Poison: it was poison", characterId: fighter.id, total: 6 });
expectCard(world, before, { attacker: { kind: "hazard", id: null, name: "Potion of Poison", hazard: "item" }, detail: "3d6 poison on Aria", characterId: fighter.id, total: 6 });
});

await test("Dice of harm no character dealt to an object are a card with no attacker that names the object.", async () => {
await test("Dice of harm no character dealt to an object are the GM's roll, and name the object.", async () => {
const { world } = await table([FIGHTER]);
const before = snapshot(world);
world.dice(3, 3);
const out = await world.invoke("damage_object", { name: "the oak door", material: "wood", size: "medium", damage: "2d6", damageType: "fire" });
world.clearDice();
assert.equal(out.ok, true, out.error);
expectCard(world, before, { attacker: null, detail: "fire on the oak door", characterId: null, total: 6 });
expectCard(world, before, { attacker: { kind: "hazard", id: null, name: "the GM", hazard: "gm" }, detail: "2d6 fire on the oak door", characterId: null, total: 6 });
});

// ---- the rest of the server's dice ----
Expand Down
Loading
Loading