feat: New features (research, invest, gambling, new game+, trophies)

This commit is contained in:
gauvainboiche
2026-10-08 14:03:00 +02:00
parent 1caa4d92b9
commit fc0d5e3ba4
56 changed files with 4332 additions and 249 deletions
+38
View File
@@ -0,0 +1,38 @@
// Research: labs (bought with funds) produce research points slowly over time;
// points buy nodes of a small tree. Research survives a legacy restart.
export function labCost(state, ctx) {
const r = ctx.rules.research;
return Math.ceil(r.labBaseCost * r.labCostGrowth ** state.labs);
}
export function rpPerSecond(state, ctx, mods) {
return state.labs * ctx.rules.research.rpPerLabPerSecond * mods.rp;
}
export function buyLab(state, ctx) {
const { labMax } = ctx.rules.research;
const cost = labCost(state, ctx);
if (state.labs >= labMax || state.funds < cost) return false;
state.funds -= cost;
state.labs += 1;
return true;
}
/** 'owned' | 'available' | 'locked' */
export function researchStatus(state, node) {
if (state.research.includes(node.id)) return 'owned';
return node.requires.every((id) => state.research.includes(id)) ? 'available' : 'locked';
}
export function buyResearch(state, ctx, id) {
const node = ctx.researchById.get(id);
if (!node || researchStatus(state, node) !== 'available' || state.rp < node.cost) return false;
state.rp -= node.cost;
state.research.push(id);
return true;
}
export function stepResearch(state, ctx, dt, mods) {
state.rp += rpPerSecond(state, ctx, mods) * dt;
}