midasbot.js 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. module.exports = class MidasBot {
  2. constructor() {
  3. this.id = 1;
  4. this.name = "Midas";
  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"];
  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_tick(time) {
  50. if(time >= this.lastIdle) {
  51. var idleMessages = [
  52. "emote wonders about a programming problem.",
  53. ""
  54. ];
  55. var randomIdle = idleMessages[parseInt(Math.random() * idleMessages.length)];
  56. this.mud_addCommand(this, randomIdle);
  57. this.lastIdle = time + this.idleDelay;
  58. }
  59. if(this.waitTime > 0) {
  60. this.waitTime--;
  61. }
  62. if(this.commandQueue.length > 0 && this.waitTime <= 0) {
  63. world.mud_handleInput(this.roomId, this.id, this.commandQueue.shift().split(" "));
  64. this.lastIdle = time + this.idleDelay;
  65. this.waitTime = 0;
  66. }
  67. }
  68. wait(room, mobile, input) {
  69. this.waitTime = parseInt(input.join(" "));
  70. return true;
  71. }
  72. follow(room, mobile, input) {
  73. this.followTarget = input.join(" ");
  74. }
  75. mud_enterRoom(direction) {
  76. if(direction != null) {
  77. return this.name + " " + direction + ".";
  78. }
  79. return this.name + " enters the room.";
  80. }
  81. mud_leaveRoom(direction) {
  82. if(direction != null) {
  83. return this.name + " " + direction + ".";
  84. }
  85. return this.name + " leaves.";
  86. }
  87. };