adjust character data to consist of basic character data

This commit is contained in:
Johannes Loher 2020-12-29 22:44:56 +01:00
parent 589a3c87ce
commit 59fb033db8
5 changed files with 218 additions and 66 deletions

View file

@ -54,5 +54,30 @@
"DS4.ArmorMaterialTypeChain": "Chain", "DS4.ArmorMaterialTypeChain": "Chain",
"DS4.ArmorMaterialTypeChainAbbr": "Chain", "DS4.ArmorMaterialTypeChainAbbr": "Chain",
"DS4.ArmorMaterialTypePlate": "Plate", "DS4.ArmorMaterialTypePlate": "Plate",
"DS4.ArmorMaterialTypePlateAbbr": "Plate" "DS4.ArmorMaterialTypePlateAbbr": "Plate",
"DS4.AttributeBody": "Body",
"DS4.AttributeMobility": "Mobility",
"DS4.AttributeMind": "Mind",
"DS4.TraitStrength": "Strength",
"DS4.TraitConstitution": "Constitution",
"DS4.TraitAgility": "Agility",
"DS4.TraitDexterity": "Dexterity",
"DS4.TraitIntellect": "Intellect",
"DS4.TraitAura": "Aura",
"DS4.CombatValuesHitPoints": "Hit Points",
"DS4.CombatValuesDefense": "Defense",
"DS4.CombatValuesInitiative": "Initiative",
"DS4.CombatValuesMovement": "Movement",
"DS4.CombatValuesMeleeAttack": "Melee Attack",
"DS4.CombatValuesRangedAttack": "Ranged Attack",
"DS4.CombatValuesSpellcasting": "Spellcasting",
"DS4.CombatValuestargetedSpellcasting": "TargetedSpellcasting",
"DS4.BaseInfoRace": "Race",
"DS4.BaseInfoClass": "Class",
"DS4.BaseInfoHeroClass": "Hero Class",
"DS4.BaseInfoRacialAbilities": "Racial Abilites",
"DS4.ProgressionLevel": "Level",
"DS4.ProgressionExperiencePoints": "Experience Points",
"DS4.ProgressionTalentPoints": "Tylent Points",
"DS4.ProgressionProgressPoints": "Progress Points"
} }

View file

@ -1,26 +1,65 @@
export interface DS4ActorDataType { export interface DS4ActorDataType {
attributes: DS4ActorDataAttributes; attributes: DS4ActorDataAttributes;
traits: DS4ActorDataTraits; traits: DS4ActorDataTraits;
combatValues: DS4ActorDataCombatValues;
baseInfo: DS4ActorDataBaseInfo;
progression: DS4ActorDataProgression;
} }
interface DS4ActorDataAttributes { interface DS4ActorDataAttributes {
body: BodyAttribute; body: BodyAttribute;
mobility: ExtensibleData<number>; mobility: ModifiableData<number>;
mind: ExtensibleData<number>; mind: ModifiableData<number>;
} }
interface ExtensibleData<T> { export interface ModifiableData<T> {
initial: T; base: T;
mod: T;
total?: T;
}
interface UsableResource<T> {
total: T;
used: T;
}
interface CurrentData<T> extends ModifiableData<T> {
current: T;
} }
// Blueprint in case we need more detailed differentiation // Blueprint in case we need more detailed differentiation
type BodyAttribute = ExtensibleData<number>; type BodyAttribute = ModifiableData<number>;
interface DS4ActorDataTraits { interface DS4ActorDataTraits {
strength: ExtensibleData<number>; strength: ModifiableData<number>;
constitution: ExtensibleData<number>; constitution: ModifiableData<number>;
agility: ExtensibleData<number>; agility: ModifiableData<number>;
dexterity: ExtensibleData<number>; dexterity: ModifiableData<number>;
intellect: ExtensibleData<number>; intellect: ModifiableData<number>;
aura: ExtensibleData<number>; aura: ModifiableData<number>;
}
interface DS4ActorDataCombatValues {
hitPoints: CurrentData<number>;
defense: ModifiableData<number>;
initiative: ModifiableData<number>;
movement: ModifiableData<number>;
meleeAttack: ModifiableData<number>;
rangedAttack: ModifiableData<number>;
spellcasting: ModifiableData<number>;
targetedSpellcasting: ModifiableData<number>;
}
interface DS4ActorDataBaseInfo {
race: string;
class: string;
heroClass: string;
racialAbilities: string;
}
interface DS4ActorDataProgression {
level: number;
experiencePoints: number;
talenPoints: UsableResource<number>;
progressPoints: UsableResource<number>;
} }

