adjust character data to consist of basic character data
This commit is contained in:
parent
589a3c87ce
commit
59fb033db8
5 changed files with 218 additions and 66 deletions
|
@ -1,26 +1,65 @@
|
|||
export interface DS4ActorDataType {
|
||||
attributes: DS4ActorDataAttributes;
|
||||
traits: DS4ActorDataTraits;
|
||||
combatValues: DS4ActorDataCombatValues;
|
||||
baseInfo: DS4ActorDataBaseInfo;
|
||||
progression: DS4ActorDataProgression;
|
||||
}
|
||||
|
||||
interface DS4ActorDataAttributes {
|
||||
body: BodyAttribute;
|
||||
mobility: ExtensibleData<number>;
|
||||
mind: ExtensibleData<number>;
|
||||
mobility: ModifiableData<number>;
|
||||
mind: ModifiableData<number>;
|
||||
}
|
||||
|
||||
interface ExtensibleData<T> {
|
||||
initial: T;
|
||||
export interface ModifiableData<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
|
||||
type BodyAttribute = ExtensibleData<number>;
|
||||
type BodyAttribute = ModifiableData<number>;
|
||||
|
||||
interface DS4ActorDataTraits {
|
||||
strength: ExtensibleData<number>;
|
||||
constitution: ExtensibleData<number>;
|
||||
agility: ExtensibleData<number>;
|
||||
dexterity: ExtensibleData<number>;
|
||||
intellect: ExtensibleData<number>;
|
||||
aura: ExtensibleData<number>;
|
||||
strength: ModifiableData<number>;
|
||||
constitution: ModifiableData<number>;
|
||||
agility: ModifiableData<number>;
|
||||
dexterity: ModifiableData<number>;
|
||||
intellect: ModifiableData<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>;
|
||||
}
|
||||
|
|
|
@ -1,43 +1,22 @@
|
|||
import { DS4Item } from "../item/item";
|
||||
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> {
|
||||
/** @override */
|
||||
prepareDerivedData(): void {
|
||||
const data = this.data;
|
||||
this._prepareCombatValues(data);
|
||||
}
|
||||
|
||||
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 attributes = data.data.attributes;
|
||||
Object.values(attributes).forEach(
|
||||
(attribute: ModifiableData<number>) => (attribute.total = attribute.base + attribute.mod),
|
||||
);
|
||||
|
||||
const defenseModifier = getProperty(data, "data.combatValues.defense.modifier") || 0;
|
||||
setProperty(
|
||||
data,
|
||||
"data.combatValues.defense.value",
|
||||
actorData.attributes.body.initial +
|
||||
actorData.traits.constitution.initial +
|
||||
this._getArmorValue() +
|
||||
defenseModifier,
|
||||
);
|
||||
}
|
||||
const traits = data.data.traits;
|
||||
Object.values(traits).forEach((trait: ModifiableData<number>) => (trait.total = trait.base + trait.mod));
|
||||
|
||||
private _getArmorValue(): number {
|
||||
return this.data["items"]
|
||||
.filter((item) => ["armor", "shield"].includes(item.type))
|
||||
.filter((item) => item.data.equipped)
|
||||
.map((item) => item.data.armorValue)
|
||||
.reduce((a, b) => a + b, 0);
|
||||
const combatValues = data.data.combatValues;
|
||||
Object.values(combatValues).forEach(
|
||||
(combatValue: ModifiableData<number>) => (combatValue.total = combatValue.base + combatValue.mod),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue