fledgling/src/scorer.ts

69 lines
1.7 KiB
TypeScript

import {VNScene} from "./vnscene.ts";
import {getPlayerProgress} from "./playerprogress.ts";
import {getSkills} from "./skills.ts";
import {SCORING_CATEGORIES, ScoringCategory} from "./datatypes.ts";
import {sceneBat, sceneCharm, sceneLore, sceneParty, sceneStare, sceneStealth} from "./endings.ts";
class Scorer {
constructor() { }
pickEnding(): Ending {
let learnedSkills = getPlayerProgress().getLearnedSkills();
let scores: Record<string, number> = {};
for (const skill of learnedSkills.values()) {
let data = getSkills().get(skill);
for (let [category, number] of Object.entries(data.governing.scoring)) {
scores[category] = (scores[category] ?? 0) + number;
}
}
// NOTE: This approach isn't efficient but it's easy to understand
// and it allows me to arbitrate ties however I want
const isMax = (cat: ScoringCategory, min: number) => {
let score = scores[cat] ?? 0;
scores[cat] = 0; // each category, once checked, can't disqualify any other category
if (score < min) {
return false;
}
for (let cat of SCORING_CATEGORIES.values()) {
if (scores[cat] > score) {
return false;
}
}
return true;
}
if (isMax("stare", 3)) {
return {scene: sceneStare}
}
if (isMax("lore", 3)) {
return {scene: sceneLore};
}
if (isMax("charm", 2)) {
return {scene: sceneCharm}
}
if (isMax("party", 1)) {
return {scene: sceneParty};
}
if (isMax("stealth", 0)) {
return {scene: sceneStealth}
}
// if (isMax("bat")) {
{
return {scene: sceneBat};
}
}
}
type Ending = {
scene: VNScene
}
let active = new Scorer();
export function getScorer(): Scorer {
return active;
}