From 2c53073f216ceba659bedf4ce8bb7282bb22d62b Mon Sep 17 00:00:00 2001 From: Daniel Xie Date: Thu, 4 May 2017 15:50:17 -0500 Subject: [PATCH] Format numbers to look nice, update info that is displayed on Character page --- css/menupages.css | 6 ++ src/Faction.js | 6 +- src/HacknetNode.js | 14 ++--- src/Player.js | 108 ++++++++++++++++----------------- src/engine.js | 81 +++++++++++++++++-------- utils/StringHelperFunctions.js | 8 +++ 6 files changed, 133 insertions(+), 90 deletions(-) diff --git a/css/menupages.css b/css/menupages.css index 558f25dc6..4a2d29212 100644 --- a/css/menupages.css +++ b/css/menupages.css @@ -4,10 +4,16 @@ /* Character Info */ #character-container { position: fixed; + height: 100%; padding-top: 10px; padding-left: 10px; margin-left: 10%; width: 99%; + overflow-y: scroll; +} + +#character-info { + overflow-y: scroll; } diff --git a/src/Faction.js b/src/Faction.js index d4e40723a..ddb2766c4 100644 --- a/src/Faction.js +++ b/src/Faction.js @@ -522,7 +522,7 @@ displayFactionContent = function(factionName) { var faction = Factions[factionName]; document.getElementById("faction-name").innerHTML = factionName; document.getElementById("faction-info").innerHTML = faction.info; - document.getElementById("faction-reputation").innerHTML = "Reputation: " + faction.playerReputation.toFixed(3); + document.getElementById("faction-reputation").innerHTML = "Reputation: " + formatNumber(faction.playerReputation, 4); var hackDiv = document.getElementById("faction-hack-div"); var fieldWorkDiv = document.getElementById("faction-fieldwork-div"); @@ -749,11 +749,11 @@ displayFactionAugmentations = function(factionName) { var req = aug.baseRepRequirement * faction.augmentationRepRequirementMult; if (faction.playerReputation >= req) { aElem.setAttribute("class", "a-link-button"); - pElem.innerHTML = "UNLOCKED - $" + aug.baseCost * faction.augmentationPriceMult; + pElem.innerHTML = "UNLOCKED - $" + formatNumber(aug.baseCost * faction.augmentationPriceMult, 2); //TODO Event listener for button to purchase augmentation } else { aElem.setAttribute("class", "a-link-button-inactive"); - pElem.innerHTML = "LOCKED (Requires " + req + " faction reputation)"; + pElem.innerHTML = "LOCKED (Requires " + formatNumber(req, 4) + " faction reputation)"; pElem.style.color = "red"; } aElem.style.display = "inline-block"; diff --git a/src/HacknetNode.js b/src/HacknetNode.js index 106a1144a..2b424936f 100644 --- a/src/HacknetNode.js +++ b/src/HacknetNode.js @@ -144,7 +144,7 @@ updateHacknetNodesContent = function() { //Set purchase button to inactive if not enough money, and update its price display var cost = getCostOfNextHacknetNode(); var purchaseButton = document.getElementById("hacknet-nodes-purchase-button"); - purchaseButton.innerHTML = "Purchase Hacknet Node - $" + cost.toFixed(2); + purchaseButton.innerHTML = "Purchase Hacknet Node - $" + formatNumber(cost, 2); if (cost > Player.money) { purchaseButton.setAttribute("class", "a-link-button-inactive"); } else { @@ -152,7 +152,7 @@ updateHacknetNodesContent = function() { } //Update player's money - document.getElementById("hacknet-nodes-money").innerHTML = "Money: $" + Player.money.toFixed(2); + document.getElementById("hacknet-nodes-money").innerHTML = "Money: $" + formatNumber(Player.money, 2); //Update information in each owned hacknet node for (var i = 0; i < Player.hacknetNodes.length; ++i) { @@ -228,8 +228,8 @@ updateHacknetNodeDomElement = function(nodeObj) { var txt = document.getElementById("hacknet-node-text-" + nodeName); if (txt == null) {throw new Error("Cannot find text element");} txt.innerHTML = "Node name: " + nodeName + "
" + - "Production: $" + nodeObj.totalMoneyGenerated.toFixed(2) + - " ($" + nodeObj.moneyGainRatePerSecond.toFixed(2) + " / second)
" + + "Production: $" + formatNumber(nodeObj.totalMoneyGenerated, 2) + + " ($" + formatNumber(nodeObj.moneyGainRatePerSecond, 2) + " / second)
" + "Level: " + nodeObj.level + "
" + "RAM: " + nodeObj.ram + "GB
" + "Cores: " + nodeObj.numCores; @@ -237,7 +237,7 @@ updateHacknetNodeDomElement = function(nodeObj) { var upgradeLevelButton = document.getElementById("hacknet-node-upgrade-level-" + nodeName); if (upgradeLevelButton == null) {throw new Error("Cannot find upgrade level button element");} var upgradeLevelCost = nodeObj.calculateLevelUpgradeCost(); - upgradeLevelButton.innerHTML = "Upgrade Hacknet Node Level - $" + upgradeLevelCost.toFixed(2); + upgradeLevelButton.innerHTML = "Upgrade Hacknet Node Level - $" + formatNumber(upgradeLevelCost, 2); if (upgradeLevelCost > Player.money) { upgradeLevelButton.setAttribute("class", "a-link-button-inactive"); } else { @@ -247,7 +247,7 @@ updateHacknetNodeDomElement = function(nodeObj) { var upgradeRamButton = document.getElementById("hacknet-node-upgrade-ram-" + nodeName); if (upgradeRamButton == null) {throw new Error("Cannot find upgrade ram button element");} var upgradeRamCost = nodeObj.calculateRamUpgradeCost(); - upgradeRamButton.innerHTML = "Upgrade Hacknet Node RAM -$" + upgradeRamCost.toFixed(2); + upgradeRamButton.innerHTML = "Upgrade Hacknet Node RAM -$" + formatNumber(upgradeRamCost, 2); if (upgradeRamCost > Player.money) { upgradeRamButton.setAttribute("class", "a-link-button-inactive"); } else { @@ -257,7 +257,7 @@ updateHacknetNodeDomElement = function(nodeObj) { var upgradeCoreButton = document.getElementById("hacknet-node-upgrade-core-" + nodeName); if (upgradeCoreButton == null) {throw new Error("Cannot find upgrade cores button element");} var upgradeCoreCost = nodeObj.calculateCoreUpgradeCost(); - upgradeCoreButton.innerHTML = "Purchase additional CPU Core - $" + upgradeCoreCost.toFixed(2); + upgradeCoreButton.innerHTML = "Purchase additional CPU Core - $" + formatNumber(upgradeCoreCost, 2); if (upgradeCoreCost > Player.money) { upgradeCoreButton.setAttribute("class", "a-link-button-inactive"); } else { diff --git a/src/Player.js b/src/Player.js index a0f5f085d..b54bd00e4 100644 --- a/src/Player.js +++ b/src/Player.js @@ -384,26 +384,26 @@ PlayerObject.prototype.finishWork = function(cancelled) { txt = "You worked a short shift of " + convertTimeMsToTimeElapsedString(this.timeWorked) + "

