Add enemy pools and getNodeEnemy by node type

This commit is contained in:
Jared Miller 2026-02-25 09:53:16 -05:00
parent a7c5cbc56a
commit 7dfcc416d4
Signed by: shmup
GPG key ID: 22B5C6D66A38B06C
2 changed files with 69 additions and 1 deletions

View file

@ -1,3 +1,15 @@
const ENCOUNTER_POOL = [
"jaw_worm",
"cultist",
"fungi_beast",
"small_slime",
"red_louse",
"green_louse",
"blue_slaver",
];
const ELITE_POOL = ["lagavulin", "gremlin_nob", "sentry"];
const BOSS_POOL = ["slime_boss", "the_guardian"];
const ACT1_LAYOUT = [
"encounter",
"encounter",
@ -33,3 +45,14 @@ export function advanceMap(map) {
export function getCurrentNode(map) {
return map.nodes[map.currentNode];
}
export function getNodeEnemy(nodeType) {
const pools = {
encounter: ENCOUNTER_POOL,
elite: ELITE_POOL,
boss: BOSS_POOL,
};
const pool = pools[nodeType];
if (!pool) return null;
return pool[Math.floor(Math.random() * pool.length)];
}

View file

@ -1,5 +1,5 @@
import { describe, expect, test } from "bun:test";
import { advanceMap, createMap, getCurrentNode } from "./map.js";
import { advanceMap, createMap, getCurrentNode, getNodeEnemy } from "./map.js";
describe("createMap", () => {
test("returns 10 nodes", () => {
@ -79,3 +79,48 @@ describe("getCurrentNode", () => {
expect(node.id).toBe(1);
});
});
const ENCOUNTER_POOL = [
"jaw_worm",
"cultist",
"fungi_beast",
"small_slime",
"red_louse",
"green_louse",
"blue_slaver",
];
const ELITE_POOL = ["lagavulin", "gremlin_nob", "sentry"];
const BOSS_POOL = ["slime_boss", "the_guardian"];
describe("getNodeEnemy", () => {
test("encounter returns an id from the encounter pool", () => {
const enemy = getNodeEnemy("encounter");
expect(ENCOUNTER_POOL).toContain(enemy);
});
test("elite returns an id from the elite pool", () => {
const enemy = getNodeEnemy("elite");
expect(ELITE_POOL).toContain(enemy);
});
test("boss returns an id from the boss pool", () => {
const enemy = getNodeEnemy("boss");
expect(BOSS_POOL).toContain(enemy);
});
test("campfire returns null", () => {
expect(getNodeEnemy("campfire")).toBeNull();
});
test("unknown type returns null", () => {
expect(getNodeEnemy("shop")).toBeNull();
});
test("encounter pool has randomness across 50 calls", () => {
const results = new Set();
for (let i = 0; i < 50; i++) {
results.add(getNodeEnemy("encounter"));
}
expect(results.size).toBeGreaterThan(1);
});
});