From 24e5650f093f76c08ce280ba83661a7917a0ceb0 Mon Sep 17 00:00:00 2001 From: Talon Date: Wed, 10 Nov 2021 22:11:30 +0100 Subject: [PATCH] Add statue puzzle --- src/engine/state.js | 5 +++-- src/game/items/statue1.js | 13 ++++++++++++- src/game/items/statue2.js | 12 +++++++++++- 3 files changed, 26 insertions(+), 4 deletions(-) diff --git a/src/engine/state.js b/src/engine/state.js index fa89ce2..5d1488e 100644 --- a/src/engine/state.js +++ b/src/engine/state.js @@ -3,9 +3,10 @@ class State { this.states = new Map(); } - get(key) { + get(key, defaultValue = null) { if (!this.states.has(key)) { - return null; + this.states.set(key, defaultValue); + return defaultValue; } return this.states.get(key); } diff --git a/src/game/items/statue1.js b/src/game/items/statue1.js index 4f6b87c..d49db84 100644 --- a/src/game/items/statue1.js +++ b/src/game/items/statue1.js @@ -9,6 +9,17 @@ export default new ItemBuilder() .isTakeable(false) .isUsable(true) .withUseCallback(async function (context) { - context.print(`You press the button on the round device attached to the statue's arm.`) + context.print(`You press the button on the round device attached to the statue's arm.`); + let value = context.state.get("statue1.pressed", 0); + value++; + context.state.set("statue1.pressed", value); + if (value == 3) { + context.print(`You hear a sattisfying click.`); + context.state.set("statues.unlocked", true); + } + if (context.state.get('statue1.pressed') > 2 && context.state.get('statue2.pressed') > 1) { + context.print(`You hear a low rumble somewhere deep within the bowels of the structure.`); + context.state.set("statues.unlocked", true); + } }) .create(); \ No newline at end of file diff --git a/src/game/items/statue2.js b/src/game/items/statue2.js index 0b2a120..c88a70d 100644 --- a/src/game/items/statue2.js +++ b/src/game/items/statue2.js @@ -9,6 +9,16 @@ export default new ItemBuilder() .isTakeable(false) .isUsable(true) .withUseCallback(async function (context) { - context.print(`You press the button on the rectangular device attached to the statue's arm.`) + context.print(`You press the button on the rectangular device attached to the statue's arm.`); + let value = context.state.get("statue2.pressed", 0); + value++; + context.state.set("statue2.pressed", value); + if (value == 2) { + context.print(`You hear a sattisfying click.`); + } + if (context.state.get('statue1.pressed') > 2 && context.state.get('statue2.pressed') > 1) { + context.print(`You hear a low rumble somewhere deep within the bowels of the structure.`); + context.state.set("statues.unlocked", true); + } }) .create(); \ No newline at end of file