" + "Since you cancelled your work early, you only gained half of the experience, money, and reputation you earned.

" + "You earned a total of:
" + - "$" + (this.workMoneyGained / cancMult).toFixed(2) + "
" + - (this.workRepGained / cancMult).toFixed(3) + " reputation for the company
" + - (this.workHackExpGained / cancMult).toFixed(3) + " hacking exp
" + - (this.workStrExpGained / cancMult).toFixed(3) + " strength exp
" + - (this.workDefExpGained / cancMult).toFixed(3) + " defense exp
" + - (this.workDexExpGained / cancMult).toFixed(3) + " dexterity exp
" + - (this.workAgiExpGained / cancMult).toFixed(3) + " agility exp
" + - (this.workChaExpGained / cancMult).toFixed(3) + " charisma exp
"; + "$" + formatNumber(this.workMoneyGained / cancMult, 2) + "
" + + formatNumber(this.workRepGained / cancMult, 4) + " reputation for the company
" + + formatNumber(this.workHackExpGained / cancMult, 4) + " hacking exp
" + + formatNumber(this.workStrExpGained / cancMult, 4) + " strength exp
" + + formatNumber(this.workDefExpGained / cancMult, 4) + " defense exp
" + + formatNumber(this.workDexExpGained / cancMult, 4) + " dexterity exp
" + + formatNumber(this.workAgiExpGained / cancMult, 4) + " agility exp
" + + formatNumber(this.workChaExpGained / cancMult, 4) + " charisma exp
"; } else { txt = "You worked a full shift of 8 hours!

