Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(advancement): add basic advancement #202

Merged
merged 5 commits into from
Jan 25, 2025
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions src/style/sheets/actor/module.scss
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,17 @@
mask: var(--star-cosmere-svg) no-repeat center;
opacity: 0.5;
}

input {
position: absolute;
left: 0;
top: 0;
width: 100%;
height: 100%;
padding: 5px 0 0 0;
z-index: 1;
text-align: center;
MangoFVTT marked this conversation as resolved.
Show resolved Hide resolved
}
}
}
}
Expand Down
6 changes: 3 additions & 3 deletions src/system/applications/actor/components/character/paths.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,9 +86,9 @@ export class CharacterPathsComponent extends HandlebarsApplicationComponent<
.rank,
mod: this.application.actor.system.skills[skillId].mod,
})),
level: this.application.actor.system.level.paths[
path.system.id
],
level: this.application.actor.talents.filter(
(talent) => talent.pathId === path.id,
).length,
})),
});
}
Expand Down
183 changes: 183 additions & 0 deletions src/system/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -370,6 +370,189 @@ const COSMERE: CosmereRPGConfig = {
},
},

advancement: {
rules: [
{
level: 1,
tier: 1,
maxSkillRanks: 2,
attributePoints: 12,
health: 10,
healthIncludeStrength: true,
skillRanks: 4,
talents: 1,
}, // Level 1
{
level: 2,
tier: 1,
maxSkillRanks: 2,
health: 5,
skillRanks: 2,
talents: 1,
}, // Level 2
{
level: 3,
tier: 1,
maxSkillRanks: 2,
attributePoints: 1,
health: 5,
skillRanks: 2,
talents: 1,
}, // Level 3
{
level: 4,
tier: 1,
maxSkillRanks: 2,
health: 5,
skillRanks: 2,
talents: 1,
}, // Level 4
{
level: 5,
tier: 1,
maxSkillRanks: 2,
health: 5,
skillRanks: 2,
talents: 1,
}, // Level 5
{
level: 6,
tier: 2,
maxSkillRanks: 3,
attributePoints: 1,
health: 4,
healthIncludeStrength: true,
skillRanks: 2,
talents: 1,
}, // Level 6
{
level: 7,
tier: 2,
maxSkillRanks: 3,
health: 4,
skillRanks: 2,
talents: 1,
}, // Level 7
{
level: 8,
tier: 2,
maxSkillRanks: 3,
health: 4,
skillRanks: 2,
talents: 1,
}, // Level 8
{
level: 9,
tier: 2,
maxSkillRanks: 3,
attributePoints: 1,
health: 4,
skillRanks: 2,
talents: 1,
}, // Level 9
{
level: 10,
tier: 2,
maxSkillRanks: 3,
health: 4,
skillRanks: 2,
talents: 1,
}, // Level 10
{
level: 11,
tier: 3,
maxSkillRanks: 4,
health: 3,
healthIncludeStrength: true,
skillRanks: 2,
talents: 1,
}, // Level 11
{
level: 12,
tier: 3,
maxSkillRanks: 4,
attributePoints: 1,
health: 3,
skillRanks: 2,
talents: 1,
}, // Level 12
{
level: 13,
tier: 3,
maxSkillRanks: 4,
health: 3,
skillRanks: 2,
talents: 1,
}, // Level 13
{
level: 14,
tier: 3,
maxSkillRanks: 4,
health: 3,
skillRanks: 2,
talents: 1,
}, // Level 14
{
level: 15,
tier: 3,
maxSkillRanks: 4,
attributePoints: 1,
health: 3,
skillRanks: 2,
talents: 1,
}, // Level 15
{
level: 16,
tier: 4,
maxSkillRanks: 5,
health: 2,
healthIncludeStrength: true,
skillRanks: 2,
talents: 1,
}, // Level 16
{
level: 17,
tier: 4,
maxSkillRanks: 5,
health: 2,
skillRanks: 2,
talents: 1,
}, // Level 17
{
level: 18,
tier: 4,
maxSkillRanks: 5,
attributePoints: 1,
health: 2,
skillRanks: 2,
talents: 1,
}, // Level 18
{
level: 19,
tier: 4,
maxSkillRanks: 5,
health: 2,
skillRanks: 2,
talents: 1,
}, // Level 19
{
level: 20,
tier: 4,
maxSkillRanks: 5,
health: 2,
skillRanks: 2,
talents: 1,
}, // Level 20
{
level: 21,
tier: 5,
maxSkillRanks: 5,
health: 1,
skillRanksOrTalents: 1,
}, // Level 21
],
},

