Adds mod management (WIP)
This commit is contained in:
@@ -1,5 +1,7 @@
|
||||
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 { M5RollData, M5RollResult, M5Skill } from "../M5Base"
|
||||
import { enumKeys, M5Attributes, M5ItemMod, M5ModType, M5RollData, M5RollResult, M5Skill, M5Stats } from "../M5Base"
|
||||
import { M5Roll } from "../rolls/M5Roll"
|
||||
|
||||
export class M5Item extends Item {
|
||||
@@ -16,7 +18,8 @@ export class M5Item extends Item {
|
||||
|
||||
if (context.data?.attribute && context.data?.attribute !== "" && character) {
|
||||
const attribute = character.attribute(context.data.attribute)
|
||||
calc.bonus += M5Character.attributeBonus(attribute)
|
||||
if (attribute)
|
||||
calc.bonus += M5Character.attributeBonus(attribute)
|
||||
}
|
||||
|
||||
calc.ew = context.data.fw + calc.bonus
|
||||
@@ -29,9 +32,12 @@ export class M5Item extends Item {
|
||||
|
||||
if (actor) {
|
||||
const actorCalc = character.derivedData({ weapons: true, defensiveWeapons: true, armor: true, items: true, spells: true })
|
||||
calc.ew += actorCalc.stats.attackBonus
|
||||
if (actorCalc) {
|
||||
calc.ew += actorCalc.stats.attackBonus
|
||||
calc.combatSkills = actorCalc.skills.combat
|
||||
}
|
||||
|
||||
const skill = character.getSkill(context.data.skillId) as any
|
||||
const skill = character.getItem(context.data.skillId)
|
||||
//console.log("M5Item.prepareDerivedData:weapon", context.data, skill?.data?.data)
|
||||
if (skill) {
|
||||
skill.prepareDerivedData()
|
||||
@@ -40,8 +46,6 @@ export class M5Item extends Item {
|
||||
calc.bonus += skillData.calc.bonus
|
||||
calc.fw += skillData.fw
|
||||
}
|
||||
|
||||
calc.combatSkills = actorCalc.skills.combat
|
||||
}
|
||||
} else if (context.type === "defensiveWeapon") {
|
||||
calc.fw = 0
|
||||
@@ -52,9 +56,12 @@ export class M5Item extends Item {
|
||||
|
||||
if (actor) {
|
||||
const actorCalc = character.derivedData({ weapons: true, defensiveWeapons: true, armor: true, items: true, spells: true })
|
||||
calc.ew += actorCalc.stats.defense + actorCalc.stats.defenseBonus
|
||||
if (actorCalc) {
|
||||
calc.ew += actorCalc.stats.defense + actorCalc.stats.defenseBonus
|
||||
calc.combatSkills = actorCalc.skills.combat
|
||||
}
|
||||
|
||||
const skill = character.getSkill(context.data.skillId) as any
|
||||
const skill = character.getItem(context.data.skillId)
|
||||
//console.log("M5Item.prepareDerivedData:weapon", context.data, skill?.data?.data)
|
||||
if (skill) {
|
||||
skill.prepareDerivedData()
|
||||
@@ -63,15 +70,90 @@ export class M5Item extends Item {
|
||||
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
|
||||
if (actorCalc) {
|
||||
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 => {
|
||||
const mod = context.data.mods[key]
|
||||
const modCalc = {}
|
||||
switch (mod.type) {
|
||||
case M5ModType.ATTRIBUTE: {
|
||||
for (const key of enumKeys(M5Attributes)) {
|
||||
const val = M5Attributes[key]
|
||||
modCalc[key] = (game as Game).i18n.localize(`midgard5.actor-${val}-long`)
|
||||
}
|
||||
break
|
||||
}
|
||||
case M5ModType.STAT: {
|
||||
for (const key of enumKeys(M5Stats)) {
|
||||
const val = M5Stats[key]
|
||||
modCalc[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)
|
||||
modCalc[skillId] = `${category}: ${skill.data.name}`
|
||||
})
|
||||
}
|
||||
}
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
calc.mods[key] = modCalc
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
@@ -128,6 +210,10 @@ export class M5Item extends Item {
|
||||
})
|
||||
return null
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
getItem(itemId: string): any {
|
||||
return (this as any).getEmbeddedDocument("Item", itemId)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user