" + "You earned a total of:
" + - "$" + (this.workMoneyGained / cancMult) + "
" + - (this.workRepGained / cancMult).toFixed(3) + " reputation for the company
" + - (this.workHackExpGained / cancMult).toFixed(3) + " hacking exp
" + - (this.workStrExpGained / cancMult).toFixed(3) + " strength exp
" + - (this.workDefExpGained / cancMult).toFixed(3) + " defense exp
" + - (this.workDexExpGained / cancMult).toFixed(3) + " dexterity exp
" + - (this.workAgiExpGained / cancMult).toFixed(3) + " agility exp
" + - (this.workChaExpGained / cancMult).toFixed(3) + " charisma exp
"; + "$" + formatNumber(this.workMoneyGained / cancMult, 2) + "
" + + formatNumber(this.workRepGained / cancMult, 4) + " reputation for the company
" + + formatNumber(this.workHackExpGained / cancMult, 4) + " hacking exp
" + + formatNumber(this.workStrExpGained / cancMult, 4) + " strength exp
" + + formatNumber(this.workDefExpGained / cancMult, 4) + " defense exp
" + + formatNumber(this.workDexExpGained / cancMult, 4) + " dexterity exp
" + + formatNumber(this.workAgiExpGained / cancMult, 4) + " agility exp
" + + formatNumber(this.workChaExpGained / cancMult, 4) + " charisma exp
"; } dialogBoxCreate(txt); @@ -481,14 +481,14 @@ PlayerObject.prototype.work = function(numCycles) { " at " + Player.companyName + "

" + "You have been working for " + convertTimeMsToTimeElapsedString(this.timeWorked) + "

" + "You have earned:

" + - "$" + this.workMoneyGained.toFixed(2) + " ($" + (this.workMoneyGainRate * cyclesPerSec).toFixed(2) + " / sec)

" + - this.workRepGained.toFixed(3) + " (" + (this.workRepGainRate * cyclesPerSec).toFixed(3) + " / sec) reputation for this company

" + - this.workHackExpGained.toFixed(3) + " (" + (this.workHackExpGainRate * cyclesPerSec).toFixed(3) + " / sec) hacking exp

" + - this.workStrExpGained.toFixed(3) + " (" + (this.workStrExpGainRate * cyclesPerSec).toFixed(3) + " / sec) strength exp
" + - this.workDefExpGained.toFixed(3) + " (" + (this.workDefExpGainRate * cyclesPerSec).toFixed(3) + " / sec) defense exp
" + - this.workDexExpGained.toFixed(3) + " (" + (this.workDexExpGainRate * cyclesPerSec).toFixed(3) + " / sec) dexterity exp
" + - this.workAgiExpGained.toFixed(3) + " (" + (this.workAgiExpGainRate * cyclesPerSec).toFixed(3) + " / sec) agility exp

" + - this.workChaExpGained.toFixed(3) + " (" + (this.workChaExpGainRate * cyclesPerSec).toFixed(3) + " / sec) charisma exp

" + + "$" + formatNumber(this.workMoneyGained, 2) + " ($" + formatNumber(this.workMoneyGainRate * cyclesPerSec, 2) + " / sec)

