More tests againts rolls
This commit is contained in:
@@ -42,12 +42,20 @@ export default class AwEActor extends Actor {
|
||||
const attribute = this.system.attributes[attributeId]
|
||||
if (!attribute) return null
|
||||
|
||||
// Collect knowledge bonuses from embedded Field items
|
||||
const knowledgeBonuses = this.itemTypes.field?.map(f => ({
|
||||
label: f.name,
|
||||
bonus: f.system.knowledgeBonus ?? ""
|
||||
})).filter(f => f.bonus !== "") ?? []
|
||||
|
||||
return AwERoll.prompt({
|
||||
attributeKey: attributeId,
|
||||
modifier: attribute.mod ?? 0,
|
||||
actorId: this.id,
|
||||
actorName: this.name,
|
||||
actorImage: this.img,
|
||||
attributeKey: attributeId,
|
||||
modifier: attribute.mod ?? 0,
|
||||
attributeBonus: attribute.bonus ?? 0,
|
||||
knowledgeBonuses,
|
||||
actorId: this.id,
|
||||
actorName: this.name,
|
||||
actorImage: this.img,
|
||||
...options
|
||||
})
|
||||
}
|
||||
|
||||
@@ -5,19 +5,8 @@ export default class AwEChatMessage extends ChatMessage {
|
||||
async _renderRollContent(messageData) {
|
||||
if (this.rolls[0] instanceof AwERoll) {
|
||||
const isPrivate = !this.isContentVisible
|
||||
const roll = this.rolls[0]
|
||||
|
||||
const html = await foundry.applications.handlebars.renderTemplate(
|
||||
AwERoll.CHAT_TEMPLATE,
|
||||
{
|
||||
flavor: this.flavor,
|
||||
total: roll.total,
|
||||
outcome: isPrivate ? null : roll.outcome,
|
||||
dc: roll.dc,
|
||||
isPrivate
|
||||
}
|
||||
)
|
||||
messageData.message.content = html
|
||||
const rollHTML = await this._renderRollHTML(isPrivate)
|
||||
messageData.message.content = rollHTML
|
||||
return
|
||||
}
|
||||
return super._renderRollContent(messageData)
|
||||
|
||||
+94
-32
@@ -6,15 +6,17 @@ export default class AwERoll extends Roll {
|
||||
|
||||
// --- Accessors for roll options ---
|
||||
|
||||
get attributeKey() { return this.options.attributeKey }
|
||||
get rollName() { return this.options.rollName }
|
||||
get modifier() { return this.options.modifier ?? 0 }
|
||||
get bonus() { return this.options.bonus ?? 0 }
|
||||
get dc() { return this.options.dc }
|
||||
get outcome() { return this.options.outcome }
|
||||
get actorId() { return this.options.actorId }
|
||||
get actorName() { return this.options.actorName }
|
||||
get actorImage() { return this.options.actorImage }
|
||||
get attributeKey() { return this.options.attributeKey }
|
||||
get rollName() { return this.options.rollName }
|
||||
get modifier() { return this.options.modifier ?? 0 }
|
||||
get attributeBonus() { return this.options.attributeBonus ?? 0 }
|
||||
get bonus() { return this.options.bonus ?? 0 }
|
||||
get knowledgeBonus() { return this.options.knowledgeBonus ?? 0 }
|
||||
get dc() { return this.options.dc }
|
||||
get outcome() { return this.options.outcome }
|
||||
get actorId() { return this.options.actorId }
|
||||
get actorName() { return this.options.actorName }
|
||||
get actorImage() { return this.options.actorImage }
|
||||
|
||||
// --- Outcome calculation ---
|
||||
|
||||
@@ -51,38 +53,74 @@ export default class AwERoll extends Roll {
|
||||
* then evaluate and post the roll to chat.
|
||||
*
|
||||
* @param {object} options
|
||||
* @param {string} options.attributeKey Attribute id (agility | fitness | awareness | influence)
|
||||
* @param {number} options.modifier Base attribute modifier
|
||||
* @param {number} [options.dc] Pre-set DC (skips DC field if provided)
|
||||
* @param {string} options.attributeKey Attribute id (agility | fitness | awareness | influence)
|
||||
* @param {number} options.modifier Base attribute modifier (level + boostLevel)
|
||||
* @param {number} [options.attributeBonus] Persistent attribute bonus/penalty from the +/- column
|
||||
* @param {object[]} [options.knowledgeBonuses] Field knowledge bonuses [{label, bonus}]
|
||||
* @param {number} [options.dc] Pre-set DC
|
||||
* @param {string} options.actorId
|
||||
* @param {string} options.actorName
|
||||
* @param {string} options.actorImage
|
||||
* @returns {Promise<AwERoll|null>} Resolved roll, or null if dialog was cancelled
|
||||
*/
|
||||
static async prompt(options = {}) {
|
||||
const attrLabel = options.attributeKey
|
||||
const attrLabel = options.attributeKey
|
||||
? game.i18n.localize(SYSTEM.ATTRIBUTES[options.attributeKey]?.label ?? options.attributeKey)
|
||||
: (options.rollName ?? game.i18n.localize("AWEMMY.Roll.Check"))
|
||||
const mod = options.modifier ?? 0
|
||||
const attrBonus = options.attributeBonus ?? 0
|
||||
const knowledgeBonuses = options.knowledgeBonuses ?? []
|
||||
|
||||
const rollModes = Object.fromEntries(
|
||||
Object.entries(CONFIG.Dice.rollModes).map(([k, v]) => [k, game.i18n.localize(v.label ?? v)])
|
||||
)
|
||||
|
||||
// Bonus choices: -5 to +5
|
||||
const bonusChoices = Array.from({length: 11}, (_, i) => i - 5)
|
||||
.map(v => ({ value: v, label: v > 0 ? `+${v}` : String(v), selected: v === 0 }))
|
||||
|
||||
// DC choices: blank + 10..30
|
||||
const dcChoices = [{ value: "", label: "—", selected: !options.dc }]
|
||||
.concat(Array.from({length: 21}, (_, i) => i + 10)
|
||||
.map(v => ({ value: v, label: String(v), selected: v === (options.dc ?? null) })))
|
||||
|
||||
const content = await foundry.applications.handlebars.renderTemplate(
|
||||
"systems/fvtt-adventures-with-emmy/templates/roll-dialog.hbs",
|
||||
{
|
||||
attrLabel,
|
||||
modifier: options.modifier ?? 0,
|
||||
dc: options.dc ?? "",
|
||||
modifier: mod,
|
||||
attributeBonus: attrBonus,
|
||||
totalMod: mod + attrBonus,
|
||||
knowledgeBonuses,
|
||||
bonusChoices,
|
||||
dcChoices,
|
||||
rollModes,
|
||||
visibility: game.settings.get("core", "rollMode")
|
||||
visibility: game.settings.get("core", "rollMode")
|
||||
}
|
||||
)
|
||||
|
||||
const result = await foundry.applications.api.DialogV2.wait({
|
||||
window: { title: game.i18n.format("AWEMMY.Roll.DialogTitle", { name: attrLabel }) },
|
||||
classes: ["awemmy"],
|
||||
window: { title: game.i18n.format("AWEMMY.Roll.DialogTitle", { name: attrLabel }) },
|
||||
classes: ["awemmy"],
|
||||
content,
|
||||
render: (event, dialog) => {
|
||||
const baseMod = mod + attrBonus
|
||||
const el = dialog.element
|
||||
const bonusSelect = el.querySelector('#awe-bonus')
|
||||
const knowledgeSel = el.querySelector('#awe-knowledge')
|
||||
const preview = el.querySelector('#awe-formula-preview')
|
||||
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}`
|
||||
}
|
||||
bonusSelect?.addEventListener('change', updatePreview)
|
||||
knowledgeSel?.addEventListener('change', updatePreview)
|
||||
updatePreview()
|
||||
},
|
||||
buttons: [{
|
||||
label: game.i18n.localize("AWEMMY.Roll.Roll"),
|
||||
callback: (_event, button) =>
|
||||
@@ -96,25 +134,28 @@ export default class AwERoll extends Roll {
|
||||
|
||||
if (!result) return null
|
||||
|
||||
const mod = options.modifier ?? 0
|
||||
const bonus = parseInt(result.bonus) || 0
|
||||
const dc = result.dc !== "" ? parseInt(result.dc) : undefined
|
||||
const rollMode = result.visibility ?? game.settings.get("core", "rollMode")
|
||||
const bonus = parseInt(result.bonus) || 0
|
||||
const knowledgeBonus = parseInt(result.knowledgeBonus) || 0
|
||||
const dc = result.dc !== "" ? parseInt(result.dc) : undefined
|
||||
const rollMode = result.visibility ?? game.settings.get("core", "rollMode")
|
||||
|
||||
// Build formula: 1d20 + mod [± bonus]
|
||||
let formula = `1d20 + ${mod}`
|
||||
if (bonus > 0) formula += ` + ${bonus}`
|
||||
else if (bonus < 0) formula += ` - ${Math.abs(bonus)}`
|
||||
// Formula: 1d20 + (mod + attrBonus) [± bonus] [± knowledgeBonus]
|
||||
const totalMod = mod + attrBonus + bonus + knowledgeBonus
|
||||
let formula = `1d20`
|
||||
if (totalMod > 0) formula += ` + ${totalMod}`
|
||||
else if (totalMod < 0) formula += ` - ${Math.abs(totalMod)}`
|
||||
|
||||
const roll = new this(formula, {}, {
|
||||
attributeKey: options.attributeKey,
|
||||
rollName: attrLabel,
|
||||
modifier: mod,
|
||||
attributeKey: options.attributeKey,
|
||||
rollName: attrLabel,
|
||||
modifier: mod + attrBonus,
|
||||
attributeBonus: attrBonus,
|
||||
bonus,
|
||||
knowledgeBonus,
|
||||
dc,
|
||||
actorId: options.actorId,
|
||||
actorName: options.actorName,
|
||||
actorImage: options.actorImage
|
||||
actorId: options.actorId,
|
||||
actorName: options.actorName,
|
||||
actorImage: options.actorImage
|
||||
})
|
||||
|
||||
await roll.evaluate()
|
||||
@@ -133,4 +174,25 @@ export default class AwERoll extends Roll {
|
||||
|
||||
return roll
|
||||
}
|
||||
|
||||
/** @override — render the custom chat message template */
|
||||
async render(chatOptions = {}) {
|
||||
const isPrivate = chatOptions.isPrivate ?? false
|
||||
return foundry.applications.handlebars.renderTemplate(
|
||||
AwERoll.CHAT_TEMPLATE,
|
||||
{
|
||||
flavor: this.rollName,
|
||||
total: this.total,
|
||||
modifier: this.modifier,
|
||||
bonus: this.bonus,
|
||||
knowledgeBonus: this.knowledgeBonus,
|
||||
dice: this.dice,
|
||||
outcome: isPrivate ? null : this.outcome,
|
||||
dc: this.dc,
|
||||
actorName: this.actorName,
|
||||
actorImage: this.actorImage,
|
||||
isPrivate
|
||||
}
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user