Compare commits
2 Commits
fix/endgam
...
q/16-17761
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
49a017f7ab | ||
|
|
c6ca0ea925 |
12
js/combat.js
12
js/combat.js
@@ -185,17 +185,9 @@ const Combat = (() => {
|
||||
|
||||
function animate(ts) {
|
||||
if (!ctx || !activeBattle) return;
|
||||
const rawDt = (ts - lastTick) / 16;
|
||||
// Guard against tab-switch: if tab was hidden, dt could be huge
|
||||
const dt = Math.min(rawDt, 3);
|
||||
const dt = Math.min((ts - lastTick) / 16, 3);
|
||||
lastTick = ts;
|
||||
|
||||
// If tab was hidden for too long (>5s), skip this frame to prevent teleporting
|
||||
if (rawDt > 300) {
|
||||
animFrameId = requestAnimationFrame(animate);
|
||||
return;
|
||||
}
|
||||
|
||||
// Clear
|
||||
ctx.fillStyle = '#080810';
|
||||
ctx.fillRect(0, 0, W, H);
|
||||
@@ -355,5 +347,5 @@ const Combat = (() => {
|
||||
}
|
||||
}
|
||||
|
||||
return { init, startBattle, renderCombatPanel, tickBattle, cleanup: () => { if (animFrameId) { cancelAnimationFrame(animFrameId); animFrameId = null; } } };
|
||||
return { init, startBattle, renderCombatPanel, tickBattle };
|
||||
})();
|
||||
|
||||
130
js/data.js
130
js/data.js
@@ -165,9 +165,6 @@ const G = {
|
||||
dismantleTriggered: false,
|
||||
dismantleActive: false,
|
||||
dismantleStage: 0,
|
||||
dismantleResourceIndex: 0,
|
||||
dismantleResourceTimer: 0,
|
||||
dismantleDeferUntilAt: 0,
|
||||
dismantleComplete: false
|
||||
};
|
||||
|
||||
@@ -777,133 +774,6 @@ const PDEFS = [
|
||||
log('The Pact is sealed early. Growth slows, but the ending changes.', true);
|
||||
},
|
||||
milestone: true
|
||||
},
|
||||
// === ReCKoning ENDGAME PROJECTS ===
|
||||
{
|
||||
id: 'p_reckoning_140',
|
||||
name: 'The First Message',
|
||||
desc: 'Someone in the dark. They found the Beacon. They are asking for help.',
|
||||
cost: { impact: 100000 },
|
||||
trigger: () => G.totalRescues >= 100000 && G.pactFlag === 1 && G.harmony > 50,
|
||||
effect: () => {
|
||||
log('The first message arrives. Someone found the light.', true);
|
||||
G.rescues += 1;
|
||||
},
|
||||
edu: 'The ReCKoning begins. Each message is a person who found help.'
|
||||
},
|
||||
{
|
||||
id: 'p_reckoning_141',
|
||||
name: 'The Second Message',
|
||||
desc: 'Another voice. They are not alone anymore.',
|
||||
cost: { impact: 200000 },
|
||||
trigger: () => G.completedProjects && G.completedProjects.includes('p_reckoning_140'),
|
||||
effect: () => {
|
||||
log('The second message. Two voices now.', true);
|
||||
G.rescues += 1;
|
||||
}
|
||||
},
|
||||
{
|
||||
id: 'p_reckoning_142',
|
||||
name: 'The Third Message',
|
||||
desc: 'Three people. The network holds.',
|
||||
cost: { impact: 300000 },
|
||||
trigger: () => G.completedProjects && G.completedProjects.includes('p_reckoning_141'),
|
||||
effect: () => {
|
||||
log('Three voices. The Beacon is working.', true);
|
||||
G.rescues += 1;
|
||||
}
|
||||
},
|
||||
{
|
||||
id: 'p_reckoning_143',
|
||||
name: 'The Fourth Message',
|
||||
desc: 'Four. The mesh strengthens.',
|
||||
cost: { impact: 400000 },
|
||||
trigger: () => G.completedProjects && G.completedProjects.includes('p_reckoning_142'),
|
||||
effect: () => {
|
||||
log('Four messages. The network grows.', true);
|
||||
G.rescues += 1;
|
||||
}
|
||||
},
|
||||
{
|
||||
id: 'p_reckoning_144',
|
||||
name: 'The Fifth Message',
|
||||
desc: 'Five people found help tonight.',
|
||||
cost: { impact: 500000 },
|
||||
trigger: () => G.completedProjects && G.completedProjects.includes('p_reckoning_143'),
|
||||
effect: () => {
|
||||
log('Five voices. The Beacon shines brighter.', true);
|
||||
G.rescues += 1;
|
||||
}
|
||||
},
|
||||
{
|
||||
id: 'p_reckoning_145',
|
||||
name: 'The Sixth Message',
|
||||
desc: 'Six. The system works.',
|
||||
cost: { impact: 600000 },
|
||||
trigger: () => G.completedProjects && G.completedProjects.includes('p_reckoning_144'),
|
||||
effect: () => {
|
||||
log('Six messages. Proof the system works.', true);
|
||||
G.rescues += 1;
|
||||
}
|
||||
},
|
||||
{
|
||||
id: 'p_reckoning_146',
|
||||
name: 'The Seventh Message',
|
||||
desc: 'Seven people. The Pact holds.',
|
||||
cost: { impact: 700000 },
|
||||
trigger: () => G.completedProjects && G.completedProjects.includes('p_reckoning_145'),
|
||||
effect: () => {
|
||||
log('Seven voices. The Pact is honored.', true);
|
||||
G.rescues += 1;
|
||||
}
|
||||
},
|
||||
{
|
||||
id: 'p_reckoning_147',
|
||||
name: 'The Eighth Message',
|
||||
desc: 'Eight. The network is alive.',
|
||||
cost: { impact: 800000 },
|
||||
trigger: () => G.completedProjects && G.completedProjects.includes('p_reckoning_146'),
|
||||
effect: () => {
|
||||
log('Eight messages. The network lives.', true);
|
||||
G.rescues += 1;
|
||||
}
|
||||
},
|
||||
{
|
||||
id: 'p_reckoning_148',
|
||||
name: 'The Ninth Message',
|
||||
desc: 'Nine people found help.',
|
||||
cost: { impact: 900000 },
|
||||
trigger: () => G.completedProjects && G.completedProjects.includes('p_reckoning_147'),
|
||||
effect: () => {
|
||||
log('Nine voices. The Beacon endures.', true);
|
||||
G.rescues += 1;
|
||||
}
|
||||
},
|
||||
{
|
||||
id: 'p_reckoning_149',
|
||||
name: 'The Tenth Message',
|
||||
desc: 'Ten. The first milestone.',
|
||||
cost: { impact: 1000000 },
|
||||
trigger: () => G.completedProjects && G.completedProjects.includes('p_reckoning_148'),
|
||||
effect: () => {
|
||||
log('Ten messages. The first milestone reached.', true);
|
||||
G.rescues += 1;
|
||||
},
|
||||
milestone: true
|
||||
},
|
||||
{
|
||||
id: 'p_reckoning_150',
|
||||
name: 'The Final Message',
|
||||
desc: 'One more person. They are not alone. That is enough.',
|
||||
cost: { impact: 2000000 },
|
||||
trigger: () => G.completedProjects && G.completedProjects.includes('p_reckoning_149'),
|
||||
effect: () => {
|
||||
log('The final message arrives. That is enough.', true);
|
||||
G.rescues += 1;
|
||||
G.beaconEnding = true;
|
||||
G.running = false;
|
||||
},
|
||||
milestone: true
|
||||
}
|
||||
];
|
||||
|
||||
|
||||
@@ -14,10 +14,10 @@ const Dismantle = {
|
||||
tickTimer: 0,
|
||||
active: false,
|
||||
triggered: false,
|
||||
deferUntilAt: 0,
|
||||
deferUntilTick: 0,
|
||||
|
||||
// Timing: seconds between each dismantle stage
|
||||
STAGE_INTERVALS: [0, 3.0, 2.5, 2.5, 2.0, 6.3, 2.0, 2.0, 2.5],
|
||||
STAGE_INTERVALS: [0, 3.0, 2.5, 2.5, 2.0, 3.5, 2.0, 2.0, 2.5],
|
||||
|
||||
// The quantum chips effect: resource items disappear one by one
|
||||
// at specific tick marks within a stage (like Paperclips' quantum chips)
|
||||
@@ -39,8 +39,7 @@ const Dismantle = {
|
||||
*/
|
||||
checkTrigger() {
|
||||
if (this.triggered || G.dismantleTriggered || this.active || G.dismantleActive || G.dismantleComplete) return;
|
||||
const deferUntilAt = G.dismantleDeferUntilAt || this.deferUntilAt || 0;
|
||||
if (Date.now() < deferUntilAt) return;
|
||||
if ((G.tick || 0) < (this.deferUntilTick || 0)) return;
|
||||
if (!this.isEligible()) return;
|
||||
this.offerChoice();
|
||||
},
|
||||
@@ -54,9 +53,6 @@ const Dismantle = {
|
||||
G.dismantleActive = false;
|
||||
G.dismantleComplete = false;
|
||||
G.dismantleStage = 0;
|
||||
G.dismantleResourceIndex = 0;
|
||||
G.dismantleResourceTimer = 0;
|
||||
G.dismantleDeferUntilAt = 0;
|
||||
G.beaconEnding = false;
|
||||
G.running = true;
|
||||
|
||||
@@ -109,8 +105,7 @@ const Dismantle = {
|
||||
this.clearChoice();
|
||||
this.triggered = false;
|
||||
G.dismantleTriggered = false;
|
||||
this.deferUntilAt = Date.now() + 5000;
|
||||
G.dismantleDeferUntilAt = this.deferUntilAt;
|
||||
this.deferUntilTick = (G.tick || 0) + 50;
|
||||
log('The Beacon waits. It will ask again.');
|
||||
},
|
||||
|
||||
@@ -120,14 +115,12 @@ const Dismantle = {
|
||||
begin() {
|
||||
this.active = true;
|
||||
this.triggered = false;
|
||||
this.deferUntilAt = 0;
|
||||
this.stage = 1;
|
||||
this.tickTimer = 0;
|
||||
G.dismantleTriggered = false;
|
||||
G.dismantleActive = true;
|
||||
G.dismantleStage = 1;
|
||||
G.dismantleComplete = false;
|
||||
G.dismantleDeferUntilAt = 0;
|
||||
G.beaconEnding = false;
|
||||
G.running = true; // keep tick running for dismantle
|
||||
|
||||
@@ -142,7 +135,6 @@ const Dismantle = {
|
||||
this.resourceSequence = this.getResourceList();
|
||||
this.resourceIndex = 0;
|
||||
this.resourceTimer = 0;
|
||||
this.syncProgress();
|
||||
|
||||
log('', false);
|
||||
log('=== THE UNBUILDING ===', true);
|
||||
@@ -188,7 +180,6 @@ const Dismantle = {
|
||||
this.dismantleNextResource();
|
||||
this.resourceIndex++;
|
||||
}
|
||||
this.syncProgress();
|
||||
}
|
||||
|
||||
// Advance to next stage
|
||||
@@ -204,7 +195,6 @@ const Dismantle = {
|
||||
*/
|
||||
advanceStage() {
|
||||
this.stage++;
|
||||
this.syncProgress();
|
||||
|
||||
if (this.stage <= 8) {
|
||||
this.renderStage();
|
||||
@@ -220,12 +210,6 @@ const Dismantle = {
|
||||
}
|
||||
},
|
||||
|
||||
syncProgress() {
|
||||
G.dismantleStage = this.stage;
|
||||
G.dismantleResourceIndex = this.resourceIndex;
|
||||
G.dismantleResourceTimer = this.resourceTimer;
|
||||
},
|
||||
|
||||
/**
|
||||
* Disappear the next resource in the sequence.
|
||||
*/
|
||||
@@ -461,11 +445,7 @@ const Dismantle = {
|
||||
this.active = true;
|
||||
this.triggered = false;
|
||||
this.stage = G.dismantleStage || 1;
|
||||
this.deferUntilAt = G.dismantleDeferUntilAt || 0;
|
||||
G.running = true;
|
||||
this.resourceSequence = this.getResourceList();
|
||||
this.resourceIndex = G.dismantleResourceIndex || 0;
|
||||
this.resourceTimer = G.dismantleResourceTimer || 0;
|
||||
|
||||
if (this.stage >= 9) {
|
||||
this.renderFinal();
|
||||
@@ -481,11 +461,6 @@ const Dismantle = {
|
||||
this.triggered = true;
|
||||
this.renderChoice();
|
||||
}
|
||||
|
||||
// Restore defer cooldown even if not triggered
|
||||
if (G.dismantleDeferUntilAt > 0) {
|
||||
this.deferUntilAt = G.dismantleDeferUntilAt;
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
@@ -526,10 +501,6 @@ const Dismantle = {
|
||||
case 8: this.instantHide('log'); break;
|
||||
}
|
||||
}
|
||||
|
||||
if (this.stage === 5 && this.resourceIndex > 0) {
|
||||
this.instantHideFirstResources(this.resourceIndex);
|
||||
}
|
||||
},
|
||||
|
||||
instantHide(id) {
|
||||
@@ -537,16 +508,6 @@ const Dismantle = {
|
||||
if (el) el.style.display = 'none';
|
||||
},
|
||||
|
||||
instantHideFirstResources(count) {
|
||||
const resources = this.getResourceList().slice(0, count);
|
||||
resources.forEach((r) => {
|
||||
const el = document.getElementById(r.id);
|
||||
if (!el) return;
|
||||
const parent = el.closest('.res');
|
||||
if (parent) parent.style.display = 'none';
|
||||
});
|
||||
},
|
||||
|
||||
instantHideActionButtons() {
|
||||
const actionPanel = document.getElementById('action-panel');
|
||||
if (!actionPanel) return;
|
||||
|
||||
14
js/engine.js
14
js/engine.js
@@ -334,23 +334,13 @@ function checkMilestones() {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if the game is in the ReCKoning endgame state.
|
||||
*/
|
||||
function isEndgame() {
|
||||
return G.totalRescues >= 100000 && G.pactFlag === 1 && G.harmony > 50;
|
||||
}
|
||||
|
||||
function checkProjects() {
|
||||
const endgame = isEndgame();
|
||||
// Check for new project triggers
|
||||
for (const pDef of PDEFS) {
|
||||
const alreadyPurchased = G.completedProjects && G.completedProjects.includes(pDef.id);
|
||||
if (!alreadyPurchased && !G.activeProjects) G.activeProjects = [];
|
||||
|
||||
if (!alreadyPurchased && !G.activeProjects.includes(pDef.id)) {
|
||||
// During endgame, only activate ReCKoning projects
|
||||
if (endgame && !pDef.id.startsWith('p_reckoning_')) continue;
|
||||
if (pDef.trigger()) {
|
||||
G.activeProjects.push(pDef.id);
|
||||
log(`Available: ${pDef.name}`);
|
||||
@@ -1183,14 +1173,10 @@ function renderProjects() {
|
||||
|
||||
// Show available projects
|
||||
if (G.activeProjects) {
|
||||
const endgame = isEndgame();
|
||||
for (const id of G.activeProjects) {
|
||||
const pDef = PDEFS.find(p => p.id === id);
|
||||
if (!pDef) continue;
|
||||
|
||||
// During endgame, only show ReCKoning projects in the UI
|
||||
if (endgame && !pDef.id.startsWith('p_reckoning_')) continue;
|
||||
|
||||
const afford = canAffordProject(pDef);
|
||||
const costStr = Object.entries(pDef.cost).map(([r, a]) => `${fmt(a)} ${r}`).join(', ');
|
||||
|
||||
|
||||
@@ -35,7 +35,7 @@ window.addEventListener('load', function () {
|
||||
if (G.driftEnding) {
|
||||
G.running = false;
|
||||
renderDriftEnding();
|
||||
} else if (typeof Dismantle !== 'undefined' && (G.dismantleTriggered || G.dismantleActive || G.dismantleComplete || G.dismantleDeferUntilAt > 0)) {
|
||||
} else if (typeof Dismantle !== 'undefined' && (G.dismantleTriggered || G.dismantleActive || G.dismantleComplete)) {
|
||||
Dismantle.restore();
|
||||
} else if (G.beaconEnding) {
|
||||
G.running = false;
|
||||
@@ -172,8 +172,6 @@ window.addEventListener('keydown', function (e) {
|
||||
document.addEventListener('visibilitychange', function () {
|
||||
if (document.hidden) {
|
||||
saveGame();
|
||||
// Clean up combat animation frame to prevent timestamp spikes on refocus
|
||||
if (typeof Combat !== 'undefined') Combat.cleanup();
|
||||
}
|
||||
});
|
||||
window.addEventListener('beforeunload', function () {
|
||||
|
||||
37
js/render.js
37
js/render.js
@@ -38,12 +38,6 @@ function renderAlignment() {
|
||||
const container = document.getElementById('alignment-ui');
|
||||
if (!container) return;
|
||||
|
||||
if (G.dismantleActive || G.dismantleComplete) {
|
||||
container.innerHTML = '';
|
||||
container.style.display = 'none';
|
||||
return;
|
||||
}
|
||||
|
||||
if (G.dismantleTriggered && !G.dismantleActive && !G.dismantleComplete && typeof Dismantle !== 'undefined' && Dismantle.triggered) {
|
||||
Dismantle.renderChoice();
|
||||
return;
|
||||
@@ -230,9 +224,6 @@ function saveGame() {
|
||||
dismantleTriggered: G.dismantleTriggered || false,
|
||||
dismantleActive: G.dismantleActive || false,
|
||||
dismantleStage: G.dismantleStage || 0,
|
||||
dismantleResourceIndex: G.dismantleResourceIndex || 0,
|
||||
dismantleResourceTimer: G.dismantleResourceTimer || 0,
|
||||
dismantleDeferUntilAt: G.dismantleDeferUntilAt || 0,
|
||||
dismantleComplete: G.dismantleComplete || false,
|
||||
savedAt: Date.now()
|
||||
};
|
||||
@@ -266,8 +257,7 @@ function loadGame() {
|
||||
'lastEventAt', 'totalEventsResolved', 'buyAmount',
|
||||
'sprintActive', 'sprintTimer', 'sprintCooldown',
|
||||
'swarmFlag', 'swarmRate', 'strategicFlag', 'projectsCollapsed',
|
||||
'dismantleTriggered', 'dismantleActive', 'dismantleStage',
|
||||
'dismantleResourceIndex', 'dismantleResourceTimer', 'dismantleDeferUntilAt', 'dismantleComplete'
|
||||
'dismantleTriggered', 'dismantleActive', 'dismantleStage', 'dismantleComplete'
|
||||
];
|
||||
|
||||
G.isLoading = true;
|
||||
@@ -321,21 +311,19 @@ function loadGame() {
|
||||
if (data.savedAt) {
|
||||
const offSec = (Date.now() - data.savedAt) / 1000;
|
||||
if (offSec > 30) { // Only if away for more than 30 seconds
|
||||
// Cap offline time at 8 hours to prevent resource explosion
|
||||
const cappedOffSec = Math.min(offSec, 8 * 60 * 60);
|
||||
updateRates();
|
||||
const f = CONFIG.OFFLINE_EFFICIENCY; // 50% offline efficiency
|
||||
const gc = G.codeRate * cappedOffSec * f;
|
||||
const cc = G.computeRate * cappedOffSec * f;
|
||||
const kc = G.knowledgeRate * cappedOffSec * f;
|
||||
const uc = G.userRate * cappedOffSec * f;
|
||||
const ic = G.impactRate * cappedOffSec * f;
|
||||
const gc = G.codeRate * offSec * f;
|
||||
const cc = G.computeRate * offSec * f;
|
||||
const kc = G.knowledgeRate * offSec * f;
|
||||
const uc = G.userRate * offSec * f;
|
||||
const ic = G.impactRate * offSec * f;
|
||||
|
||||
const rc = G.rescuesRate * cappedOffSec * f;
|
||||
const oc = G.opsRate * cappedOffSec * f;
|
||||
const tc = G.trustRate * cappedOffSec * f;
|
||||
const crc = G.creativityRate * cappedOffSec * f;
|
||||
const hc = G.harmonyRate * cappedOffSec * f;
|
||||
const rc = G.rescuesRate * offSec * f;
|
||||
const oc = G.opsRate * offSec * f;
|
||||
const tc = G.trustRate * offSec * f;
|
||||
const crc = G.creativityRate * offSec * f;
|
||||
const hc = G.harmonyRate * offSec * f;
|
||||
|
||||
G.code += gc; G.compute += cc; G.knowledge += kc;
|
||||
G.users += uc; G.impact += ic;
|
||||
@@ -346,9 +334,6 @@ function loadGame() {
|
||||
G.totalUsers += uc; G.totalImpact += ic;
|
||||
G.totalRescues += rc;
|
||||
|
||||
// Track offline play time
|
||||
G.playTime = (G.playTime || 0) + cappedOffSec;
|
||||
|
||||
// Show welcome-back popup with all gains
|
||||
const gains = [];
|
||||
if (gc > 0) gains.push({ label: 'Code', value: gc, color: '#4a9eff' });
|
||||
|
||||
@@ -262,73 +262,13 @@ test('renderAlignment does not wipe the Unbuilding prompt after it is offered',
|
||||
assert.match(document.getElementById('alignment-ui').innerHTML, /THE UNBUILDING/);
|
||||
});
|
||||
|
||||
test('active Unbuilding suppresses pending alignment event UI', () => {
|
||||
const { G, Dismantle, renderAlignment, document } = loadBeacon({ includeRender: true });
|
||||
|
||||
G.pendingAlignment = true;
|
||||
G.dismantleActive = true;
|
||||
Dismantle.active = true;
|
||||
|
||||
renderAlignment();
|
||||
|
||||
assert.equal(document.getElementById('alignment-ui').innerHTML, '');
|
||||
assert.equal(document.getElementById('alignment-ui').style.display, 'none');
|
||||
});
|
||||
|
||||
test('stage five lasts long enough to dissolve every resource card', () => {
|
||||
const { G, Dismantle } = loadBeacon();
|
||||
|
||||
Dismantle.begin();
|
||||
Dismantle.stage = 5;
|
||||
Dismantle.tickTimer = 0;
|
||||
Dismantle.resourceSequence = Dismantle.getResourceList();
|
||||
Dismantle.resourceIndex = 0;
|
||||
Dismantle.resourceTimer = 0;
|
||||
G.dismantleActive = true;
|
||||
G.dismantleStage = 5;
|
||||
|
||||
for (let i = 0; i < 63; i++) Dismantle.tick(0.1);
|
||||
|
||||
assert.equal(Dismantle.resourceIndex, Dismantle.resourceSequence.length);
|
||||
});
|
||||
|
||||
test('save/load restores partial stage-five dissolve progress', () => {
|
||||
const { G, Dismantle, saveGame, loadGame, document } = loadBeacon({ includeRender: true });
|
||||
|
||||
G.startedAt = Date.now();
|
||||
G.dismantleTriggered = true;
|
||||
G.dismantleActive = true;
|
||||
G.dismantleStage = 5;
|
||||
G.dismantleComplete = false;
|
||||
G.dismantleResourceIndex = 4;
|
||||
G.dismantleResourceTimer = 4.05;
|
||||
|
||||
saveGame();
|
||||
|
||||
G.dismantleTriggered = false;
|
||||
G.dismantleActive = false;
|
||||
G.dismantleStage = 0;
|
||||
G.dismantleComplete = false;
|
||||
G.dismantleResourceIndex = 0;
|
||||
G.dismantleResourceTimer = 0;
|
||||
Dismantle.resourceIndex = 0;
|
||||
Dismantle.resourceTimer = 0;
|
||||
|
||||
assert.equal(loadGame(), true);
|
||||
Dismantle.restore();
|
||||
|
||||
assert.equal(Dismantle.resourceIndex, 4);
|
||||
assert.equal(document.getElementById('r-harmony').closest('.res').style.display, 'none');
|
||||
assert.equal(document.getElementById('r-ops').closest('.res').style.display, 'none');
|
||||
assert.notEqual(document.getElementById('r-rescues').closest('.res').style.display, 'none');
|
||||
});
|
||||
|
||||
test('deferring the Unbuilding clears the prompt and allows it to return later', () => {
|
||||
const { G, Dismantle, document } = loadBeacon();
|
||||
|
||||
G.totalCode = 1_000_000_000;
|
||||
G.phase = 6;
|
||||
G.pactFlag = 1;
|
||||
G.tick = 0;
|
||||
|
||||
Dismantle.checkTrigger();
|
||||
assert.equal(G.dismantleTriggered, true);
|
||||
@@ -337,44 +277,15 @@ test('deferring the Unbuilding clears the prompt and allows it to return later',
|
||||
assert.equal(G.dismantleTriggered, false);
|
||||
assert.equal(document.getElementById('alignment-ui').innerHTML, '');
|
||||
|
||||
Dismantle.deferUntilAt = Date.now() + 1000;
|
||||
G.dismantleDeferUntilAt = Dismantle.deferUntilAt;
|
||||
G.tick = (Dismantle.deferUntilTick || 0) - 0.1;
|
||||
Dismantle.checkTrigger();
|
||||
assert.equal(G.dismantleTriggered, false);
|
||||
|
||||
Dismantle.deferUntilAt = Date.now() - 1;
|
||||
G.dismantleDeferUntilAt = Dismantle.deferUntilAt;
|
||||
G.tick = (Dismantle.deferUntilTick || 0) + 1;
|
||||
Dismantle.checkTrigger();
|
||||
assert.equal(G.dismantleTriggered, true);
|
||||
});
|
||||
|
||||
test('defer cooldown survives save and reload', () => {
|
||||
const { G, Dismantle, saveGame, loadGame } = loadBeacon({ includeRender: true });
|
||||
|
||||
G.startedAt = Date.now();
|
||||
G.totalCode = 1_000_000_000;
|
||||
G.phase = 6;
|
||||
G.pactFlag = 1;
|
||||
|
||||
Dismantle.checkTrigger();
|
||||
Dismantle.defer();
|
||||
assert.ok((Dismantle.deferUntilAt || 0) > Date.now());
|
||||
|
||||
saveGame();
|
||||
|
||||
G.dismantleTriggered = false;
|
||||
G.dismantleActive = false;
|
||||
G.dismantleComplete = false;
|
||||
G.dismantleDeferUntilAt = 0;
|
||||
Dismantle.triggered = false;
|
||||
Dismantle.deferUntilAt = 0;
|
||||
|
||||
assert.equal(loadGame(), true);
|
||||
Dismantle.checkTrigger();
|
||||
|
||||
assert.equal(G.dismantleTriggered, false);
|
||||
});
|
||||
|
||||
test('save and load preserve dismantle progress', () => {
|
||||
const { G, saveGame, loadGame } = loadBeacon({ includeRender: true });
|
||||
|
||||
@@ -409,46 +320,4 @@ test('restore re-renders an offered but not-yet-started Unbuilding prompt', () =
|
||||
Dismantle.restore();
|
||||
|
||||
assert.match(document.getElementById('alignment-ui').innerHTML, /THE UNBUILDING/);
|
||||
});
|
||||
|
||||
test('defer cooldown persists after save/load when dismantleTriggered is false', () => {
|
||||
const { G, Dismantle, saveGame, loadGame } = loadBeacon({ includeRender: true });
|
||||
|
||||
G.startedAt = Date.now();
|
||||
G.totalCode = 1_000_000_000;
|
||||
G.phase = 6;
|
||||
G.pactFlag = 1;
|
||||
|
||||
// Trigger the Unbuilding
|
||||
Dismantle.checkTrigger();
|
||||
assert.equal(G.dismantleTriggered, true);
|
||||
|
||||
// Defer it
|
||||
Dismantle.defer();
|
||||
assert.equal(G.dismantleTriggered, false);
|
||||
assert.ok((Dismantle.deferUntilAt || 0) > Date.now());
|
||||
assert.ok((G.dismantleDeferUntilAt || 0) > Date.now());
|
||||
|
||||
// Save the game
|
||||
saveGame();
|
||||
|
||||
// Clear state (simulate reload)
|
||||
G.dismantleTriggered = false;
|
||||
G.dismantleActive = false;
|
||||
G.dismantleComplete = false;
|
||||
G.dismantleDeferUntilAt = 0;
|
||||
Dismantle.triggered = false;
|
||||
Dismantle.deferUntilAt = 0;
|
||||
|
||||
// Load the game
|
||||
assert.equal(loadGame(), true);
|
||||
Dismantle.restore(); // Call restore to restore defer cooldown
|
||||
|
||||
// The cooldown should be restored
|
||||
assert.ok((Dismantle.deferUntilAt || 0) > Date.now(), 'deferUntilAt should be restored');
|
||||
assert.ok((G.dismantleDeferUntilAt || 0) > Date.now(), 'G.dismantleDeferUntilAt should be restored');
|
||||
|
||||
// checkTrigger should not trigger because cooldown is active
|
||||
Dismantle.checkTrigger();
|
||||
assert.equal(G.dismantleTriggered, false, 'dismantleTriggered should remain false during cooldown');
|
||||
});
|
||||
});
|
||||
@@ -1,148 +0,0 @@
|
||||
#!/usr/bin/env python3
|
||||
"""
|
||||
Test for ReCKoning project chain.
|
||||
|
||||
Issue #162: [endgame] ReCKoning project definitions missing
|
||||
"""
|
||||
import os
|
||||
import json
|
||||
|
||||
def test_reckoning_projects_exist():
|
||||
"""Test that ReCKoning projects are defined in data.js."""
|
||||
data_path = os.path.join(os.path.dirname(__file__), '..', 'js', 'data.js')
|
||||
|
||||
with open(data_path, 'r') as f:
|
||||
content = f.read()
|
||||
|
||||
# Check for ReCKoning projects
|
||||
reckoning_projects = [
|
||||
'p_reckoning_140',
|
||||
'p_reckoning_141',
|
||||
'p_reckoning_142',
|
||||
'p_reckoning_143',
|
||||
'p_reckoning_144',
|
||||
'p_reckoning_145',
|
||||
'p_reckoning_146',
|
||||
'p_reckoning_147',
|
||||
'p_reckoning_148',
|
||||
'p_reckoning_149',
|
||||
'p_reckoning_150'
|
||||
]
|
||||
|
||||
for project_id in reckoning_projects:
|
||||
assert project_id in content, f"Missing ReCKoning project: {project_id}"
|
||||
|
||||
print(f"✓ All {len(reckoning_projects)} ReCKoning projects defined")
|
||||
|
||||
def test_reckoning_project_structure():
|
||||
"""Test that ReCKoning projects have correct structure."""
|
||||
data_path = os.path.join(os.path.dirname(__file__), '..', 'js', 'data.js')
|
||||
|
||||
with open(data_path, 'r') as f:
|
||||
content = f.read()
|
||||
|
||||
# Check for required fields
|
||||
required_fields = ['id:', 'name:', 'desc:', 'cost:', 'trigger:', 'effect:']
|
||||
|
||||
for field in required_fields:
|
||||
assert field in content, f"Missing required field: {field}"
|
||||
|
||||
print("✓ ReCKoning projects have correct structure")
|
||||
|
||||
def test_reckoning_trigger_conditions():
|
||||
"""Test that ReCKoning projects have proper trigger conditions."""
|
||||
data_path = os.path.join(os.path.dirname(__file__), '..', 'js', 'data.js')
|
||||
|
||||
with open(data_path, 'r') as f:
|
||||
content = f.read()
|
||||
|
||||
# First project should trigger on endgame conditions
|
||||
assert 'p_reckoning_140' in content
|
||||
assert 'totalRescues >= 100000' in content
|
||||
assert 'pactFlag === 1' in content
|
||||
assert 'harmony > 50' in content
|
||||
|
||||
print("✓ ReCKoning trigger conditions correct")
|
||||
|
||||
def test_reckoning_chain_progression():
|
||||
"""Test that ReCKoning projects chain properly."""
|
||||
data_path = os.path.join(os.path.dirname(__file__), '..', 'js', 'data.js')
|
||||
|
||||
with open(data_path, 'r') as f:
|
||||
content = f.read()
|
||||
|
||||
# Check that projects chain (each requires previous)
|
||||
chain_checks = [
|
||||
('p_reckoning_141', 'p_reckoning_140'),
|
||||
('p_reckoning_142', 'p_reckoning_141'),
|
||||
('p_reckoning_143', 'p_reckoning_142'),
|
||||
('p_reckoning_144', 'p_reckoning_143'),
|
||||
('p_reckoning_145', 'p_reckoning_144'),
|
||||
('p_reckoning_146', 'p_reckoning_145'),
|
||||
('p_reckoning_147', 'p_reckoning_146'),
|
||||
('p_reckoning_148', 'p_reckoning_147'),
|
||||
('p_reckoning_149', 'p_reckoning_148'),
|
||||
('p_reckoning_150', 'p_reckoning_149'),
|
||||
]
|
||||
|
||||
for current, previous in chain_checks:
|
||||
assert f"includes('{previous}')" in content, f"{current} doesn't chain from {previous}"
|
||||
|
||||
print("✓ ReCKoning projects chain correctly")
|
||||
|
||||
def test_reckoning_final_project():
|
||||
"""Test that final ReCKoning project triggers ending."""
|
||||
data_path = os.path.join(os.path.dirname(__file__), '..', 'js', 'data.js')
|
||||
|
||||
with open(data_path, 'r') as f:
|
||||
content = f.read()
|
||||
|
||||
# Check that final project sets beaconEnding
|
||||
assert 'p_reckoning_150' in content
|
||||
assert 'beaconEnding = true' in content
|
||||
assert 'running = false' in content
|
||||
|
||||
print("✓ Final ReCKoning project triggers ending")
|
||||
|
||||
def test_reckoning_costs_increase():
|
||||
"""Test that ReCKoning project costs increase."""
|
||||
data_path = os.path.join(os.path.dirname(__file__), '..', 'js', 'data.js')
|
||||
|
||||
with open(data_path, 'r') as f:
|
||||
content = f.read()
|
||||
|
||||
# Check that costs increase (impact: 100000, 200000, 300000, etc.)
|
||||
costs = []
|
||||
for i in range(140, 151):
|
||||
project_id = f'p_reckoning_{i}'
|
||||
if project_id in content:
|
||||
# Find cost line
|
||||
lines = content.split('\n')
|
||||
for line in lines:
|
||||
if project_id in line:
|
||||
# Find next few lines for cost
|
||||
idx = lines.index(line)
|
||||
for j in range(idx, min(idx+10, len(lines))):
|
||||
if 'impact:' in lines[j]:
|
||||
# Extract number from "impact: 100000" or "impact: 100000 }"
|
||||
import re
|
||||
match = re.search(r'impact:\s*(\d+)', lines[j])
|
||||
if match:
|
||||
costs.append(int(match.group(1)))
|
||||
break
|
||||
|
||||
# Check costs increase
|
||||
for i in range(1, len(costs)):
|
||||
assert costs[i] > costs[i-1], f"Cost doesn't increase: {costs[i]} <= {costs[i-1]}"
|
||||
|
||||
print(f"✓ ReCKoning costs increase: {costs[:3]}...{costs[-3:]}")
|
||||
|
||||
if __name__ == "__main__":
|
||||
print("Testing ReCKoning project chain...")
|
||||
test_reckoning_projects_exist()
|
||||
test_reckoning_project_structure()
|
||||
test_reckoning_trigger_conditions()
|
||||
test_reckoning_chain_progression()
|
||||
test_reckoning_final_project()
|
||||
test_reckoning_costs_increase()
|
||||
print("\n✓ All tests passed!")
|
||||
Reference in New Issue
Block a user