" + + formatNumber(this.workRepGained, 4) + " (" + formatNumber(this.workRepGainRate * cyclesPerSec, 4) + " / sec) reputation for this company

" + + formatNumber(this.workHackExpGained, 4) + " (" + formatNumber(this.workHackExpGainRate * cyclesPerSec, 4) + " / sec) hacking exp

" + + formatNumber(this.workStrExpGained, 4) + " (" + formatNumber(this.workStrExpGainRate * cyclesPerSec, 4) + " / sec) strength exp
" + + formatNumber(this.workDefExpGained, 4) + " (" + formatNumber(this.workDefExpGainRate * cyclesPerSec, 4) + " / sec) defense exp
" + + formatNumber(this.workDexExpGained, 4) + " (" + formatNumber(this.workDexExpGainRate * cyclesPerSec, 4) + " / sec) dexterity exp
" + + formatNumber(this.workAgiExpGained, 4) + " (" + formatNumber(this.workAgiExpGainRate * cyclesPerSec, 4) + " / sec) agility exp

" + + formatNumber(this.workChaExpGained, 4) + " (" + formatNumber(this.workChaExpGainRate * cyclesPerSec, 4) + " / sec) charisma exp

" + "You will automatically finish after working for 8 hours. You can cancel earlier if you wish,
" + @@ -509,14 +509,14 @@ PlayerObject.prototype.finishFactionWork = function(cancelled, faction) { var txt = "You worked for your faction " + faction.name + " for a total of " + convertTimeMsToTimeElapsedString(this.timeWorked) + "

" + "You earned a total of:
" + - "$" + (this.workMoneyGained).toFixed(2) + "
" + - (this.workRepGained).toFixed(3) + " reputation for the faction
" + - (this.workHackExpGained).toFixed(3) + " hacking exp
" + - (this.workStrExpGained).toFixed(3) + " strength exp
" + - (this.workDefExpGained).toFixed(3) + " defense exp
" + - (this.workDexExpGained).toFixed(3) + " dexterity exp
" + - (this.workAgiExpGained).toFixed(3) + " agility exp
" + - (this.workChaExpGained).toFixed(3) + " charisma exp
"; + "$" + formatNumber(this.workMoneyGained, 2) + "
" + + formatNumber(this.workRepGained, 4) + " reputation for the faction
" + + formatNumber(this.workHackExpGained, 4) + " hacking exp
" + + formatNumber(this.workStrExpGained, 4) + " strength exp
" + + formatNumber(this.workDefExpGained, 4) + " defense exp
" + + formatNumber(this.workDexExpGained, 4) + " dexterity exp
" + + formatNumber(this.workAgiExpGained, 4) + " agility exp
" + + formatNumber(this.workChaExpGained, 4) + " charisma exp
"; dialogBoxCreate(txt); var mainMenu = document.getElementById("mainmenu-container"); @@ -644,14 +644,14 @@ PlayerObject.prototype.workForFaction = function(numCycles) { txt.innerHTML = "You are currently " + this.currentWorkFactionDescription + " for your faction " + faction.name + "." + "You have been doing this for " + convertTimeMsToTimeElapsedString(this.timeWorked) + "

" + "You have earned:

" + - "$" + this.workMoneyGained + " (" + (this.workMoneyGainRate * cyclesPerSec).toFixed(2) + " / sec)

" + - this.workRepGained.toFixed(3) + " (" + (this.workRepGainRate * cyclesPerSec).toFixed(3) + " / sec) reputation for this faction

" + - this.workHackExpGained.toFixed(3) + " (" + (this.workHackExpGainRate * cyclesPerSec).toFixed(3) + " / sec) hacking exp

" + - this.workStrExpGained.toFixed(3) + " (" + (this.workStrExpGainRate * cyclesPerSec).toFixed(3) + " / sec) strength exp
" + - this.workDefExpGained.toFixed(3) + " (" + (this.workDefExpGainRate * cyclesPerSec).toFixed(3) + " / sec) defense exp
" + - this.workDexExpGained.toFixed(3) + " (" + (this.workDexExpGainRate * cyclesPerSec).toFixed(3) + " / sec) dexterity exp
" + - this.workAgiExpGained.toFixed(3) + " (" + (this.workAgiExpGainRate * cyclesPerSec).toFixed(3) + " / sec) agility exp

" + - this.workChaExpGained.toFixed(3) + " (" + (this.workChaExpGainRate * cyclesPerSec).toFixed(3) + " / sec) charisma exp

" + + "$" + formatNumber(this.workMoneyGained, 2) + " (" + formatNumber(this.workMoneyGainRate * cyclesPerSec, 2) + " / sec)

" + + formatNumber(this.workRepGained, 4) + " (" + formatNumber(this.workRepGainRate * cyclesPerSec, 4) + " / sec) reputation for this faction

" + + formatNumber(this.workHackExpGained, 4) + " (" + formatNumber(this.workHackExpGainRate * cyclesPerSec, 4) + " / sec) hacking exp

" + + formatNumber(this.workStrExpGained, 4) + " (" + formatNumber(this.workStrExpGainRate * cyclesPerSec, 4) + " / sec) strength exp
" + + formatNumber(this.workDefExpGained, 4) + " (" + formatNumber(this.workDefExpGainRate * cyclesPerSec, 4) + " / sec) defense exp
" + + formatNumber(this.workDexExpGained, 4) + " (" + formatNumber(this.workDexExpGainRate * cyclesPerSec, 4) + " / sec) dexterity exp
" + + formatNumber(this.workAgiExpGained, 4) + " (" + formatNumber(this.workAgiExpGainRate * cyclesPerSec, 4) + " / sec) agility exp

" + + formatNumber(this.workChaExpGained, 4) + " (" + formatNumber(this.workChaExpGainRate * cyclesPerSec, 4) + " / sec) charisma exp

" + "You will automatically finish after working for 20 hours. You can cancel earlier if you wish.
" + "There is no penalty for cancelling earlier."; @@ -878,14 +878,14 @@ PlayerObject.prototype.takeClass = function(numCycles) { var txt = document.getElementById("work-in-progress-text"); txt.innerHTML = "You have been " + className + " for " + convertTimeMsToTimeElapsedString(this.timeWorked) + ".

" + "This has cost you:
" + - "$" + this.workMoneyGained.toFixed(2) + " ($" + (this.workMoneyLossRate * cyclesPerSec).toFixed(2) + " / sec)

" + + "$" + formatNumber(this.workMoneyGained, 2) + " ($" + formatNumber(this.workMoneyLossRate * cyclesPerSec, 2) + " / sec)

" + "You have gained:
" + - this.workHackExpGained.toFixed(3) + " (" + (this.workHackExpGainRate * cyclesPerSec).toFixed(3) + " / sec) hacking exp
" + - this.workStrExpGained.toFixed(3) + " (" + (this.workStrExpGainRate * cyclesPerSec).toFixed(3) + " / sec) strength exp
" + - this.workDefExpGained.toFixed(3) + " (" + (this.workDefExpGainRate * cyclesPerSec).toFixed(3) + " / sec) defense exp
" + - this.workDexExpGained.toFixed(3) + " (" + (this.workDexExpGainRate * cyclesPerSec).toFixed(3) + " / sec) dexterity exp
" + - this.workAgiExpGained.toFixed(3) + " (" + (this.workAgiExpGainRate * cyclesPerSec).toFixed(3) + " / sec) agility exp
" + - this.workChaExpGained.toFixed(3) + " (" + (this.workChaExpGainRate * cyclesPerSec).toFixed(3) + " / sec) charisma exp
" + + formatNumber(this.workHackExpGained, 4) + " (" + formatNumber(this.workHackExpGainRate * cyclesPerSec, 4) + " / sec) hacking exp
" + + formatNumber(this.workDefExpGained, 4) + " (" + formatNumber(this.workDefExpGainRate * cyclesPerSec, 4) + " / sec) defense exp
" + + formatNumber(this.workStrExpGained, 4) + " (" + formatNumber(this.workStrExpGainRate * cyclesPerSec, 4) + " / sec) strength exp
" + + formatNumber(this.workDexExpGained, 4) + " (" + formatNumber(this.workDexExpGainRate * cyclesPerSec, 4) + " / sec) dexterity exp
" + + formatNumber(this.workAgiExpGained, 4) + " (" + formatNumber(this.workAgiExpGainRate * cyclesPerSec, 4) + " / sec) agility exp
" + + formatNumber(this.workChaExpGained, 4) + " (" + formatNumber(this.workChaExpGainRate * cyclesPerSec, 4) + " / sec) charisma exp
" + "You may cancel at any time"; } @@ -899,14 +899,14 @@ PlayerObject.prototype.finishClass = function() { this.updateSkillLevels(); var txt = "After " + this.className + " for " + convertTimeMsToTimeElapsedString(this.timeWorked) + ",
" + - "you spent a total of $" + this.workMoneyGained * -1 + ".

