Add enemy pools and getNodeEnemy by node type
This commit is contained in:
parent
a7c5cbc56a
commit
7dfcc416d4
2 changed files with 69 additions and 1 deletions
23
src/map.js
23
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 = [
|
const ACT1_LAYOUT = [
|
||||||
"encounter",
|
"encounter",
|
||||||
"encounter",
|
"encounter",
|
||||||
|
|
@ -33,3 +45,14 @@ export function advanceMap(map) {
|
||||||
export function getCurrentNode(map) {
|
export function getCurrentNode(map) {
|
||||||
return map.nodes[map.currentNode];
|
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)];
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
import { describe, expect, test } from "bun:test";
|
import { describe, expect, test } from "bun:test";
|
||||||
import { advanceMap, createMap, getCurrentNode } from "./map.js";
|
import { advanceMap, createMap, getCurrentNode, getNodeEnemy } from "./map.js";
|
||||||
|
|
||||||
describe("createMap", () => {
|
describe("createMap", () => {
|
||||||
test("returns 10 nodes", () => {
|
test("returns 10 nodes", () => {
|
||||||
|
|
@ -79,3 +79,48 @@ describe("getCurrentNode", () => {
|
||||||
expect(node.id).toBe(1);
|
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);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue