From c0f07143247d1c619d42578ed1c0d227392e23cf Mon Sep 17 00:00:00 2001 From: Majid-Shahani Date: Wed, 27 May 2026 18:07:14 +0300 Subject: [PATCH 1/4] Add heat observer --- src/data/gameData.js | 50 +++++++++++++++++++++++++++++++++----------- 1 file changed, 38 insertions(+), 12 deletions(-) diff --git a/src/data/gameData.js b/src/data/gameData.js index aa1b0ca..69df74e 100644 --- a/src/data/gameData.js +++ b/src/data/gameData.js @@ -3,20 +3,40 @@ const gameData = { heat: 1, }; +let heatListeners = []; +function attachHeatListener(observer) { + if (heatListeners.includes(observer)) return false; + + heatListeners.push(observer); + return true; +} +function detachHeatListener(observer) { + const index = heatListeners.indexOf(observer); + if (index === -1) return false; + + heatListeners.splice(index, 1); + return true; +} + +function callHeatListeners() { + heatListeners.forEach((observer) => observer(gameData.heat)); +} + +function increaseHeat() { + gameData.heat++; + callHeatListeners(); +} + const activeOrders = []; function makeDelivery() { gameData.essence += 25; currentState.ordersFullfilled++; if (currentState.ordersFullfilled >= currentState.nextHeat) { - // increase heat - gameData.heat++; - currentState.nextHeat += gameData.heat + 1; - currentState.baseTime = defaultState.baseTime / (1 + gameData.heat); - currentState.timeToNextOrder = - defaultState.orderAdditionRatio * currentState.baseTime; + increaseHeat(); } } + function addOrder(recipe) { if (activeOrders.length > 2) return; activeOrders.push({ @@ -45,11 +65,16 @@ const currentState = { function resetState() { gameData.essence = 0; gameData.heat = 1; - - currentState.baseTime = defaultState.baseTime / (1 + gameData.heat); - currentState.timeToNextOrder = - defaultState.orderAdditionRatio * defaultState.baseTime; currentState.ordersFullfilled = 0; + + heatListeners.length = 0; + attachHeatListener((heatLevel) => { + currentState.nextHeat += heatLevel + 1; + currentState.baseTime = defaultState.baseTime / (1 + heatLevel); + currentState.timeToNextOrder = + defaultState.orderAdditionRatio * currentState.baseTime; + }); + callHeatListeners(); } export { @@ -60,6 +85,7 @@ export { defaultState, currentState, resetState, + attachHeatListener, + detachHeatListener, + increaseHeat, }; - -// WE PROBABLY WILL ADD MORE STUFF HERE LATER From aab029f643a714bab6a2c2a09223cba00ec4b0e6 Mon Sep 17 00:00:00 2001 From: Majid-Shahani Date: Wed, 27 May 2026 20:31:13 +0300 Subject: [PATCH 2/4] Refactor cook and station time ratios --- src/data/gameData.js | 18 ++++++++++-------- src/entities/station.js | 13 ++++++------- 2 files changed, 16 insertions(+), 15 deletions(-) diff --git a/src/data/gameData.js b/src/data/gameData.js index 69df74e..3ac7bf6 100644 --- a/src/data/gameData.js +++ b/src/data/gameData.js @@ -49,17 +49,19 @@ function addOrder(recipe) { } const defaultState = Object.freeze({ - baseTime: 8000, // in ms - orderAdditionRatio: 8, - orderDurationRatio: 12, + baseTime: 15000, // in ms + orderAdditionRatio: 9, + orderDurationRatio: 7, + cookRatio: 3, + stationRatio: 2 / 3, }); +// check reset State for starting values const currentState = { - baseTime: defaultState.baseTime / (1 + gameData.heat), - timeToNextOrder: - (defaultState.orderAdditionRatio * defaultState.baseTime) / 2, + baseTime: 0, + timeToNextOrder: 0, ordersFullfilled: 0, - nextHeat: gameData.heat + 1, + nextHeat: 0, }; function resetState() { @@ -70,7 +72,7 @@ function resetState() { heatListeners.length = 0; attachHeatListener((heatLevel) => { currentState.nextHeat += heatLevel + 1; - currentState.baseTime = defaultState.baseTime / (1 + heatLevel); + currentState.baseTime = defaultState.baseTime / (2 + heatLevel); currentState.timeToNextOrder = defaultState.orderAdditionRatio * currentState.baseTime; }); diff --git a/src/entities/station.js b/src/entities/station.js index 01afb89..34dc532 100644 --- a/src/entities/station.js +++ b/src/entities/station.js @@ -8,6 +8,7 @@ import { } from "../data/items.js"; import { gameData, + defaultState, activeOrders, addOrder, makeDelivery, @@ -40,7 +41,7 @@ class Station { this.startWorking = (baseTime) => { this._work_lock = true; - this.duration = (baseTime * 2) / 3; + this.duration = Math.ceil(baseTime * defaultState.stationRatio); }; this.doWork = (timeStep) => { @@ -127,8 +128,8 @@ class Ingredient { class Glass { constructor(glassType) { this.inventory = glassType; - this.canPlace = (playerInv) => playerInv.ingredient === this.inventory; - this.place = (playerInv) => (playerInv.ingredient = 0); + this.canPlace = (playerInv) => playerInv.glass === this.inventory; + this.place = (playerInv) => (playerInv.glass = 0); this.canTake = (playerInv) => playerInv.empty(); this.take = (playerInv) => { @@ -191,12 +192,11 @@ class Cauldron { this.itemCount = 0; }; - // to be re-written this.canWork = () => this.duration === 0 && this._get_base(this.inventory) !== 0; this.startWorking = (baseTime) => { - this.duration = 4 * baseTime; + this.duration = baseTime * defaultState.cookRatio; this._first_brew = true; }; @@ -237,8 +237,7 @@ class Cauldron { }; this._in_inventory = (ing) => { - if ((this.inventory & ing) === 0) return false; - return true; + return (this.inventory & ing) !== 0; }; } } From eb163090b510ebf308fdb3bbf8e3c4f8c9386f8d Mon Sep 17 00:00:00 2001 From: Majid-Shahani Date: Wed, 27 May 2026 21:27:30 +0300 Subject: [PATCH 3/4] Increase time between new orders --- src/data/gameData.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/data/gameData.js b/src/data/gameData.js index 3ac7bf6..5d50789 100644 --- a/src/data/gameData.js +++ b/src/data/gameData.js @@ -23,6 +23,7 @@ function callHeatListeners() { } function increaseHeat() { + if (gameData.heat >= defaultState.maxHeat) return; gameData.heat++; callHeatListeners(); } @@ -50,7 +51,8 @@ function addOrder(recipe) { const defaultState = Object.freeze({ baseTime: 15000, // in ms - orderAdditionRatio: 9, + maxHeat: 6, + orderAdditionRatio: 14, orderDurationRatio: 7, cookRatio: 3, stationRatio: 2 / 3, From 9678d94099f202438d37c7d09c62fc5355a68cc2 Mon Sep 17 00:00:00 2001 From: Majid-Shahani Date: Wed, 27 May 2026 21:44:52 +0300 Subject: [PATCH 4/4] adjust time ratios --- src/data/gameData.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/data/gameData.js b/src/data/gameData.js index 5d50789..2efb193 100644 --- a/src/data/gameData.js +++ b/src/data/gameData.js @@ -52,8 +52,8 @@ function addOrder(recipe) { const defaultState = Object.freeze({ baseTime: 15000, // in ms maxHeat: 6, - orderAdditionRatio: 14, - orderDurationRatio: 7, + orderAdditionRatio: 12, + orderDurationRatio: 6, cookRatio: 3, stationRatio: 2 / 3, });