Pick a successor at the end of the game
This commit is contained in:
@ -1,30 +1,41 @@
|
||||
import {Skill, Stat} from "./datatypes.ts";
|
||||
import {ALL_STATS, Skill, Stat, SuccessorOption, Wish} from "./datatypes.ts";
|
||||
import {getSkills} from "./skills.ts";
|
||||
|
||||
export class PlayerProgress {
|
||||
#name: string
|
||||
#stats: Record<Stat, number>
|
||||
#talents: Record<Stat, number>
|
||||
#wish: Wish | null;
|
||||
#exp: number;
|
||||
#blood: number
|
||||
#itemsPurloined: number
|
||||
#skillsLearned: number[] // use the raw ID representation for indexOf
|
||||
#untrimmedSkillsAvailable: Skill[]
|
||||
|
||||
constructor() {
|
||||
this.#stats = {
|
||||
AGI: 10,
|
||||
INT: 10,
|
||||
CHA: 10,
|
||||
PSI: 10,
|
||||
};
|
||||
constructor(asSuccessor: SuccessorOption, withWish: Wish | null) {
|
||||
this.#name = asSuccessor.name;
|
||||
this.#stats = {...asSuccessor.stats};
|
||||
this.#talents = {...asSuccessor.talents};
|
||||
this.#wish = withWish;
|
||||
this.#exp = 0;
|
||||
this.#blood = 0;
|
||||
this.#itemsPurloined = 0;
|
||||
this.#skillsLearned = [];
|
||||
this.#untrimmedSkillsAvailable = []
|
||||
this.#skillsLearned = []
|
||||
this.#untrimmedSkillsAvailable = [];
|
||||
|
||||
this.refill();
|
||||
}
|
||||
|
||||
applyEndOfTurn() {
|
||||
for (let stat of ALL_STATS.values()) {
|
||||
this.#stats[stat] += this.#talents[stat];
|
||||
}
|
||||
}
|
||||
|
||||
get name(): string {
|
||||
return this.#name;
|
||||
}
|
||||
|
||||
refill() {
|
||||
this.#blood = 2000;
|
||||
|
||||
@ -113,6 +124,10 @@ export class PlayerProgress {
|
||||
return this.#stats[stat]
|
||||
}
|
||||
|
||||
getTalent(stat: Stat): number {
|
||||
return this.#talents[stat];
|
||||
}
|
||||
|
||||
getBlood(): number {
|
||||
return Math.floor(Math.max(this.#blood, 0));
|
||||
}
|
||||
@ -152,8 +167,15 @@ export class PlayerProgress {
|
||||
}
|
||||
}
|
||||
|
||||
let active: PlayerProgress = new PlayerProgress();
|
||||
let active: PlayerProgress | null = null;
|
||||
|
||||
export function initPlayerProgress(asSuccessor: SuccessorOption, withWish: Wish | null){
|
||||
active = new PlayerProgress(asSuccessor, withWish);
|
||||
}
|
||||
|
||||
export function getPlayerProgress(): PlayerProgress {
|
||||
if (active == null) {
|
||||
throw `trying to get player progress before it has been initialized`
|
||||
}
|
||||
return active
|
||||
}
|
Reference in New Issue
Block a user