Fix actor sheet modifications/updates
This commit is contained in:
@@ -25,6 +25,7 @@ export default class AwERoll extends Roll {
|
||||
get damageCritical() { return this.options.damageCritical ?? false }
|
||||
get conditionBonus() { return this.options.conditionBonus ?? 0 }
|
||||
get conditionLabels() { return this.options.conditionLabels ?? [] }
|
||||
get rollTwice() { return this.options.rollTwice ?? "" }
|
||||
|
||||
// --- Outcome calculation ---
|
||||
|
||||
@@ -116,17 +117,23 @@ export default class AwERoll extends Roll {
|
||||
const el = dialog.element
|
||||
const bonusSelect = el.querySelector('#awe-bonus')
|
||||
const knowledgeSel = el.querySelector('#awe-knowledge')
|
||||
const rollTwiceSel = el.querySelector('#awe-roll-twice')
|
||||
const preview = el.querySelector('#awe-formula-preview')
|
||||
const diceExprEl = el.querySelector('#awe-dice-expr')
|
||||
function updatePreview() {
|
||||
const sit = parseInt(bonusSelect?.value) || 0
|
||||
const kn = parseInt(knowledgeSel?.value) || 0
|
||||
const total = baseMod + sit + kn
|
||||
const sign = total >= 0 ? '+' : '−'
|
||||
const abs = Math.abs(total)
|
||||
preview.textContent = total === 0 ? '1d20' : `1d20 ${sign} ${abs}`
|
||||
const mode = rollTwiceSel?.value
|
||||
const dice = mode === 'higher' ? '2d20kh1' : mode === 'lower' ? '2d20kl1' : '1d20'
|
||||
if (diceExprEl) diceExprEl.textContent = dice
|
||||
preview.textContent = total === 0 ? dice : `${dice} ${sign} ${abs}`
|
||||
}
|
||||
bonusSelect?.addEventListener('change', updatePreview)
|
||||
knowledgeSel?.addEventListener('change', updatePreview)
|
||||
rollTwiceSel?.addEventListener('change', updatePreview)
|
||||
updatePreview()
|
||||
},
|
||||
buttons: [{
|
||||
@@ -146,10 +153,16 @@ export default class AwERoll extends Roll {
|
||||
const knowledgeBonus = parseInt(result.knowledgeBonus) || 0
|
||||
const dc = result.dc !== "" ? parseInt(result.dc) : undefined
|
||||
const rollMode = result.visibility ?? game.settings.get("core", "rollMode")
|
||||
const rollTwice = result.rollTwice ?? ""
|
||||
|
||||
// Formula: 1d20 + (mod + attrBonus) [± bonus] [± knowledgeBonus] [± conditionBonus]
|
||||
// Dice expression based on roll-twice mode
|
||||
const diceExpr = rollTwice === 'higher' ? '2d20kh1'
|
||||
: rollTwice === 'lower' ? '2d20kl1'
|
||||
: '1d20'
|
||||
|
||||
// Formula: {diceExpr} + (mod + attrBonus) [± bonus] [± knowledgeBonus] [± conditionBonus]
|
||||
const totalMod = mod + attrBonus + bonus + knowledgeBonus + (options.conditionBonus ?? 0)
|
||||
let formula = `1d20`
|
||||
let formula = diceExpr
|
||||
if (totalMod > 0) formula += ` + ${totalMod}`
|
||||
else if (totalMod < 0) formula += ` - ${Math.abs(totalMod)}`
|
||||
|
||||
@@ -162,6 +175,7 @@ export default class AwERoll extends Roll {
|
||||
knowledgeBonus,
|
||||
conditionBonus: options.conditionBonus ?? 0,
|
||||
conditionLabels: options.conditionLabels ?? [],
|
||||
rollTwice,
|
||||
dc,
|
||||
actorId: options.actorId,
|
||||
actorName: options.actorName,
|
||||
@@ -175,8 +189,9 @@ export default class AwERoll extends Roll {
|
||||
await roll.evaluate()
|
||||
|
||||
// Compute degree of success when a DC is known
|
||||
// Use the *kept* die result (active:true) for nat-20/nat-1 adjustment
|
||||
if (dc !== undefined) {
|
||||
const d20Value = roll.dice[0]?.results[0]?.result ?? 0
|
||||
const d20Value = roll.dice[0]?.results.find(r => r.active)?.result ?? 0
|
||||
roll.options.outcome = AwERoll.computeOutcome(roll.total, dc, d20Value)
|
||||
}
|
||||
|
||||
@@ -220,6 +235,7 @@ export default class AwERoll extends Roll {
|
||||
conditionBonus: isPrivate ? null : this.conditionBonus,
|
||||
conditionLabels: this.conditionLabels,
|
||||
dice: this.dice,
|
||||
rollTwice: this.rollTwice,
|
||||
outcome: isPrivate ? null : this.outcome,
|
||||
dc: this.dc,
|
||||
actorId: this.actorId,
|
||||
|
||||
Reference in New Issue
Block a user