diff --git a/constants.js b/constants.js index 97633e3..39369e8 100644 --- a/constants.js +++ b/constants.js @@ -302,7 +302,9 @@ function createTemplateUpgrades() { createHelperUpgrades(); createClickVictimUpgrades(); createPowerupFreqUpgrades(); + createFreeBuildingPowerups(); deepFreeze(upgrades); + deepFreeze(powerups); } const prodUpgradeCounts = [1, 5, 10, 25, 50, 75, 100]; @@ -1198,27 +1200,19 @@ const powerups = { name: "Free Food", description: "Tasty!", icon: "fa-drumstick-bite", + prereqs: state => true, effect: state => state.resources.food += state.currentProductivity.food * 60, popup: (self, e) => { clickPopup("GULP!", "gulp", [e.clientX, e.clientY]); clickPopup("+60 seconds of food", "food", [e.clientX, e.clientY]); } }, - "free-car": { - name: "Free Car", - description: "It's FREE!", - icon: "fa-car", - effect: state => state.belongings.car.count += 1, - popup: (self, e) => { - clickPopup("CAR!", "gulp", [e.clientX, e.clientY]); - clickPopup("+1 car", "food", [e.clientX, e.clientY]); - } - }, "double": { name: "Double Dip", description: "Doubled productivity!", icon: "fa-cogs", duration: 10000, + prereqs: state => true, effect: state => state.currentProductivity.food *= 2, popup: (self, e) => { clickPopup("VROOM!", "gulp", [e.clientX, e.clientY]); @@ -1226,6 +1220,32 @@ const powerups = { } } +function createFreeBuildingPowerups() { + const prefix = "free-"; + Object.entries(freeBuildingPowerupText).forEach(([building, text]) => { + const key = prefix + building; + + powerups[key] = { + name: text.name, + description: text.desc, + icon: buildings[building].icon, + prereqs: state => state.belongings[building].count > 0 && state.belongings[building].count < 100, + effect: state => state.belongings[building].count += 1, + popup: (self, e) => clickPopup("+1 " + buildings[building].name, "food", [e.clientX, e.clientY]) + } + }); +} + +const freeBuildingPowerupText = { + car: { + name: "Free Car", + desc: "It's FREE!" + }, + bus: { + name: "Deserted Bus", + desc: "Just kidding. It's full of people." + } +} deepFreeze(prodUpgradeText); deepFreeze(prodAllUpgradeText); deepFreeze(clickUpgradeText); diff --git a/gorge.js b/gorge.js index 45fee21..b53eec1 100644 --- a/gorge.js +++ b/gorge.js @@ -984,8 +984,16 @@ function doPowerup() { const choices = []; + const state = { + ownedUpgrades: ownedUpgrades, + resources: resources, + currentProductivity: currentProductivity, + belongings: belongings + }; + Object.entries(powerups).forEach(([key, val]) => { - choices.push(key); + if (val.prereqs(state)) + choices.push(key); }); const choice = Math.floor(Math.random() * choices.length); @@ -1015,13 +1023,6 @@ function doPowerup() { doPowerup(); }, delay); - const state = { - ownedUpgrades: ownedUpgrades, - resources: resources, - currentProductivity: currentProductivity, - belongings: belongings - }; - button.addEventListener("mousedown", e => { if (powerup.duration !== undefined) { addPowerup(powerup);