Compare commits
1 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| f6fb0b68b8 |
+264
-251
@@ -526,281 +526,294 @@ Hooks.on("createChatMessage", async (message) => {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
// Si le défenseur est un personnage qui perd, proposer Grit/Luck (seulement s'il a des points)
|
// Reaction phase — both sides may use grit/luck/shield/mulligan before the outcome is resolved.
|
||||||
// Seulement si l'utilisateur actuel est le propriétaire du défenseur
|
// After a mulligan reroll (either side), the comparison restarts so both sides can react to the new numbers.
|
||||||
let defenderHandledBonus = false
|
let defenderHandledBonus = false
|
||||||
|
let attackerHandledBonus = false
|
||||||
let shieldReaction = null
|
let shieldReaction = null
|
||||||
let shieldBlocked = false
|
let shieldBlocked = false
|
||||||
const isSpellOrMiracle = attackRollType === "spell-attack" || attackRollType === "miracle-attack"
|
const isSpellOrMiracle = attackRollType === "spell-attack" || attackRollType === "miracle-attack"
|
||||||
if (defender && defenseRoll < attackRoll && isPrimaryController(defender) && !isSpellOrMiracle) {
|
|
||||||
const shieldData = LethalFantasyUtils.getShieldReactionData(defender)
|
|
||||||
let canRerollDefense = LethalFantasyUtils.hasD30Reroll(defenseD30message)
|
|
||||||
let canShieldReact = !!shieldData
|
|
||||||
let canAdHocShield = !shieldData
|
|
||||||
|
|
||||||
while (defenseRoll < attackRoll) {
|
|
||||||
const currentGrit = Number(defender.system?.grit?.current) || 0
|
|
||||||
const currentLuck = Number(defender.system?.luck?.current) || 0
|
|
||||||
const buttons = []
|
|
||||||
|
|
||||||
if (currentGrit > 0) {
|
|
||||||
buttons.push({
|
|
||||||
action: "grit",
|
|
||||||
label: `Spend 1 Grit (+1D6) [${currentGrit} left]`,
|
|
||||||
icon: "fa-solid fa-fist-raised",
|
|
||||||
callback: () => "grit"
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
if (currentLuck > 0) {
|
|
||||||
buttons.push({
|
|
||||||
action: "luck",
|
|
||||||
label: `Spend 1 Luck (+1D6) [${currentLuck} left]`,
|
|
||||||
icon: "fa-solid fa-clover",
|
|
||||||
callback: () => "luck"
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
buttons.push({
|
|
||||||
action: "bonusDie",
|
|
||||||
label: "Add bonus die",
|
|
||||||
icon: "fa-solid fa-dice",
|
|
||||||
callback: () => "bonusDie"
|
|
||||||
})
|
|
||||||
|
|
||||||
if (canRerollDefense) {
|
|
||||||
buttons.push({
|
|
||||||
action: "rerollDefense",
|
|
||||||
label: "Re-roll defense",
|
|
||||||
icon: "fa-solid fa-rotate-right",
|
|
||||||
callback: () => "rerollDefense"
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
if (canShieldReact) {
|
|
||||||
buttons.push({
|
|
||||||
action: "shieldReact",
|
|
||||||
label: `Roll shield (${shieldData.label})`,
|
|
||||||
icon: "fa-solid fa-shield",
|
|
||||||
callback: () => "shieldReact"
|
|
||||||
})
|
|
||||||
} else if (canAdHocShield) {
|
|
||||||
// No pre-configured shield — offer ad-hoc shield option (useful for monsters)
|
|
||||||
buttons.push({
|
|
||||||
action: "adHocShield",
|
|
||||||
label: "Roll ad-hoc shield (choose dice + DR)",
|
|
||||||
icon: "fa-solid fa-shield-halved",
|
|
||||||
callback: () => "adHocShield"
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
buttons.push({
|
|
||||||
action: "continue",
|
|
||||||
label: "Continue (no defense bonus)",
|
|
||||||
icon: "fa-solid fa-forward",
|
|
||||||
callback: () => "continue"
|
|
||||||
})
|
|
||||||
|
|
||||||
const choice = await foundry.applications.api.DialogV2.wait({
|
|
||||||
window: { title: "Defense reactions" },
|
|
||||||
classes: ["lethalfantasy"],
|
|
||||||
content: `
|
|
||||||
<div class="grit-luck-dialog">
|
|
||||||
<div class="combat-status">
|
|
||||||
<p><strong>${attackerName}</strong> rolled <strong>${attackRoll}</strong></p>
|
|
||||||
<p><strong>${defenderName}</strong> currently has <strong>${defenseRoll}</strong></p>
|
|
||||||
${defenseD30message ? `<p class="bonus-info">D30 special: ${defenseD30message.description}</p>` : ""}
|
|
||||||
</div>
|
|
||||||
<p class="offer-text">Choose how to improve the defense before resolving the hit.</p>
|
|
||||||
</div>
|
|
||||||
`,
|
|
||||||
buttons,
|
|
||||||
rejectClose: false
|
|
||||||
})
|
|
||||||
|
|
||||||
if (!choice || choice === "continue") break
|
|
||||||
|
|
||||||
defenderHandledBonus = true
|
|
||||||
|
|
||||||
if (choice === "grit") {
|
|
||||||
const bonusRoll = await LethalFantasyUtils.rollBonusDie("1d6", defender, (total) => `<p><strong>${defenderName}</strong> spends 1 Grit and rolls <strong>${total}</strong> for defense.</p>`)
|
|
||||||
defenseRoll += bonusRoll
|
|
||||||
await defender.update({ "system.grit.current": currentGrit - 1 })
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
|
|
||||||
if (choice === "luck") {
|
|
||||||
const bonusRoll = await LethalFantasyUtils.rollBonusDie("1d6", defender, (total) => `<p><strong>${defenderName}</strong> spends 1 Luck and rolls <strong>${total}</strong> for defense.</p>`)
|
|
||||||
defenseRoll += bonusRoll
|
|
||||||
await defender.update({ "system.luck.current": currentLuck - 1 })
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
|
|
||||||
if (choice === "bonusDie") {
|
|
||||||
const bonusDie = await LethalFantasyUtils.promptCombatBonusDie(defenderName, "attack", defenseRoll, attackRoll)
|
|
||||||
if (!bonusDie) continue
|
|
||||||
const bonusRoll = await LethalFantasyUtils.rollBonusDie(bonusDie, defender, (total, formula) => `<p><strong>${defenderName}</strong> adds <strong>${formula.toUpperCase()}</strong> and rolls <strong>${total}</strong> for defense.</p>`)
|
|
||||||
defenseRoll += bonusRoll
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
|
|
||||||
if (choice === "rerollDefense" && canRerollDefense) {
|
|
||||||
const oldDefenseRoll = defenseRoll
|
|
||||||
const reroll = await LethalFantasyUtils.rerollConfiguredRoll(defenseRerollContext)
|
|
||||||
canRerollDefense = false
|
|
||||||
if (!reroll) continue
|
|
||||||
defenseRoll = reroll.options?.rollTotal || reroll.total || oldDefenseRoll
|
|
||||||
await createReactionMessage(defender, `<p><strong>${defenderName}</strong> uses Mulligan and re-rolls defense: <strong>${oldDefenseRoll}</strong> → <strong>${defenseRoll}</strong>.</p>`)
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
|
|
||||||
if (choice === "shieldReact" && canShieldReact) {
|
|
||||||
const shieldBonus = await LethalFantasyUtils.rollBonusDie(shieldData.formula, defender)
|
|
||||||
const newDefenseTotal = defenseRoll + shieldBonus
|
|
||||||
defenseRoll = newDefenseTotal
|
|
||||||
canShieldReact = false
|
|
||||||
|
|
||||||
if (newDefenseTotal >= attackRoll) {
|
|
||||||
shieldBlocked = true
|
|
||||||
shieldReaction = {
|
|
||||||
damageReduction: shieldData.damageReduction,
|
|
||||||
label: shieldData.label,
|
|
||||||
bonus: shieldBonus
|
|
||||||
}
|
|
||||||
await createReactionMessage(
|
|
||||||
defender,
|
|
||||||
`<p><strong>${defenderName}</strong> rolls <strong>${shieldData.label}</strong> and adds <strong>${shieldBonus}</strong> to defense (${newDefenseTotal} ≥ ${attackRoll}). <strong>Shield blocked the attack!</strong> Both armor DR and shield DR <strong>${shieldData.damageReduction}</strong> will apply to damage.</p>`
|
|
||||||
)
|
|
||||||
} else {
|
|
||||||
shieldReaction = null
|
|
||||||
await createReactionMessage(
|
|
||||||
defender,
|
|
||||||
`<p><strong>${defenderName}</strong> rolls <strong>${shieldData.label}</strong> and adds <strong>${shieldBonus}</strong> to defense (${newDefenseTotal} < ${attackRoll}). Shield did not block — normal hit, armor DR only.</p>`
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (choice === "adHocShield") {
|
|
||||||
const adHoc = await LethalFantasyUtils.promptAdHocShield(defenderName, attackRoll, defenseRoll)
|
|
||||||
if (!adHoc) continue
|
|
||||||
const shieldBonus = await LethalFantasyUtils.rollBonusDie(adHoc.formula, defender)
|
|
||||||
const newDefenseTotal = defenseRoll + shieldBonus
|
|
||||||
defenseRoll = newDefenseTotal
|
|
||||||
canShieldReact = false
|
|
||||||
canAdHocShield = false
|
|
||||||
|
|
||||||
if (newDefenseTotal >= attackRoll) {
|
|
||||||
shieldBlocked = true
|
|
||||||
shieldReaction = {
|
|
||||||
damageReduction: adHoc.damageReduction,
|
|
||||||
label: `${adHoc.formula.toUpperCase()} shield`,
|
|
||||||
bonus: shieldBonus
|
|
||||||
}
|
|
||||||
await createReactionMessage(
|
|
||||||
defender,
|
|
||||||
`<p><strong>${defenderName}</strong> rolls <strong>${adHoc.formula.toUpperCase()}</strong> shield and adds <strong>${shieldBonus}</strong> to defense (${newDefenseTotal} ≥ ${attackRoll}). <strong>Shield blocked the attack!</strong> Both armor DR and shield DR <strong>${adHoc.damageReduction}</strong> will apply to damage.</p>`
|
|
||||||
)
|
|
||||||
} else {
|
|
||||||
shieldReaction = null
|
|
||||||
await createReactionMessage(
|
|
||||||
defender,
|
|
||||||
`<p><strong>${defenderName}</strong> rolls <strong>${adHoc.formula.toUpperCase()}</strong> shield and adds <strong>${shieldBonus}</strong> to defense (${newDefenseTotal} < ${attackRoll}). Shield did not block — normal hit, armor DR only.</p>`
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
// These persist across mulligan restarts (once used they stay consumed)
|
||||||
|
const shieldData = LethalFantasyUtils.getShieldReactionData(defender)
|
||||||
|
let canRerollDefense = LethalFantasyUtils.hasD30Reroll(defenseD30message)
|
||||||
|
let canShieldReact = !!shieldData
|
||||||
|
let canAdHocShield = !shieldData
|
||||||
let attackRollFinal = attackRoll
|
let attackRollFinal = attackRoll
|
||||||
let attackerHandledBonus = false
|
let canRerollAttack = LethalFantasyUtils.hasD30Reroll(attackD30message)
|
||||||
|
let mulliganRestart = false
|
||||||
|
|
||||||
// Si l'attaquant est un personnage qui perd et a du Grit
|
do {
|
||||||
// Seulement si l'utilisateur actuel est le propriétaire de l'attaquant (pas le MJ)
|
mulliganRestart = false
|
||||||
if (!defenderHandledBonus && attacker && attackRollFinal <= defenseRoll && isPrimaryController(attacker)) {
|
defenderHandledBonus = false
|
||||||
let canRerollAttack = LethalFantasyUtils.hasD30Reroll(attackD30message)
|
attackerHandledBonus = false
|
||||||
|
|
||||||
while (attackRollFinal <= defenseRoll) {
|
// ── Defense reaction loop ──────────────────────────────────────────────
|
||||||
const currentGrit = Number(attacker.system?.grit?.current) || 0
|
if (defender && defenseRoll < attackRollFinal && isPrimaryController(defender) && !isSpellOrMiracle) {
|
||||||
const buttons = []
|
while (defenseRoll < attackRollFinal) {
|
||||||
|
const currentGrit = Number(defender.system?.grit?.current) || 0
|
||||||
|
const currentLuck = Number(defender.system?.luck?.current) || 0
|
||||||
|
const buttons = []
|
||||||
|
|
||||||
|
if (currentGrit > 0) {
|
||||||
|
buttons.push({
|
||||||
|
action: "grit",
|
||||||
|
label: `Spend 1 Grit (+1D6) [${currentGrit} left]`,
|
||||||
|
icon: "fa-solid fa-fist-raised",
|
||||||
|
callback: () => "grit"
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
if (currentLuck > 0) {
|
||||||
|
buttons.push({
|
||||||
|
action: "luck",
|
||||||
|
label: `Spend 1 Luck (+1D6) [${currentLuck} left]`,
|
||||||
|
icon: "fa-solid fa-clover",
|
||||||
|
callback: () => "luck"
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
if (currentGrit > 0) {
|
|
||||||
buttons.push({
|
buttons.push({
|
||||||
action: "grit",
|
action: "bonusDie",
|
||||||
label: `Spend 1 Grit (+1D6) [${currentGrit} left]`,
|
label: "Add bonus die",
|
||||||
icon: "fa-solid fa-fist-raised",
|
icon: "fa-solid fa-dice",
|
||||||
callback: () => "grit"
|
callback: () => "bonusDie"
|
||||||
})
|
})
|
||||||
}
|
|
||||||
|
|
||||||
buttons.push({
|
if (canRerollDefense) {
|
||||||
action: "bonusDie",
|
buttons.push({
|
||||||
label: "Add bonus die",
|
action: "rerollDefense",
|
||||||
icon: "fa-solid fa-dice",
|
label: "Re-roll defense (Mulligan)",
|
||||||
callback: () => "bonusDie"
|
icon: "fa-solid fa-rotate-right",
|
||||||
})
|
callback: () => "rerollDefense"
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
if (canShieldReact) {
|
||||||
|
buttons.push({
|
||||||
|
action: "shieldReact",
|
||||||
|
label: `Roll shield (${shieldData.label})`,
|
||||||
|
icon: "fa-solid fa-shield",
|
||||||
|
callback: () => "shieldReact"
|
||||||
|
})
|
||||||
|
} else if (canAdHocShield) {
|
||||||
|
buttons.push({
|
||||||
|
action: "adHocShield",
|
||||||
|
label: "Roll ad-hoc shield (choose dice + DR)",
|
||||||
|
icon: "fa-solid fa-shield-halved",
|
||||||
|
callback: () => "adHocShield"
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
if (canRerollAttack && attackRerollContext) {
|
|
||||||
buttons.push({
|
buttons.push({
|
||||||
action: "rerollAttack",
|
action: "continue",
|
||||||
label: "Re-roll attack",
|
label: "Continue (no defense bonus)",
|
||||||
icon: "fa-solid fa-rotate-right",
|
icon: "fa-solid fa-forward",
|
||||||
callback: () => "rerollAttack"
|
callback: () => "continue"
|
||||||
})
|
})
|
||||||
}
|
|
||||||
|
|
||||||
buttons.push({
|
const choice = await foundry.applications.api.DialogV2.wait({
|
||||||
action: "continue",
|
window: { title: "Defense reactions" },
|
||||||
label: "Continue (no attack bonus)",
|
classes: ["lethalfantasy"],
|
||||||
icon: "fa-solid fa-forward",
|
content: `
|
||||||
callback: () => "continue"
|
<div class="grit-luck-dialog">
|
||||||
})
|
<div class="combat-status">
|
||||||
|
<p><strong>${attackerName}</strong> rolled <strong>${attackRollFinal}</strong></p>
|
||||||
const choice = await foundry.applications.api.DialogV2.wait({
|
<p><strong>${defenderName}</strong> currently has <strong>${defenseRoll}</strong></p>
|
||||||
window: { title: "Attack reactions" },
|
${defenseD30message ? `<p class="bonus-info">D30 special: ${defenseD30message.description}</p>` : ""}
|
||||||
classes: ["lethalfantasy"],
|
</div>
|
||||||
content: `
|
<p class="offer-text">Choose how to improve the defense before resolving the hit.</p>
|
||||||
<div class="grit-luck-dialog">
|
|
||||||
<div class="combat-status">
|
|
||||||
<p><strong>${attackerName}</strong> currently has <strong>${attackRollFinal}</strong></p>
|
|
||||||
<p><strong>${defenderName}</strong> rolled <strong>${defenseRoll}</strong></p>
|
|
||||||
${attackD30message ? `<p class="bonus-info">D30 special: ${attackD30message.description}</p>` : ""}
|
|
||||||
</div>
|
</div>
|
||||||
<p class="offer-text">Choose how to improve the attack before resolving the combat result.</p>
|
`,
|
||||||
</div>
|
buttons,
|
||||||
`,
|
rejectClose: false
|
||||||
buttons,
|
})
|
||||||
rejectClose: false
|
|
||||||
})
|
|
||||||
|
|
||||||
if (!choice || choice === "continue") break
|
if (!choice || choice === "continue") break
|
||||||
|
|
||||||
attackerHandledBonus = true
|
defenderHandledBonus = true
|
||||||
|
|
||||||
if (choice === "grit") {
|
if (choice === "grit") {
|
||||||
const attackBonus = await LethalFantasyUtils.rollBonusDie("1d6", attacker, (total) => `<p><strong>${attackerName}</strong> spends 1 Grit and rolls <strong>${total}</strong> for attack.</p>`)
|
const bonusRoll = await LethalFantasyUtils.rollBonusDie("1d6", defender, total => `<p><strong>${defenderName}</strong> spends 1 Grit and rolls <strong>${total}</strong> for defense.</p>`)
|
||||||
attackRollFinal += attackBonus
|
defenseRoll += bonusRoll
|
||||||
await attacker.update({ "system.grit.current": currentGrit - 1 })
|
await defender.update({ "system.grit.current": currentGrit - 1 })
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
if (choice === "bonusDie") {
|
if (choice === "luck") {
|
||||||
const bonusDie = await LethalFantasyUtils.promptCombatBonusDie(attackerName, "defense", attackRollFinal, defenseRoll)
|
const bonusRoll = await LethalFantasyUtils.rollBonusDie("1d6", defender, total => `<p><strong>${defenderName}</strong> spends 1 Luck and rolls <strong>${total}</strong> for defense.</p>`)
|
||||||
if (!bonusDie) continue
|
defenseRoll += bonusRoll
|
||||||
const attackBonus = await LethalFantasyUtils.rollBonusDie(bonusDie, attacker, (total, formula) => `<p><strong>${attackerName}</strong> adds <strong>${formula.toUpperCase()}</strong> and rolls <strong>${total}</strong> for attack.</p>`)
|
await defender.update({ "system.luck.current": currentLuck - 1 })
|
||||||
attackRollFinal += attackBonus
|
continue
|
||||||
continue
|
}
|
||||||
}
|
|
||||||
|
|
||||||
if (choice === "rerollAttack" && canRerollAttack && attackRerollContext) {
|
if (choice === "bonusDie") {
|
||||||
const oldAttackRoll = attackRollFinal
|
const bonusDie = await LethalFantasyUtils.promptCombatBonusDie(defenderName, "attack", defenseRoll, attackRollFinal)
|
||||||
const reroll = await LethalFantasyUtils.rerollConfiguredRoll(attackRerollContext)
|
if (!bonusDie) continue
|
||||||
canRerollAttack = false
|
const bonusRoll = await LethalFantasyUtils.rollBonusDie(bonusDie, defender, (total, formula) => `<p><strong>${defenderName}</strong> adds <strong>${formula.toUpperCase()}</strong> and rolls <strong>${total}</strong> for defense.</p>`)
|
||||||
if (!reroll) continue
|
defenseRoll += bonusRoll
|
||||||
attackRollFinal = reroll.options?.rollTotal || reroll.total || oldAttackRoll
|
continue
|
||||||
await createReactionMessage(attacker, `<p><strong>${attackerName}</strong> uses Mulligan and re-rolls attack: <strong>${oldAttackRoll}</strong> → <strong>${attackRollFinal}</strong>.</p>`)
|
}
|
||||||
|
|
||||||
|
if (choice === "rerollDefense" && canRerollDefense) {
|
||||||
|
const oldDefenseRoll = defenseRoll
|
||||||
|
const reroll = await LethalFantasyUtils.rerollConfiguredRoll(defenseRerollContext)
|
||||||
|
canRerollDefense = false
|
||||||
|
if (!reroll) continue
|
||||||
|
defenseRoll = reroll.options?.rollTotal || reroll.total || oldDefenseRoll
|
||||||
|
await createReactionMessage(defender, `<p><strong>${defenderName}</strong> uses Mulligan and re-rolls defense: <strong>${oldDefenseRoll}</strong> → <strong>${defenseRoll}</strong>. Both sides may now react to the new numbers.</p>`)
|
||||||
|
// Restart the full comparison so both sides can react to the new roll
|
||||||
|
mulliganRestart = true
|
||||||
|
break
|
||||||
|
}
|
||||||
|
|
||||||
|
if (choice === "shieldReact" && canShieldReact) {
|
||||||
|
const shieldBonus = await LethalFantasyUtils.rollBonusDie(shieldData.formula, defender)
|
||||||
|
const newDefenseTotal = defenseRoll + shieldBonus
|
||||||
|
defenseRoll = newDefenseTotal
|
||||||
|
canShieldReact = false
|
||||||
|
|
||||||
|
if (newDefenseTotal >= attackRollFinal) {
|
||||||
|
shieldBlocked = true
|
||||||
|
shieldReaction = {
|
||||||
|
damageReduction: shieldData.damageReduction,
|
||||||
|
label: shieldData.label,
|
||||||
|
bonus: shieldBonus
|
||||||
|
}
|
||||||
|
await createReactionMessage(
|
||||||
|
defender,
|
||||||
|
`<p><strong>${defenderName}</strong> rolls <strong>${shieldData.label}</strong> and adds <strong>${shieldBonus}</strong> to defense (${newDefenseTotal} ≥ ${attackRollFinal}). <strong>Shield blocked the attack!</strong> Both armor DR and shield DR <strong>${shieldData.damageReduction}</strong> will apply to damage.</p>`
|
||||||
|
)
|
||||||
|
} else {
|
||||||
|
shieldReaction = null
|
||||||
|
await createReactionMessage(
|
||||||
|
defender,
|
||||||
|
`<p><strong>${defenderName}</strong> rolls <strong>${shieldData.label}</strong> and adds <strong>${shieldBonus}</strong> to defense (${newDefenseTotal} < ${attackRollFinal}). Shield did not block — normal hit, armor DR only.</p>`
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (choice === "adHocShield") {
|
||||||
|
const adHoc = await LethalFantasyUtils.promptAdHocShield(defenderName, attackRollFinal, defenseRoll)
|
||||||
|
if (!adHoc) continue
|
||||||
|
const shieldBonus = await LethalFantasyUtils.rollBonusDie(adHoc.formula, defender)
|
||||||
|
const newDefenseTotal = defenseRoll + shieldBonus
|
||||||
|
defenseRoll = newDefenseTotal
|
||||||
|
canShieldReact = false
|
||||||
|
canAdHocShield = false
|
||||||
|
|
||||||
|
if (newDefenseTotal >= attackRollFinal) {
|
||||||
|
shieldBlocked = true
|
||||||
|
shieldReaction = {
|
||||||
|
damageReduction: adHoc.damageReduction,
|
||||||
|
label: `${adHoc.formula.toUpperCase()} shield`,
|
||||||
|
bonus: shieldBonus
|
||||||
|
}
|
||||||
|
await createReactionMessage(
|
||||||
|
defender,
|
||||||
|
`<p><strong>${defenderName}</strong> rolls <strong>${adHoc.formula.toUpperCase()}</strong> shield and adds <strong>${shieldBonus}</strong> to defense (${newDefenseTotal} ≥ ${attackRollFinal}). <strong>Shield blocked the attack!</strong> Both armor DR and shield DR <strong>${adHoc.damageReduction}</strong> will apply to damage.</p>`
|
||||||
|
)
|
||||||
|
} else {
|
||||||
|
shieldReaction = null
|
||||||
|
await createReactionMessage(
|
||||||
|
defender,
|
||||||
|
`<p><strong>${defenderName}</strong> rolls <strong>${adHoc.formula.toUpperCase()}</strong> shield and adds <strong>${shieldBonus}</strong> to defense (${newDefenseTotal} < ${attackRollFinal}). Shield did not block — normal hit, armor DR only.</p>`
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
if (mulliganRestart) continue
|
||||||
|
|
||||||
|
// ── Attack reaction loop ───────────────────────────────────────────────
|
||||||
|
if (!defenderHandledBonus && attacker && attackRollFinal <= defenseRoll && isPrimaryController(attacker)) {
|
||||||
|
while (attackRollFinal <= defenseRoll) {
|
||||||
|
const currentGrit = Number(attacker.system?.grit?.current) || 0
|
||||||
|
const buttons = []
|
||||||
|
|
||||||
|
if (currentGrit > 0) {
|
||||||
|
buttons.push({
|
||||||
|
action: "grit",
|
||||||
|
label: `Spend 1 Grit (+1D6) [${currentGrit} left]`,
|
||||||
|
icon: "fa-solid fa-fist-raised",
|
||||||
|
callback: () => "grit"
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
buttons.push({
|
||||||
|
action: "bonusDie",
|
||||||
|
label: "Add bonus die",
|
||||||
|
icon: "fa-solid fa-dice",
|
||||||
|
callback: () => "bonusDie"
|
||||||
|
})
|
||||||
|
|
||||||
|
if (canRerollAttack && attackRerollContext) {
|
||||||
|
buttons.push({
|
||||||
|
action: "rerollAttack",
|
||||||
|
label: "Re-roll attack (Mulligan)",
|
||||||
|
icon: "fa-solid fa-rotate-right",
|
||||||
|
callback: () => "rerollAttack"
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
buttons.push({
|
||||||
|
action: "continue",
|
||||||
|
label: "Continue (no attack bonus)",
|
||||||
|
icon: "fa-solid fa-forward",
|
||||||
|
callback: () => "continue"
|
||||||
|
})
|
||||||
|
|
||||||
|
const choice = await foundry.applications.api.DialogV2.wait({
|
||||||
|
window: { title: "Attack reactions" },
|
||||||
|
classes: ["lethalfantasy"],
|
||||||
|
content: `
|
||||||
|
<div class="grit-luck-dialog">
|
||||||
|
<div class="combat-status">
|
||||||
|
<p><strong>${attackerName}</strong> currently has <strong>${attackRollFinal}</strong></p>
|
||||||
|
<p><strong>${defenderName}</strong> rolled <strong>${defenseRoll}</strong></p>
|
||||||
|
${attackD30message ? `<p class="bonus-info">D30 special: ${attackD30message.description}</p>` : ""}
|
||||||
|
</div>
|
||||||
|
<p class="offer-text">Choose how to improve the attack before resolving the combat result.</p>
|
||||||
|
</div>
|
||||||
|
`,
|
||||||
|
buttons,
|
||||||
|
rejectClose: false
|
||||||
|
})
|
||||||
|
|
||||||
|
if (!choice || choice === "continue") break
|
||||||
|
|
||||||
|
attackerHandledBonus = true
|
||||||
|
|
||||||
|
if (choice === "grit") {
|
||||||
|
const attackBonus = await LethalFantasyUtils.rollBonusDie("1d6", attacker, total => `<p><strong>${attackerName}</strong> spends 1 Grit and rolls <strong>${total}</strong> for attack.</p>`)
|
||||||
|
attackRollFinal += attackBonus
|
||||||
|
await attacker.update({ "system.grit.current": currentGrit - 1 })
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
if (choice === "bonusDie") {
|
||||||
|
const bonusDie = await LethalFantasyUtils.promptCombatBonusDie(attackerName, "defense", attackRollFinal, defenseRoll)
|
||||||
|
if (!bonusDie) continue
|
||||||
|
const attackBonus = await LethalFantasyUtils.rollBonusDie(bonusDie, attacker, (total, formula) => `<p><strong>${attackerName}</strong> adds <strong>${formula.toUpperCase()}</strong> and rolls <strong>${total}</strong> for attack.</p>`)
|
||||||
|
attackRollFinal += attackBonus
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
if (choice === "rerollAttack" && canRerollAttack && attackRerollContext) {
|
||||||
|
const oldAttackRoll = attackRollFinal
|
||||||
|
const reroll = await LethalFantasyUtils.rerollConfiguredRoll(attackRerollContext)
|
||||||
|
canRerollAttack = false
|
||||||
|
if (!reroll) continue
|
||||||
|
attackRollFinal = reroll.options?.rollTotal || reroll.total || oldAttackRoll
|
||||||
|
await createReactionMessage(attacker, `<p><strong>${attackerName}</strong> uses Mulligan and re-rolls attack: <strong>${oldAttackRoll}</strong> → <strong>${attackRollFinal}</strong>. Both sides may now react to the new numbers.</p>`)
|
||||||
|
// Restart the full comparison so both sides can react to the new roll
|
||||||
|
mulliganRestart = true
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} while (mulliganRestart)
|
||||||
|
|
||||||
const shieldDamageReduction = shieldBlocked ? shieldReaction.damageReduction : 0
|
const shieldDamageReduction = shieldBlocked ? shieldReaction.damageReduction : 0
|
||||||
const outcome = shieldBlocked ? "shielded-hit" : (attackRollFinal > defenseRoll ? "hit" : "miss")
|
const outcome = shieldBlocked ? "shielded-hit" : (attackRollFinal > defenseRoll ? "hit" : "miss")
|
||||||
|
|||||||
@@ -108,6 +108,10 @@
|
|||||||
}
|
}
|
||||||
],
|
],
|
||||||
"description": "Possible Flawless or Legendary Defense or Add D20E to Defense"
|
"description": "Possible Flawless or Legendary Defense or Add D20E to Defense"
|
||||||
|
},
|
||||||
|
"saving_throws": {
|
||||||
|
"type": "save_auto_success",
|
||||||
|
"description": "Saving Throw Succeeds Regardless of Opposing Roll"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"29": {
|
"29": {
|
||||||
@@ -145,6 +149,11 @@
|
|||||||
"type": "gain_grit",
|
"type": "gain_grit",
|
||||||
"amount": 1,
|
"amount": 1,
|
||||||
"description": "Gain 1 Grit"
|
"description": "Gain 1 Grit"
|
||||||
|
},
|
||||||
|
"saving_throws": {
|
||||||
|
"type": "gain_grit",
|
||||||
|
"amount": 1,
|
||||||
|
"description": "Gain 1 Grit"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"28": {
|
"28": {
|
||||||
@@ -199,6 +208,12 @@
|
|||||||
"amount": 1,
|
"amount": 1,
|
||||||
"target": "skill",
|
"target": "skill",
|
||||||
"description": "Add 1 to Skill Roll"
|
"description": "Add 1 to Skill Roll"
|
||||||
|
},
|
||||||
|
"saving_throws": {
|
||||||
|
"type": "bonus_flat",
|
||||||
|
"amount": 1,
|
||||||
|
"target": "save",
|
||||||
|
"description": "Add 1 to Saving Throw"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"21": {
|
"21": {
|
||||||
@@ -239,6 +254,12 @@
|
|||||||
"ranged_defense": {
|
"ranged_defense": {
|
||||||
"type": "recover_pain",
|
"type": "recover_pain",
|
||||||
"description": "Defender Recovers or ignores any flash of pain"
|
"description": "Defender Recovers or ignores any flash of pain"
|
||||||
|
},
|
||||||
|
"saving_throws": {
|
||||||
|
"type": "bonus_dice",
|
||||||
|
"dice": "D6",
|
||||||
|
"target": "save",
|
||||||
|
"description": "Granted D6 (1-6) Saving Throw Modifier for this Saving Throw Attempt"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"20": {
|
"20": {
|
||||||
@@ -349,6 +370,12 @@
|
|||||||
}
|
}
|
||||||
],
|
],
|
||||||
"description": "Possible 20/20 defense that avoids Any Attack Except a Lethal Strike or adds D12 to defense"
|
"description": "Possible 20/20 defense that avoids Any Attack Except a Lethal Strike or adds D12 to defense"
|
||||||
|
},
|
||||||
|
"saving_throws": {
|
||||||
|
"type": "bonus_flat",
|
||||||
|
"amount": 20,
|
||||||
|
"target": "save",
|
||||||
|
"description": "20 Added to Saving Throw"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"15": {
|
"15": {
|
||||||
@@ -391,6 +418,12 @@
|
|||||||
"shield_bash"
|
"shield_bash"
|
||||||
],
|
],
|
||||||
"description": "Kick, Punch or Shield Bash"
|
"description": "Kick, Punch or Shield Bash"
|
||||||
|
},
|
||||||
|
"saving_throws": {
|
||||||
|
"type": "bonus_flat",
|
||||||
|
"amount": 1,
|
||||||
|
"target": "save",
|
||||||
|
"description": "Add 1 to Saving Throw"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"13": {},
|
"13": {},
|
||||||
@@ -445,6 +478,12 @@
|
|||||||
"shield_bash"
|
"shield_bash"
|
||||||
],
|
],
|
||||||
"description": "Kick, Punch or Shield Bash"
|
"description": "Kick, Punch or Shield Bash"
|
||||||
|
},
|
||||||
|
"saving_throws": {
|
||||||
|
"type": "bonus_flat",
|
||||||
|
"amount": 1,
|
||||||
|
"target": "save",
|
||||||
|
"description": "Add 1 to Saving Throw"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"8": {
|
"8": {
|
||||||
@@ -475,6 +514,10 @@
|
|||||||
"ranged_defense": {
|
"ranged_defense": {
|
||||||
"type": "mulligan",
|
"type": "mulligan",
|
||||||
"description": "Mulligan, Can Choose to Re-Roll This Defense"
|
"description": "Mulligan, Can Choose to Re-Roll This Defense"
|
||||||
|
},
|
||||||
|
"saving_throws": {
|
||||||
|
"type": "mulligan",
|
||||||
|
"description": "Mulligan, Can Re-Roll This Saving Throw"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"7": {
|
"7": {
|
||||||
@@ -528,6 +571,12 @@
|
|||||||
"shield_bash"
|
"shield_bash"
|
||||||
],
|
],
|
||||||
"description": "Kick, Punch, or Shield Bash"
|
"description": "Kick, Punch, or Shield Bash"
|
||||||
|
},
|
||||||
|
"saving_throws": {
|
||||||
|
"type": "bonus_flat",
|
||||||
|
"amount": 1,
|
||||||
|
"target": "save",
|
||||||
|
"description": "Add 1 to Saving Throw"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"3": {
|
"3": {
|
||||||
|
|||||||
@@ -25,7 +25,8 @@ export default class D30Roll {
|
|||||||
RANGED_DEFENSE: "ranged_defense",
|
RANGED_DEFENSE: "ranged_defense",
|
||||||
ARCANE_SPELL_ATTACK: "arcane_spell_attack",
|
ARCANE_SPELL_ATTACK: "arcane_spell_attack",
|
||||||
ARCANE_SPELL_DEFENSE: "arcane_spell_defense",
|
ARCANE_SPELL_DEFENSE: "arcane_spell_defense",
|
||||||
SKILL_ROLLS: "skill_rolls"
|
SKILL_ROLLS: "skill_rolls",
|
||||||
|
SAVING_THROWS: "saving_throws"
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -137,11 +138,15 @@ export default class D30Roll {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Skill types
|
// Skill types
|
||||||
if (externalType === "skill" || externalType === "monster-skill" ||
|
if (externalType === "skill" || externalType === "monster-skill" || externalType === "challenge") {
|
||||||
externalType === "save" || externalType === "challenge") {
|
|
||||||
return this.ROLL_TYPES.SKILL_ROLLS
|
return this.ROLL_TYPES.SKILL_ROLLS
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Saving throw types
|
||||||
|
if (externalType === "save") {
|
||||||
|
return options.isSpellSave ? this.ROLL_TYPES.ARCANE_SPELL_DEFENSE : this.ROLL_TYPES.SAVING_THROWS
|
||||||
|
}
|
||||||
|
|
||||||
// If no match, return null
|
// If no match, return null
|
||||||
console.warn(`D30Roll | Unknown external roll type: ${externalType}`)
|
console.warn(`D30Roll | Unknown external roll type: ${externalType}`)
|
||||||
return null
|
return null
|
||||||
|
|||||||
@@ -609,7 +609,7 @@ export default class LethalFantasyRoll extends Roll {
|
|||||||
rollD30.total,
|
rollD30.total,
|
||||||
options.rollType,
|
options.rollType,
|
||||||
options.rollTarget?.weapon,
|
options.rollTarget?.weapon,
|
||||||
{ isRanged: isRangedForD30 }
|
{ isRanged: isRangedForD30, isSpellSave: saveSpell }
|
||||||
)
|
)
|
||||||
options.D30message = d30Message
|
options.D30message = d30Message
|
||||||
}
|
}
|
||||||
@@ -787,9 +787,18 @@ export default class LethalFantasyRoll extends Roll {
|
|||||||
let buttons = []
|
let buttons = []
|
||||||
if (currentAction) {
|
if (currentAction) {
|
||||||
if (currentAction.type === "weapon") {
|
if (currentAction.type === "weapon") {
|
||||||
|
let weaponLabel = "Roll progression dice"
|
||||||
|
if (currentAction.rangedMode) {
|
||||||
|
// Compute loading count from the speed formula (e.g. "3+1d6" → load=3)
|
||||||
|
const speedStr = currentAction.system?.speed?.[currentAction.rangedMode] ?? ""
|
||||||
|
const rangedLoad = currentAction.rangedLoad ?? (Number(speedStr.split("+")[0]) || 0)
|
||||||
|
if (rangedLoad > 0 && !currentAction.weaponLoaded) {
|
||||||
|
weaponLabel = "Load weapon"
|
||||||
|
}
|
||||||
|
}
|
||||||
buttons.push({
|
buttons.push({
|
||||||
action: "roll",
|
action: "roll",
|
||||||
label: "Roll progression dice",
|
label: weaponLabel,
|
||||||
callback: (event, button) => {
|
callback: (event, button) => {
|
||||||
let pos = $('#combat-action-dialog').position()
|
let pos = $('#combat-action-dialog').position()
|
||||||
game.user.setFlag(SYSTEM.id, "combat-action-dialog-pos", pos)
|
game.user.setFlag(SYSTEM.id, "combat-action-dialog-pos", pos)
|
||||||
@@ -908,14 +917,15 @@ export default class LethalFantasyRoll extends Roll {
|
|||||||
if (rollContext === "rollLethargyDice") {
|
if (rollContext === "rollLethargyDice") {
|
||||||
if (currentAction.spellStatus === "castingTime") {
|
if (currentAction.spellStatus === "castingTime") {
|
||||||
let time = currentAction.type === "spell" ? currentAction.system.castingTime : currentAction.system.prayerTime
|
let time = currentAction.type === "spell" ? currentAction.system.castingTime : currentAction.system.prayerTime
|
||||||
if (currentAction.castingTime <= time) {
|
if (currentAction.castingTime < time) {
|
||||||
let message = `Casting time : ${currentAction.name}, count : ${currentAction.castingTime}/${time}`
|
let message = `Casting time : ${currentAction.name}, count : ${currentAction.castingTime}/${time}`
|
||||||
ChatMessage.create({ content: message, speaker: ChatMessage.getSpeaker({ actor: combatant.actor }) })
|
ChatMessage.create({ content: message, speaker: ChatMessage.getSpeaker({ actor: combatant.actor }) })
|
||||||
currentAction.castingTime += 1
|
currentAction.castingTime += 1
|
||||||
await combatant.setFlag(SYSTEM.id, "currentAction", foundry.utils.duplicate(currentAction))
|
await combatant.setFlag(SYSTEM.id, "currentAction", foundry.utils.duplicate(currentAction))
|
||||||
return
|
return
|
||||||
} else {
|
} else {
|
||||||
let message = `Spell/Miracle ${currentAction.name} ready to be cast on next second !`
|
// Last counting second — announce ready and transition immediately (no extra second consumed)
|
||||||
|
let message = `Casting time : ${currentAction.name}, count : ${time}/${time} — ready to cast next second !`
|
||||||
ChatMessage.create({ content: message, speaker: ChatMessage.getSpeaker({ actor: combatant.actor }) })
|
ChatMessage.create({ content: message, speaker: ChatMessage.getSpeaker({ actor: combatant.actor }) })
|
||||||
currentAction.castingTime = 1
|
currentAction.castingTime = 1
|
||||||
currentAction.spellStatus = "toBeCasted"
|
currentAction.spellStatus = "toBeCasted"
|
||||||
|
|||||||
Reference in New Issue
Block a user