Adds mod calculation
This commit is contained in:
@@ -1,7 +1,6 @@
|
||||
import { ItemData } from "@league-of-foundry-developers/foundry-vtt-types/src/foundry/common/data/module.mjs"
|
||||
import { ConstructorDataType } from "@league-of-foundry-developers/foundry-vtt-types/src/types/helperTypes"
|
||||
import { M5Character } from "../actors/M5Character"
|
||||
import { enumKeys, M5Attributes, M5ItemMod, M5ModType, M5RollData, M5RollResult, M5Skill, M5Stats } from "../M5Base"
|
||||
import M5ModAggregate from "../actors/M5ModAggregate"
|
||||
import { enumKeys, M5Attributes, M5ModOperation, M5ModPair, M5ModType, M5RollData, M5RollResult, M5Stats } from "../M5Base"
|
||||
import { M5Roll } from "../rolls/M5Roll"
|
||||
|
||||
export class M5Item extends Item {
|
||||
@@ -14,15 +13,48 @@ export class M5Item extends Item {
|
||||
const calc = context.data.calc
|
||||
|
||||
if (context.type === "skill") {
|
||||
calc.fw = context.data.fw
|
||||
calc.bonus = 0
|
||||
|
||||
if (context.data?.attribute && context.data?.attribute !== "" && character) {
|
||||
const attribute = character.attribute(context.data.attribute)
|
||||
if (attribute)
|
||||
calc.bonus += M5Character.attributeBonus(attribute)
|
||||
let pairs: Array<M5ModPair> = [{
|
||||
source: context.name,
|
||||
mod: {
|
||||
type: M5ModType.SKILL,
|
||||
id: context._id,
|
||||
operation: M5ModOperation.SET,
|
||||
value: context.data.fw
|
||||
}
|
||||
}]
|
||||
|
||||
if (character) {
|
||||
const actorCalc = character.derivedData({ skills: true, weapons: true, defensiveWeapons: true, armor: true, items: true, spells: true })
|
||||
if (actorCalc?.skillMods && Object.keys(actorCalc.skillMods).indexOf(context._id) !== -1) {
|
||||
pairs = pairs.concat(actorCalc.skillMods[context._id])
|
||||
}
|
||||
|
||||
if (context.data?.attribute && context.data?.attribute !== "") {
|
||||
pairs.push({
|
||||
source: context.name,
|
||||
mod: {
|
||||
type: M5ModType.SKILL,
|
||||
id: context._id,
|
||||
operation: M5ModOperation.ADD,
|
||||
value: actorCalc.attributes[context.data.attribute].bonus
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
calc.ew = context.data.fw + calc.bonus
|
||||
const res = M5ModAggregate.processPairs(pairs)
|
||||
res.mods.forEach(mod => {
|
||||
if ([M5ModOperation.SET, M5ModOperation.FIXED].includes(mod.operation))
|
||||
calc.fw = mod.value
|
||||
else
|
||||
calc.bonus += mod.value
|
||||
})
|
||||
|
||||
calc.ew = calc.fw + calc.bonus
|
||||
calc.sources = res.mods
|
||||
} else if (context.type === "weapon") {
|
||||
calc.fw = 0
|
||||
calc.bonus = 0
|
||||
@@ -57,7 +89,7 @@ export class M5Item extends Item {
|
||||
if (actor) {
|
||||
const actorCalc = character.derivedData({ weapons: true, defensiveWeapons: true, armor: true, items: true, spells: true })
|
||||
if (actorCalc) {
|
||||
calc.ew += actorCalc.stats.defense + actorCalc.stats.defenseBonus
|
||||
calc.ew += actorCalc.stats.defense.value + actorCalc.stats.defenseBonus.value
|
||||
calc.combatSkills = actorCalc.skills.combat
|
||||
}
|
||||
|
||||
@@ -79,43 +111,6 @@ export class M5Item extends Item {
|
||||
calc.ew += actorCalc.stats.spellCasting
|
||||
}
|
||||
}
|
||||
} else if (context.type === "mod") {
|
||||
const parent = (this as any).parent
|
||||
const actor = parent?.actor
|
||||
const character = actor as M5Character
|
||||
|
||||
calc.ids = {}
|
||||
|
||||
switch (context.data.type as M5ModType) {
|
||||
case M5ModType.ATTRIBUTE: {
|
||||
for (const key of enumKeys(M5Attributes)) {
|
||||
const val = M5Attributes[key]
|
||||
calc.ids[key] = (game as Game).i18n.localize(`midgard5.actor-${val}-long`)
|
||||
}
|
||||
break
|
||||
}
|
||||
case M5ModType.STAT: {
|
||||
for (const key of enumKeys(M5Stats)) {
|
||||
const val = M5Stats[key]
|
||||
calc.ids[key] = (game as Game).i18n.localize(`midgard5.mod-stat-${val}`)
|
||||
}
|
||||
break
|
||||
}
|
||||
case M5ModType.SKILL: {
|
||||
if (character) {
|
||||
const actorCalc = character.derivedData({ weapons: true, defensiveWeapons: true, armor: true, items: true, spells: true })
|
||||
if (actorCalc) {
|
||||
let category = (game as Game).i18n.localize("midgard5.innate-ability")
|
||||
Object.keys(actorCalc.skills.innate).forEach(skillId => {
|
||||
const skill = character.getItem(skillId)
|
||||
if (skill)
|
||||
calc.ids[skillId] = `${category}: ${skill.data.name}`
|
||||
})
|
||||
}
|
||||
}
|
||||
break
|
||||
}
|
||||
}
|
||||
} else if (context.type === "item") {
|
||||
calc.mods = {}
|
||||
Object.keys(context.data?.mods).forEach(key => {
|
||||
@@ -140,7 +135,28 @@ export class M5Item extends Item {
|
||||
if (character) {
|
||||
const actorCalc = character.derivedData({ weapons: true, defensiveWeapons: true, armor: true, items: true, spells: true })
|
||||
if (actorCalc) {
|
||||
let category = (game as Game).i18n.localize("midgard5.innate-ability")
|
||||
let category = (game as Game).i18n.localize("midgard5.skill")
|
||||
Object.keys(actorCalc.skills.general).forEach(skillId => {
|
||||
const skill = character.getItem(skillId)
|
||||
if (skill)
|
||||
modCalc[skillId] = `${category}: ${skill.data.name}`
|
||||
})
|
||||
|
||||
category = (game as Game).i18n.localize("midgard5.language")
|
||||
Object.keys(actorCalc.skills.language).forEach(skillId => {
|
||||
const skill = character.getItem(skillId)
|
||||
if (skill)
|
||||
modCalc[skillId] = `${category}: ${skill.data.name}`
|
||||
})
|
||||
|
||||
category = (game as Game).i18n.localize("midgard5.weapon-skill")
|
||||
Object.keys(actorCalc.skills.combat).forEach(skillId => {
|
||||
const skill = character.getItem(skillId)
|
||||
if (skill)
|
||||
modCalc[skillId] = `${category}: ${skill.data.name}`
|
||||
})
|
||||
|
||||
category = (game as Game).i18n.localize("midgard5.innate-ability")
|
||||
Object.keys(actorCalc.skills.innate).forEach(skillId => {
|
||||
const skill = character.getItem(skillId)
|
||||
if (skill)
|
||||
|
||||
Reference in New Issue
Block a user