harvest.js 1.1 KB

1234567891011121314151617181920212223242526272829303132
  1. states.push({
  2. id: "harvest",
  3. button: "Gather Debris",
  4. action: "Harvesting",
  5. duration: () => selectedItems.length * 500,
  6. step: () => selectedItems.length,
  7. requires: () => {
  8. let selectCount = selectedItems.length;
  9. let enoughEnergy = userData.energy >= selectCount;
  10. let enoughSpace = selectCount <= userData.maxCargoCapacity && (userData.maxCargoCapacity - userData.inCargoHold.length >= selectCount);
  11. if (!enoughEnergy) { errorMessage = "insufficient energy to gather all selected debris"; }
  12. if (!enoughSpace) { errorMessage = "insufficient cargo space to store all selected debris"; }
  13. if(selectedItems.length == 0) {
  14. receiveMessage({name:"[Ship]", id:-1, style: ""}, "No valid targets to gather. Please select debris.")
  15. }
  16. return enoughEnergy && enoughSpace;
  17. },
  18. start: () => {
  19. play('harvesting-debris');
  20. },
  21. run: () => {
  22. selectedItems.forEach(item => {
  23. let index = userData.debrisInSpace.indexOf(item);
  24. if(index > -1) {
  25. userData.debrisInSpace.splice(index, 1);
  26. userData.inCargoHold.push(item);
  27. userData.energy--;
  28. }
  29. });
  30. selectedItems = [];
  31. },
  32. });