linkshell.js 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  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_getDescription() {
  23. var desc = "A small opalecent spiral shell.";
  24. if(!this.isOpen) {
  25. desc += " The opening looks to be sealed shut.";
  26. } else {
  27. desc += " It looks like it is full of pearls. You could probably {hint}take{/hint} one out.";
  28. }
  29. return desc;
  30. }
  31. get(room, mobile, input) {
  32. return this.take(room, mobile, input);
  33. }
  34. take(room, mobile, input) {
  35. var command = input.join(" ");
  36. switch(command) {
  37. case "pearl":
  38. return this.mud_takePearl(room, mobile);
  39. break;
  40. }
  41. }
  42. open(room, mobile, input) {
  43. var command = input.join(" ");
  44. switch(command) {
  45. case "linkshell":
  46. case "shell":
  47. if(this.owner == "") {
  48. libs.Output.toMobile(mobile.id, "You press hard against the seal and crack it open.");
  49. libs.Output.toRoom(room.id, mobile.name + " cracks open the linkshell.", mobile);
  50. this.owner = mobile.name;
  51. this.isOpen = true;
  52. this.linkshellId = mobile.name + (new Date().getTime());
  53. } else {
  54. libs.Output.toMobile(mobile.id, "The shell is already open.");
  55. }
  56. return true;
  57. break;
  58. }
  59. }
  60. mud_takePearl(room, mobile) {
  61. if(this.isOpen) {
  62. libs.Output.toMobile(mobile.id, "You pull out a pearl.");
  63. libs.Output.toRoom(room.id, mobile.name + " pulls a pearl out of a linkshell.", mobile);
  64. var pearl = builder.mud_spawnItem("Linkpearl");
  65. pearl.belongsTo = this.linkshellId;
  66. world.mud_addItemToMobile(mobile.id, pearl.id);
  67. return true;
  68. } else {
  69. libs.Output.toMobile(mobile.id, "The shell is sealed, you would have to {hint}open{/hint} it.");
  70. return true;
  71. }
  72. }
  73. mud_saveItem() {
  74. var dataToSave = {};
  75. dataToSave.isOpen = this.isOpen;
  76. dataToSave.owner = this.owner;
  77. dataToSave.linkshellId = this.linkshellId;
  78. return dataToSave;
  79. }
  80. mud_loadItem(itemData) {
  81. for(var dataIndex in itemData) {
  82. if(this.hasOwnProperty(dataIndex)) {
  83. this[dataIndex] = itemData[dataIndex];
  84. }
  85. }
  86. }
  87. }