Adds skills and how to add them to the sheet

This commit is contained in:
mstein
2022-06-09 23:50:19 +02:00
parent 403109921c
commit 0f06d4020b
16 changed files with 478 additions and 162 deletions
+51 -32
View File
@@ -1,31 +1,45 @@
import { M5Character } from "../actors/M5Character"
import { M5Skill } from "../M5Base"
import { M5RollData, M5Skill } from "../M5Base"
export class M5Item extends Item {
static readonly SKILL = "skill"
getRollData() {
if (!this.actor)
return null
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 = 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)
let ret: M5RollData = actor?.getRollData() ?? {
c: null,
i: null,
rolls: {},
res: {}
}
ret.i = context.data
return ret
}
@@ -38,27 +52,32 @@ export class M5Item extends Item {
const label = `[${item.type}] ${item.name}`
// If there's no roll data, send a chat message.
if (!item.data.formula) {
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 ?? ''
})
} 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
return null
}
}