Thralls deteriorate over many bites
This commit is contained in:
@ -1,5 +1,6 @@
|
||||
import {ALL_STATS, Skill, Stat, SuccessorOption, Wish} from "./datatypes.ts";
|
||||
import {getSkills} from "./skills.ts";
|
||||
import {getThralls, LifeStage, Thrall} from "./thralls.ts";
|
||||
|
||||
export class PlayerProgress {
|
||||
#name: string
|
||||
@ -12,6 +13,8 @@ export class PlayerProgress {
|
||||
#itemsPurloined: number
|
||||
#skillsLearned: number[] // use the raw ID representation for indexOf
|
||||
#untrimmedSkillsAvailable: Skill[]
|
||||
#thrallsUnlocked: number[]
|
||||
#thrallDamage: Record<number, number>
|
||||
|
||||
constructor(asSuccessor: SuccessorOption, withWish: Wish | null) {
|
||||
this.#name = asSuccessor.name;
|
||||
@ -24,6 +27,8 @@ export class PlayerProgress {
|
||||
this.#itemsPurloined = 0;
|
||||
this.#skillsLearned = []
|
||||
this.#untrimmedSkillsAvailable = [];
|
||||
this.#thrallsUnlocked = [];
|
||||
this.#thrallDamage = {};
|
||||
|
||||
this.refill();
|
||||
}
|
||||
@ -52,6 +57,12 @@ export class PlayerProgress {
|
||||
}
|
||||
}
|
||||
|
||||
for (let thrall of getThralls().getAll()) {
|
||||
let stage = this.getThrallLifeStage(thrall);
|
||||
if (stage == LifeStage.Vampirized || stage == LifeStage.Dead) { continue; }
|
||||
this.#thrallDamage[thrall.id] = Math.max(this.#thrallDamage[thrall.id] ?? 0 - 0.2, 0.0);
|
||||
}
|
||||
|
||||
this.#untrimmedSkillsAvailable = learnableSkills
|
||||
}
|
||||
|
||||
@ -175,7 +186,38 @@ export class PlayerProgress {
|
||||
}
|
||||
|
||||
getStats() { return {...this.#stats} }
|
||||
getTalents() { return {...this.#talents} } }
|
||||
getTalents() { return {...this.#talents} }
|
||||
|
||||
unlockThrall(thrall: Thrall) {
|
||||
let {id} = thrall;
|
||||
if (this.#thrallsUnlocked.indexOf(id) != -1) { return; }
|
||||
this.#thrallsUnlocked.push(id);
|
||||
}
|
||||
|
||||
isThrallUnlocked(thrall: Thrall) {
|
||||
return this.#thrallsUnlocked.indexOf(thrall.id) != -1;
|
||||
}
|
||||
|
||||
damageThrall(thrall: Thrall, amount: number) {
|
||||
if (amount <= 0.0) {
|
||||
throw new Error(`damage must be some positive amount, not ${amount}`)
|
||||
}
|
||||
let stage = this.getThrallLifeStage(thrall);
|
||||
|
||||
if (stage == LifeStage.Vampirized) { this.#thrallDamage[thrall.id] = 4.0; }
|
||||
this.#thrallDamage[thrall.id] = (this.#thrallDamage[thrall.id] ?? 0.0) + amount
|
||||
}
|
||||
|
||||
getThrallLifeStage(thrall: Thrall): LifeStage {
|
||||
let damage = this.#thrallDamage[thrall.id] ?? 0;
|
||||
console.log(`damage: ${damage}`)
|
||||
if (damage < 0.5) { return LifeStage.Fresh; }
|
||||
if (damage < 1.75) { return LifeStage.Average; }
|
||||
if (damage < 3.0) { return LifeStage.Poor; }
|
||||
if (damage < 4.0) { return LifeStage.Vampirized; }
|
||||
return LifeStage.Dead;
|
||||
}
|
||||
}
|
||||
|
||||
let active: PlayerProgress | null = null;
|
||||
|
||||
@ -185,7 +227,7 @@ export function initPlayerProgress(asSuccessor: SuccessorOption, withWish: Wish
|
||||
|
||||
export function getPlayerProgress(): PlayerProgress {
|
||||
if (active == null) {
|
||||
throw `trying to get player progress before it has been initialized`
|
||||
throw new Error(`trying to get player progress before it has been initialized`)
|
||||
}
|
||||
return active
|
||||
}
|
Reference in New Issue
Block a user