224 lines
7.2 KiB
TypeScript
224 lines
7.2 KiB
TypeScript
import { M5Item } from "../items/M5Item"
|
|
import { M5Attribute, M5RollData, M5Skill, M5SkillLearned } from "../M5Base"
|
|
|
|
export interface M5CharacterCalculatedData {
|
|
level: number
|
|
attributes: {
|
|
st: { value: number, bonus: number }
|
|
gs: { value: number, bonus: number }
|
|
gw: { value: number, bonus: number }
|
|
ko: { value: number, bonus: number }
|
|
in: { value: number, bonus: number }
|
|
zt: { value: number, bonus: number }
|
|
au: { value: number, bonus: number }
|
|
pa: { value: number, bonus: number }
|
|
wk: { value: number, bonus: number }
|
|
}
|
|
stats: {
|
|
armor: number
|
|
defense: number
|
|
damageBonus: number
|
|
attackBonus: number
|
|
defenseBonus: number
|
|
movementBonus: number
|
|
resistanceMind: number
|
|
resistanceBody: number
|
|
spellCasting: number
|
|
brawl: number
|
|
poisonResistance: number
|
|
enduranceBonus: number
|
|
}
|
|
skills: {
|
|
general: {}
|
|
}
|
|
}
|
|
|
|
export class M5Character extends Actor {
|
|
|
|
// constructor(
|
|
// data: ConstructorParameters<typeof foundry.documents.BaseActor>[0],
|
|
// context?: ConstructorParameters<typeof foundry.documents.BaseActor>[1]
|
|
// ) {
|
|
// super(data, context)
|
|
// this.prepareDerivedData()
|
|
// }
|
|
|
|
static attributeMinMax(attribute: M5Attribute) {
|
|
return Math.min(100, Math.max(0, attribute.value + attribute.bonus))
|
|
}
|
|
|
|
static attributeBonus(attribute: M5Attribute) {
|
|
const value = this.attributeMinMax(attribute)
|
|
if (value > 95)
|
|
return 2
|
|
if (value > 80)
|
|
return 1
|
|
if (value > 20)
|
|
return 0
|
|
if (value > 5)
|
|
return -1
|
|
return -2
|
|
}
|
|
|
|
prepareDerivedData() {
|
|
const context = (this as any).data
|
|
|
|
context.data.calc = {
|
|
level: 0,
|
|
attributes: {
|
|
st: { value: 0, bonus: 0 },
|
|
gs: { value: 0, bonus: 0 },
|
|
gw: { value: 0, bonus: 0 },
|
|
ko: { value: 0, bonus: 0 },
|
|
in: { value: 0, bonus: 0 },
|
|
zt: { value: 0, bonus: 0 },
|
|
au: { value: 0, bonus: 0 },
|
|
pa: { value: 0, bonus: 0 },
|
|
wk: { value: 0, bonus: 0 }
|
|
},
|
|
stats: {
|
|
armor: 0,
|
|
defense: 0,
|
|
damageBonus: 0,
|
|
attackBonus: 0,
|
|
defenseBonus: 0,
|
|
movementBonus: 0,
|
|
resistanceMind: 0,
|
|
resistanceBody: 0,
|
|
spellCasting: 0,
|
|
brawl: 0,
|
|
poisonResistance: 0,
|
|
enduranceBonus: 0
|
|
},
|
|
skills: {
|
|
general: {},
|
|
combat: {},
|
|
language: {},
|
|
custom: {}
|
|
}
|
|
} as M5CharacterCalculatedData
|
|
|
|
const data = context.data
|
|
const calc = context.data.calc as M5CharacterCalculatedData
|
|
calc.level = M5Character.levelFromExp(data.es)
|
|
|
|
calc.attributes.st.value = M5Character.attributeMinMax(data.attributes.st) // TODO item effects
|
|
calc.attributes.gs.value = M5Character.attributeMinMax(data.attributes.gs)
|
|
calc.attributes.gw.value = M5Character.attributeMinMax(data.attributes.gw)
|
|
calc.attributes.ko.value = M5Character.attributeMinMax(data.attributes.ko)
|
|
calc.attributes.in.value = M5Character.attributeMinMax(data.attributes.in)
|
|
calc.attributes.zt.value = M5Character.attributeMinMax(data.attributes.zt)
|
|
calc.attributes.au.value = M5Character.attributeMinMax(data.attributes.au)
|
|
calc.attributes.pa.value = M5Character.attributeMinMax(data.attributes.pa)
|
|
calc.attributes.wk.value = M5Character.attributeMinMax(data.attributes.wk)
|
|
|
|
calc.attributes.st.bonus = M5Character.attributeBonus(data.attributes.st)
|
|
calc.attributes.gs.bonus = M5Character.attributeBonus(data.attributes.gs)
|
|
calc.attributes.gw.bonus = M5Character.attributeBonus(data.attributes.gw)
|
|
calc.attributes.ko.bonus = M5Character.attributeBonus(data.attributes.ko)
|
|
calc.attributes.in.bonus = M5Character.attributeBonus(data.attributes.in)
|
|
calc.attributes.zt.bonus = M5Character.attributeBonus(data.attributes.zt)
|
|
calc.attributes.au.bonus = M5Character.attributeBonus(data.attributes.au)
|
|
calc.attributes.pa.bonus = M5Character.attributeBonus(data.attributes.pa)
|
|
calc.attributes.wk.bonus = M5Character.attributeBonus(data.attributes.wk)
|
|
|
|
calc.stats.armor = 0
|
|
calc.stats.defense = M5Character.defenseFromLevel(calc.level)
|
|
calc.stats.damageBonus = Math.floor(calc.attributes.st.value/20) + Math.floor(calc.attributes.gs.value/30) - 3
|
|
calc.stats.attackBonus = calc.attributes.gs.bonus
|
|
calc.stats.defenseBonus = calc.attributes.gw.bonus
|
|
calc.stats.movementBonus = 0
|
|
calc.stats.resistanceMind = calc.stats.defense
|
|
calc.stats.resistanceBody = calc.stats.defense + 1
|
|
calc.stats.spellCasting = (data.info.magicUsing ? M5Character.spellCastingFromLevel(calc.level) : 3) + calc.attributes.zt.bonus
|
|
calc.stats.brawl = Math.floor((calc.attributes.st.value + calc.attributes.gw.value) / 20)
|
|
calc.stats.poisonResistance = 30 + Math.floor(calc.attributes.ko.value / 2)
|
|
calc.stats.enduranceBonus = Math.floor(calc.attributes.ko.value/10) + Math.floor(calc.attributes.st.value/20)
|
|
|
|
context.items?.filter(item => item.data.type === "skill").forEach(item => {
|
|
item.prepareDerivedData()
|
|
const skillMap = calc.skills[item.data.data.type]
|
|
skillMap[item.data._id] = {
|
|
label: item.data.name,
|
|
fw: item.data.data.fw,
|
|
attribute: item.data.data.attribute,
|
|
calc: item.data.data.calc
|
|
}
|
|
})
|
|
}
|
|
|
|
override getRollData(): any {
|
|
return {
|
|
c: (this as any).data.data,
|
|
i: null,
|
|
rolls: {},
|
|
res: {}
|
|
} as M5RollData
|
|
}
|
|
|
|
static readonly levelThreshold: Array<number> = [0, 100, 250, 500, 750, 1000, 1250, 1500, 1750, 2000, 2500, 3000, 3500, 4000, 4500, 5000, 6000, 7000, 8000, 9000, 10000, 12500, 15000, 17500, 20000, 22500, 25000, 30000, 35000, 40000, 45000, 50000, 55000, 60000, 65000, 70000, 75000, 80000, 85000, 90000, 95000, 100000, 105000, 110000, 115000, 120000, 125000, 130000, 135000, 140000, 145000, 150000, 155000, 160000, 165000, 170000, 175000, 180000, 185000, 190000, 195000, 200000, 205000, 210000, 215000, 220000, 225000, 230000, 235000, 240000, 245000, 250000, 255000, 260000, 265000, 270000, 275000, 280000]
|
|
static levelFromExp(exp: number): number {
|
|
const ret = M5Character.levelThreshold.findIndex(val => val > exp)
|
|
return ret === -1 ? M5Character.levelThreshold.length : ret
|
|
}
|
|
|
|
static readonly defenseThreshold: Array<[number, number]> = [
|
|
[1, 11],
|
|
[2, 12],
|
|
[5, 13],
|
|
[10, 14],
|
|
[15, 15],
|
|
[20, 16],
|
|
[25, 17],
|
|
[30, 18]
|
|
]
|
|
static defenseFromLevel(lvl: number): number {
|
|
const ret = M5Character.defenseThreshold.find(val => val[0] >= lvl)
|
|
return ret ? ret[1] : M5Character.defenseThreshold[M5Character.defenseThreshold.length - 1][1]
|
|
}
|
|
|
|
static readonly spellCastingThreshold: Array<[number, number]> = [
|
|
[1, 11],
|
|
[2, 12],
|
|
[4, 13],
|
|
[6, 14],
|
|
[8, 15],
|
|
[10, 16],
|
|
[15, 17],
|
|
[20, 18]
|
|
]
|
|
static spellCastingFromLevel(lvl: number): number {
|
|
const ret = M5Character.spellCastingThreshold.find(val => val[0] >= lvl)
|
|
return ret ? ret[1] : M5Character.spellCastingThreshold[M5Character.spellCastingThreshold.length - 1][1]
|
|
}
|
|
|
|
skillBonus(skill: M5Skill, skillName?: string) {
|
|
const attribute = this.attribute(skill.attribute)
|
|
let ret = attribute ? M5Character.attributeBonus(attribute) : 0
|
|
return ret
|
|
}
|
|
|
|
skillEw(skill: M5Skill, skillName?: string) {
|
|
const bonus = this.skillBonus(skill, skillName)
|
|
return skill.fw + bonus
|
|
}
|
|
|
|
attribute(name: string): M5Attribute {
|
|
const context = (this as any).data
|
|
return context.data.attributes[name]
|
|
}
|
|
|
|
createSkill(skillName: string): Promise<M5Item> {
|
|
const itemData = {
|
|
name: skillName,
|
|
type: "skill"
|
|
};
|
|
|
|
return (this as any).createEmbeddedDocuments("Item", [itemData]).then(docs => {
|
|
const item = docs[0]
|
|
return item as M5Item
|
|
})
|
|
}
|
|
|
|
}
|