First row of tests and fixes
This commit is contained in:
+11
-27
@@ -1,3 +1,5 @@
|
||||
import AwERoll from "./roll.mjs"
|
||||
|
||||
export default class AwEActor extends Actor {
|
||||
/** @override */
|
||||
prepareData() {
|
||||
@@ -33,38 +35,20 @@ export default class AwEActor extends Actor {
|
||||
/**
|
||||
* Roll an attribute check.
|
||||
* @param {string} attributeId - The attribute to roll.
|
||||
* @param {object} options - Roll options.
|
||||
* @returns {Promise<Roll>} The roll result.
|
||||
* @param {object} options - Roll options (passed through to AwERoll.prompt).
|
||||
* @returns {Promise<AwERoll|null>} The evaluated roll, or null if cancelled.
|
||||
*/
|
||||
async rollAttribute(attributeId, options = {}) {
|
||||
const attribute = this.system.attributes[attributeId]
|
||||
if (!attribute) return null
|
||||
|
||||
const mod = attribute.mod ?? 0
|
||||
const formula = `1d20 + ${mod}`
|
||||
const roll = new Roll(formula)
|
||||
await roll.evaluate()
|
||||
|
||||
// Determine outcome vs DC if provided
|
||||
let outcome = null
|
||||
if (options.dc !== undefined) {
|
||||
const total = roll.total
|
||||
const dc = options.dc
|
||||
if (total >= dc + 10) outcome = "criticalSuccess"
|
||||
else if (total >= dc) outcome = "success"
|
||||
else if (total <= dc - 10) outcome = "criticalFailure"
|
||||
else outcome = "failure"
|
||||
}
|
||||
|
||||
// Send to chat
|
||||
const attrLabel = attributeId.charAt(0).toUpperCase() + attributeId.slice(1)
|
||||
const flavor = options.flavor || game.i18n.localize(`AWEMMY.Attribute.${attrLabel}`)
|
||||
await roll.toMessage({
|
||||
speaker: ChatMessage.getSpeaker({ actor: this }),
|
||||
flavor,
|
||||
rollMode: game.settings.get("core", "rollMode")
|
||||
return AwERoll.prompt({
|
||||
attributeKey: attributeId,
|
||||
modifier: attribute.mod ?? 0,
|
||||
actorId: this.id,
|
||||
actorName: this.name,
|
||||
actorImage: this.img,
|
||||
...options
|
||||
})
|
||||
|
||||
return { roll, outcome }
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user