friendlymobile.js 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. module.exports = class FriendlyMobile {
  2. constructor() {
  3. this.id = 1;
  4. this.name = "A friendly mobile";
  5. this.description = "An exceedingly average, incredibly friendly mobile. Why not say hi?";
  6. this.type = "mobile";
  7. this.roomId = 1;
  8. this.idleDelay = 30000;
  9. this.filename = "friendlymobile.js";
  10. this.lastIdle = 0;
  11. this.keywords = ["mobile", "friendly mobile"];
  12. this.items = [];
  13. this.commandQueue = [];
  14. this.memory = {};
  15. }
  16. mud_init() {
  17. world.mud_addMobileToRoom("PhandalinTownGreen", this.id);
  18. }
  19. mud_sendMessage(source, message) {
  20. message = message.replace(/\{.*?\}/g, "");
  21. var cleanMessage = message.trim();
  22. console.log(this.name + " sees '" + cleanMessage + "'");
  23. if(source == this) {
  24. return;
  25. }
  26. if(cleanMessage.indexOf("shout") != -1) {
  27. return;
  28. }
  29. if(libs.Conversation.basicDecency(source, cleanMessage, this)) {
  30. return;
  31. }
  32. if(cleanMessage.indexOf("banana") != -1) {
  33. this.mud_addCommand(this, "say I'm sorry, I don't have any bananas.");
  34. return;
  35. }
  36. if(libs.Conversation.followsOrders(source, cleanMessage, this)) {
  37. return;
  38. }
  39. }
  40. mud_addMemory(section, newMemory) {
  41. if(!this.memory.hasOwnProperty(section)) {
  42. this.memory[section] = [];
  43. }
  44. this.memory[section].push(memory);
  45. }
  46. mud_checkMemory(section, memoryToCheck) {
  47. if(this.memory.hasOwnProperty(section)) {
  48. if(this.memory[section].hasOwnProperty(memory)) {
  49. return true;
  50. }
  51. }
  52. return false;
  53. }
  54. mud_addCommand(source, message) {
  55. this.commandQueue.push(message);
  56. }
  57. mud_tick(time) {
  58. if(time >= this.lastIdle) {
  59. var idleMessages = ["emote grins at nothing in particular.",
  60. "emote looks around, beaming at everyone.",
  61. "emote smiles.",
  62. "emote looks at you and nods knowingly."];
  63. var randomIdle = idleMessages[parseInt(Math.random() * idleMessages.length)];
  64. this.mud_addCommand(this, randomIdle);
  65. this.lastIdle = time + this.idleDelay;
  66. }
  67. if(this.commandQueue.length > 0 ) {
  68. world.mud_handleInput(this.roomId, this.id, this.commandQueue.shift().split(" "));
  69. this.lastIdle = time + this.idleDelay;
  70. }
  71. }
  72. mud_enterRoom(direction) {
  73. if(direction != null) {
  74. return this.name + " " + direction + ".";
  75. }
  76. return this.name + " enters the room.";
  77. }
  78. mud_leaveRoom(direction) {
  79. if(direction != null) {
  80. return this.name + " " + direction + ".";
  81. }
  82. return this.name + " leaves.";
  83. }
  84. };