Skip to content

Commit

Permalink
Move many character properties to the common folder
Browse files Browse the repository at this point in the history
  • Loading branch information
sapphie132 committed Jan 12, 2024
1 parent 80672f5 commit 6bbc394
Show file tree
Hide file tree
Showing 12 changed files with 126 additions and 84 deletions.
11 changes: 10 additions & 1 deletion src/main/typescript/data/actor/character/leveling/properties.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,20 @@
import type { SkillName } from "../../../../constants.js";
import type { SkillInfo } from "../../common/skills/properties.js";
import LevelingSource from "./source.js";

export default class LevelingProperties extends LevelingSource {
export default class LevelingProperties
extends LevelingSource
implements SkillInfo
{
constructor(source: LevelingSource) {
super();
foundry.utils.mergeObject(this, source);
}

getValue(skill: SkillName): number {
return this.skillRanks[skill];
}

/** The current level of the character */
get level(): number {
return Math.floor((1 + Math.sqrt(this.experience / 12.5 + 1)) / 2);
Expand Down
4 changes: 2 additions & 2 deletions src/main/typescript/data/actor/character/properties.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import LevelingProperties from "./leveling/properties.js";
import MagicProperties from "./magic/properties.js";
import SkillsProperties from "./skills/properties.js";
import { CharacterDataSourceData } from "./source.js";
import SpecialsProperties, { Special } from "./specials/properties.js";
import VitalsProperties from "./vitals/properties.js";
import SpecialsProperties, { Special } from "../common/specials/properties.js";
import VitalsProperties from "../common/vitals/properties.js";

export default interface CharacterDataProperties {
type: typeof TYPES.ACTOR.CHARACTER;
Expand Down
80 changes: 4 additions & 76 deletions src/main/typescript/data/actor/character/skills/properties.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,83 +5,11 @@ import {
} from "../../../../constants.js";
import { CompositeNumber } from "../../../common.js";
import type LevelingProperties from "../leveling/properties.js";
import type SpecialsProperties from "../specials/properties.js";
import type SpecialsProperties from "../../common/specials/properties.js";
import BaseSkillsProperties from "../../common/skills/properties.js";

export default class SkillsProperties
implements Record<SkillName, CompositeNumber>
{
/** The Barter skill of the character */
barter = new CompositeNumber();

/** The Diplomacy skill of the character */
diplomacy = new CompositeNumber();

/** The Explosives skill of the character */
explosives = new CompositeNumber();

/** The Firearms skill of the character */
firearms = new CompositeNumber();

/** The Intimidation skill of the character */
intimidation = new CompositeNumber();

/** The Lockpick skill of the character */
lockpick = new CompositeNumber();

/** The Magical Energy Weapons skill of the character */
magicalEnergyWeapons = new CompositeNumber();

/** The Mechanics skill of the character */
mechanics = new CompositeNumber();

/** The Medicine skill of the character */
medicine = new CompositeNumber();

/** The Melee skill of the character */
melee = new CompositeNumber();

/** The Science skill of the character */
science = new CompositeNumber();

/** The Sleight skill of the character */
sleight = new CompositeNumber();

/** The Sneak skill of the character */
sneak = new CompositeNumber();

/** The Survival skill of the character */
survival = new CompositeNumber();

/** The Thaumaturgy skill of the character */
thaumaturgy = new CompositeNumber();

/** The Unarmed skill of the character */
unarmed = new CompositeNumber();

/** Set the base values and skill points for all skills. */
setBaseValues(
specials: SpecialsProperties,
thaumSpecial: ThaumaturgySpecial,
leveling: LevelingProperties
) {
let skill: SkillName;
for (skill in CONSTANTS.skillSpecials) {
this[skill] = this.computeBaseSkill(
skill,
specials,
thaumSpecial,
leveling
);
}
this["thaumaturgy"] = this.computeBaseSkill(
"thaumaturgy",
specials,
thaumSpecial,
leveling
);
}

private computeBaseSkill(
export default class SkillsProperties extends BaseSkillsProperties {
override computeBaseSkill(
skill: SkillName,
specials: SpecialsProperties,
thaumSpecial: ThaumaturgySpecial,
Expand Down
2 changes: 1 addition & 1 deletion src/main/typescript/data/actor/character/source.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import BackgroundSource, {
import EquipmentSource, { EQUIPMENT_JSON_SCHEMA } from "./equipment/source.js";
import LevelingSource, { LEVELING_JSON_SCHEMA } from "./leveling/source.js";
import MagicSource, { MAGIC_JSON_SCHEMA } from "./magic/source.js";
import VitalsSource, { VITALS_JSON_SCHEMA } from "./vitals/source.js";
import VitalsSource, { VITALS_JSON_SCHEMA } from "../common/vitals/source.js";

export default interface CharacterDataSource {
type: typeof TYPES.ACTOR.CHARACTER;
Expand Down
101 changes: 101 additions & 0 deletions src/main/typescript/data/actor/common/skills/properties.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
import {
CONSTANTS,
SkillName,
ThaumaturgySpecial
} from "../../../../constants.js";
import { CompositeNumber } from "../../../common.js";
import type SpecialsProperties from "../specials/properties.js";

export default class SkillsProperties
implements Record<SkillName, CompositeNumber>
{
/** The Barter skill of the character */
barter = new CompositeNumber();

/** The Diplomacy skill of the character */
diplomacy = new CompositeNumber();

/** The Explosives skill of the character */
explosives = new CompositeNumber();

/** The Firearms skill of the character */
firearms = new CompositeNumber();

/** The Intimidation skill of the character */
intimidation = new CompositeNumber();

/** The Lockpick skill of the character */
lockpick = new CompositeNumber();

/** The Magical Energy Weapons skill of the character */
magicalEnergyWeapons = new CompositeNumber();

/** The Mechanics skill of the character */
mechanics = new CompositeNumber();

/** The Medicine skill of the character */
medicine = new CompositeNumber();

/** The Melee skill of the character */
melee = new CompositeNumber();

/** The Science skill of the character */
science = new CompositeNumber();

/** The Sleight skill of the character */
sleight = new CompositeNumber();

/** The Sneak skill of the character */
sneak = new CompositeNumber();

/** The Survival skill of the character */
survival = new CompositeNumber();

/** The Thaumaturgy skill of the character */
thaumaturgy = new CompositeNumber();

/** The Unarmed skill of the character */
unarmed = new CompositeNumber();

/** Set the base values and skill points for all skills. */
setBaseValues(
specials: SpecialsProperties,
thaumSpecial: ThaumaturgySpecial,
skillInfo: SkillInfo
) {
let skill: SkillName;
for (skill in CONSTANTS.skillSpecials) {
this[skill] = this.computeBaseSkill(
skill,
specials,
thaumSpecial,
skillInfo
);
}
this["thaumaturgy"] = this.computeBaseSkill(
"thaumaturgy",
specials,
thaumSpecial,
skillInfo
);
}

protected computeBaseSkill(
skill: SkillName,
_specials: SpecialsProperties,
_thaumSpecial: ThaumaturgySpecial,
skillInfo: SkillInfo
): CompositeNumber {
const baseSkill = 0;
const composite = new CompositeNumber(baseSkill, { min: 0, max: 85 });
composite.add({
value: skillInfo.getValue(skill),
labelComponents: [{ key: "wv.rules.skills.points.short" }]
});
return composite;
}
}

export interface SkillInfo {
getValue(skill: SkillName): number;
}
6 changes: 5 additions & 1 deletion src/main/typescript/data/actor/npc/source.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
import type { TYPES } from "../../../constants.js";
import VitalsSource from "../common/vitals/source.js";

export default interface NpcDataSource {
type: typeof TYPES.ACTOR.NPC;
data: NpcDataSourceData;
}

export class NpcDataSourceData {}
export class NpcDataSourceData {
/** The vitals of the NPC */
vitals = new VitalsSource();
}
2 changes: 1 addition & 1 deletion src/main/typescript/data/item/weapon/ranges/properties.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type WvActor from "../../../../actor/wvActor.js";
import { CONSTANTS, RangeBracket, TAGS } from "../../../../constants.js";
import type SpecialsProperties from "../../../actor/character/specials/properties.js";
import type SpecialsProperties from "../../../actor/common/specials/properties.js";
import { CompositeNumber } from "../../../common.js";
import RangesSource, { DistanceSource, RangeSource } from "./source.js";

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type WvActor from "../../actor/wvActor.js";
import { isSpecialName } from "../../constants.js";
import { Special } from "../../data/actor/character/specials/properties.js";
import { Special } from "../../data/actor/common/specials/properties.js";
import type WvItem from "../../item/wvItem.js";
import NotActorMessage from "../messages/notActorMessage.js";
import WrongSpecialNameMessage from "../messages/wrongSpecialNameMessage.js";
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type WvActor from "../../actor/wvActor.js";
import { isSpecialName } from "../../constants.js";
import { Special } from "../../data/actor/character/specials/properties.js";
import { Special } from "../../data/actor/common/specials/properties.js";
import type WvItem from "../../item/wvItem.js";
import NotActorMessage from "../messages/notActorMessage.js";
import WrongSpecialNameMessage from "../messages/wrongSpecialNameMessage.js";
Expand Down

0 comments on commit 6bbc394

Please sign in to comment.