diff --git a/registration-system/view/signups/game1/js/environment.js b/registration-system/view/signups/game1/js/environment.js index 6f9b69d22b290789e04ed9bc53c4491ad951ab2d..95dd2245e25a7029e29e9a9d8da2d334ccfecca3 100644 --- a/registration-system/view/signups/game1/js/environment.js +++ b/registration-system/view/signups/game1/js/environment.js @@ -17,6 +17,7 @@ Environment.progress = { // ----------------------------- // INVENTORY inventory_money: false, + inventory_ruestung: false, inventory_goatDroppings: false }; diff --git a/registration-system/view/signups/game1/js/events.js b/registration-system/view/signups/game1/js/events.js index f19b4d916e1688b8fc032f24cbbd3fe1bec657b3..d62e074f7913ff691917a173e8a16709956a8a41 100644 --- a/registration-system/view/signups/game1/js/events.js +++ b/registration-system/view/signups/game1/js/events.js @@ -84,6 +84,7 @@ EventHandler.prototype.triggerEventOn = function (trigger, x, y) { * @param event */ EventHandler.prototype.handleEvent = function (event, context) { + var eventWasActive = true; switch (event.type) { case 'achievement': Game.achievements.triggerAchievement(event.id, context); @@ -92,118 +93,34 @@ EventHandler.prototype.handleEvent = function (event, context) { Game.instance.nextMap(event.destination, event.target); break; case 'special': - EventHandler.handleAction(event); + eventWasActive = EventHandler.handleAction(event); break; } - if (event.stopsWalk) { + if (event.stopsWalk && eventWasActive) { Game.char.stopMovement(); } }; EventHandler.handleAction = function (event) { - if (event.action && event.action in EventHandler.actions) { + var isPossible = Story.actions[event.action].possible(); + // check, whether action exists and is allowed at this point + if (event.action && event.action in Story.actions && isPossible) { + // in case the action requires to walk to a location first if (event.walkTo) { var spawn = Game.char.svg.select('#' + event.walkTo); if (spawn[0][0]) { var bbox = spawn[0][0].getBBox(); var xy = Vec.add(getTranslation(spawn[0][0], Game.char.svg[0][0]), [bbox.x, bbox.y]); - Game.char.setMoveTarget(xy[0], xy[1], EventHandler.actions[event.action]); - } - } else { - EventHandler.actions[event.action](); - } - } -}; -EventHandler.actions = { - 'fs_open_board': function () { - console.log('fuck yeah!'); - Game.log('Kontaktdaten verloren.'); - Game.log('Lieber schnell wieder raus hier!'); - // TODO implement board fill - }, - 'fs_screamingGeorge': function () {dialogueHelper([ - { - bubble: '#george_speech', - message: 'EY! MELD\' DICH MAL ZUR FACHSCHAFTSFAHRT AN!!' - },{ - bubble: '#george_speech', - message: 'SCHREIB\' DICH AN DER TAFEL DAZU EIN!!!' - } - ], function () { - Game.log('Geh\' zur Tafel.'); - Environment.progress.fs_firstApproach = true; - }); - Environment.progress.fs_georgeScreamed = true; - }, - 'fs_firstApproach': function () { - dialogueHelper([ - { - bubble: '#tim_speech', - message: 'Willkommen in der Fachschaft!' - }, { - bubble: '#manu_speech', - message: 'Yoh, geh\' mal rüber zu George.' - } - ], function () { - Game.log('Finde George.'); - Environment.progress.fs_firstApproach = true; - }); - }, - 'fs_exit_hint': function () { - dialogueHelper([ - { - bubble: '#tim_speech', - message: 'Du bist hier noch nicht fertig. Vorher kommst du nicht raus!' + // walk to the action point, start action on callback + Game.char.setMoveTarget(xy[0], xy[1], Story.actions[event.action].action); } - ]); - } -}; - -function dialogueHelper(dialogue, done) { - - var speed = { - talk: UrlComponents.isSet('fastTalk') ? 1 : 40, - pause: UrlComponents.isSet('fastTalk') ? 50 : 1000 - }; - - Game.actionsBlocked = true; - var dialogueBox = $('#gameDialogue'); - dialogueBox.html(''); - dialogueBox.show(); - - var dialogue_i = 0; - dialogueStepper(); - - function dialogueStepper() { - if (dialogue_i >= dialogue.length) { - dialogueBox.hide(); - Game.actionsBlocked = false; - if (typeof done === 'function') done(); - } else { - var part = dialogue[dialogue_i]; - dialogue_i++; - // TODO: antwort selektion implementieren - plotMessage(part.bubble, part.message, dialogueStepper); + } + // otherwise start action directly + else { + Story.actions[event.action].action(); } } - - function plotMessage(bubble, message, plotDone) { - var i = 0; - var messageStepper = setInterval(function () { - i++; - if (i > message.length) { - clearInterval(messageStepper); - Game.char.svg.select(bubble).style('display', 'block'); - setTimeout(function() { - Game.char.svg.select(bubble).style('display', 'none'); - plotDone(); - }, speed.pause) - } else { - Game.char.svg.select(bubble).style('display', (i % 2) ? 'none' : 'block'); - dialogueBox.text(message.substring(0, i)); - } - }, speed.talk); - } -} \ No newline at end of file + return isPossible; +}; \ No newline at end of file diff --git a/registration-system/view/signups/game1/js/game.js b/registration-system/view/signups/game1/js/game.js index b7429d84b69a2d82b5343599c5f1af56da6835c6..3730d4be7a0c3d079651594bd56dfab37b848b06 100644 --- a/registration-system/view/signups/game1/js/game.js +++ b/registration-system/view/signups/game1/js/game.js @@ -110,6 +110,7 @@ Game.prototype.loadMap = function (map, spawn) { mousePointer.attr('cy', xy.y); var colour = Game.char.pathFinder.canWalkOn(xy.x, xy.y) ? 'green' : 'red'; if (Game.eventHandler.hasEventOn('click', xy.x, xy.y)) colour = 'blue'; + if (Game.actionsBlocked) colour = 'red'; mousePointer.style("fill", colour); }); diff --git a/registration-system/view/signups/game1/js/story.js b/registration-system/view/signups/game1/js/story.js new file mode 100644 index 0000000000000000000000000000000000000000..e7a9613668b5a75c4bda5a59c5b6e8e03375be9f --- /dev/null +++ b/registration-system/view/signups/game1/js/story.js @@ -0,0 +1,201 @@ +function Story() { + +} + +Story.actions = { + + // ================================================================================================================= + // Actions in the Fachschaft room + + 'fs_firstApproach': { + state: { + welcome_message: false, // welcome message spoken + failed: false, // was approached before, but had no money + successful: false // all done with this action (equivalent to Environment.progress.fs_firstApproach) + }, + possible: function () { + return (!Story.actions.fs_firstApproach.state.successful && !Story.actions.fs_firstApproach.state.failed) || + (!Environment.progress.fs_firstApproach && Environment.progress.inventory_money); + }, + action: function () { + var state = Story.actions.fs_firstApproach.state; + + Story.dialogueHelper([{ + bubble: '#tim_speech', + message: 'Willkommen in der Fachschaft!', + condition: !state.welcome_message + }, { + bubble: '#tim_speech', + message: state.failed ? + 'Wie ich sehe, hast du etwas gefunden? Noch Lust auf die Rüstung?' : + 'Du bist ohne Rüstung unterwegs, das kann gefährlich werden. Gegen eine Spende könntest du eine bekommen.' + }, { + answer: [{ + message: 'Gib her, hier ist ein dicker Sack', + condition: Environment.progress.inventory_money, + action: function () { + Environment.progress.inventory_ruestung = true; + } + }, { + message: 'Was? Spende? Ich hab\' nichts!', + condition: !Environment.progress.inventory_money, + action: function () { + Game.log('Finde den Schatz bei den Fahrstühlen.'); + state.failed = true; + } + }] + }, { + bubble: '#manu_speech', + message: 'Yoh, geh\' mal rüber zu George.', + condition: Environment.progress.inventory_ruestung + }], + state, + function () { + state.welcome_message = true; + Environment.progress.fs_firstApproach = true; + if (Environment.progress.inventory_ruestung) { + Game.log('Finde George.'); + state.successful = true; + } + }); + } + }, + 'fs_screamingGeorge': { + possible: function () { + return !Environment.progress.fs_georgeScreamed && Story.actions.fs_firstApproach.state.successful; + }, + action: function () { + Story.dialogueHelper([ + { + bubble: '#george_speech', + message: 'EY! MELD\' DICH MAL ZUR FACHSCHAFTSFAHRT AN!!' + }, { + bubble: '#george_speech', + message: 'SCHREIB\' DICH AN DER TAFEL DAZU EIN!!!' + } + ], null, function () { + Game.log('Schreib\' an die zur Tafel.'); + Environment.progress.fs_firstApproach = true; + }); + Environment.progress.fs_georgeScreamed = true; + } + }, + // some hint message when trying to leave fs without all actions complete + 'fs_exit_hint': { + state: { + hintGiven: false + }, + possible: function () { + return !Story.actions.fs_exit_hint.state.hintGiven &&!Environment.progress.fs_filledBoard + && Environment.progress.fs_firstApproach && Environment.progress.inventory_money; + }, + action: function () { + Story.dialogueHelper([ + { + bubble: '#tim_speech', + message: 'Du bist hier noch nicht fertig. Vorher kommst du nicht raus!' + } + ]); + } + }, + // name/email signup board + 'fs_open_board': { + possible: function () { + return Environment.progress.fs_georgeScreamed; + }, + action: function () { + console.log('fuck yeah!'); + Game.log('Kontaktdaten verloren.'); + Game.log('Lieber schnell wieder raus hier!'); + // TODO implement board fill + } + }, + + + // ================================================================================================================= + // Actions on the landing map + + 'landing_goatFight': { + possible: function () { + return true; + }, + action: function () { + + } + } +}; + +Story.dialogueHelper = function (dialogue, context, done) { + + var speed = { + talk: UrlComponents.isSet('fastTalk') ? 1 : 45, + pause: UrlComponents.isSet('fastTalk') ? 50 : 1000 + }; + + Game.actionsBlocked = true; + var dialogueBox = $('#gameDialogue'); + dialogueBox.html(''); + dialogueBox.show(); + + var dialogue_i = 0; + dialogueStepper(); + + function dialogueStepper() { + if (dialogue_i >= dialogue.length) { + dialogueBox.hide(); + Game.actionsBlocked = false; + if (typeof done === 'function') done(); + } else { + var part = dialogue[dialogue_i]; + dialogue_i++; + if ('condition' in part && !part.condition) { + dialogueStepper(); + } else if (part.answer) { + answerSelection(part.answer); + } else { + plotMessage(part.bubble, part.message, dialogueStepper); + } + } + } + + function answerSelection(answers) { + var possibleAnswers = answers.map(function (answer, i) { + if ('condition' in answer && answer.condition) + return '<li gameDialogueAnswer="' + i + '">' + answer.message + '</li>'; + else return null; + }).filter(function (answer) { + return !!answer; + }); + + if (possibleAnswers.length > 0) { + var list = '<ul>' + possibleAnswers.join('') + '</ul>'; + dialogueBox.html(list); + $('[gameDialogueAnswer]').on('click', function () { + var answer = $(this).attr('gameDialogueAnswer'); + if (typeof answers[answer].action() === 'function') answers[answer].action(); + dialogueStepper(); + }) + } else { + dialogueStepper(); + } + } + + function plotMessage(bubble, message, plotDone) { + var i = 0; + var bubbleNode = !bubble ? null : Game.char.svg.select(bubble); + var messageStepper = setInterval(function () { + i++; + if (i > message.length) { + clearInterval(messageStepper); + if (bubbleNode) bubbleNode.style('display', 'block'); + setTimeout(function () { + if (bubbleNode) bubbleNode.style('display', 'none'); + plotDone(); + }, speed.pause) + } else { + if (bubbleNode) bubbleNode.style('display', (i % 2) ? 'none' : 'block'); + dialogueBox.text(message.substring(0, i)); + } + }, speed.talk); + } +}; \ No newline at end of file diff --git a/registration-system/view/signups/game1/maps/castle_fs.svg b/registration-system/view/signups/game1/maps/castle_fs.svg index 0971efa75f6e9549140a91320b729f61737ffd0b..f68a98adba4abe770ba64200e8b87f4ce509d1f6 100644 Binary files a/registration-system/view/signups/game1/maps/castle_fs.svg and b/registration-system/view/signups/game1/maps/castle_fs.svg differ diff --git a/registration-system/view/signups/game1/maps/dorf.svg b/registration-system/view/signups/game1/maps/dorf.svg index 687074329bec96c1a0b57dc211e65bb8c2008568..3e1df597912fc0837400bdea1482b49aaa2988c8 100644 Binary files a/registration-system/view/signups/game1/maps/dorf.svg and b/registration-system/view/signups/game1/maps/dorf.svg differ diff --git a/registration-system/view/signups/game1/maps/map_landing.svg b/registration-system/view/signups/game1/maps/map_landing.svg index c5e121480efce80a255643a91a3cebd0934e8e8a..db4ae1a6fd048a97f29e8f8cff017fac75dcbd70 100644 Binary files a/registration-system/view/signups/game1/maps/map_landing.svg and b/registration-system/view/signups/game1/maps/map_landing.svg differ diff --git a/registration-system/view/signups/game1/test.html b/registration-system/view/signups/game1/test.html index a1c4091ce9a8f8a860983c772bb3466a10dc288f..5b853da56143a873771a5e4bc80601e1e7d5314b 100644 --- a/registration-system/view/signups/game1/test.html +++ b/registration-system/view/signups/game1/test.html @@ -16,6 +16,7 @@ <script src="js/character.js" type="text/javascript"></script> <script src="js/camera.js" type="text/javascript"></script> <script src="js/environment.js" type="text/javascript"></script> + <script src="js/story.js" type="text/javascript"></script> <script src="js/game.js" type="text/javascript"></script> </head> <body> @@ -50,7 +51,7 @@ <div id="game-game"> <div id="gameCanvas" style="overflow:hidden;position:relative"> <div id="gameRoot" style="position:relative"></div> - <div id="gameDialogue" class="bordered-box">Some dialogue</div> + <div id="gameDialogue" class="bordered-box"></div> </div> </div> </div> diff --git a/registration-system/view/signups/game1/ui.css b/registration-system/view/signups/game1/ui.css index fea0e6a1a9523e5b21bc9c4bd5eb85e97b05437b..0757bf87c3d9107b3e4b557b799c5953f183f6bb 100644 --- a/registration-system/view/signups/game1/ui.css +++ b/registration-system/view/signups/game1/ui.css @@ -34,15 +34,36 @@ } #gameDialogue { - height: 50px; + font-size: 11pt; + height: 4em; position: absolute; bottom: 20px; left: 20px; right: 20px; - padding: 5px; + padding: 0.5em 1em; display: none; } +#gameDialogue ul { + margin: 0; + padding: 0 0 0 0.5em; + list-style: none; +} +#gameDialogue ul li { + padding: 0.1em; +} +#gameDialogue ul li:hover { + background-color: #474c46; +} +#gameDialogue ul li:before { + content: '⇢'; + font-size: 15pt; + line-height: 11pt; + margin-right: 0.3em; +} +#gameDialogue ul li:hover:before { + content: '↠'; +} /* #2E2E2E dark