Przeglądaj źródła

Fix more instances of accessing the wrong production values/mixing up numbers and objects

tags/v0.0.6
Fen Dweller 5 lat temu
rodzic
commit
12b7a0093e
Nie znaleziono w bazie danych klucza dla tego podpisu ID klucza GPG: E80B35A6F11C3656
2 zmienionych plików z 22 dodań i 20 usunięć
  1. +3
    -3
      constants.js
  2. +19
    -17
      gorge.js

+ 3
- 3
constants.js Wyświetl plik

@@ -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": [
{


+ 19
- 17
gorge.js Wyświetl plik

@@ -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;


Ładowanie…
Anuluj
Zapisz