Adds gear and spells as items.

Adds custom roll logic, inclusing chat message.
This commit is contained in:
mstein
2022-06-19 00:18:41 +02:00
parent ca82fa119f
commit 8b6bfd2efb
33 changed files with 1334 additions and 482 deletions
+53 -20
View File
@@ -1,5 +1,6 @@
import { M5Character } from "../actors/M5Character"
import { M5RollData, M5Skill } from "../M5Base"
import { M5RollData, M5RollResult, M5Skill } from "../M5Base"
import { M5Roll } from "../rolls/M5Roll"
export class M5Item extends Item {
static readonly SKILL = "skill"
@@ -13,22 +14,21 @@ export class M5Item extends Item {
if (context.type === "skill") {
calc.bonus = 0
if (context.data.attribute && context.data.attribute !== "") {
if (context.data?.attribute && context.data?.attribute !== "" && character) {
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") {
calc.ew = context.data.stats.attackBonus
calc.fw = 0
calc.bonus = 0
calc.special = context.data.special ? 2 : 0
calc.ew = calc.special + context.data.stats.attackBonus
calc.combatSkills = null
if (actor) {
const actorCalc = character.derivedData(false, true)
const actorCalc = character.derivedData({ weapons: true, defensiveWeapons: true, armor: true, items: true, spells: true })
calc.ew += actorCalc.stats.attackBonus
const skill = character.getSkill(context.data.skillId) as any
@@ -37,10 +37,41 @@ export class M5Item extends Item {
skill.prepareDerivedData()
const skillData = skill.data.data
calc.ew += skillData.calc.ew
calc.bonus += skillData.calc.bonus
calc.fw += skillData.fw
}
calc.combatSkills = actorCalc.skills.combat
}
} else if (context.type === "defensiveWeapon") {
calc.fw = 0
calc.bonus = 0
calc.special = context.data.special ? 2 : 0
calc.ew = calc.special + context.data.stats.defenseBonus
calc.combatSkills = null
if (actor) {
const actorCalc = character.derivedData({ weapons: true, defensiveWeapons: true, armor: true, items: true, spells: true })
calc.ew += actorCalc.stats.defense + actorCalc.stats.defenseBonus
const skill = character.getSkill(context.data.skillId) as any
//console.log("M5Item.prepareDerivedData:weapon", context.data, skill?.data?.data)
if (skill) {
skill.prepareDerivedData()
const skillData = skill.data.data
calc.ew += skillData.calc.ew
calc.bonus += skillData.calc.bonus
calc.fw += skillData.fw
}
calc.combatSkills = actorCalc.skills.combat
}
} else if (context.type === "spell") {
calc.ew = context.data.bonus
if (actor) {
const actorCalc = character.derivedData({ weapons: true, defensiveWeapons: true, armor: true, items: true, spells: true })
calc.ew += actorCalc.stats.spellCasting
}
}
}
@@ -51,11 +82,13 @@ export class M5Item extends Item {
let ret: M5RollData = actor?.getRollData() ?? {
c: null,
i: null,
iType: null,
rolls: {},
res: {}
}
ret.i = context.data
ret.iType = context.type
return ret
}
@@ -71,21 +104,21 @@ export class M5Item extends Item {
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)
rollData.rolls[formulaName] = {
formula: formula.formula,
label: formula.label,
type: formula.type,
result: "",
total: 0,
totalStr: "",
dice: {}
} as M5RollResult
})
return ret
const roll = new M5Roll(rollData, this.actor, item.name)
return roll.toMessage()
} else {
ChatMessage.create({
speaker: speaker,