View file

@ -1,43 +1,22 @@
import { DS4Item } from "../item/item"; import { DS4Item } from "../item/item";
import { DS4ItemDataType } from "../item/item-data"; import { DS4ItemDataType } from "../item/item-data";
import { DS4ActorDataType } from "./actor-data"; import { DS4ActorDataType, ModifiableData } from "./actor-data";
/**
* Extend the base Actor entity by defining a custom roll data structure which is ideal for the Simple system.
* @extends {Actor}
*/
export class DS4Actor extends Actor<DS4ActorDataType, DS4ItemDataType, DS4Item> { export class DS4Actor extends Actor<DS4ActorDataType, DS4ItemDataType, DS4Item> {
/** @override */ /** @override */
prepareDerivedData(): void { prepareDerivedData(): void {
const data = this.data; const data = this.data;
this._prepareCombatValues(data); const attributes = data.data.attributes;
} Object.values(attributes).forEach(
(attribute: ModifiableData<number>) => (attribute.total = attribute.base + attribute.mod),
private _prepareCombatValues(data: ActorData<DS4ActorDataType>): void {
const hitPointsModifier = getProperty(data, "data.combatValues.hitPoints.modifier") || 0;
const actorData = data.data;
setProperty(
data,
"data.combatValues.hitPoints.max",
actorData.attributes.body.initial + actorData.traits.constitution.initial + 10 + hitPointsModifier,
); );
const defenseModifier = getProperty(data, "data.combatValues.defense.modifier") || 0; const traits = data.data.traits;
setProperty( Object.values(traits).forEach((trait: ModifiableData<number>) => (trait.total = trait.base + trait.mod));
data,
"data.combatValues.defense.value",
actorData.attributes.body.initial +
actorData.traits.constitution.initial +
this._getArmorValue() +
defenseModifier,
);
}
private _getArmorValue(): number { const combatValues = data.data.combatValues;
return this.data["items"] Object.values(combatValues).forEach(
.filter((item) => ["armor", "shield"].includes(item.type)) (combatValue: ModifiableData<number>) => (combatValue.total = combatValue.base + combatValue.mod),
.filter((item) => item.data.equipped) );
.map((item) => item.data.armorValue)
.reduce((a, b) => a + b, 0);
} }
} }

View file