" + + "you spent a total of $" + formatNumber(this.workMoneyGained * -1, 2) + ".

" + "You earned a total of:
" + - (this.workHackExpGained).toFixed(3) + " hacking exp
" + - (this.workStrExpGained).toFixed(3) + " strength exp
" + - (this.workDefExpGained).toFixed(3) + " defense exp
" + - (this.workDexExpGained).toFixed(3) + " dexterity exp
" + - (this.workAgiExpGained).toFixed(3) + " agility exp
" + - (this.workChaExpGained).toFixed(3) + " charisma exp
"; + formatNumber(this.workHackExpGained, 4) + " hacking exp
" + + formatNumber(this.workStrExpGained, 4) + " strength exp
" + + formatNumber(this.workDefExpGained, 4) + " defense exp
" + + formatNumber(this.workDexExpGained, 4) + " dexterity exp
" + + formatNumber(this.workAgiExpGained, 4) + " agility exp
" + + formatNumber(this.workChaExpGained, 4) + " charisma exp
"; dialogBoxCreate(txt); diff --git a/src/engine.js b/src/engine.js index 324a0c2d9..b3ec2e5df 100644 --- a/src/engine.js +++ b/src/engine.js @@ -311,24 +311,53 @@ var Engine = { if (Player.companyPosition != "") { companyPosition = Player.companyPosition.positionName; } - Engine.Display.characterInfo.innerHTML = 'Current City: ' + Player.city + '

' + - 'Employer: ' + Player.companyName + '

' + - 'Job Title: ' + companyPosition + '



' + - 'Money: $' + (Player.money.toFixed(2)).toLocaleString() + '

' + - 'Hacking Level: ' + (Player.hacking_skill).toLocaleString() + '

' + - 'Strength: ' + (Player.strength).toLocaleString() + '

' + - 'Defense: ' + (Player.defense).toLocaleString() + '

' + - 'Dexterity: ' + (Player.dexterity).toLocaleString() + '

' + - 'Agility: ' + (Player.agility).toLocaleString() + '

' + - 'Charisma: ' + (Player.charisma).toLocaleString() + '

' + - 'Servers owned: ' + Player.purchasedServers.length + '

' + - 'Hacknet Nodes owned: ' + Player.hacknetNodes.length + '

' + - 'Hacking experience: ' + (Player.hacking_exp.toFixed(4)).toLocaleString() + '

' + - 'Strength experience: ' + (Player.strength_exp.toFixed(4)).toLocaleString() + '

' + - 'Defense experience: ' + (Player.defense_exp.toFixed(4)).toLocaleString() + '

' + - 'Dexterity experience: ' + (Player.dexterity_exp.toFixed(4)).toLocaleString() + '

' + - 'Agility experience: ' + (Player.agility_exp.toFixed(4)).toLocaleString() + '

' + - 'Charisma experience: ' + (Player.charisma_exp.toFixed(4)).toLocaleString(); + Engine.Display.characterInfo.innerHTML = + 'General

