85 lines
2.0 KiB
TypeScript
85 lines
2.0 KiB
TypeScript
import { M5Character } from "../actors/M5Character"
|
|
import { M5RollData, M5Skill } from "../M5Base"
|
|
|
|
export class M5Item extends Item {
|
|
static readonly SKILL = "skill"
|
|
|
|
prepareDerivedData() {
|
|
const actor = (this.actor as any)
|
|
const character = actor as M5Character
|
|
const context = (this as any).data
|
|
const calc = context.data.calc
|
|
|
|
if (context.type === "skill") {
|
|
calc.bonus = 0
|
|
|
|
if (context.data.attribute && context.data.attribute !== "") {
|
|
//console.log(context.name, context.data)
|
|
const attribute = character.attribute(context.data.attribute)
|
|
calc.bonus += M5Character.attributeBonus(attribute)
|
|
}
|
|
|
|
if (context._id === actor.data.data.skills.preferredCombatSkill) {
|
|
calc.bonus += 2
|
|
}
|
|
|
|
calc.ew = context.data.fw + calc.bonus
|
|
} else if (context.type === "weapon") {
|
|
}
|
|
}
|
|
|
|
getRollData() {
|
|
const actor = this.actor as any
|
|
const context = (this as any).data
|
|
|
|
let ret: M5RollData = actor?.getRollData() ?? {
|
|
c: null,
|
|
i: null,
|
|
rolls: {},
|
|
res: {}
|
|
}
|
|
|
|
ret.i = 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.
|
|
const formulaNames = item.data.rolls?.formulas ? Object.keys(item.data.rolls.formulas) : []
|
|
if (formulaNames.length > 0) {
|
|
const rollData = this.getRollData()
|
|
let ret = []
|
|
|
|
formulaNames.forEach(formulaName => {
|
|
const formula = item.data.rolls.formulas[formulaName]
|
|
const roll = new Roll(formula.formula, rollData)
|
|
|
|
roll.toMessage({
|
|
speaker: speaker,
|
|
rollMode: rollMode,
|
|
flavor: label,
|
|
})
|
|
ret.push(roll)
|
|
})
|
|
|
|
return ret
|
|
} else {
|
|
ChatMessage.create({
|
|
speaker: speaker,
|
|
rollMode: rollMode,
|
|
flavor: label,
|
|
content: item.data.description ?? ''
|
|
})
|
|
return null
|
|
}
|
|
}
|
|
|
|
}
|