FIx mulligan rolls
Release Creation / build (release) Successful in 2m19s

This commit is contained in:
2026-07-01 10:38:19 +02:00
parent 25648aa2a3
commit 1ea1a4b4b7
4 changed files with 70 additions and 17 deletions
+42 -4
View File
@@ -1,6 +1,6 @@
import { SYSTEM } from "../config/system.mjs"
import { log } from "./helpers.mjs"
import { processD30BonusDice } from "./d30.mjs"
import { processD30BonusDice, hasD30Reroll } from "./d30.mjs"
export async function handleSocketEvent(msg = {}) {
log(`handleSocketEvent !`, msg)
@@ -100,7 +100,7 @@ export async function handleAttackBoosted(msg) {
attackerHandledBonus, attackRollFinal, defenseRoll, attackWeaponId, attackRollType, attackRollKey,
shieldDamageReduction: initialShieldDR,
d30Bleed, d30DamageMultiplier, d30DrMultiplier,
damageTier, attackD30message, defenseD30message,
damageTier, attackD30message, defenseD30message, defenseRerollContext,
hasShield, shieldLabel, shieldFormula, shieldDr, canAdHocShield
} = msg
@@ -139,7 +139,7 @@ export async function handleAttackBoosted(msg) {
if (defender) {
while (updatedDefenseRoll < attackRollFinal) {
const shieldData = canShieldReact ? { label: shieldLabel, formula: shieldFormula, damageReduction: shieldDr } : null
const buttons = buildDefenseReactionButtons(defender, { canRerollDefense: false, shieldData, canShieldReact, canAdHocShield: canAdHoc })
const buttons = buildDefenseReactionButtons(defender, { canRerollDefense: hasD30Reroll(defenseD30message), shieldData, canShieldReact, canAdHocShield: canAdHoc })
const choice = await foundry.applications.api.DialogV2.wait({
window: { title: "Defense reactions — attack boosted" },
@@ -151,7 +151,7 @@ export async function handleAttackBoosted(msg) {
defenderName,
defenseRoll: updatedDefenseRoll,
defenseStatus: "currently has",
d30message: null,
d30message: defenseD30message || null,
offerText: "The attack was boosted! Choose how to improve the defense."
}),
buttons,
@@ -200,6 +200,44 @@ export async function handleAttackBoosted(msg) {
speaker: ChatMessage.getSpeaker({ actor: defender })
})
}
} else if (choice === "rerollDefense" && defenseRerollContext) {
const oldDefenseRoll = updatedDefenseRoll
const reroll = await rerollConfiguredRoll(defenseRerollContext)
if (!reroll) continue
updatedDefenseRoll = reroll.options?.rollTotal || reroll.total || oldDefenseRoll
let newD30message = reroll.options?.D30message || null
const mulliganContent = await foundry.applications.handlebars.renderTemplate("systems/fvtt-lethal-fantasy/templates/chat/reaction-message.hbs", {
type: "mulligan",
actorName: defenderName,
side: "defense",
oldRoll: oldDefenseRoll,
newRoll: updatedDefenseRoll,
diceResults: reroll.options?.diceResults || [],
D30result: reroll.options?.D30result,
D30message: newD30message
})
await ChatMessage.create({content: mulliganContent, speaker: ChatMessage.getSpeaker({actor: defender})})
// Process new D30 bonus dice from the reroll
if (newD30message) {
defenseD30message = newD30message
const d30Result = await processD30BonusDice(defenseD30message, "defense", null, defender, true)
if (d30Result.modifier) {
updatedDefenseRoll += d30Result.modifier
if (d30Result.modifier > 0) {
const rmContent = await foundry.applications.handlebars.renderTemplate("systems/fvtt-lethal-fantasy/templates/chat/reaction-message.hbs", {type:"d30Bonus", actorName:defenderName, value:d30Result.modifier, side:"defense"})
await ChatMessage.create({content: rmContent, speaker: ChatMessage.getSpeaker({actor: defender})})
}
}
if (d30Result.specialEffect === "flag") {
const rmContent = await foundry.applications.handlebars.renderTemplate("systems/fvtt-lethal-fantasy/templates/chat/reaction-message.hbs", {type:"d30Flag", actorName:defenderName, specialName:d30Result.specialName || "Special Effect"})
await ChatMessage.create({content: rmContent, speaker: ChatMessage.getSpeaker({actor: defender})})
}
if (d30Result.specialEffect === "drMultiplier") {
const rmContent = await foundry.applications.handlebars.renderTemplate("systems/fvtt-lethal-fantasy/templates/chat/reaction-message.hbs", {type:"d30DRMultiplier", actorName:defenderName, value:d30Result.multiplier})
await ChatMessage.create({content: rmContent, speaker: ChatMessage.getSpeaker({actor: defender})})
}
}
continue
} else if (choice === "adHocShield" && canAdHoc) {
const adHoc = await promptAdHocShield(defenderName, attackRollFinal, updatedDefenseRoll)
if (adHoc) {
+5
View File
@@ -66,6 +66,11 @@ export async function processD30BonusDice(d30Message, side, naturalRoll = null,
}
}
// ── Bleed type (ranged attacks) — flag for wound creation, same as combo bleed
if (d30Message.type === "bleed") {
return { modifier: 0, specialEffect: "bleed", specialName: "Bleeding" }
}
// ── Damage multiplier type (2x/3x damage before DR)
if (d30Message.type === "damage_multiplier") {
return { modifier: 0, specialEffect: "damageMultiplier", specialName: `x${d30Message.multiplier} Damage`, multiplier: d30Message.multiplier }