Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
68 changes: 49 additions & 19 deletions src/data/gameData.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,41 @@ 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() {
if (gameData.heat >= defaultState.maxHeat) return;
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({
Expand All @@ -29,27 +50,35 @@ function addOrder(recipe) {
}

const defaultState = Object.freeze({
baseTime: 8000, // in ms
orderAdditionRatio: 8,
orderDurationRatio: 12,
baseTime: 15000, // in ms
maxHeat: 6,
orderAdditionRatio: 12,
orderDurationRatio: 6,
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() {
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 / (2 + heatLevel);
currentState.timeToNextOrder =
defaultState.orderAdditionRatio * currentState.baseTime;
});
callHeatListeners();
}

export {
Expand All @@ -60,6 +89,7 @@ export {
defaultState,
currentState,
resetState,
attachHeatListener,
detachHeatListener,
increaseHeat,
};

// WE PROBABLY WILL ADD MORE STUFF HERE LATER
13 changes: 6 additions & 7 deletions src/entities/station.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
} from "../data/items.js";
import {
gameData,
defaultState,
activeOrders,
addOrder,
makeDelivery,
Expand Down Expand Up @@ -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) => {
Expand Down Expand Up @@ -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) => {
Expand Down Expand Up @@ -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;
};

Expand Down Expand Up @@ -237,8 +237,7 @@ class Cauldron {
};

this._in_inventory = (ing) => {
if ((this.inventory & ing) === 0) return false;
return true;
return (this.inventory & ing) !== 0;
};
}
}
Expand Down