diff --git a/src/map.js b/src/map.js index fcd12c8..557c9d7 100644 --- a/src/map.js +++ b/src/map.js @@ -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)]; +} diff --git a/src/map.test.js b/src/map.test.js index e7aba6e..a1b9f4d 100644 --- a/src/map.test.js +++ b/src/map.test.js @@ -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); + }); +});