Fix CSS issues and add omen re-roll function
This commit is contained in:
@@ -70,15 +70,16 @@ async function renderCard(context) {
|
||||
}
|
||||
|
||||
export default class MGNERoll {
|
||||
static async promptCheck({ actor, abilityId, label, baseDR = 12, rollType = "check", item = null }) {
|
||||
static async promptCheck({ actor, abilityId, label, baseDR = 12, modifier = 0, rollType = "check", item = null }) {
|
||||
const abilityLabel = SYSTEM.abilities[abilityId]?.label ?? abilityId
|
||||
const content = await foundry.applications.handlebars.renderTemplate(`systems/${SYSTEM_ID}/templates/roll-dialog.hbs`, {
|
||||
actorName: actor.name,
|
||||
label,
|
||||
abilityLabel,
|
||||
baseDR,
|
||||
modifier,
|
||||
drOptions: numericOptions(6, 20, baseDR),
|
||||
modifierOptions: numericOptions(-6, 6, 0),
|
||||
modifierOptions: numericOptions(-6, 6, modifier),
|
||||
omens: actor.system.omens?.current ?? 0,
|
||||
rollType,
|
||||
})
|
||||
@@ -99,15 +100,15 @@ export default class MGNERoll {
|
||||
|
||||
if (!dialogData) return null
|
||||
|
||||
const modifier = Number.parseInt(dialogData.modifier ?? 0, 10) || 0
|
||||
const dialogModifier = Number.parseInt(dialogData.modifier ?? 0, 10) || 0
|
||||
const spendOmen = Boolean(dialogData.spendOmen)
|
||||
// Re-read omens after dialog close to avoid race condition (omen could have changed)
|
||||
const currentOmensAfterDialog = actor.system.omens?.current ?? 0
|
||||
const canSpendOmen = spendOmen && currentOmensAfterDialog > 0
|
||||
const dr = (Number.parseInt(dialogData.dr ?? baseDR, 10) || baseDR) - (canSpendOmen ? 4 : 0)
|
||||
const abilityValue = actor.system.abilities?.[abilityId]?.value ?? 0
|
||||
const sign = modifier >= 0 ? "+" : "-"
|
||||
const formula = modifier === 0 ? `1d20 + ${abilityValue}` : `1d20 + ${abilityValue} ${sign} ${Math.abs(modifier)}`
|
||||
const sign = dialogModifier >= 0 ? "+" : "-"
|
||||
const formula = dialogModifier === 0 ? `1d20 + ${abilityValue}` : `1d20 + ${abilityValue} ${sign} ${Math.abs(dialogModifier)}`
|
||||
const roll = await (new Roll(formula)).evaluate()
|
||||
const natural = roll.dice?.[0]?.results?.[0]?.result ?? roll.total
|
||||
|
||||
@@ -143,6 +144,7 @@ export default class MGNERoll {
|
||||
}
|
||||
|
||||
const showDamageButton = rollType === "attack" && (success || critical) && !!item
|
||||
const showOmenRerollButton = Boolean(omenRerollReminder)
|
||||
const contentHtml = await renderCard({
|
||||
mode: "check",
|
||||
actorName: actor.name,
|
||||
@@ -160,6 +162,14 @@ export default class MGNERoll {
|
||||
damageItemId: showDamageButton ? item.id : null,
|
||||
damageFormula: showDamageButton ? (item.system.damage || "1") : null,
|
||||
damageCritical: showDamageButton && critical,
|
||||
showOmenRerollButton,
|
||||
omenRerollActorId: showOmenRerollButton ? actor.id : null,
|
||||
omenRerollAbilityId: showOmenRerollButton ? abilityId : null,
|
||||
omenRerollLabel: showOmenRerollButton ? label : null,
|
||||
omenRerollBaseDR: showOmenRerollButton ? baseDR : null,
|
||||
omenRerollModifier: showOmenRerollButton ? dialogModifier : 0,
|
||||
omenRerollRollType: showOmenRerollButton ? rollType : null,
|
||||
omenRerollItemId: showOmenRerollButton ? item?.id : null,
|
||||
_roll: roll,
|
||||
})
|
||||
|
||||
|
||||
Reference in New Issue
Block a user