pickaxe.js 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. module.exports = class Pickaxe {
  2. constructor() {
  3. this.id = 0;
  4. this.name = "a pickaxe";
  5. this.description = "An iron pickaxe with a rough wooden handle. The head has spots of rust and the point is a little worn, but it would still work fine for {hint}mining{/hint}.";
  6. this.type = "item";
  7. this.keywords = ["pick", "pickaxe", "tool"];
  8. this.resetDelay = 12000000;
  9. this.mud_reset(0);
  10. this.filename = "pickaxe.js";
  11. this.heldBy = -1;
  12. this.isWorn = -1;
  13. this.inRoom = -1;
  14. this.value = 25;
  15. this.itemSlot = libs.ItemSlot.MainHand;
  16. }
  17. mud_reset(time) {
  18. this.itemExpires = time + this.resetDelay;
  19. }
  20. mud_tick(time) {
  21. if(time >= this.itemExpires) {
  22. this.mud_reset(time);
  23. }
  24. }
  25. mud_getName() {
  26. var dispName = "{item}"+this.name+"{/item}";
  27. if(this.isWorn != -1) {
  28. dispName += " (wielded)";
  29. }
  30. return dispName;
  31. }
  32. mud_getDescription() {
  33. return this.description;
  34. }
  35. mine(room, mobile, input) {
  36. if(this.isWorn == mobile.id) {
  37. if(room.isMiningPoint) {
  38. var itemName = room.mineItems.shift();
  39. if(itemName == null) {
  40. libs.Output.toMobile(mobile.id, "You swing your pickaxe a few times but don't find anything.");
  41. libs.Output.toRoom(mobile.roomId, mobile.mud_getName() + " mines some ore.", mobile);
  42. return true;
  43. }
  44. libs.Output.toMobile(mobile.id, "You swing your pickaxe a few times and break off some ore.");
  45. libs.Output.toRoom(mobile.roomId, mobile.mud_getName() + " mines some ore.", mobile);
  46. var minedItem = builder.mud_spawnItem(itemName);
  47. if(typeof minedItem.mud_getName == "function") {
  48. libs.Output.toMobile(mobile.id, "You receive " + minedItem.mud_getName() + "!");
  49. } else {
  50. libs.Output.toMobile(mobile.id, "You receive {item}" + minedItem.mud_getName() + "{/item}!");
  51. }
  52. world.mud_addItemToMobile(mobile.id, minedItem.id);
  53. return true;
  54. }
  55. libs.Output.toMobile(mobile.id, "You swing your pickaxe and smash a small stone to bits.");
  56. libs.Output.toRoom(mobile.roomId, mobile.mud_getName() + " swings " + this.mud_getName() + " haphazardly.", mobile);
  57. return true;
  58. } else if(this.isWorn != mobile.id) {
  59. libs.Output.toMobile(mobile.id, "You would have to {hint}hold{/hint} a pickaxe first.");
  60. return true;
  61. }
  62. }
  63. }