Run prettier over everything
This commit is contained in:
@ -1,31 +1,31 @@
|
||||
import {ALL_STATS, Skill, Stat, SuccessorOption, Wish} from "./datatypes.ts";
|
||||
import {getSkills} from "./skills.ts";
|
||||
import {getThralls, LifeStage, Thrall} from "./thralls.ts";
|
||||
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
|
||||
#stats: Record<Stat, number>
|
||||
#talents: Record<Stat, number>
|
||||
#name: string;
|
||||
#stats: Record<Stat, number>;
|
||||
#talents: Record<Stat, number>;
|
||||
#isInPenance: boolean;
|
||||
#wish: Wish | null;
|
||||
#exp: number;
|
||||
#blood: number
|
||||
#itemsPurloined: number
|
||||
#skillsLearned: number[] // use the raw ID representation for indexOf
|
||||
#untrimmedSkillsAvailable: Skill[]
|
||||
#thrallsUnlocked: number[]
|
||||
#thrallDamage: Record<number, number>
|
||||
#blood: number;
|
||||
#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;
|
||||
this.#stats = {...asSuccessor.stats};
|
||||
this.#talents = {...asSuccessor.talents};
|
||||
this.#stats = { ...asSuccessor.stats };
|
||||
this.#talents = { ...asSuccessor.talents };
|
||||
this.#isInPenance = asSuccessor.inPenance;
|
||||
this.#wish = withWish;
|
||||
this.#exp = 0;
|
||||
this.#blood = 0;
|
||||
this.#itemsPurloined = 0;
|
||||
this.#skillsLearned = []
|
||||
this.#skillsLearned = [];
|
||||
this.#untrimmedSkillsAvailable = [];
|
||||
this.#thrallsUnlocked = [];
|
||||
this.#thrallDamage = {};
|
||||
@ -50,8 +50,10 @@ export class PlayerProgress {
|
||||
refill() {
|
||||
this.#blood = 2000;
|
||||
|
||||
let learnableSkills = []; // TODO: Also include costing info
|
||||
for (let skill of getSkills().getAvailableSkills(this.#isInPenance).values()) {
|
||||
let learnableSkills = []; // TODO: Also include costing info
|
||||
for (let skill of getSkills()
|
||||
.getAvailableSkills(this.#isInPenance)
|
||||
.values()) {
|
||||
if (this.#canBeAvailable(skill)) {
|
||||
learnableSkills.push(skill);
|
||||
}
|
||||
@ -59,11 +61,16 @@ 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);
|
||||
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
|
||||
this.#untrimmedSkillsAvailable = learnableSkills;
|
||||
}
|
||||
|
||||
hasLearned(skill: Skill) {
|
||||
@ -72,14 +79,16 @@ export class PlayerProgress {
|
||||
|
||||
learnSkill(skill: Skill) {
|
||||
if (this.#skillsLearned.indexOf(skill.id) != -1) {
|
||||
return
|
||||
return;
|
||||
}
|
||||
this.#skillsLearned.push(skill.id);
|
||||
|
||||
// remove entries for that skill
|
||||
let skills2 = [];
|
||||
for (let entry of this.#untrimmedSkillsAvailable.values()) {
|
||||
if (entry.id == skill.id) { continue; }
|
||||
if (entry.id == skill.id) {
|
||||
continue;
|
||||
}
|
||||
skills2.push(entry);
|
||||
}
|
||||
this.#untrimmedSkillsAvailable = skills2;
|
||||
@ -96,7 +105,7 @@ export class PlayerProgress {
|
||||
// make sure the prereqs are met
|
||||
for (let prereq of data.prereqs.values()) {
|
||||
if (!this.hasLearned(prereq)) {
|
||||
return false
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@ -109,12 +118,12 @@ export class PlayerProgress {
|
||||
}
|
||||
|
||||
getItemsPurloined() {
|
||||
return this.#itemsPurloined
|
||||
return this.#itemsPurloined;
|
||||
}
|
||||
|
||||
add(stat: Stat, amount: number) {
|
||||
if (amount != Math.floor(amount)) {
|
||||
throw `stat increment must be integer: ${amount}`
|
||||
throw `stat increment must be integer: ${amount}`;
|
||||
}
|
||||
this.#stats[stat] += amount;
|
||||
this.#stats[stat] = Math.min(Math.max(this.#stats[stat], -99), 999);
|
||||
@ -125,18 +134,18 @@ export class PlayerProgress {
|
||||
}
|
||||
|
||||
getExperience(): number {
|
||||
return this.#exp
|
||||
return this.#exp;
|
||||
}
|
||||
|
||||
spendExperience(cost: number) {
|
||||
if (this.#exp < cost) {
|
||||
throw `can't spend ${cost}`
|
||||
throw `can't spend ${cost}`;
|
||||
}
|
||||
this.#exp -= cost;
|
||||
}
|
||||
|
||||
getStat(stat: Stat): number {
|
||||
return this.#stats[stat]
|
||||
return this.#stats[stat];
|
||||
}
|
||||
|
||||
getTalent(stat: Stat): number {
|
||||
@ -149,7 +158,7 @@ export class PlayerProgress {
|
||||
|
||||
addBlood(amt: number) {
|
||||
this.#blood += amt;
|
||||
this.#blood = Math.min(this.#blood, 5000)
|
||||
this.#blood = Math.min(this.#blood, 5000);
|
||||
}
|
||||
|
||||
spendBlood(amt: number) {
|
||||
@ -157,7 +166,7 @@ export class PlayerProgress {
|
||||
}
|
||||
|
||||
getWish(): Wish | null {
|
||||
return this.#wish
|
||||
return this.#wish;
|
||||
}
|
||||
|
||||
getAvailableSkills(): Skill[] {
|
||||
@ -167,30 +176,40 @@ export class PlayerProgress {
|
||||
let name1 = getSkills().get(a).profile.name;
|
||||
let name2 = getSkills().get(b).profile.name;
|
||||
|
||||
if (name1 < name2) { return -1; }
|
||||
if (name1 > name2) { return 1; }
|
||||
if (name1 < name2) {
|
||||
return -1;
|
||||
}
|
||||
if (name1 > name2) {
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
});
|
||||
skillsAvailable.sort((a, b) => {
|
||||
return getSkills().computeCost(a) - getSkills().computeCost(b)
|
||||
return getSkills().computeCost(a) - getSkills().computeCost(b);
|
||||
});
|
||||
return skillsAvailable.slice(0, 6)
|
||||
return skillsAvailable.slice(0, 6);
|
||||
}
|
||||
|
||||
getLearnedSkills() {
|
||||
let learnedSkills = []
|
||||
let learnedSkills = [];
|
||||
for (let s of this.#skillsLearned.values()) {
|
||||
learnedSkills.push({id: s})
|
||||
learnedSkills.push({ id: s });
|
||||
}
|
||||
return learnedSkills;
|
||||
}
|
||||
|
||||
getStats() { return {...this.#stats} }
|
||||
getTalents() { return {...this.#talents} }
|
||||
getStats() {
|
||||
return { ...this.#stats };
|
||||
}
|
||||
getTalents() {
|
||||
return { ...this.#talents };
|
||||
}
|
||||
|
||||
unlockThrall(thrall: Thrall) {
|
||||
let {id} = thrall;
|
||||
if (this.#thrallsUnlocked.indexOf(id) != -1) { return; }
|
||||
let { id } = thrall;
|
||||
if (this.#thrallsUnlocked.indexOf(id) != -1) {
|
||||
return;
|
||||
}
|
||||
this.#thrallsUnlocked.push(id);
|
||||
}
|
||||
|
||||
@ -200,34 +219,50 @@ export class PlayerProgress {
|
||||
|
||||
damageThrall(thrall: Thrall, amount: number) {
|
||||
if (amount <= 0.0) {
|
||||
throw new Error(`damage must be some positive amount, not ${amount}`)
|
||||
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
|
||||
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; }
|
||||
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;
|
||||
|
||||
export function initPlayerProgress(asSuccessor: SuccessorOption, withWish: Wish | null){
|
||||
export function initPlayerProgress(
|
||||
asSuccessor: SuccessorOption,
|
||||
withWish: Wish | null,
|
||||
) {
|
||||
active = new PlayerProgress(asSuccessor, withWish);
|
||||
}
|
||||
|
||||
export function getPlayerProgress(): PlayerProgress {
|
||||
if (active == null) {
|
||||
throw new Error(`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
|
||||
}
|
||||
return active;
|
||||
}
|
||||
|
Reference in New Issue
Block a user