Fixes regarding shields usage and spells

This commit is contained in:
2026-04-14 21:31:03 +02:00
parent 343abc32e2
commit 2e2a917a45
30 changed files with 217 additions and 104 deletions

View File

@@ -346,6 +346,36 @@ Hooks.on(hookName, (message, html, data) => {
return
}
// Pour les sorts, rouler les dés de dégâts avec option bypass DR
if (damageType === "spell" && damageFormula) {
const bypassArmor = await foundry.applications.api.DialogV2.confirm({
window: { title: "Spell Damage" },
classes: ["lethalfantasy"],
content: "<p>Does this spell's damage bypass armor DR?</p>",
yes: { label: "Yes (ignore armor)", icon: "fa-solid fa-wand-magic-sparkles" },
no: { label: "No (apply armor DR)", icon: "fa-solid fa-shield" }
})
const rollOpts = {
type: "spell-damage",
rollType: "spell-damage",
rollName: damageFormula,
isDamage: true,
rollData: { isDamage: true },
bypassArmor: bypassArmor ?? false,
defenderId,
defenderTokenId,
actorId: actor.id,
actorName: actor.name,
actorImage: actor.img
}
const roll = new LethalFantasyRoll(damageFormula, {}, rollOpts)
await roll.evaluate()
roll.options.rollTotal = roll.total
if (game?.dice3d) await game.dice3d.showForRoll(roll, game.user, true)
await roll.toMessage()
return
}
// Pour les boutons de résultat de combat (monster damage)
if (damageType === "monster" && attackKey) {
await actor.system.prepareMonsterRoll("monster-damage", attackKey, undefined, undefined, undefined, defenderId, defenderTokenId, extraShieldDr)
@@ -394,7 +424,7 @@ Hooks.on("preCreateChatMessage", (message) => {
const rollType = message.rolls[0]?.options?.rollType
// Si c'est un message de défense et qu'on a des données en attente
if ((rollType === "weapon-defense" || rollType === "monster-defense") && game.lethalFantasy?.nextDefenseData) {
if ((rollType === "weapon-defense" || rollType === "monster-defense" || rollType === "save") && game.lethalFantasy?.nextDefenseData) {
// Ajouter les données dans les flags du message
message.updateSource({
[`flags.${SYSTEM.id}.attackData`]: game.lethalFantasy.nextDefenseData
@@ -414,7 +444,7 @@ Hooks.on("createChatMessage", async (message) => {
console.log("Defense hook checking message, rollType:", rollType)
// Vérifier si c'est un message de défense
if (rollType !== "weapon-defense" && rollType !== "monster-defense") return
if (rollType !== "weapon-defense" && rollType !== "monster-defense" && rollType !== "save") return
// Récupérer les données d'attaque depuis les flags
const attackData = message.flags?.[SYSTEM.id]?.attackData
@@ -483,7 +513,9 @@ Hooks.on("createChatMessage", async (message) => {
// Seulement si l'utilisateur actuel est le propriétaire du défenseur
let defenderHandledBonus = false
let shieldReaction = null
if (defender && defenseRoll < attackRoll && isPrimaryController(defender)) {
let shieldBlocked = false
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
@@ -598,17 +630,30 @@ Hooks.on("createChatMessage", async (message) => {
if (choice === "shieldReact" && canShieldReact) {
const shieldBonus = await LethalFantasyUtils.rollBonusDie(shieldData.formula, defender)
defenseRoll += shieldBonus
shieldReaction = {
damageReduction: shieldData.damageReduction,
label: shieldData.label,
bonus: shieldBonus
}
const newDefenseTotal = defenseRoll + shieldBonus
defenseRoll = newDefenseTotal
canShieldReact = false
await createReactionMessage(
defender,
`<p><strong>${defenderName}</strong> rolls <strong>${shieldData.label}</strong> and adds <strong>${shieldBonus}</strong> to defense.${defenseRoll < attackRoll ? ` The hit still lands, but shield DR <strong>${shieldData.damageReduction}</strong> will reduce the damage.` : ""}</p>`
)
if (newDefenseTotal >= attackRoll) {
// Shield roll tied or exceeded the attack — shield blocked
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 {
// Shield roll not enough — hit still lands, armor DR only
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>`
)
}
}
}
}
@@ -704,8 +749,8 @@ Hooks.on("createChatMessage", async (message) => {
}
}
const shieldDamageReduction = shieldReaction && attackRollFinal > defenseRoll ? shieldReaction.damageReduction : 0
const outcome = shieldDamageReduction > 0 ? "shielded-hit" : (attackRollFinal > defenseRoll ? "hit" : "miss")
const shieldDamageReduction = shieldBlocked ? shieldReaction.damageReduction : 0
const outcome = shieldBlocked ? "shielded-hit" : (attackRollFinal > defenseRoll ? "hit" : "miss")
// Créer le message de comparaison - uniquement par le client qui a géré le dernier bonus
// Priorité: attaquant si il a géré le bonus, sinon défenseur si il a géré le bonus, sinon défenseur
@@ -788,7 +833,8 @@ Hooks.on("createChatMessage", async (message) => {
const attackerName = message.rolls[0]?.options?.actorName || "Unknown Attacker"
// Calculer les DR
const armorDR = defender.computeDamageReduction() || 0
const bypassArmor = message.rolls[0]?.options?.bypassArmor || false
const armorDR = bypassArmor ? 0 : (defender.computeDamageReduction() || 0)
const extraShieldDr = Number(message.rolls[0]?.options?.extraShieldDr) || 0
const totalDR = armorDR + extraShieldDr
const finalDamage = Math.max(0, damageTotal - totalDR)
@@ -823,7 +869,7 @@ Hooks.on("createChatMessage", async (message) => {
{
targetName: defender.name,
damage: finalDamage,
drText: totalDR > 0 ? `Armor DR: ${armorDR}${extraShieldDr > 0 ? ` + Shield DR: ${extraShieldDr}` : ""}` : "",
drText: bypassArmor ? "Armor DR bypassed (spell)" : (totalDR > 0 ? `Armor DR: ${armorDR}${extraShieldDr > 0 ? ` + Shield DR: ${extraShieldDr}` : ""}` : ""),
weaponName: weaponName,
attackerName: attackerName,
rawDamage: damageTotal