From 0ded5cae05778e20e885437a0d1cef0e8d8178ea Mon Sep 17 00:00:00 2001 From: "Z. Cliffe Schreuders" Date: Tue, 28 Oct 2025 14:26:52 +0000 Subject: [PATCH] refactor: Simplify key generation by using generic names for keys in KeySelection --- js/core/game.js | 3 --- js/minigames/lockpicking/key-selection.js | 26 +++++++++++--------- locksmith-forge.html | 30 +---------------------- 3 files changed, 16 insertions(+), 43 deletions(-) diff --git a/js/core/game.js b/js/core/game.js index 352efff..649d0fd 100644 --- a/js/core/game.js +++ b/js/core/game.js @@ -674,9 +674,6 @@ function findObjectsAtPosition(worldX, worldY) { // Normalize keyPins from 0-100 scale to 25-65 scale in entire scenario function normalizeScenarioKeyPins(scenario) { - if (!scenario || !scenario.rooms) { - return; - } // Helper function to convert a single keyPins value function convertKeyPin(value) { diff --git a/js/minigames/lockpicking/key-selection.js b/js/minigames/lockpicking/key-selection.js index 89890e4..5505f46 100644 --- a/js/minigames/lockpicking/key-selection.js +++ b/js/minigames/lockpicking/key-selection.js @@ -65,14 +65,18 @@ export class KeySelection { if (validKeys.length === 0) { // No valid keys in inventory, generate random ones - const key1 = this.parent.generateRandomKey(this.parent.pinCount); - const key2 = this.parent.generateRandomKey(this.parent.pinCount); - const key3 = this.parent.generateRandomKey(this.parent.pinCount); + const key1 = this.generateRandomKey(this.parent.pinCount); + const key2 = this.generateRandomKey(this.parent.pinCount); + const key3 = this.generateRandomKey(this.parent.pinCount); // Make the first key correct key1.cuts = this.parent.keyData.cuts; key1.id = correctKeyId || 'correct_key'; - key1.name = 'Correct Key'; + key1.name = `Key ${Math.floor(Math.random() * 10000)}`; + + // Give other keys generic names too + key2.name = `Key ${Math.floor(Math.random() * 10000)}`; + key3.name = `Key ${Math.floor(Math.random() * 10000)}`; // Randomize the order const keys = [key1, key2, key3]; @@ -92,18 +96,18 @@ export class KeySelection { // Create keys for challenge mode (like locksmith-forge.html) // Generates 3 keys with one guaranteed correct key - const key1 = this.parent.generateRandomKey(this.parent.pinCount); - const key2 = this.parent.generateRandomKey(this.parent.pinCount); - const key3 = this.parent.generateRandomKey(this.parent.pinCount); + const key1 = this.generateRandomKey(this.parent.pinCount); + const key2 = this.generateRandomKey(this.parent.pinCount); + const key3 = this.generateRandomKey(this.parent.pinCount); // Make the first key correct by copying the actual key cuts key1.cuts = this.parent.keyData.cuts; key1.id = correctKeyId; - key1.name = 'Correct Key'; + key1.name = `Key ${Math.floor(Math.random() * 10000)}`; - // Give other keys descriptive names - key2.name = 'Wrong Key 1'; - key3.name = 'Wrong Key 2'; + // Give other keys generic names too + key2.name = `Key ${Math.floor(Math.random() * 10000)}`; + key3.name = `Key ${Math.floor(Math.random() * 10000)}`; // Randomize the order of keys const keys = [key1, key2, key3]; diff --git a/locksmith-forge.html b/locksmith-forge.html index d537319..2b6e445 100644 --- a/locksmith-forge.html +++ b/locksmith-forge.html @@ -608,35 +608,7 @@ // If this is a key mode level, automatically show key selection if (config.keyMode) { setTimeout(() => { - // Override the createKeysForChallenge method to use generic names - const originalCreateKeysForChallenge = this.currentGame.createKeysForChallenge.bind(this.currentGame); - this.currentGame.createKeysForChallenge = (correctKeyId = 'challenge_key') => { - // Create keys for challenge mode (like locksmith-forge.html) - // Generates 3 keys with one guaranteed correct key - - const key1 = this.currentGame.generateRandomKey(this.currentGame.pinCount); - const key2 = this.currentGame.generateRandomKey(this.currentGame.pinCount); - const key3 = this.currentGame.generateRandomKey(this.currentGame.pinCount); - - // Make the first key correct by copying the actual key cuts - key1.cuts = this.currentGame.keyData.cuts; - key1.id = correctKeyId; - key1.name = `Key ${Math.floor(Math.random() * 1000)}`; // Generic name - - // Give other keys generic names too - key2.name = `Key ${Math.floor(Math.random() * 1000)}`; - key3.name = `Key ${Math.floor(Math.random() * 1000)}`; - - // Randomize the order of keys - const keys = [key1, key2, key3]; - this.currentGame.shuffleArray(keys); - - // Find the new index of the correct key after shuffling - const correctKeyIndex = keys.findIndex(key => key.id === correctKeyId); - - return this.currentGame.createKeySelectionUI(keys, correctKeyId); - }; - + // Start key selection challenge this.currentGame.startWithKeySelection(); }, 500); // Small delay to ensure game is fully initialized }