Fix hp < 0 and D30 with D20 bonus roll

This commit is contained in:
2026-06-11 20:48:46 +02:00
parent c20750caa7
commit ea7acf6bf8
29 changed files with 130 additions and 110 deletions
+23 -7
View File
@@ -548,7 +548,7 @@ export default class LethalFantasyUtils {
* @param {Object} actor The actor (for dice3d display)
* @returns {Promise<{modifier: number, specialEffect: string|null, specialName: string|null}>}
*/
static async processD30BonusDice(d30Message, side, naturalRoll = null, actor = null) {
static async processD30BonusDice(d30Message, side, naturalRoll = null, actor = null, canDialog = true) {
if (!d30Message) return { modifier: 0, specialEffect: null, specialName: null }
const validTargets = side === "attack" ? ["attack", "spell_attack"] : ["defense", "spell_defense"]
@@ -556,12 +556,26 @@ export default class LethalFantasyUtils {
// ── Simple bonus_dice type ── auto-roll if target matches
if (d30Message.type === "bonus_dice") {
if (!validTargets.includes(d30Message.target)) return { modifier: 0, specialEffect: null, specialName: null }
const modifier = await this._rollD30BonusDie(d30Message.dice, actor)
const modifier = await this._rollD30BonusDie(d30Message.dice, actor, !canDialog)
return { modifier, specialEffect: null, specialName: null }
}
// ── Choice type ── present all options to the player
if (d30Message.type === "choice") {
// Try to find a bonus_dice option matching this side
const autoBonus = d30Message.choices.find(c => c.type === "bonus_dice" && validTargets.includes(c.target))
// If we can't show dialogs (wrong client), auto-roll bonus dice if available
if (!canDialog) {
if (autoBonus) {
const modifier = await this._rollD30BonusDie(autoBonus.dice, actor, true)
return { modifier, specialEffect: null, specialName: null }
}
// No bonus dice available on this side — just report as flag
const first = d30Message.choices[0]
return { modifier: 0, specialEffect: "flag", specialName: first?.type || "choice" }
}
const buttons = d30Message.choices.map(c => {
let label
let icon
@@ -642,17 +656,19 @@ export default class LethalFantasyUtils {
* @param {Object} actor Actor for chat message speaker
* @returns {Promise<number>} The roll total
*/
static async _rollD30BonusDie(formula, actor) {
static async _rollD30BonusDie(formula, actor, silent = false) {
const cleaned = formula.replace(/NE$/i, "").replace("E", "")
const roll = new Roll(cleaned)
await roll.evaluate()
if (game?.dice3d) {
await game.dice3d.showForRoll(roll, game.user, true)
}
await ChatMessage.create({
content: `<p>D30 bonus: rolled <strong>${cleaned.toUpperCase()}</strong> = <strong>${roll.total}</strong></p>`,
speaker: ChatMessage.getSpeaker({ actor })
})
if (!silent) {
await ChatMessage.create({
content: `<p>D30 bonus: rolled <strong>${cleaned.toUpperCase()}</strong> = <strong>${roll.total}</strong></p>`,
speaker: ChatMessage.getSpeaker({ actor })
})
}
return roll.total
}