' + + 'Current City: ' + Player.city + '

' + + 'Employer: ' + Player.companyName + '
' + + 'Job Title: ' + companyPosition + '

' + + 'Money: $' + formatNumber(Player.money, 2)+ '


' + + 'Stats

' + + 'Hacking Level: ' + (Player.hacking_skill).toLocaleString() + + " (" + formatNumber(Player.hacking_exp, 4) + ' experience)
' + + 'Strength: ' + (Player.strength).toLocaleString() + + " (" + formatNumber(Player.strength_exp, 4) + ' experience)
' + + 'Defense: ' + (Player.defense).toLocaleString() + + " (" + formatNumber(Player.defense_exp, 4) + ' experience)
' + + 'Dexterity: ' + (Player.dexterity).toLocaleString() + + " (" + formatNumber(Player.dexterity_exp, 4) + ' experience)
' + + 'Agility: ' + (Player.agility).toLocaleString() + + " (" + formatNumber(Player.agility_exp, 4) + ' experience)
' + + 'Charisma: ' + (Player.charisma).toLocaleString() + + " (" + formatNumber(Player.charisma_exp, 4) + ' experience)


' + + 'Multipliers

' + + 'Hacking Chance multiplier: ' + formatNumber(Player.hacking_chance_mult * 100, 2) + '%
' + + 'Hacking Speed multiplier: ' + formatNumber(Player.hacking_speed_mult * 100, 2) + '%
' + + 'Hacking money multiplier: ' + formatNumber(Player.hacking_money_mult * 100, 2) + '%

' + + 'Hacking Level multiplier: ' + formatNumber(Player.hacking_mult * 100, 2) + '%
' + + 'Hacking Experience multiplier: ' + formatNumber(Player.hacking_exp_mult * 100, 2) + '%

' + + 'Strength Level multiplier: ' + formatNumber(Player.strength_mult * 100, 2) + '%
' + + 'Strength Experience multiplier: ' + formatNumber(Player.strength_exp_mult * 100, 2) + '%

' + + 'Defense Level multiplier: ' + formatNumber(Player.defense_mult * 100, 2) + '%
' + + 'Defense Experience multiplier: ' + formatNumber(Player.defense_exp_mult * 100, 2) + '%

' + + 'Dexterity Level multiplier: ' + formatNumber(Player.dexterity_mult * 100, 2) + '%
' + + 'Dexterity Experience multiplier: ' + formatNumber(Player.dexterity_exp_mult * 100, 2) + '%

' + + 'Agility Level multiplier: ' + formatNumber(Player.agility_mult * 100, 2) + '%
' + + 'Agility Experience multiplier: ' + formatNumber(Player.agility_exp_mult * 100, 2) + '%

' + + 'Charisma Level multiplier: ' + formatNumber(Player.charisma_mult * 100, 2) + '%
' + + 'Charisma Experience multiplier: ' + formatNumber(Player.charisma_exp_mult * 100, 2) + '%

' + + 'Hacknet Node production multiplier: ' + formatNumber(Player.hacknet_node_money_mult * 100, 2) + '%
' + + 'Hacknet Node purchase cost multiplier: '+ formatNumber(Player.hacknet_node_purchase_cost_mult * 100, 2) + '%
' + + 'Hacknet Node RAM upgrade cost multiplier: ' + formatNumber(Player.hacknet_node_ram_cost_mult * 100, 2) + '%
' + + 'Hacknet Node Core purchase cost multiplier: ' + formatNumber(Player.hacknet_node_core_cost_mult * 100, 2) + '%
' + + 'Hacknet Node level upgrade cost multiplier: ' + formatNumber(Player.hacknet_node_level_cost_mult * 100, 2) + '%

' + + 'Company reputation gain multiplier: ' + formatNumber(Player.company_rep_mult * 100, 2) + '%
' + + 'Faction reputation gain multiplier: ' + formatNumber(Player.faction_rep_mult * 100, 2) + '%
' + + 'Salary multiplier: ' + formatNumber(Player.work_money_mult * 100, 2) + '%


