linkshell.js 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. module.exports = class Linkshell {
  2. constructor() {
  3. this.id = 0;
  4. this.name = "a small shell";
  5. this.type = "item";
  6. this.keywords = ["shell", "linkshell"];
  7. this.resetDelay = 12000000;
  8. this.filename = "linkshell.js";
  9. this.isOpen = false;
  10. this.owner = "";
  11. this.linkshellId = 0;
  12. this.itemExpires = 0;
  13. }
  14. mud_reset(time) {
  15. this.itemExpires = time + this.resetDelay;
  16. }
  17. mud_tick(time) {
  18. if(time >= this.itemExpires) {
  19. this.mud_reset(time);
  20. }
  21. }
  22. mud_getName() {
  23. return "{item}" + this.name + "{/item}";
  24. }
  25. mud_getDescription() {
  26. var desc = "A small opalecent spiral shell.";
  27. if(!this.isOpen) {
  28. desc += " The opening looks to be sealed shut.";
  29. } else {
  30. desc += " It looks like it is full of pearls. You could probably {hint}take{/hint} one out.";
  31. }
  32. return desc;
  33. }
  34. get(room, mobile, input) {
  35. return this.take(room, mobile, input);
  36. }
  37. take(room, mobile, input) {
  38. var command = input.join(" ");
  39. switch(command) {
  40. case "pearl":
  41. return this.mud_takePearl(room, mobile);
  42. break;
  43. }
  44. }
  45. open(room, mobile, input) {
  46. var command = input.join(" ");
  47. switch(command) {
  48. case "linkshell":
  49. case "shell":
  50. if(this.owner == "") {
  51. libs.Output.toMobile(mobile.id, "You press hard against the seal and crack it open.");
  52. libs.Output.toRoom(room.id, mobile.name + " cracks open the linkshell.", mobile);
  53. this.owner = mobile.name;
  54. this.isOpen = true;
  55. this.linkshellId = mobile.name + (new Date().getTime());
  56. } else {
  57. libs.Output.toMobile(mobile.id, "The shell is already open.");
  58. }
  59. return true;
  60. break;
  61. }
  62. }
  63. mud_takePearl(room, mobile) {
  64. if(this.isOpen) {
  65. libs.Output.toMobile(mobile.id, "You pull out a pearl.");
  66. libs.Output.toRoom(room.id, mobile.name + " pulls a pearl out of a linkshell.", mobile);
  67. var pearl = builder.mud_spawnItem("Linkpearl");
  68. pearl.belongsTo = this.linkshellId;
  69. world.mud_addItemToMobile(mobile.id, pearl.id);
  70. return true;
  71. } else {
  72. libs.Output.toMobile(mobile.id, "The shell is sealed, you would have to {hint}open{/hint} it.");
  73. return true;
  74. }
  75. }
  76. mud_saveItem() {
  77. var dataToSave = {};
  78. dataToSave.isOpen = this.isOpen;
  79. dataToSave.owner = this.owner;
  80. dataToSave.linkshellId = this.linkshellId;
  81. return dataToSave;
  82. }
  83. mud_loadItem(itemData) {
  84. for(var dataIndex in itemData) {
  85. if(this.hasOwnProperty(dataIndex)) {
  86. this[dataIndex] = itemData[dataIndex];
  87. }
  88. }
  89. }
  90. }