slaywithfriends/src/map.js

58 lines
1.1 KiB
JavaScript

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",
"campfire",
"encounter",
"elite",
"encounter",
"campfire",
"encounter",
"elite",
"boss",
];
export function createMap() {
return {
nodes: ACT1_LAYOUT.map((type, id) => ({ id, type, cleared: false })),
currentNode: 0,
};
}
export function advanceMap(map) {
const last = map.nodes.length - 1;
const nodes = map.nodes.map((n, i) =>
i === map.currentNode ? { ...n, cleared: true } : n,
);
return {
...map,
nodes,
currentNode: Math.min(map.currentNode + 1, last),
};
}
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)];
}