midasbot.js 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. module.exports = class MidasBot {
  2. constructor() {
  3. this.id = 1;
  4. this.name = "MidasBot";
  5. this.description = "The immortal Midas.";
  6. this.type = "mobile";
  7. this.roomId = "Void1";
  8. this.idleDelay = 30000;
  9. this.filename = "midasbot.js";
  10. this.lastIdle = 0;
  11. this.keywords = ["midas", "midasbot"];
  12. this.items = [];
  13. this.commandQueue = [];
  14. this.waitTime = 0;
  15. this.query = "";
  16. }
  17. mud_sendMessage(source, message) {
  18. var cleanMessage = message.trim();
  19. if(source != this && source != null) {
  20. if(libs.Conversation.basicDecency(source, cleanMessage, this)) {
  21. return;
  22. }
  23. if(cleanMessage.indexOf("yes") != -1) {
  24. if(this.query == "follow") {
  25. this.addCommand(this, "say Yea, ok.");
  26. this.addCommand(this, "follow " + source.name);
  27. }
  28. this.query = "";
  29. return;
  30. }
  31. if(cleanMessage.indexOf("no") != -1) {
  32. //this.addCommand(this, "say You want me to follow you?");
  33. this.query = "";
  34. return;
  35. }
  36. if(cleanMessage.indexOf("follow") != -1) {
  37. this.addCommand(this, "say You want me to follow you?");
  38. this.query = "follow";
  39. return;
  40. }
  41. }
  42. /*if(libs.conversation.followsOrders(source, cleanMessage, this)) {
  43. return;
  44. }*/
  45. }
  46. mud_addCommand(source, message) {
  47. this.commandQueue.push(message);
  48. }
  49. mud_reset(time) {
  50. var idleMessages = [
  51. "emote wonders about a programming problem.",
  52. ""
  53. ];
  54. var randomIdle = idleMessages[parseInt(Math.random() * idleMessages.length)];
  55. this.mud_addCommand(this, randomIdle);
  56. this.lastIdle = time + this.idleDelay;
  57. }
  58. mud_tick(time) {
  59. if(time >= this.lastIdle) {
  60. this.mud_reset(time);
  61. }
  62. if(this.waitTime > 0) {
  63. this.waitTime--;
  64. }
  65. if(this.commandQueue.length > 0 && this.waitTime <= 0) {
  66. world.mud_handleInput(this.roomId, this.id, this.commandQueue.shift().split(" "));
  67. this.lastIdle = time + this.idleDelay;
  68. this.waitTime = 0;
  69. }
  70. }
  71. mud_addMemory(section, newMemory) {
  72. if(!this.memory.hasOwnProperty(section)) {
  73. this.memory[section] = [];
  74. }
  75. if(!this.mud_checkMemory(section, newMemory)) {
  76. this.memory[section].push(newMemory);
  77. }
  78. }
  79. mud_checkMemory(section, memoryToCheck) {
  80. if(this.memory.hasOwnProperty(section)) {
  81. if(this.memory[section].indexOf(memoryToCheck) != -1) {
  82. return true;
  83. }
  84. }
  85. return false;
  86. }
  87. mud_getName() {
  88. return "{mobile}" + this.name + "{/mobile}";
  89. }
  90. mud_getDescription() {
  91. return this.description;
  92. }
  93. wait(room, mobile, input) {
  94. this.waitTime = parseInt(input.join(" "));
  95. return true;
  96. }
  97. follow(room, mobile, input) {
  98. this.followTarget = input.join(" ");
  99. }
  100. };