playermobile.js 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  1. module.exports = class PlayerMobile {
  2. constructor() {
  3. this.id = 0;
  4. this.login = null;
  5. this.name = "";
  6. this.description = "A player.";
  7. this.type = "mobile";
  8. this.roomId = "ZebedeeTemple";
  9. this.filename = "playermobile.js";
  10. this.keywords = [];
  11. this.items = [];
  12. this.health = 100;
  13. this.maxHealth = 100;
  14. this.roles = [];
  15. this.memory = {};
  16. this.title = "the player";
  17. this.account = 0;
  18. this.itemSlots = {};
  19. this.aliases = {};
  20. }
  21. mud_sendMessage(source, message) {
  22. this.login.sendMessage(message);
  23. }
  24. mud_addMemory(section, newMemory) {
  25. if(!this.memory.hasOwnProperty(section)) {
  26. this.memory[section] = [];
  27. }
  28. this.memory[section].push(memory);
  29. }
  30. mud_checkMemory(section, memoryToCheck) {
  31. if(this.memory.hasOwnProperty(section)) {
  32. if(this.memory[section].hasOwnProperty(memory)) {
  33. return true;
  34. }
  35. }
  36. return false;
  37. }
  38. mud_addCurrency(amount) {
  39. this.account += amount;
  40. }
  41. mud_removeCurrency(amount) {
  42. this.account -= amount;
  43. this.account = Math.max(0, this.account);
  44. }
  45. mud_tick(time) {
  46. if(this.health != this.maxHealth) {
  47. this.health++;
  48. this.hp();
  49. }
  50. }
  51. mud_getName() {
  52. return "{mobile}" + this.name + "{/mobile}";
  53. }
  54. mud_getDescription() {
  55. return this.description;
  56. }
  57. mud_wearInSlot(itemId, slot) {
  58. if(this.itemSlots.hasOwnProperty(slot) && this.itemSlots[slot] != null) {
  59. return this.itemSlots[slot];
  60. }
  61. this.itemSlots[slot] = itemId;
  62. }
  63. mud_removeSlot(slot) {
  64. if(!this.itemSlots.hasOwnProperty(slot) || this.itemSlots[slot] == null) {
  65. return false;
  66. }
  67. this.itemSlots[slot] = null;
  68. }
  69. mud_hasEquipped(itemName) {
  70. for(var index in this.itemSlots) {
  71. var slot = this.itemSlots[index];
  72. if(slot != null) {
  73. if(world.mud_getItem(slot).constructor.name == itemName) {
  74. return true;
  75. }
  76. }
  77. }
  78. if(Object.keys(this.itemSlots).length > 0) {
  79. var inventoryItem = libs.Utilities.getSpecific(itemName, Object.values(this.itemSlots), session.items);
  80. if(inventoryItem != null) {
  81. return true;
  82. }
  83. }
  84. return false;
  85. }
  86. mud_setAlias(aliasKey, instructions) {
  87. this.aliases[aliasKey] = instructions;
  88. var commands = instructions.split(";");
  89. this[aliasKey] = function() {
  90. for(var index in commands) {
  91. var command = commands[index];
  92. world.mud_handleInput(this.roomId, this.id, command.split(" "));
  93. }
  94. };
  95. }
  96. hp(room, mobile, input) {
  97. libs.Output.toMobile(mobile.id, "[HP: "+mobile.health+"/" +mobile.maxHealth+"]");
  98. return true;
  99. }
  100. quit(room, mobile, input) {
  101. this.login.logout();
  102. return true;
  103. }
  104. save(room, mobile, input) {
  105. libs.Output.toMobile(mobile.id, "Saving player information.");
  106. world.mud_playerSave(this);
  107. libs.Output.toMobile(mobile.id, "Saved successfully.");
  108. return true;
  109. }
  110. hint(room, mobile, input) {
  111. if(["on", "please"].indexOf(input[0]) != -1) {
  112. mobile.hintColor = "FgMagenta";
  113. libs.Output.toMobile(mobile.id, "Enabling hints.");
  114. return true;
  115. }
  116. if (["off"].indexOf(input[0]) != -1) {
  117. mobile.hintColor = "Reset";
  118. libs.Output.toMobile(mobile.id, "Disabling hints.");
  119. return true;
  120. }
  121. libs.Output.toMobile(mobile.id, "hint [on|off] - controls highlighting in description text.");
  122. return true;
  123. }
  124. setting(room, mobile, input) {
  125. }
  126. chpass(room, mobile, input) {
  127. var username = mobile.name.toLowerCase();
  128. mobile.password = world.mud_generateHash(username + input.join(" "));
  129. world.mud_playerSave(mobile);
  130. libs.Output.toMobile(mobile.id, "Password has been updated!");
  131. return true;
  132. }
  133. };