book.js 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. module.exports = class Book {
  2. constructor() {
  3. this.id = 0;
  4. this.name = "a leather-bound book";
  5. this.defaultName = "a leather-bound book";
  6. this.description = "A beautiful old book bound in aged brown leather.";
  7. this.defaultDescription = "A beautiful old book bound in aged brown leather.";
  8. this.type = "item";
  9. this.keywords = ["book"];
  10. this.resetDelay = 12000000;
  11. this.mud_reset(0);
  12. this.filename = "book.js";
  13. this.heldBy = 0;
  14. }
  15. mud_reset(time) {
  16. this.itemExpires = time + this.resetDelay;
  17. }
  18. mud_tick(time) {
  19. if(time >= this.itemExpires) {
  20. this.mud_reset(time);
  21. }
  22. }
  23. read(room, mobile, input) {
  24. if(this.heldBy == mobile.id) {
  25. libs.Output.toMobile(mobile.id, "Flipping briefly through the book, you see the pages are all blank.", mobile);
  26. return true;
  27. } else if(this.heldBy != mobile.id) {
  28. libs.Output.toMobile(mobile.id, "You would have to {hint}hold{/hint} it first.", mobile);
  29. return true;
  30. }
  31. }
  32. drop(room, mobile, input) {
  33. if(this.keywords.indexOf(input.join(" ")) != -1) {
  34. this.heldBy = 0;
  35. this.description = this.defaultDescription;
  36. this.name = this.defaultName;
  37. }
  38. return false;
  39. }
  40. hold(room, mobile, input) {
  41. if(this.keywords.indexOf(input.join(" ")) != -1) {
  42. libs.Output.toMobile(mobile.id, "You hold "+this.name+" in your hand.", mobile);
  43. libs.Output.toRoom(mobile.roomId, mobile.name + " holds " + this.name + ".", mobile);
  44. this.heldBy = mobile.id;
  45. this.description = this.defaultDescription;
  46. this.name = this.defaultName + "(held)";
  47. return true;
  48. }
  49. }
  50. }