1234567891011121314151617181920212223242526272829303132 |
- states.push({
- id: "harvest",
- button: "Gather Debris",
- action: "Harvesting",
- duration: () => selectedItems.length * 500,
- step: () => selectedItems.length,
- requires: () => {
- let selectCount = selectedItems.length;
- let enoughEnergy = userData.energy >= selectCount;
- let enoughSpace = selectCount <= userData.maxCargoCapacity && (userData.maxCargoCapacity - userData.inCargoHold.length >= selectCount);
- if (!enoughEnergy) { errorMessage = "insufficient energy to gather all selected debris"; }
- if (!enoughSpace) { errorMessage = "insufficient cargo space to store all selected debris"; }
- if(selectedItems.length == 0) {
- receiveMessage({name:"[Ship]", id:-1, style: ""}, "No valid targets to gather. Please select debris.")
- }
- return enoughEnergy && enoughSpace;
- },
- start: () => {
- play('harvesting-debris');
- },
- run: () => {
- selectedItems.forEach(item => {
- let index = userData.debrisInSpace.indexOf(item);
- if(index > -1) {
- userData.debrisInSpace.splice(index, 1);
- userData.inCargoHold.push(item);
- userData.energy--;
- }
- });
- selectedItems = [];
- },
- });
|