class Conversation { constructor() { this.simple = [ { "trigger": ["hello", "hey", "hi"], "response": ["say Hello {source.name}", "say hi {source.name}", "say hello", "say hey", "say hi", "emote waves.", "emote smiles.", "How are you, {source.name}?", "Ahh, nice to see you {source.name}."], "topic": "conversation-greeting" }, { "trigger": ["help", "oh no", "oops"], "response": ["say Are you ok, {source.name}?", "say What's wrong?", "say How can I help?"], "topic": "conversation-assist" }, { "trigger": ["whats your name", "who are you"], "response": ["say I'm {listener.name}", "say {listener.name}", "say Oh! It's {listener.name}!", "say Me?"], "topic": "conversation-identify" }, { "trigger": ["how are you", "you ok"], "response": ["say I'm fine", "say Pretty good", "say peachy", "say ehh", "say I'm good. How are you, {source.name}?"], "topic": "conversation-status" }, { "trigger": ["whats up", "whats wrong"], "response": ["say Not much", "say nothing", "say Everything is great", "say ehh"], "topic": "conversation-status" }, { "trigger": ["bye", "goodbye", "good bye", "see you"], "response": ["say Bye!", "say Goodbye {source.name}", "say It was a pleasure talking to you.", "emote waves."], "topic": "conversation-end" }, { "trigger": ["good luck"], "response": ["say Thanks."], "topic": "conversation-luck" }, { "trigger": ["thanks", "thank you"], "response": ["say You're welcome!", "say No problem.", "say The pleasure was mine."], "topic": "conversation-thanks" }, { "trigger": ["how do you know"], "response": ["say Lucky guess, I guess", "emote shrugs."], "topic": null }, { "trigger": ["do you know", "who i am"], "response": ["say You're kinda famous, {source.name}. I imagine everyone knows you.", "say I mean, you are {source.name}, right?", "say You're {source.name}."], "topic": null }, { "trigger": ["i like you", "youre great", "your great"], "response": ["say Aww.", "say I like you too!", "say That's nice of you to say."], "topic": null }, ]; this.orders = [ { "trigger": ["go east"], "response": ["east"] }, { "trigger": ["go west"], "response": ["west"] }, { "trigger": ["go north"], "response": ["north"] }, { "trigger": ["go south"], "response": ["south"] }, { "trigger": ["go northwest"], "response": ["nw"] }, { "trigger": ["go northeast"], "response": ["ne"] }, { "trigger": ["go southwest"], "response": ["sw"] }, { "trigger": ["go southeast"], "response": ["se"] }, { "trigger": ["go up"], "response": ["up"] }, { "trigger": ["go down"], "response": ["down"] }, { "trigger": ["enter"], "response": ["enter"] }, { "trigger": ["leave"], "response": ["leave"] }, { "trigger": ["inventory"], "response": ["inventory"] }, ]; } basicDecency(source, message, listener) { return this.mobileInstructionRules(source, message, listener, this.simple); } followsOrders(source, message, listener) { return this.mobileInstructionRules(source, message, listener, this.orders); } canWander(mobile) { var responses = this.getRoomExits(mobile); return responses[parseInt(Math.random() * responses.length)]; } getRoomExits(mobile) { var roomId = mobile.roomId; var room = session.rooms[roomId]; return room.roomExits; } mobileInstructionRules(source, message, listener, instructionset) { if(source == null) { return false; } if(message.indexOf("shout") != -1) { return false; } for(var i = 0; i < instructionset.length; i++) { var response = this.triggerResponse( instructionset[i], message ); if(response != null) { var cleanResponse = this.parsedResponse(response.action, source, listener, message); if(typeof listener['mud_addCommand'] == 'function') { var remembers = false; if(typeof listener['mud_checkMemory'] == 'function') { if(response.topic != null) { remembers = listener.mud_checkMemory(response.topic, source.name); } } if (!remembers) { listener.mud_addCommand(listener, cleanResponse); } if(typeof listener['mud_addMemory'] == 'function') { if(response.topic != null) { listener.mud_addMemory(response.topic, source.name); } } return true; } return true; } } return false; } parsedResponse(response, source, listener) { response = response.replace("{source.name}", source.name); response = response.replace("{listener.name}", listener.name); return response; } triggerResponse(instructionset, message) { var triggers = instructionset.trigger; var responses = instructionset.response; if(this.contains(triggers, message)) { var response = { "action": this.random(responses), "topic": instructionset.topic }; return response; } } random(responses) { var index = parseInt(Math.random() * responses.length); return responses[index]; } contains(keys, message) { var cleanMessage = message.replace(/'/g, ""); for(var i = 0; i < keys.length; i++) { var regex = new RegExp("\\b" + keys[i] + "\\b", "i"); if(cleanMessage.search(regex) != -1) { return true; } } return false; } } module.exports = new Conversation();