Remove events system entirely
CI / build-and-push (push) Successful in 36s

The random events (GPU shortages, regulatory hearings, PR crises, etc.)
added interruption without enough gameplay value. Removed all event
types, definitions (~1800 lines of event data), the event processor,
EventModal UI, store actions, and tick integration. Updated docs to
reflect the removal. Bundle size drops ~47kB.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-04-24 19:54:44 -04:00
parent 0005e580a7
commit 95f2f97121
16 changed files with 16 additions and 2191 deletions
@@ -1,118 +0,0 @@
import type { GameState, EventState, ActiveEvent, EventDefinition, EventCondition } from '@ai-tycoon/shared';
import { uuid } from '@ai-tycoon/shared';
export interface EventTickResult {
events: EventState;
newEvents: ActiveEvent[];
}
export function processEvents(
state: GameState,
definitions: EventDefinition[],
): EventTickResult {
const tick = state.meta.tickCount;
const events = { ...state.events };
const newEvents: ActiveEvent[] = [];
// Remove expired events (auto-choose default)
const stillActive: ActiveEvent[] = [];
for (const event of events.activeEvents) {
if (tick >= event.expiresAtTick) {
events.eventHistory = [
...events.eventHistory,
{
eventId: event.eventId,
instanceId: event.instanceId,
title: event.title,
category: event.category,
tick,
chosenOptionIndex: event.defaultChoiceIndex,
},
];
} else {
stillActive.push(event);
}
}
events.activeEvents = stillActive;
if (events.eventHistory.length > 50) {
events.eventHistory = events.eventHistory.slice(-50);
}
// Only try to fire a new event every 30 ticks, and max 1 active at a time
if (tick % 30 !== 0 || events.activeEvents.length > 0) {
return { events, newEvents };
}
const eraOrder = ['startup', 'scaleup', 'bigtech', 'agi'];
const currentEraIdx = eraOrder.indexOf(state.meta.currentEra);
const eligible = definitions.filter(def => {
if (!def.eras.some(e => eraOrder.indexOf(e) <= currentEraIdx)) return false;
const occ = events.eventOccurrences[def.id] ?? 0;
if (occ >= def.maxOccurrences) return false;
const cooldownEnd = events.eventCooldowns[def.id] ?? 0;
if (tick < cooldownEnd) return false;
if (def.prerequisites.some(p => !state.research.completedResearch.includes(p))) return false;
if (!def.conditions.every(c => evaluateCondition(state, c))) return false;
return true;
});
if (eligible.length === 0) return { events, newEvents };
const totalWeight = eligible.reduce((s, d) => s + d.weight, 0);
let roll = Math.random() * totalWeight;
let chosen: EventDefinition | null = null;
for (const def of eligible) {
roll -= def.weight;
if (roll <= 0) { chosen = def; break; }
}
if (!chosen) return { events, newEvents };
// Only fire with 30% probability per check to space events out
if (Math.random() > 0.3) return { events, newEvents };
const activeEvent: ActiveEvent = {
eventId: chosen.id,
instanceId: uuid(),
triggeredAtTick: tick,
expiresAtTick: tick + chosen.expiryTicks,
title: chosen.title,
description: chosen.descriptionTemplate,
category: chosen.category,
choices: chosen.choices,
defaultChoiceIndex: chosen.defaultChoiceIndex,
};
events.activeEvents = [...events.activeEvents, activeEvent];
events.eventCooldowns = { ...events.eventCooldowns, [chosen.id]: tick + chosen.cooldownTicks };
events.eventOccurrences = {
...events.eventOccurrences,
[chosen.id]: (events.eventOccurrences[chosen.id] ?? 0) + 1,
};
newEvents.push(activeEvent);
return { events, newEvents };
}
function evaluateCondition(state: GameState, condition: EventCondition): boolean {
const value = getNestedValue(state, condition.field);
if (value === undefined) return false;
switch (condition.operator) {
case 'gt': return value > condition.value;
case 'lt': return value < condition.value;
case 'gte': return value >= condition.value;
case 'lte': return value <= condition.value;
case 'eq': return value === condition.value;
}
}
function getNestedValue(obj: object, path: string): number | undefined {
const parts = path.split('.');
let current: unknown = obj;
for (const part of parts) {
if (current == null || typeof current !== 'object') return undefined;
current = (current as Record<string, unknown>)[part];
}
return typeof current === 'number' ? current : undefined;
}