From 0823ee5a752654d271672f6e519016991dfb6303 Mon Sep 17 00:00:00 2001 From: Big Bad Waffle Date: Mon, 27 Feb 2017 18:52:58 +0200 Subject: [PATCH] Fixes #101 --- src/client/ui/templates/talk/talk.js | 5 ++ src/server/components/dialogue.js | 34 +++++++++++++- src/server/config/maps/tutorial/dialogues.js | 48 +++++++++++++++++++- 3 files changed, 84 insertions(+), 3 deletions(-) diff --git a/src/client/ui/templates/talk/talk.js b/src/client/ui/templates/talk/talk.js index 596c9994..21e606ee 100644 --- a/src/client/ui/templates/talk/talk.js +++ b/src/client/ui/templates/talk/talk.js @@ -18,6 +18,11 @@ define([ postRender: function() { this.onEvent('onGetTalk', this.onGetTalk.bind(this)); + this.onEvent('onRezone', this.onRezone.bind(this)); + }, + + onRezone: function() { + this.hide(); }, onGetTalk: function(dialogue) { diff --git a/src/server/components/dialogue.js b/src/server/components/dialogue.js index 403760eb..991e3a94 100644 --- a/src/server/components/dialogue.js +++ b/src/server/components/dialogue.js @@ -95,8 +95,18 @@ define([ if (stateConfig.cpn) { var cpn = sourceObj[stateConfig.cpn]; - cpn[stateConfig.method].apply(cpn, stateConfig.args); - return; + var newArgs = extend(true, [], stateConfig.args); + newArgs.push(this.obj); + var result = cpn[stateConfig.method].apply(cpn, newArgs); + + if (stateConfig.goto) { + if (result) + return this.getState(sourceObj, stateConfig.goto.success); + else + return this.getState(sourceObj, stateConfig.goto.failure); + } + else + return null; } var result = { @@ -158,6 +168,26 @@ define([ return { type: 'dialogue' }; + }, + + //These don't belong here, but I can't figure out where to put them right now + //They are actions that can be performed while chatting with someone + teleport: function(msg) { + this.obj.syncer.set(true, 'dialogue', 'state', null); + + var portal = extend(true, {}, require('./components/portal'), msg); + portal.collisionEnter(this.obj); + }, + + getItem: function(msg, source) { + var inventory = this.obj.inventory; + var exists = inventory.items.find(i => (i.name == msg.item.name)); + if (!exists) { + inventory.getItem(msg.item); + return true; + } + else + return false; } }; }); \ No newline at end of file diff --git a/src/server/config/maps/tutorial/dialogues.js b/src/server/config/maps/tutorial/dialogues.js index 540fc427..1dccd7dd 100644 --- a/src/server/config/maps/tutorial/dialogues.js +++ b/src/server/config/maps/tutorial/dialogues.js @@ -3,7 +3,7 @@ module.exports = { '1': { msg: [{ msg: `What? Oh...what are you doing here?`, - options: [1.1, 1.2, 1.3, 1.4, 1.5] + options: [1.1, 1.2, 1.3, 1.4, 1.5, 1.6, 1.7] }], options: { '1.1': { @@ -25,6 +25,14 @@ module.exports = { '1.5': { msg: `I changed my mind, I want to buy something back.`, goto: 'tradeBuyback' + }, + '1.6': { + msg: `Send me to the big city.`, + goto: 'portalCity' + }, + '1.7': { + msg: `Gimme`, + goto: 'getItem' } } }, @@ -85,6 +93,18 @@ module.exports = { } } }, + '4': { + msg: `There you go!`, + options: { + + } + }, + '5': { + msg: `You already have that!`, + options: { + + } + }, tradeBuy: { cpn: 'trade', method: 'startBuy', @@ -105,6 +125,32 @@ module.exports = { args: [{ targetName: 'hermit' }] + }, + portalCity: { + cpn: 'dialogue', + method: 'teleport', + args: [{ + toZone: 'city', + toPos: { + x: 136, + y: 216 + } + }] + }, + getItem: { + cpn: 'dialogue', + method: 'getItem', + args: [{ + item: { + name: 'fancy feather', + quest: true, + sprite: [0, 0] + } + }], + goto: { + success: 4, + failure: 5 + } } } }; \ No newline at end of file