Bathroom puzzle - need to lock down scenery items

main
Ashelyn Dawn 4 years ago
parent 3ec1f9f9c1
commit f0e9939cb5

@ -25,7 +25,12 @@ export default class Parser {
try {
renderer.hidePrompt()
let start = window.performance.now()
await this.runCommand(rawCommand)
let end = window.performance.now()
if(end - start > 200)
console.warn(`Command execution took ${end - start}ms`)
await timer
} catch (err) {
await timer

@ -0,0 +1,20 @@
import Parser from "../Parser";
import RulesEngine from "../RulesEngine";
import Game from "../Game";
import {hints} from '../../gameSetup/2-phases-and-hints'
export default function(parser : Parser, rules : RulesEngine, game : Game) {
parser.understand('hint')
.as('hint')
rules.onCommand('hint', () => {
const phase = game.getProperty('gamePhase')
const hint = hints.get(phase)
if(hint)
game.say(hint)
else
game.say(`Well this is embarassing - no hint for this game phase`)
})
}

@ -9,5 +9,6 @@ export default [
require('./inventory'),
require('./help'),
require('./options'),
require('./map')
require('./map'),
require('./hint')
]

@ -1,4 +1,7 @@
import {game, rules} from '../engine'
import { ObjectType, Item } from '../engine/types/GameState'
import { Draft } from 'immer'
import { Phase } from './2-phases-and-hints'
/**
* Cabin
@ -18,14 +21,27 @@ rules.on('beforePrintItems', () => {
throw new Error('You cannot make out much more without light.')
})
// After picking up flashlight, update game phase
rules.onAfterCommand(() => {
const state = game.getState()
const flashlightLocation = state.items.get('flashlight')?.location
const wrenchExists = state.items.has('wrench')
if(flashlightLocation === 'inventory' && !wrenchExists)
if(flashlightLocation === 'inventory' && !wrenchExists){
if(game.getProperty('gamePhase') < Phase.hasFlashlight)
game.setProperty('gamePhase', Phase.hasFlashlight)
game.addItem('wrench', 'Just generally useful for repairs and adjustments to the various mechanical parts of the ship.', 'cabin')
}
})
// After picking up wrench, update game phase
rules.onAfterCommand(command => {
if(command.verb.name !== 'take' || command.subject?.name !== 'wrench')
return
if(game.getProperty('gamePhase') < Phase.gotWrench)
game.setProperty('gamePhase', Phase.gotWrench)
})
/**
@ -44,6 +60,51 @@ flashlight.aliases.push('flash light')
flashlight.aliases.push('light')
flashlight.aliases.push('torch')
const cupboard = game.addItem('cabinet', 'A metal cupboard beneath the sink. It is currently closed.', 'bathroom')
cupboard.aliases.push('cupboard')
cupboard.aliases.push('cupboard door')
cupboard.aliases.push('cabinet door')
rules.onBeforeCommand(command => {
if(command.verb.name !== 'openItem') return;
if(command.subject?.name !== 'cabinet') return;
const wrench = game.findObjectByName('wrench', ObjectType.Item) as Item
const item = game.findObjectByName('cabinet', ObjectType.Item) as Draft<Item>
item.description = `
A small metal cupboard beneath the sing. It is currently open.
At the bottom of the cupboard you see a loose metal panel you might be able to fit through.
`
const sinkPanel = game.addItem('floor panel', 'A loose metal panel in the bathroom floor.', 'bathroom')
sinkPanel.aliases.push('panel')
sinkPanel.aliases.push('loose panel')
if(wrench?.location === 'inventory')
game.setProperty('gamePhase', Phase.gotWrench)
else
game.setProperty('gamePhase', Phase.checkedUnderSink)
// Prevent normal command execution
throw new Error('You open the sink cupboard, revealing a loose metal panel in the bathroom floor.')
})
rules.onBeforeCommand(command => {
if(command.verb.name !== 'openItem') return;
if(command.subject?.name !== 'floor panel') return;
game.setNeighbor('bathroom', 'down', 'docking')
if(game.getProperty('gamePhase') < Phase.openedSinkPanel)
game.setProperty('gamePhase', Phase.openedSinkPanel)
const panel = game.findObjectByName('floor panel', ObjectType.Item) as Draft<Item>
panel.printableName = 'hole in the floor'
throw new Error('It takes you a few minutes, but eventually you pull up the floor panel. You should be able to get down to the docking bay from here.')
})
/**
* Comms
*/
@ -122,6 +183,3 @@ game.setNeighbor('stairupper', 'down', 'stairlower')
game.setNeighbor('stairlower', 'fore', 'mainframe')
game.setNeighbor('mainframe', 'starboard', 'engine')
game.setNeighbor('engine', 'starboard', 'docking')
// Secret passageways
game.setNeighbor('bathroom', 'down', 'docking')

@ -24,7 +24,7 @@ export enum Phase {
// TODO: Replace [thing]
export const hints : Map<Phase, string> = new Map()
hints.set(Phase.wakeUp, 'You may be able to assess your situation better if you retrieve your flashlight.')
hints.set(Phase.wakeUp, 'You may be able to assess your situation better if you find a light.')
hints.set(Phase.hasFlashlight, 'With the security door shut and power cut off, you\'ll have to find another way into the rest of the ship.')
hints.set(Phase.checkedUnderSink, `There is a panel under the sink that you might be able to fit through - you'll need a wrench to get it open though.`)
hints.set(Phase.gotWrench, `You have a wrench and can open the panel under the sink.`)
@ -44,4 +44,6 @@ hints.set(Phase.returnedUpToBathroom, 'Someone locked the comms room locker. Th
hints.set(Phase.hasKey, `You've retrieved the spare key to the comms locker, and can finally get the [thing] to repair the mainframe.`)
hints.set(Phase.unlockedLocker, 'Locker is empty - whoever was in your ship made sure you wouldn\'t be able to repair it.')
game.createProperty('gamePhase', Phase.wakeUp)
setImmediate(() => {
game.createProperty('gamePhase', Phase.wakeUp)
})

Loading…
Cancel
Save