2PlayerGame/detective-game/casegen/evening.js
2026-08-15 14:07:39 +03:00

33 lines
1.4 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

// casegen/evening.js — налаштування вечора злочину:
// де хто був насправді (evening) і що каже (claim), брехуни, спільники
const { chance, pick } = require('./rng');
const { unitBuilding } = require('./district');
const N = require('./names');
function setupEvening(ctx) {
const { r, citizens, victim, killer, herring, district, scene, coveredB } = ctx;
for (const c of citizens) {
c.evening = c.workplace && chance(r, 0.2) ? c.workplace
: chance(r, 0.2) ? pick(r, ['bar', 'diner']) : unitBuilding(c.home);
c.liar = chance(r, 0.15);
}
victim.evening = scene.building; victim.liar = false;
killer.evening = scene.building; killer.liar = true;
herring.evening = pick(r, coveredB.filter(b => b !== scene.building && b !== 'station')) || unitBuilding(herring.home);
herring.liar = false;
const otherB = b => pick(r, district.buildings.filter(x => x.id !== b && x.id !== 'station')).id;
for (const c of citizens) c.claim = c.liar ? otherB(c.evening) : c.evening;
killer.claim = pick(r, coveredB.filter(b => b !== scene.building && b !== 'station')) || otherB(scene.building);
for (const c of citizens) {
if (!c.liar || c === killer) continue;
c.excuse = pick(r, N.EXCUSES);
const m2 = citizens.find(o => o !== c && o.id !== victim.id && o.id !== killer.id && o.evening === c.evening);
c.mate = m2 ? m2.id : null;
}
}
module.exports = { setupEvening };