' + + 'Misc

' + + 'Servers owned: ' + Player.purchasedServers.length + '
' + + 'Hacknet Nodes owned: ' + Player.hacknetNodes.length + '
'; + }, /* Display locations in the world*/ @@ -436,22 +465,22 @@ var Engine = { var serverIpHostname = "Server: " + hostname + "(" + workerscript.serverIp + ")"; //Online - var onlineTotalMoneyMade = "Total online production: $" + workerscript.scriptRef.onlineMoneyMade.toFixed(2); - var onlineTotalExpEarned = (Array(26).join(" ") + workerscript.scriptRef.onlineExpGained.toFixed(2) + " exp").replace( / /g, " "); + var onlineTotalMoneyMade = "Total online production: $" + formatNumber(workerscript.scriptRef.onlineMoneyMade, 2); + var onlineTotalExpEarned = (Array(26).join(" ") + formatNumber(workerscript.scriptRef.onlineExpGained, 2) + " hacking exp").replace( / /g, " "); var onlineMps = workerscript.scriptRef.onlineMoneyMade / workerscript.scriptRef.onlineRunningTime; - var onlineMpsText = "Online production rate: $" + onlineMps.toFixed(2) + "/second"; + var onlineMpsText = "Online production rate: $" + formatNumber(onlineMps, 2) + "/second"; var onlineEps = workerscript.scriptRef.onlineExpGained / workerscript.scriptRef.onlineRunningTime; - var onlineEpsText = (Array(25).join(" ") + onlineEps.toFixed(4) + " exp/second").replace( / /g, " "); + var onlineEpsText = (Array(25).join(" ") + formatNumber(onlineEps, 4) + " hacking exp/second").replace( / /g, " "); //Offline - var offlineTotalMoneyMade = "Total offline production: $" + workerscript.scriptRef.offlineMoneyMade.toFixed(2); - var offlineTotalExpEarned = (Array(27).join(" ") + workerscript.scriptRef.offlineExpGained.toFixed(2) + " exp").replace( / /g, " "); + var offlineTotalMoneyMade = "Total offline production: $" + formatNumber(workerscript.scriptRef.offlineMoneyMade, 2); + var offlineTotalExpEarned = (Array(27).join(" ") + formatNumber(workerscript.scriptRef.offlineExpGained, 2) + " hacking exp").replace( / /g, " "); var offlineMps = workerscript.scriptRef.offlineMoneyMade / workerscript.scriptRef.offlineRunningTime; - var offlineMpsText = "Offline production rate: $" + offlineMps.toFixed(2) + "/second"; + var offlineMpsText = "Offline production rate: $" + formatNumber(offlineMps, 2) + "/second"; var offlineEps = workerscript.scriptRef.offlineExpGained / workerscript.scriptRef.offlineRunningTime; - var offlineEpsText = (Array(26).join(" ") + offlineEps.toFixed(4) + " exp/second").replace( / /g, " "); + var offlineEpsText = (Array(26).join(" ") + formatNumber(offlineEps, 4) + " hacking exp/second").replace( / /g, " "); itemText.innerHTML = serverIpHostname + "
" + onlineTotalMoneyMade + "
" + onlineTotalExpEarned + "
" + onlineMpsText + "
" + onlineEpsText + "
" + offlineTotalMoneyMade + "
" + offlineTotalExpEarned + "
" + diff --git a/utils/StringHelperFunctions.js b/utils/StringHelperFunctions.js index a61a78687..a97224d46 100644 --- a/utils/StringHelperFunctions.js +++ b/utils/StringHelperFunctions.js @@ -63,4 +63,12 @@ function isString(str) { //Returns whether an array contains entirely of string objects function containsAllStrings(arr) { return arr.every(isString); +} + +//Formats a number with commas and a specific number of decimal digits +function formatNumber(num, numFractionDigits) { + return num.toLocaleString(undefined, { + minimumFractionDigits: numFractionDigits, + maximumFractionDigits: numFractionDigits + }); } \ No newline at end of file