95 lines
2.7 KiB
JavaScript
95 lines
2.7 KiB
JavaScript
import AwERoll from "./roll.mjs"
|
|
|
|
export default class AwEActor extends Actor {
|
|
/** @override */
|
|
prepareData() {
|
|
super.prepareData()
|
|
}
|
|
|
|
/** @override */
|
|
prepareBaseData() {}
|
|
|
|
/** @override */
|
|
prepareDerivedData() {
|
|
const actorData = this
|
|
this._prepareCharacterData(actorData)
|
|
this._prepareCreatureData(actorData)
|
|
}
|
|
|
|
/**
|
|
* Prepare character data.
|
|
* @param {object} actorData - The actor data.
|
|
*/
|
|
_prepareCharacterData(actorData) {
|
|
if (actorData.type !== "character") return
|
|
}
|
|
|
|
/**
|
|
* Prepare creature data.
|
|
* @param {object} actorData - The actor data.
|
|
*/
|
|
_prepareCreatureData(actorData) {
|
|
if (actorData.type !== "creature") return
|
|
}
|
|
|
|
/**
|
|
* Roll a weapon attack: attack roll + damage if hit.
|
|
* @param {Item} weaponItem - The weapon item being used.
|
|
* @param {object} options - Additional roll options.
|
|
* @returns {Promise<AwERoll|null>} The evaluated roll, or null if cancelled.
|
|
*/
|
|
async rollWeapon(weaponItem, options = {}) {
|
|
const attrId = weaponItem.system.attackAttribute
|
|
const attribute = this.system.attributes[attrId]
|
|
if (!attribute) return null
|
|
|
|
const knowledgeBonuses = this.itemTypes.field?.map(f => ({
|
|
label: f.name,
|
|
bonus: f.system.knowledgeBonus ?? ""
|
|
})).filter(f => f.bonus !== "") ?? []
|
|
|
|
return AwERoll.prompt({
|
|
attributeKey: attrId,
|
|
modifier: attribute.mod ?? 0,
|
|
attributeBonus: attribute.bonus ?? 0,
|
|
knowledgeBonuses,
|
|
actorId: this.id,
|
|
actorName: this.name,
|
|
actorImage: this.img,
|
|
sourceItemName: weaponItem.name,
|
|
sourceItemImg: weaponItem.img,
|
|
damageFormula: weaponItem.system.damageFormula,
|
|
damageType: weaponItem.system.damageType,
|
|
...options
|
|
})
|
|
}
|
|
|
|
/**
|
|
* Roll an attribute check.
|
|
* @param {string} attributeId - The attribute to roll.
|
|
* @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
|
|
|
|
// 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,
|
|
attributeBonus: attribute.bonus ?? 0,
|
|
knowledgeBonuses,
|
|
actorId: this.id,
|
|
actorName: this.name,
|
|
actorImage: this.img,
|
|
...options
|
|
})
|
|
}
|
|
}
|