mine.js 952 B

12345678910111213141516171819202122232425262728293031323334
  1. states.push({
  2. id: "mine",
  3. button: "Mine Asteroid",
  4. action: "Blasting",
  5. duration: 7000,
  6. requires: () => {
  7. let enoughEnergy = userData.energy > 0;
  8. if (!enoughEnergy) { errorMessage = "insufficient energy to mine asteroid"; }
  9. return enoughEnergy;
  10. },
  11. start: () => {
  12. play('mining-asteroid-field');
  13. },
  14. run: () => {
  15. userData.energy--;
  16. addDebrisToSpace();
  17. },
  18. });
  19. function addDebrisToSpace() {
  20. var miningItems = [
  21. { type: "ironore", name: "Iron Ore", probability: 75 },
  22. { type: "silverore", name: "Silver Ore", probability: 10 },
  23. { type: "goldore", name: "Gold Ore", probability: 10 },
  24. { type: "platinumore", name: "Platinum Ore", probability: 4 },
  25. { type: "rawdiamond", name: "Raw Diamond", probability: 1 },
  26. ];
  27. let count = Math.floor(8 * Math.random()) + 3;
  28. for (let i = 0; i < count; i++) {
  29. let item = pickRandomItem(miningItems);
  30. userData.debrisInSpace.push({ id: 1, type: item.type, description: item.name });
  31. }
  32. }