diff --git a/constants.js b/constants.js index 8c6e14a..458ea62 100644 --- a/constants.js +++ b/constants.js @@ -244,7 +244,7 @@ deepFreeze(buildings); const effect_types = { "prod": { "apply": function (effect, productivity) { - scaleCost(productivity, effect); + return scaleCost(productivity, effect.amount); }, "desc": function (effect) { return round(effect.amount, 2) + "x food production from " + buildings[effect.target].plural; @@ -252,7 +252,7 @@ const effect_types = { }, "prod-all": { "apply": function (effect, productivity) { - scaleCost(productivity, effect); + return scaleCost(productivity, effect.amount); }, "desc": function (effect) { return round((effect.amount - 1) * 100) + "% increase to food production"; @@ -433,7 +433,7 @@ function createHelperUpgrades() { "desc": text.desc, "icon": "fa-hand-holding", "cost": { - "food": buildings[helper].cost * 25 * counter + buildings[helped].cost * 50 * counter + "food": buildings[helper].cost.food * 25 * counter + buildings[helped].cost.food * 50 * counter }, "effects": [ { diff --git a/gorge.js b/gorge.js index 18dffa4..dc3a568 100644 --- a/gorge.js +++ b/gorge.js @@ -13,6 +13,7 @@ const resources = {}; let updateRate = 30; const currentProductivity = {}; +const contributions = {}; let clickBonus = 0; let clickVictim = "micro"; @@ -67,25 +68,25 @@ function addPowerup(powerup) { updateAll(); } -function getGlobalProdBonus() { - - let productivity = 1; +function applyGlobalProdBonus(cost) { for (let effect of effects["prod-all"]) { if (ownedUpgrades[effect.parent]) { - productivity = effect.apply(productivity); + cost = effect.apply(cost); } } - return productivity; + return cost; } function calculateProductivity() { let productivity = makeCost(); for (const [key, value] of Object.entries(belongings)) { - productivity = addCost(productivity, productivityOf(key)); + const provided = productivityOf(key); + productivity = addCost(productivity, provided); + contributions[key] = provided; } return productivity; @@ -93,32 +94,31 @@ function calculateProductivity() { // here's where upgrades will go :3 -function productivityMultiplierOf(type) { - let base = 1; +function applyProductivityMultipliers(type, cost) { for (let effect of effects["prod"]) { if (ownedUpgrades[effect.parent] && effect.target == type) { - base = effect.apply(base); + cost = effect.apply(cost); } } for (let effect of effects["helper"]) { if (ownedUpgrades[effect.parent] && effect.helped == type) { - base = effect.apply(base, belongings[effect.helper].count); + cost = effect.apply(cost, belongings[effect.helper].count); } } - return base; + return cost; } function productivityOf(type) { let baseProd = makeCost(buildings[type].prod); - baseProd = scaleCost(baseProd, productivityMultiplierOf(type)); + baseProd = applyProductivityMultipliers(type, baseProd); - baseProd = scaleCost(baseProd, productivityMultiplierOf(type)); + baseProd = applyGlobalProdBonus(baseProd); baseProd = scaleCost(baseProd, belongings[type].count); @@ -135,6 +135,7 @@ function addCost(cost1, cost2) { } function scaleCost(cost, scale) { + if (typeof(scale) != "number") console.log(scale) return deepFreeze(Object.keys(resourceTypes).reduce((o, k) => ({ ...o, [k]: cost[k] * scale}), {})); } @@ -393,7 +394,7 @@ function buyUpgrade(id, e) { } function eatPrey() { - const add = buildings[clickVictim]["prod"].food * 10 * productivityMultiplierOf(clickVictim) + clickBonus; + const add = buildings[clickVictim]["prod"].food * 10 + clickBonus; resources.food += add; return add; } @@ -440,6 +441,7 @@ function initializeData() { belongings[key] = {}; belongings[key].count = 0; belongings[key].visible = false; + contributions[key] = makeCost(); } for (const [key, value] of Object.entries(resourceTypes)) { @@ -927,14 +929,14 @@ function prodSummary(id) { let list = []; list.push( - { "text": "Each " + buildings[id].name + " produces " + round(productivityMultiplierOf(id) * buildings[id].prod, 1) + " food/sec" } + { "text": "Each " + buildings[id].name + " produces " + contributions[id].food + " food/sec" } ); list.push( - { "text": "Your " + render(belongings[id].count) + " " + (belongings[id].count == 1 ? buildings[id].name + " is" : buildings[id].plural + " are") + " producing " + round(productivityOf(id), 1) + " food/sec" } + { "text": "Your " + render(belongings[id].count) + " " + (belongings[id].count == 1 ? buildings[id].name + " is" : buildings[id].plural + " are") + " producing " + round(productivityOf(id).food, 1) + " food/sec" } ); - let percentage = round(100 * productivityOf(id) / currentProductivity["food"], 2); + let percentage = round(100 * productivityOf(id).food / currentProductivity["food"], 2); if (isNaN(percentage)) { percentage = 0;