From 289a005fbb2345aaf47ff26471cb3a668f0a368a Mon Sep 17 00:00:00 2001 From: Olivier Gagnon Date: Thu, 7 Jun 2018 14:54:34 -0400 Subject: [PATCH 1/2] made upgrade home ram cost consistent and precision to 5 to display better in game --- src/Location.js | 16 ++++------------ src/NetscriptFunctions.js | 20 ++------------------ src/Player.js | 14 ++++++++++++++ 3 files changed, 20 insertions(+), 30 deletions(-) diff --git a/src/Location.js b/src/Location.js index 1f1c60800..56a39114e 100644 --- a/src/Location.js +++ b/src/Location.js @@ -1761,16 +1761,8 @@ function initLocationButtons() { }); purchaseHomeRam.addEventListener("click", function() { - //Calculate how many times ram has been upgraded (doubled) - var currentRam = Player.getHomeComputer().maxRam; - var newRam = currentRam * 2; - var numUpgrades = Math.log2(currentRam); - - //Calculate cost - //Have cost increase by some percentage each time RAM has been upgraded - var cost = currentRam * CONSTANTS.BaseCostFor1GBOfRamHome; - var mult = Math.pow(1.58, numUpgrades); - cost = cost * mult; + const cost = Player.getUpgradeHomeRamCost(); + const ram = Player.getHomeComputer().maxRam; var yesBtn = yesNoBoxGetYesButton(), noBtn = yesNoBoxGetNoButton(); yesBtn.innerHTML = "Purchase"; noBtn.innerHTML = "Cancel"; @@ -1782,8 +1774,8 @@ function initLocationButtons() { yesNoBoxClose(); }); yesNoBoxCreate("Would you like to purchase additional RAM for your home computer?

" + - "This will upgrade your RAM from " + currentRam + "GB to " + newRam + "GB.

" + - "This will cost $" + formatNumber(cost, 2)); + "This will upgrade your RAM from " + ram + "GB to " + ram*2 + "GB.

" + + "This will cost " + numeral(cost).format('$0.000a')); }); purchaseHomeCores.addEventListener("click", function() { diff --git a/src/NetscriptFunctions.js b/src/NetscriptFunctions.js index 62577fe1a..e1f3bac71 100644 --- a/src/NetscriptFunctions.js +++ b/src/NetscriptFunctions.js @@ -2506,15 +2506,7 @@ function NetscriptFunctions(workerScript) { } } - //Calculate how many times ram has been upgraded (doubled) - var currentRam = Player.getHomeComputer().maxRam; - var numUpgrades = Math.log2(currentRam); - - //Calculate cost - //Have cost increase by some percentage each time RAM has been upgraded - var cost = currentRam * CONSTANTS.BaseCostFor1GBOfRamHome; - var mult = Math.pow(1.55, numUpgrades); - cost = cost * mult; + const cost = Player.getUpgradeHomeRamCost(); if (Player.money.lt(cost)) { workerScript.scriptRef.log("ERROR: upgradeHomeRam() failed because you don't have enough money"); @@ -2546,15 +2538,7 @@ function NetscriptFunctions(workerScript) { } } - //Calculate how many times ram has been upgraded (doubled) - var currentRam = Player.getHomeComputer().maxRam; - var numUpgrades = Math.log2(currentRam); - - //Calculate cost - //Have cost increase by some percentage each time RAM has been upgraded - var cost = currentRam * CONSTANTS.BaseCostFor1GBOfRamHome; - var mult = Math.pow(1.55, numUpgrades); - return cost * mult; + return Player.getUpgradeHomeRamCost(); }, workForCompany : function() { var ramCost = CONSTANTS.ScriptSingularityFn2RamCost; diff --git a/src/Player.js b/src/Player.js index a8db3cdec..bdf6bbea0 100644 --- a/src/Player.js +++ b/src/Player.js @@ -405,6 +405,20 @@ PlayerObject.prototype.getHomeComputer = function() { return AllServers[this.homeComputer]; } +PlayerObject.prototype.getUpgradeHomeRamCost = function() { + //Calculate how many times ram has been upgraded (doubled) + const currentRam = Player.getHomeComputer().maxRam; + const numUpgrades = Math.log2(currentRam); + + //Calculate cost + //Have cost increase by some percentage each time RAM has been upgraded + const mult = Math.pow(1.58, numUpgrades); + var cost = currentRam * CONSTANTS.BaseCostFor1GBOfRamHome; + cost = cost * mult; + cost = cost.toPrecision(5); + return cost; +} + //Calculates skill level based on experience. The same formula will be used for every skill PlayerObject.prototype.calculateSkill = function(exp) { return Math.max(Math.floor(32 * Math.log(exp + 534.5) - 200), 1); From 7fbced64dee30f6875c44b072dde9602e385b3dd Mon Sep 17 00:00:00 2001 From: Olivier Gagnon Date: Thu, 7 Jun 2018 21:56:22 -0400 Subject: [PATCH 2/2] addressing comments --- src/Player.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/Player.js b/src/Player.js index bdf6bbea0..0f221b1be 100644 --- a/src/Player.js +++ b/src/Player.js @@ -413,8 +413,7 @@ PlayerObject.prototype.getUpgradeHomeRamCost = function() { //Calculate cost //Have cost increase by some percentage each time RAM has been upgraded const mult = Math.pow(1.58, numUpgrades); - var cost = currentRam * CONSTANTS.BaseCostFor1GBOfRamHome; - cost = cost * mult; + var cost = currentRam * CONSTANTS.BaseCostFor1GBOfRamHome * mult; cost = cost.toPrecision(5); return cost; }