(function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o 0) { entryTimer += dt; } else { entryTimer = 0; } if (entryTimer > 1) { setState("closeEntryDoors"); } } // // closeEntryDoors // function closeEntryDoorsEnter() { // slam the door! var id = lookupEntityByName("entry-collision"); var doorPosition = DEFAULT_CONTAINER_LOCATION; if (id) { doorPosition = Entities.getEntityProperties(id, "position").position; } if (doorSlamSound.downloaded) { if (doorSlamInjector) { doorSlamInjector.restart(); } else { doorSlamInjector = Audio.playSound(doorSlamSound, { position: doorPosition, volume: 1.0, loop: false }); } } editEntity("entry-collision", { collisionless: false, visible: true }); // turn out the lights! editEntity("entry-light", { intensity: 0 }); } function closeEntryDoorsUpdate(dt) { if (timeInState > 1.0) { setState("lightsOut"); } } // // lightsOut // function lightsOutEnter() { // begin the scream track var id = lookupEntityByName("container-trigger"); var screamPosition = DEFAULT_CONTAINER_LOCATION; if (id) { screamPosition = Entities.getEntityProperties(id, "position").position; } if (screamSound.downloaded) { if (screamInjector) { screamInjector.restart(); } else { screamInjector = Audio.playSound(screamSound, { position: screamPosition, volume: 1.0, loop: false }); } } } function lightsOutUpdate() { if (timeInState > 6) { setState("strobe"); } } // // strobe // function strobeEnter() { strobeTimer = 0; // show the bloody interior editEntity("bloody-container", { visible: true }); } function strobeUpdate(dt) { strobeTimer += dt; if (strobeTimer > 0.05) { strobeTimer = 0.0; strobeBlink = !strobeBlink; editEntity("strobe-light", { intensity: strobeBlink ? 0.7 : 0.0 }); } // after five seconds turn the lights out again! if (timeInState > 8.0) { setState("lightsOutAgain"); } } // // lightsOutAgain // function lightsOutAgainEnter() { // turn off the strobe editEntity("strobe-light", { intensity: 0.0 }); // hide the bloody interior editEntity("bloody-container", { visible: false }); } function lightsOutAgainUpdate(dt) { if (timeInState > 4.0) { setState("openExitDoors"); } } // // openExitDoors // function openExitDoorsEnter() { editEntity("strobe-light", { intensity: 0.0 }); editEntity("bloody-container", { visible: false }); editEntity("exit-collision", { collisionless: true, visible: false }); editEntity("exit-light", { intensity: 0.5 }); // play door slam var id = lookupEntityByName("exit-collision"); var doorPosition = DEFAULT_CONTAINER_LOCATION; if (id) { doorPosition = Entities.getEntityProperties(id, "position").position; } if (doorSlamSound.downloaded) { if (doorSlamInjector) { doorSlamInjector.restart(); } else { doorSlamInjector = Audio.playSound(doorSlamSound, { position: doorPosition, volume: 1.0, loop: false }); } } } function openExitDoorsUpdate(dt) { // wait till all avatars leave the container if (numAvatarsInContainer() === 0) { setState("idle"); } } // // // function setState(newState) { if (state !== newState) { // exit old state if (stateTable[state]) { var exitFunc = stateTable[state].exit; if (exitFunc) { exitFunc(); } } else { debug("ERROR: no state table for state = " + state); } stateEnterTime = Date.now(); timeInState = 0; // enter new state if (stateTable[newState]) { var enterFunc = stateTable[newState].enter; if (enterFunc) { enterFunc(); } } else { debug("ERROR: no state table for state = " + newState); } state = newState; debug("state = " + state); } } function numAvatarsInEntry() { var count = 0; var keys = Object.keys(numAvatarsInEntryTriggerMap); var i, l = keys.length; for (i = 0; i < l; i++) { if (numAvatarsInEntryTriggerMap[keys[i]] > 0.0) { count++; } } return count; } function numAvatarsInContainer() { var count = 0; var keys = Object.keys(numAvatarsInContainerTriggerMap); var i, l = keys.length; for (i = 0; i < l; i++) { if (numAvatarsInContainerTriggerMap[keys[i]] > 0.0) { count++; } } return count; } function update(dt) { var updateFunc = stateTable[state].update; timeInState = (Date.now() - stateEnterTime) / 1000.0; if (updateFunc) { updateFunc(dt); } // decrement timers for trigger maps var keys = Object.keys(numAvatarsInEntryTriggerMap); var i, l = keys.length; for (i = 0; i < l; i++) { numAvatarsInEntryTriggerMap[keys[i]] -= dt; } keys = Object.keys(numAvatarsInContainerTriggerMap); l = keys.length; for (i = 0; i < l; i++) { numAvatarsInContainerTriggerMap[keys[i]] -= dt; } } function reset() { goToState("idle"); } EntityViewer.setPosition(DEFAULT_CONTAINER_LOCATION); EntityViewer.setCenterRadius(100); var octreeQueryInterval = Script.setInterval(function() { EntityViewer.queryOctree(); }, 1000); Script.update.connect(update); Messages.subscribe(TRIGGER_CHANNEL); Messages.messageReceived.connect(function (channel, message, senderID) { var AVATAR_TRIGGER_TIMEOUT = 10.0; //print("MESSAGE, channel = " + channel + ", message = " + message + ", senderID = " + senderID); if (channel === TRIGGER_CHANNEL) { var data = JSON.parse(message); if (data.inside) { if (data.entityID === lookupEntityByName("entry-back-trigger")) { numAvatarsInEntryTriggerMap[senderID] = AVATAR_TRIGGER_TIMEOUT; } else if (data.entityID === lookupEntityByName("container-trigger")) { numAvatarsInContainerTriggerMap[senderID] = AVATAR_TRIGGER_TIMEOUT; } } else { if (data.entityID === lookupEntityByName("entry-back-trigger")) { numAvatarsInEntryTriggerMap[senderID] = 0; } else if (data.entityID === lookupEntityByName("container-trigger")) { numAvatarsInContainerTriggerMap[senderID] = 0; } } } else if (channel === RESET_CHANNEL) { reset(); } }); setState("uninitialized"); },{}]},{},[1]);