- Weapons and items can carry effects: bonuses and penalties to AC, speed, initiative, max HP, passive Perception, ability scores, saving throws and skills, plus a note. They apply on their own while equipped and stop when the thing comes off. Armor is an item with an AC effect. The DM sets them with "Effects" on a row in the weapon or item pool. - The sheet's "armor bonus" is now "Extra AC", the DM's own adjustment on top of gear, and only the DM can set it. - Only what is equipped counts: a weapon has to be equipped to be used in an encounter. A character can have two things equipped at once, one of them a weapon (campaign settings). Equipping at the limit is refused with a message, and can be changed at any time, mid-encounter included. - A built-in item library: armor, shields, worn gear and supplies, with their effects set. The weapon library gains paired weapons (a pair of daggers is one weapon). - A floating character button on every page opens a panel with a character's numbers and everything they hold, with equip ticks. Players get their own characters, the DM everyone's, and each character card in an encounter has an Inventory button. It replaces the quick stats drawer. - A player's own characters stand out: marked and highlighted in encounters, with a button that jumps to their card; highlighted on the party screen; and listed once, not twice, on the campaign page. - All packages at version 1.11.0. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
36 lines
1.4 KiB
JavaScript
36 lines
1.4 KiB
JavaScript
// Loading a character so that its sheet comes out right. The sheet depends on
|
|
// what the character has equipped (game/calculations.js, activeGear), so every
|
|
// query that feeds computeCharacterSheet includes the same relations.
|
|
|
|
const { computeCharacterSheet } = require('../game/calculations');
|
|
|
|
const SHEET_INCLUDE = {
|
|
skillProficiencies: true,
|
|
saveProficiencies: true,
|
|
inventoryItems: { include: { item: true } },
|
|
weapons: { include: { weapon: true } },
|
|
};
|
|
|
|
function sheetOf(character) {
|
|
return computeCharacterSheet(character, character.skillProficiencies, character.saveProficiencies);
|
|
}
|
|
|
|
// Equipping, unequipping or changing gear can lower a character's maximum HP.
|
|
// Brings current HP back down to the new maximum where it is now above it,
|
|
// and returns the ids of the characters that changed. Takes a Prisma client or
|
|
// transaction client as `db`.
|
|
async function settleHp(db, characterIds) {
|
|
const changed = [];
|
|
const characters = await db.character.findMany({ where: { id: { in: [...new Set(characterIds)] }, buildStage: 'COMPLETE' }, include: SHEET_INCLUDE });
|
|
for (const character of characters) {
|
|
const max = sheetOf(character).hp.max;
|
|
if (character.currentHp > max) {
|
|
await db.character.update({ where: { id: character.id }, data: { currentHp: max } });
|
|
changed.push(character.id);
|
|
}
|
|
}
|
|
return changed;
|
|
}
|
|
|
|
module.exports = { SHEET_INCLUDE, sheetOf, settleHp };
|