Add luck option after roll, attributes above 6, fix miracle icon and grit bonus
All checks were successful
Release Creation / build (release) Successful in 1m36s

This commit is contained in:
2026-04-20 08:23:33 +02:00
parent 36cb3bc755
commit b4211c121d
19 changed files with 373 additions and 26 deletions

View File

@@ -139,6 +139,7 @@ export async function rollSkillCheck(actor, skillKey, dv, options = {}) {
content,
rolls: allRolls,
sound: CONFIG.sounds.dice,
flags: { "fvtt-oath-hammer": { luckRoll: _luckFlagData(actor, threshold, colorType, dv, isOpposed, explodeOn5) } },
}
ChatMessage.applyRollMode(msgData, rollMode)
await ChatMessage.create(msgData)
@@ -224,6 +225,59 @@ export function _diceHtml(diceResults, threshold) {
}).join(" ")
}
/**
* Build the luck flag data to store on a chat message, enabling post-roll luck spending.
* @param {Actor} actor
* @param {number} threshold Dice success threshold (2/3/4)
* @param {string} colorType "white"|"red"|"black"
* @param {number} dv Difficulty value (0 = opposed)
* @param {boolean} isOpposed
* @param {boolean} explodeOn5
*/
export function _luckFlagData(actor, threshold, colorType, dv, isOpposed, explodeOn5) {
return { actorUuid: actor.uuid, threshold, colorType, dv, isOpposed, explodeOn5 }
}
/**
* Perform a post-roll luck spend: roll extra dice and update the chat message.
* @param {ChatMessage} message
* @param {number} luckSpend
* @param {boolean} luckIsHuman
*/
export async function rollPostRollLuck(message, luckSpend, luckIsHuman) {
const flag = message.getFlag("fvtt-oath-hammer", "luckRoll")
if (!flag || flag.used || luckSpend <= 0) return
const actor = await fromUuid(flag.actorUuid)
if (!actor) return
const currentLuck = actor.system.luck?.value ?? 0
const safeSpend = Math.min(luckSpend, currentLuck)
if (safeSpend <= 0) {
ui.notifications.warn(game.i18n.localize("OATHHAMMER.Roll.NoLuckLeft"))
return
}
const luckDicePerPoint = luckIsHuman ? 3 : 2
const extraDice = safeSpend * luckDicePerPoint
const { successes, diceResults } = await _rollPool(extraDice, flag.threshold, flag.explodeOn5)
await actor.update({ "system.luck.value": Math.max(0, currentLuck - safeSpend) })
const luckDiceHtml = _diceHtml(diceResults, flag.threshold)
await message.setFlag("fvtt-oath-hammer", "luckRoll", {
...flag,
used: true,
luckSpend: safeSpend,
luckIsHuman,
bonusSuccesses: successes,
extraDiceResults: diceResults,
luckDiceHtml,
})
}
// ============================================================
// WEAPON ATTACK ROLL
// ============================================================
@@ -309,7 +363,7 @@ export async function rollWeaponAttack(actor, weapon, options = {}) {
content,
rolls: rolls,
sound: CONFIG.sounds.dice,
flags: { "fvtt-oath-hammer": { weaponAttack: flagData } },
flags: { "fvtt-oath-hammer": { weaponAttack: flagData, luckRoll: _luckFlagData(actor, threshold, colorType, 0, true, explodeOn5) } },
}
ChatMessage.applyRollMode(msgData, rollMode)
await ChatMessage.create(msgData)
@@ -506,11 +560,13 @@ export async function rollSpellCast(actor, spell, options = {}) {
`
const rollMode = visibility ?? game.settings.get("core", "rollMode")
const spellColorType = redDice ? "red" : "white"
const msgData = {
speaker: ChatMessage.getSpeaker({ actor }),
content,
rolls: rolls,
sound: CONFIG.sounds.dice,
flags: { "fvtt-oath-hammer": { luckRoll: _luckFlagData(actor, threshold, spellColorType, dv, false, explodeOn5) } },
}
ChatMessage.applyRollMode(msgData, rollMode)
await ChatMessage.create(msgData)
@@ -608,6 +664,7 @@ export async function rollMiracleCast(actor, miracle, options = {}) {
content,
rolls: rolls,
sound: CONFIG.sounds.dice,
flags: { "fvtt-oath-hammer": { luckRoll: _luckFlagData(actor, threshold, "white", dv, false, explodeOn5) } },
}
ChatMessage.applyRollMode(msgData, rollMode)
await ChatMessage.create(msgData)
@@ -683,11 +740,13 @@ export async function rollDefense(actor, options = {}) {
`
const rollMode = visibility ?? game.settings.get("core", "rollMode")
const defColorType = redDice ? "red" : "white"
const msgData = {
speaker: ChatMessage.getSpeaker({ actor }),
content,
rolls: rolls,
sound: CONFIG.sounds.dice,
flags: { "fvtt-oath-hammer": { luckRoll: _luckFlagData(actor, threshold, defColorType, 0, true, false) } },
}
ChatMessage.applyRollMode(msgData, rollMode)
await ChatMessage.create(msgData)
@@ -786,6 +845,7 @@ export async function rollWeaponDefense(actor, weapon, options = {}) {
content,
rolls: rolls,
sound: CONFIG.sounds.dice,
flags: { "fvtt-oath-hammer": { luckRoll: _luckFlagData(actor, threshold, colorOverride, 0, true, explodeOn5) } },
}
ChatMessage.applyRollMode(msgData, rollMode)
await ChatMessage.create(msgData)