villager1.js 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. module.exports = class PhandalinVillager1 {
  2. constructor() {
  3. this.id = 1;
  4. this.name = "A villager";
  5. this.description = "She is a human woman wearing a brightly colored coverall with her hair up in a frizzy bun. She is returning from a delivery and looks pretty pleased with herself.";
  6. this.type = "mobile";
  7. this.roomId = 1;
  8. this.idleDelay = 30000;
  9. this.filename = "phandalin/villager1.js";
  10. this.lastIdle = 0;
  11. this.keywords = ["villager", "lady", "woman", "human"];
  12. this.items = [];
  13. this.commandQueue = [];
  14. this.memory = {};
  15. }
  16. mud_init() {
  17. world.mud_addMobileToRoom("PhandalinRoad1", this.id);
  18. }
  19. mud_sendMessage(source, message) {
  20. message = message.replace(/\{.*?\}/g, "");
  21. var cleanMessage = message.trim();
  22. if(source == this) {
  23. return;
  24. }
  25. if(cleanMessage.indexOf("shout") != -1) {
  26. return;
  27. }
  28. if(libs.Conversation.basicDecency(source, cleanMessage, this)) {
  29. return;
  30. }
  31. /*if(libs.Conversation.followsOrders(source, cleanMessage, this)) {
  32. return;
  33. }*/
  34. }
  35. mud_addMemory(section, newMemory) {
  36. if(!this.memory.hasOwnProperty(section)) {
  37. this.memory[section] = [];
  38. }
  39. this.memory[section].push(memory);
  40. }
  41. mud_checkMemory(section, memoryToCheck) {
  42. if(this.memory.hasOwnProperty(section)) {
  43. if(this.memory[section].hasOwnProperty(memory)) {
  44. return true;
  45. }
  46. }
  47. return false;
  48. }
  49. mud_addCommand(source, message) {
  50. this.commandQueue.push(message);
  51. }
  52. mud_tick(time) {
  53. if(time >= this.lastIdle) {
  54. var idleMessages = ["emote wipes some sweat from her brow.",
  55. "emote whistles happily as she walks.",
  56. "emote brushes a strand of hair from her face and frowns.",
  57. "emote stops for a minute and retightens her hair bun."
  58. ];
  59. var randomIdle = idleMessages[parseInt(Math.random() * idleMessages.length)];
  60. this.mud_addCommand(this, randomIdle);
  61. this.lastIdle = time + this.idleDelay;
  62. }
  63. if(this.commandQueue.length > 0 ) {
  64. world.mud_handleInput(this.roomId, this.id, this.commandQueue.shift().split(" "));
  65. this.lastIdle = time + this.idleDelay;
  66. }
  67. }
  68. };