paths: {
types: {
[PathType.Heroic]: {
Expand Down
100 changes: 76 additions & 24 deletions src/system/data/actor/character.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
// Types
import { Resource } from '@system/types/cosmere';
import { DeepPartial, AnyObject } from '@system/types/utils';

import { CommonActorDataModel, CommonActorData } from './common';

// Utils
import * as Advancement from '@system/utils/advancement';

// Fields
import { DerivedValueField, Derived, MappingField } from '../fields';

Expand All @@ -14,10 +21,16 @@ interface ConnectionData {
}

export interface CharacterActorData extends CommonActorData {
level: {
paths: Record<string, number>;
total: Derived<number>;
};
/* --- Advancement --- */
level: number;

/**
* Derived value for the maximum rank a skill can be.
* Based on the configured advancement rules.
*/
maxSkillRank: number;

/* --- Derived statistics --- */
recovery: { die: Derived<string> };

/* --- Goals, Connections, Purpose, and Obstacle --- */
Expand All @@ -30,25 +43,25 @@ export interface CharacterActorData extends CommonActorData {
export class CharacterActorDataModel extends CommonActorDataModel<CharacterActorData> {
public static defineSchema() {
return foundry.utils.mergeObject(super.defineSchema(), {
level: new foundry.data.fields.SchemaField({
paths: new MappingField(
new foundry.data.fields.NumberField({
integer: true,
min: 0,
}),
{
required: true,
nullable: false,
},
),
total: new DerivedValueField(
new foundry.data.fields.NumberField({
min: 0,
integer: true,
}),
),
/* --- Advancement --- */
level: new foundry.data.fields.NumberField({
required: true,
nullable: false,
integer: true,
min: 1,
initial: 1,
label: 'COSMERE.Actor.Level.Label',
}),

maxSkillRank: new foundry.data.fields.NumberField({
required: true,
nullable: false,
integer: true,
initial: 2,
max: 5,
}),

/* --- Derived statistics --- */
recovery: new foundry.data.fields.SchemaField({
die: new DerivedValueField(
new foundry.data.fields.StringField({
Expand Down Expand Up @@ -109,14 +122,53 @@ export class CharacterActorDataModel extends CommonActorDataModel<CharacterActor
public prepareDerivedData() {
super.prepareDerivedData();

this.level.total.value = Object.values(this.level.paths).reduce(
(sum, lvl) => sum + lvl,
0,
// Get advancement rules relevant to the character
const advancementRules = Advancement.getAdvancementRulesUpToLevel(
this.level,
);
const currentAdvancementRule =
advancementRules[advancementRules.length - 1];

// Derive the tier
this.tier = currentAdvancementRule.tier;

// Derive the maximum skill rank
this.maxSkillRank = currentAdvancementRule.maxSkillRanks;

// Derive the recovery die based on the character's willpower
this.recovery.die.value = willpowerToRecoveryDie(
this.attributes.wil.value,
);

// Derive resource max
(Object.keys(this.resources) as Resource[]).forEach((key) => {
// Get the resource
const resource = this.resources[key];

if (key === Resource.Health) {
// Get strength mod
const strength =
this.attributes.str.value + this.attributes.str.bonus;

// Assign max
resource.max.value =
Advancement.deriveMaxHealth(advancementRules, strength) +
(resource.max.bonus ?? 0);
} else if (key === Resource.Focus) {
// Get willpower mod
const willpower =
this.attributes.wil.value + this.attributes.wil.bonus;

// Assign max
resource.max.value = 2 + willpower + (resource.max.bonus ?? 0);
}

// Get max
const max = Derived.getValue(resource.max)!;

// Ensure resource value is between max mand min
resource.value = Math.max(0, Math.min(max, resource.value));
});
}
}

Expand Down
26 changes: 0 additions & 26 deletions src/system/data/actor/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -532,32 +532,6 @@ export class CommonActorDataModel<
this.defenses[group].value.value = 10 + attrsSum + bonus;
});

// Derive resource max
(Object.keys(this.resources) as Resource[]).forEach((key) => {
// Get the resource
const resource = this.resources[key];

if (key === Resource.Health) {
// Get strength value
const strength = this.attributes.str.value;

// Assign max
resource.max.value = 10 + strength + (resource.max.bonus ?? 0);
} else if (key === Resource.Focus) {
// Get willpower value
const willpower = this.attributes.wil.value;

// Assign max
resource.max.value = 2 + willpower + (resource.max.bonus ?? 0);
}

// Get max
const max = Derived.getValue(resource.max)!;

// Ensure resource value is between max mand min
resource.value = Math.max(0, Math.min(max, resource.value));
});

// Derive skill modifiers
(Object.keys(this.skills) as Skill[]).forEach((skill) => {
// Get the skill config
Expand Down
Loading
Loading