states.push({ id: "mine", button: "Mine Asteroid", action: "Blasting", duration: 7000, requires: () => { let enoughEnergy = userData.energy > 0; if (!enoughEnergy) { errorMessage = "insufficient energy to mine asteroid"; } return enoughEnergy; }, start: () => { play('mining-asteroid-field'); }, run: () => { userData.energy--; addDebrisToSpace(); }, }); function addDebrisToSpace() { var miningItems = [ { type: "ironore", name: "Iron Ore", probability: 75 }, { type: "silverore", name: "Silver Ore", probability: 10 }, { type: "goldore", name: "Gold Ore", probability: 10 }, { type: "platinumore", name: "Platinum Ore", probability: 4 }, { type: "rawdiamond", name: "Raw Diamond", probability: 1 }, ]; let count = Math.floor(8 * Math.random()) + 3; for (let i = 0; i < count; i++) { let item = pickRandomItem(miningItems); userData.debrisInSpace.push({ id: 1, type: item.type, description: item.name }); } }