@ -10,7 +10,6 @@ export const DS4 = {
/** /**
* Define the set of acttack types that can be performed with weapon items * Define the set of acttack types that can be performed with weapon items
* @type {Object}
*/ */
attackTypes: { attackTypes: {
melee: "DS4.AttackTypeMelee", melee: "DS4.AttackTypeMelee",
@ -19,8 +18,7 @@ export const DS4 = {
}, },
/** /**
* * Define the file paths to icon images * Define the file paths to icon images
* @type {Object}
*/ */
attackTypesIcons: { attackTypesIcons: {
melee: "systems/ds4/assets/DS4-MAT.png", melee: "systems/ds4/assets/DS4-MAT.png",
@ -30,7 +28,6 @@ export const DS4 = {
/** /**
* Define the set of item availabilties * Define the set of item availabilties
* @type {Object}
*/ */
itemAvailabilities: { itemAvailabilities: {
unset: "DS4.ItemAvailabilityUnset", unset: "DS4.ItemAvailabilityUnset",
@ -43,8 +40,7 @@ export const DS4 = {
}, },
/** /**
* * Define the set of item types * Define the set of item types
* @type {Object}
*/ */
itemTypes: { itemTypes: {
weapon: "DS4.ItemTypeWeapon", weapon: "DS4.ItemTypeWeapon",
@ -55,8 +51,7 @@ export const DS4 = {
}, },
/** /**
* * Define the set of armor types, a character may only wear one item of each at any given time * Define the set of armor types, a character may only wear one item of each at any given time
* @type {Object}
*/ */
armorTypes: { armorTypes: {
body: "DS4.ArmorTypeBody", body: "DS4.ArmorTypeBody",
@ -67,8 +62,7 @@ export const DS4 = {
}, },
/** /**
* * Define abbreviations for the armor types * Define abbreviations for the armor types
* @type {Object}
*/ */
armorTypesAbbr: { armorTypesAbbr: {
body: "DS4.ArmorTypeBodyAbbr", body: "DS4.ArmorTypeBodyAbbr",
@ -79,8 +73,7 @@ export const DS4 = {
}, },
/** /**
* * Define the set of armor materials, used to determine if a characer may wear the armor without additional penalties * Define the set of armor materials, used to determine if a characer may wear the armor without additional penalties
* @type {Object}
*/ */
armorMaterialTypes: { armorMaterialTypes: {
cloth: "DS4.ArmorMaterialTypeCloth", cloth: "DS4.ArmorMaterialTypeCloth",
@ -90,8 +83,7 @@ export const DS4 = {
}, },
/** /**
* * Define the abbreviations of armor materials * Define the abbreviations of armor materials
* @type {Object}
*/ */
armorMaterialTypesAbbr: { armorMaterialTypesAbbr: {
cloth: "DS4.ArmorMaterialTypeClothAbbr", cloth: "DS4.ArmorMaterialTypeClothAbbr",
@ -99,4 +91,59 @@ export const DS4 = {
chain: "DS4.ArmorMaterialTypeChainAbbr", chain: "DS4.ArmorMaterialTypeChainAbbr",
plate: "DS4.ArmorMaterialTypePlateAbbr", plate: "DS4.ArmorMaterialTypePlateAbbr",
}, },
/**
* Define the set of attributes a character has
*/
attributes: {
body: "DS4.AttributeBody",
mobility: "DS4.AttributeMobility",
mind: "DS4.AttributeMind",
},
/**
* Define the set of traits a character has
*/
traits: {
strength: "DS4.TraitStrength",
constitution: "DS4.TraitConstitution",
agility: "DS4.TraitAgility",
dexterity: "DS4.TraitDexterity",
intellect: "DS4.TraitIntellect",
aura: "DS4.TraitAura",
},
/**
* Define the set of combat values a character has
*/
combatValues: {
hitPoints: "DS4.CombatValuesHitPoints",
defense: "DS4.CombatValuesDefense",
initiative: "DS4.CombatValuesInitiative",
movement: "DS4.CombatValuesMovement",
meleeAttack: "DS4.CombatValuesMeleeAttack",
rangedAttack: "DS4.CombatValuesRangedAttack",
spellcasting: "DS4.CombatValuesSpellcasting",
targetedSpellcasting: "DS4.CombatValuesTargetedSpellcasting",
},
/**
* Define the base info of a character
*/
baseInfo: {
race: "DS4.BaseInfoRace",
class: "DS4.BaseInfoClass",
heroClass: "DS4.BaseInfoHeroClass",
racialAbilities: "DS4.BaseInfoRacialAbilities",
},
/**
* Definme the progression info of a character
*/
progression: {
level: "DS4.ProgressionLevel",
experiencePoints: "DS4.ProgressionExperiencePoints",
talentPoints: "DS4.ProgressionTalentPoints",
progressPoints: "DS4.ProgressionProgressPoints",
},
}; };

View file

@ -6,33 +6,95 @@
"templates": [], "templates": [],
"attributes": { "attributes": {
"body": { "body": {
"initial": 8 "base": 0,
"mod": 0
}, },
"mobility": { "mobility": {
"initial": 0 "base": 0,
"mod": 0
}, },
"mind": { "mind": {
"initial": 0 "base": 0,
"mod": 0
} }
}, },
"traits": { "traits": {
"strength": { "strength": {
"initial": 4 "base": 0,
"mod": 0
}, },
"constitution": { "constitution": {
"initial": 0 "base": 0,
"mod": 0
}, },
"agility": { "agility": {
"initial": 0 "base": 0,
"mod": 0
}, },
"dexterity": { "dexterity": {
"initial": 0 "base": 0,
"mod": 0
}, },
"intellect": { "intellect": {
"initial": 0 "base": 0,
"mod": 0
}, },
"aura": { "aura": {
"initial": 0 "base": 0,
"mod": 0
}
},
"combatValues": {
"hitPoints": {
"base": 0,
"mod": 0,
"current": 0
},
"defense": {
"base": 0,
"mod": 0
},
"initiative": {
"base": 0,
"mod": 0
},
"movement": {
"base": 0,
"mod": 0
},
"meleeAttack": {
"base": 0,
"mod": 0
},
"rangedAttack": {
"base": 0,
"mod": 0
},
"spellcasting": {
"base": 0,
"mod": 0
},
"targetedSpellcasting": {
"base": 0,
"mod": 0
}
},
"baseInfo": {
"race": "",
"class": "",
"heroClass": "",
"racialAbilities": ""
},
"progression": {
"level": 0,
"experiencePoints": 0,
"talentPoints": {
"total": 0,
"used": 0
},
"progressPoints": {
"total": 0,
"used": 0
} }
} }
} }