66 lines
1.6 KiB
TypeScript
66 lines
1.6 KiB
TypeScript
import { M5Character } from "../actors/M5Character"
|
|
import { M5Skill } from "../M5Base"
|
|
|
|
export class M5Item extends Item {
|
|
static readonly SKILL = "skill"
|
|
|
|
getRollData() {
|
|
if (!this.actor)
|
|
return null
|
|
|
|
const actor = this.actor as any
|
|
const context = (this as any).data
|
|
|
|
let ret = null
|
|
if (context.type === "skill") {
|
|
const character = actor as M5Character
|
|
const actorData = actor.data.data
|
|
const itemData = context.data as M5Skill
|
|
|
|
ret = {
|
|
fw: itemData.fw,
|
|
bonus: M5Character.attributeBonus(character.attribute(itemData.attribute))
|
|
}
|
|
} else {
|
|
ret = actor.getRollData()
|
|
ret.item = foundry.utils.deepClone(context.data)
|
|
}
|
|
|
|
return ret
|
|
}
|
|
|
|
async roll() {
|
|
const item = (this as any).data
|
|
|
|
// Initialize chat data.
|
|
const speaker = ChatMessage.getSpeaker({ actor: this.actor })
|
|
const rollMode = (game as Game).settings.get('core', 'rollMode')
|
|
const label = `[${item.type}] ${item.name}`
|
|
|
|
// If there's no roll data, send a chat message.
|
|
if (!item.data.formula) {
|
|
ChatMessage.create({
|
|
speaker: speaker,
|
|
rollMode: rollMode,
|
|
flavor: label,
|
|
content: item.data.description ?? ''
|
|
})
|
|
} else { // Otherwise, create a roll and send a chat message from it.
|
|
// Retrieve roll data.
|
|
const rollData = this.getRollData()
|
|
|
|
// Invoke the roll and submit it to chat.
|
|
const roll = new Roll(item.data.formula, rollData)
|
|
// If you need to store the value first, uncomment the next line.
|
|
// let result = await roll.roll({async: true})
|
|
roll.toMessage({
|
|
speaker: speaker,
|
|
rollMode: rollMode,
|
|
flavor: label,
|
|
})
|
|
return roll
|
|
}
|
|
}
|
|
|
|
}
|