// Resting (the Hollowcrown book's Rules Cheat Sheet, "Resting"). Each function // takes a finished character and its sheet and returns the columns to write // plus an account of what happened, for the DM to read. Pure: no DB calls. // // Short rest (an hour): spend Hit Dice to heal, each one the class's die plus // the Constitution modifier. A warlock's spell slots come back. // Long rest (a night): all HP, all spell slots, Hit Dice up to half the level // (at least one), and temp HP is gone, except what the Hardy Boon gives. const { changeHp, lifeState, NO_DEATH_SAVES } = require('./hp'); const { hardyTempHp } = require('../game/levelUp'); // Once a day on a short rest a wizard or a druid (from level 2) gets some // spent slots back. Which ones is the player's choice, so the DM puts them // back on the sheet; this is the reminder, or null when it does not apply. function recoveryNote(character, sheet) { const feature = character.characterClass === 'WIZARD' ? 'Arcane Recovery' : character.characterClass === 'DRUID' && character.level >= 2 ? 'Natural Recovery' : null; if (!feature || !sheet.spellSlots || !sheet.spellSlots.levels.some((slot) => slot.used > 0)) return null; const budget = Math.ceil(character.level / 2); return `${feature}: once per day, ${character.name} can regain spent slots adding up to ${budget} slot level${budget === 1 ? '' : 's'} (none of 6th level or higher). Put them back on the sheet.`; } // A problem with the Hit Dice asked for, or null. `rolled` is the total the // dice showed, for dice rolled at the table. function hitDiceProblem(character, sheet, dice, rolled) { if (dice === 0) return null; const { size, remaining } = sheet.hitDice; if (lifeState(character) === 'DYING') return `${character.name} is dying: steady or heal them before they spend Hit Dice.`; if (dice > remaining) return `${character.name} has ${remaining} Hit ${remaining === 1 ? 'Die' : 'Dice'} left, not ${dice}.`; if (rolled != null && (rolled < dice || rolled > dice * size)) { return `${character.name}: ${dice}d${size} adds up to between ${dice} and ${dice * size}, not ${rolled}.`; } return null; } // `rolls` is what each Hit Die showed, or `rolled` their total when they were // rolled at the table. The Constitution modifier is added once per die, and // the rest never takes HP away. function shortRest(character, sheet, { dice = 0, rolls = null, rolled = null } = {}) { const total = dice === 0 ? 0 : rolls ? rolls.reduce((sum, roll) => sum + roll, 0) : rolled; const conBonus = dice * sheet.abilities.CON.modifier; const healed = Math.max(0, total + conBonus); const pact = Boolean(sheet.spellSlots) && sheet.spellSlots.restoresOn === 'SHORT'; const slotsRestored = pact && sheet.spellSlots.levels.some((slot) => slot.used > 0); const data = { ...(healed > 0 ? changeHp(character, character.currentHp + healed, sheet.hp.max) : {}), hitDiceUsed: sheet.hitDice.used + dice, ...(pact ? { spellSlotsUsed: [] } : {}), }; const hpAfter = data.currentHp ?? character.currentHp; return { data, result: { hpBefore: character.currentHp, hpAfter, maxHp: sheet.hp.max, tempHp: character.tempHp, hitDice: { size: sheet.hitDice.size, spent: dice, rolls, total, conBonus, healed: hpAfter - character.currentHp, left: sheet.hitDice.remaining - dice, of: sheet.hitDice.count, regained: 0 }, slotsRestored, notes: [recoveryNote(character, sheet)].filter(Boolean), }, }; } function longRest(character, sheet) { const regained = Math.min(sheet.hitDice.used, Math.max(1, Math.floor(character.level / 2))); const tempHp = hardyTempHp(character.specialAbilities); const data = { currentHp: sheet.hp.max, tempHp, ...NO_DEATH_SAVES, hitDiceUsed: sheet.hitDice.used - regained, spellSlotsUsed: [] }; return { data, result: { hpBefore: character.currentHp, hpAfter: sheet.hp.max, maxHp: sheet.hp.max, tempHp, hitDice: { size: sheet.hitDice.size, spent: 0, rolls: null, total: 0, conBonus: 0, healed: 0, left: sheet.hitDice.remaining + regained, of: sheet.hitDice.count, regained }, slotsRestored: Boolean(sheet.spellSlots) && sheet.spellSlots.levels.some((slot) => slot.used > 0), notes: tempHp > 0 ? [`Hardy: ${tempHp} Temp HP for the day.`] : [], }, }; } module.exports = { hitDiceProblem, shortRest, longRest };