Skip to content

Commit

Permalink
CR metadata includes class/type and now does calculations in the npc …
Browse files Browse the repository at this point in the history
…section
  • Loading branch information
seiyria committed Sep 27, 2024
1 parent 377ad2b commit dca8128
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 9 deletions.
13 changes: 7 additions & 6 deletions src/app/tabs/npcs/npcs-editor/npcs-editor.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -42,22 +42,23 @@
<div class="form-column">
<div class="form-row">
<app-input-floating-label>Level</app-input-floating-label>
<input [(ngModel)]="editingData.level" min="0" type="number" placeholder="Choose level..." class="form-input"
(ngModelChange)="changeCRStats()" />
<input [(ngModel)]="editingData.level" min="1" type="number" placeholder="Choose level..." class="form-input"
(ngModelChange)="changeDynamicStats()" />
</div>
</div>

<div class="form-column">
<div class="form-row">
<app-input-floating-label>Skill</app-input-floating-label>
<input [(ngModel)]="editingData.skillLevels" min="0" type="number" placeholder="Choose skill..."
<input [(ngModel)]="editingData.skillLevels" min="1" type="number" placeholder="Choose skill..."
class="form-input" />
</div>
</div>
</div>

<div class="form-row">
<app-input-class [(playerClass)]="editingData.baseClass" label="NPC Class"></app-input-class>
<app-input-class [(playerClass)]="editingData.baseClass" label="NPC Class"
(change)="changeDynamicStats()"></app-input-class>
</div>

<div class="form-row">
Expand All @@ -79,7 +80,7 @@
</div>

<div class="form-row">
<app-input-category [(category)]="editingData.monsterClass"></app-input-category>
<app-input-category [(category)]="editingData.monsterClass" (change)="changeDynamicStats()"></app-input-category>
</div>

<div class="form-row split">
Expand Down Expand Up @@ -168,7 +169,7 @@
<div class="form-column">
<div class="form-row">
<app-input-floating-label>HP Multiplier</app-input-floating-label>
<input [(ngModel)]="editingData.hpMult" min="0" (ngModelChange)="changeCRStats()" type="number"
<input [(ngModel)]="editingData.hpMult" min="0" (ngModelChange)="changeDynamicStats()" type="number"
placeholder="Choose HP multiplier..." class="form-input" />
</div>
</div>
Expand Down
28 changes: 25 additions & 3 deletions src/app/tabs/npcs/npcs-editor/npcs-editor.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ export class NpcsEditorComponent
const data = this.challengeData();
if (!data) return;

this.changeCRStats();
this.changeDynamicStats();
});
}

Expand All @@ -131,7 +131,7 @@ export class NpcsEditorComponent
const npc = this.editing();

const skillLevel = levelFromSkillXP(npc.skills.martial ?? 0);
npc.skillLevels = skillLevel;
npc.skillLevels = skillLevel || 1;

const reps = npc.repMod ?? [];
npc.repMod = this.allegiances.map((allegiance) => ({
Expand Down Expand Up @@ -333,11 +333,25 @@ export class NpcsEditorComponent
this.editing.set(npc);
}

public changeCRStats() {
public changeDynamicStats() {
const npc = this.editing();
const challengeData = this.challengeData();

const level = npc.level;
const type = npc.monsterClass;
const baseClass = npc.baseClass;

let classMeta: any = {};
let typeMeta: any = {};

if (baseClass) {
classMeta = challengeData.byClass?.[baseClass]?.meta ?? {};
}

if (type) {
typeMeta = challengeData.byType?.[type]?.meta ?? {};
}

npc.hp = structuredClone(challengeData.global.stats.hp[level]);
npc.mp = structuredClone(challengeData.global.stats.mp[level]);
npc.giveXp = structuredClone(challengeData.global.stats.giveXp[level]);
Expand All @@ -346,6 +360,14 @@ export class NpcsEditorComponent
npc.hp.min = Math.floor(npc.hp.min * npc.hpMult);
npc.hp.max = Math.floor(npc.hp.max * npc.hpMult);

const stats = ['hp', 'mp', 'giveXp', 'gold'] as (keyof INPCDefinition)[];
stats.forEach((stat) => {
const mult =
(classMeta[`${stat}Mult`] ?? 1) * (typeMeta[`${stat}Mult`] ?? 1);
npc[stat].min = Math.floor(npc[stat].min * mult);
npc[stat].max = Math.floor(npc[stat].max * mult);
});

this.editing.set(npc);
}

Expand Down

0 comments on commit dca8128

Please sign in to comment.