| @@ -73,11 +73,9 @@ function applyGlobalProdBonus(cost) { | |||||
| for (let effect of effects["prod-all"]) { | for (let effect of effects["prod-all"]) { | ||||
| if (ownedUpgrades[effect.parent]) { | if (ownedUpgrades[effect.parent]) { | ||||
| cost = effect.apply(cost); | |||||
| effect.apply(cost); | |||||
| } | } | ||||
| } | } | ||||
| return cost; | |||||
| } | } | ||||
| function calculateProductivity() { | function calculateProductivity() { | ||||
| @@ -99,44 +97,42 @@ function applyProductivityMultipliers(type, cost) { | |||||
| for (let effect of effects["prod"]) { | for (let effect of effects["prod"]) { | ||||
| if (ownedUpgrades[effect.parent] && effect.target == type) { | if (ownedUpgrades[effect.parent] && effect.target == type) { | ||||
| cost = effect.apply(cost); | |||||
| effect.apply(cost); | |||||
| } | } | ||||
| } | } | ||||
| for (let effect of effects["helper"]) { | for (let effect of effects["helper"]) { | ||||
| if (ownedUpgrades[effect.parent] && effect.helped == type) { | if (ownedUpgrades[effect.parent] && effect.helped == type) { | ||||
| cost = effect.apply(cost, belongings[effect.helper].count); | |||||
| effect.apply(cost, belongings[effect.helper].count); | |||||
| } | } | ||||
| } | } | ||||
| return cost; | |||||
| } | } | ||||
| function productivityOf(type) { | function productivityOf(type) { | ||||
| let baseProd = makeCost(buildings[type].prod); | let baseProd = makeCost(buildings[type].prod); | ||||
| baseProd = applyProductivityMultipliers(type, baseProd); | |||||
| applyProductivityMultipliers(type, baseProd); | |||||
| baseProd = applyGlobalProdBonus(baseProd); | |||||
| applyGlobalProdBonus(baseProd); | |||||
| baseProd = scaleCost(baseProd, belongings[type].count); | |||||
| scaleCost(baseProd, belongings[type].count); | |||||
| return baseProd; | return baseProd; | ||||
| } | } | ||||
| function makeCost(source) { | function makeCost(source) { | ||||
| const empty = mapObject(resourceTypes, () => 0); | const empty = mapObject(resourceTypes, () => 0); | ||||
| return deepFreeze({...empty, ...source}); | |||||
| return {...empty, ...source}; | |||||
| } | } | ||||
| function addCost(cost1, cost2) { | function addCost(cost1, cost2) { | ||||
| return deepFreeze(Object.keys(resourceTypes).reduce((o, k) => ({ ...o, [k]: cost1[k] + cost2[k]}), {})); | |||||
| return Object.keys(resourceTypes).reduce((o, k) => {o[k] += cost2[k]; return o;}, cost1); | |||||
| } | } | ||||
| function scaleCost(cost, scale) { | function scaleCost(cost, scale) { | ||||
| if (typeof(scale) != "number") console.log(scale) | if (typeof(scale) != "number") console.log(scale) | ||||
| return deepFreeze(Object.keys(resourceTypes).reduce((o, k) => ({ ...o, [k]: cost[k] * scale}), {})); | |||||
| return Object.keys(resourceTypes).reduce((o, k) => {o[k] *= scale; return o;}, cost); | |||||
| } | } | ||||
| function costOfBuilding(type, count = 1) { | function costOfBuilding(type, count = 1) { | ||||