woodensword.js 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. module.exports = class WoodenSword {
  2. constructor() {
  3. this.id = 0;
  4. this.name = "a wooden sword";
  5. this.description = "This training sword has seen a lot of action and is a little splintered on the edges. It would serve pretty well as a weapon if you were to {hint}hold{/hint} it.";
  6. this.type = "item";
  7. this.keywords = ["sword"];
  8. this.resetDelay = 12000000;
  9. this.itemExpires = 0;
  10. this.filename = "woodensword.js";
  11. this.heldBy = -1;
  12. this.isWorn = -1;
  13. this.inRoom = -1;
  14. this.value = 75;
  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. attack(room, mobile, input) {
  36. if(this.isWorn == mobile.id) {
  37. if(!room.isCombatZone) {
  38. libs.Output.toMobile(mobile.id, "You lose your grip on " + this.mud_getName() + ".");
  39. var slotKey = Object.keys(mobile.itemSlots).find(key => mobile.itemSlots[key] === this.id);
  40. mobile.itemSlots[slotKey] = null;
  41. this.isWorn = -1;
  42. return true;
  43. }
  44. libs.Output.toMobile(mobile.id, "You swing your sword gracefully with large swooping motions.");
  45. libs.Output.toRoom(mobile.roomId, mobile.mud_getName() + " swings " + this.mud_getName() + " wildly, almost losing balance.", mobile);
  46. return true;
  47. } else if(this.isWorn != mobile.id) {
  48. libs.Output.toMobile(mobile.id, "You would have to {hint}wield{/hint} a weapon first.");
  49. return true;
  50. }
  51. }
  52. }