refine.js 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. states.push({
  2. id: "refine",
  3. button: "Refine Materials",
  4. action: "Smelting",
  5. duration: () => selectedItems.length * 500,
  6. step: () => selectedItems.length,
  7. requires: () => {
  8. let selectCount = selectedItems.length;
  9. let enoughEnergy = selectCount <= userData.energy;
  10. if (!enoughEnergy) { errorMessage = "insufficient energy to refine all selected ore"; }
  11. if(selectedItems.length == 0) {
  12. receiveMessage({name:"[Refinery]", id:-1, style: ""}, "Ther's nathin I can smelt!");
  13. }
  14. return enoughEnergy && selectedItems.length > 0;
  15. },
  16. start: () => {},
  17. run: () => {
  18. selectedItems.forEach(item => {
  19. let index = userData.inCargoHold.indexOf(item);
  20. if(index > -1) {
  21. userData.inCargoHold.splice(index, 1, refineItem(item));
  22. }
  23. });
  24. selectedItems = [];
  25. },
  26. });
  27. var refineMap = [
  28. { input: "ironore", output: "iron", outputName: "Iron Bar", cost: 1, duration: 500 },
  29. { input: "silverore", output: "silver", outputName: "Silver Bar", cost: 1, duration: 500 },
  30. { input: "goldore", output: "gold", outputName: "Gold Bar", cost: 1, duration: 500 },
  31. { input: "platinumore", output: "platinum", outputName: "Platinum Bar", cost: 2, duration: 500 },
  32. { input: "rawdiamond", output: "diamond", outputName: "Diamond", cost: 5, duration: 500 },
  33. ];
  34. function refineItem(item) {
  35. let refineRule = refineMap.find(refine => refine.input == item.type);
  36. if (!refineRule) {
  37. return item;
  38. }
  39. userData.energy -= refineRule.cost;
  40. return { id: item.id, type: refineRule.output, description: refineRule.outputName };
  41. }