From f1ec376f33a881ce9fc746649267cc75ecc1f418 Mon Sep 17 00:00:00 2001 From: Daniel Xie Date: Tue, 20 Dec 2016 14:18:34 -0600 Subject: [PATCH] Implemented server growth (might need rebalancing). No wwhen a script is killed it is properly removed from the Active Scripts tab --- README.md | 11 ++++++++++- src/Faction.js | 1 + src/Netscript/NetscriptWorker.js | 3 +++ src/Script.js | 4 +--- src/Server.js | 32 ++++++++++++++++++++++++++------ src/engine.js | 28 ++++++++++++++++++++++++++-- 6 files changed, 67 insertions(+), 12 deletions(-) diff --git a/README.md b/README.md index 489b0163e..868df59a4 100644 --- a/README.md +++ b/README.md @@ -28,12 +28,21 @@ TESTING TODO: Seems to work, at least the basics (for online production) Script offline progress + Delete a script from Active scripts when the WorkerScript is deleted + Seems to work + + Server growth + Implemented but it might need to be balance/formula readjusted + + Tasks TODO: ctrl+C functionality for all running command like hack(), analyze(), and tail Scroll all the way down when something is post()ed Script logging functionality? Logs to internal "log file" (property of script itself) Tutorial and help - Server growth + Secret Servers + + Purchasing Servers Hack time formula needs rebalancing I think diff --git a/src/Faction.js b/src/Faction.js index f4c3a0f32..989fe77f8 100644 --- a/src/Faction.js +++ b/src/Faction.js @@ -19,6 +19,7 @@ Faction.prototype.setAugmentations = function(augs) { } } +Factions = {} Factions = { //TODO Saving this for later, IShima is a kinda cool name maybe use it for something //Endgame diff --git a/src/Netscript/NetscriptWorker.js b/src/Netscript/NetscriptWorker.js index f531686f9..aec1dd930 100644 --- a/src/Netscript/NetscriptWorker.js +++ b/src/Netscript/NetscriptWorker.js @@ -105,6 +105,9 @@ function runScriptsLoop() { //Delete script from workerScripts workerScripts.splice(i, 1); + + //Delete script from Active Scripts + Engine.deleteActiveScriptsItem(i); } } diff --git a/src/Script.js b/src/Script.js index 549419dba..2cdd83e6f 100644 --- a/src/Script.js +++ b/src/Script.js @@ -196,9 +196,7 @@ scriptCalculateOfflineProduction = function(script) { script.offlineMoneyMade += production; script.offlineRunningTime += timePassed; script.offlineExpGained += expGain; - - //TODO EXP - + //DEBUG var serverName = AllServers[script.server].hostname; console.log(script.filename + " from server " + serverName + " generated $" + production.toString() + " while offline"); diff --git a/src/Server.js b/src/Server.js index 285d8fc8e..be3aecce2 100644 --- a/src/Server.js +++ b/src/Server.js @@ -32,11 +32,11 @@ function Server() { //Total money available on this server. How much of this you hack will be determined //by a formula related to hacking skill. The money available on a server will steadily increase //over time, and it will decrease when you hack it - this.moneyAvailable = 500; + this.moneyAvailable = 0; //Parameters used in formulas that dictate how moneyAvailable and requiredHackingSkill change. this.hackDifficulty = 1; //Affects hack success rate and how the requiredHackingSkill increases over time (1-100) - this.serverGrowth = 1; //Affects how the moneyAvailable increases (1-100) + this.serverGrowth = 0; //Affects how the moneyAvailable increases (0-100) this.timesHacked = 0; //The IP's of all servers reachable from this one (what shows up if you run scan/netstat) @@ -111,11 +111,8 @@ Server.fromJSON = function(value) { Reviver.constructors.Server = Server; - - //world_daemon: new Server(), //Final server for 2nd tier prestige. Discover that the world is a simulation - /* Initialization. Called only when loading a new game( no save file) */ initForeignServers = function() { //MegaCorporations @@ -607,6 +604,29 @@ initForeignServers = function() { } }, + +//Server growth +processServerGrowth = function(numCycles) { + var numServerGrowthCycles = Math.max(Math.floor(numCycles / 450), 0); + + for (var ip in AllServers) { + if (AllServers.hasOwnProperty(ip)) { + var server = AllServers[ip]; + + //Get the number of server growth cycles that will be applied based on the + //server's serverGrowth property + var serverGrowthPercentage = server.serverGrowth / 100; + var numServerGrowthCyclesAdjusted = numServerGrowthCycles * serverGrowthPercentage; + + //Apply serverGrowth for the calculated number of growth cycles + var serverGrowth = Math.pow(1.0001, numServerGrowthCyclesAdjusted); + console.log("serverGrowth ratio: " + serverGrowth); + server.moneyAvailable *= serverGrowth; + } + } + console.log("Server growth processed for " + numServerGrowthCycles + " cycles"); +}, + //List of all servers that exist in the game, indexed by their ip AllServers = {}; @@ -637,7 +657,7 @@ GetServerByHostname = function(hostname) { for (var ip in AllServers) { if (AllServers.hasOwnProperty(ip)) { if (AllServers[ip].hostname == hostname) { - return AllServers[i]; + return AllServers[ip]; } } } diff --git a/src/engine.js b/src/engine.js index d82d2e357..23daeaa47 100644 --- a/src/engine.js +++ b/src/engine.js @@ -181,6 +181,16 @@ var Engine = { Engine.ActiveScriptsList.appendChild(item); }, + deleteActiveScriptsItem: function(i) { + var list = Engine.ActiveScriptsList.querySelectorAll('#active-scripts-list li'); + if (i >= list.length) { + throw new Error("Trying to delete an out-of-range Active Scripts item"); + } + + var li = list[i]; + li.parentNode.removeChild(li); + }, + //Update the ActiveScriptsItems array updateActiveScriptsItems: function() { for (var i = 0; i < workerScripts.length; ++i) { @@ -216,7 +226,7 @@ var Engine = { //Server ip/hostname var hostname = workerscript.getServer().hostname; - var serverIpHostname = "Server: " + hostname + " (" + workerscript.serverIp + ")"; + var serverIpHostname = "Server: " + hostname + "(" + workerscript.serverIp + ")"; //Online var onlineMps = workerscript.scriptRef.onlineMoneyMade / workerscript.scriptRef.onlineRunningTime; @@ -285,6 +295,7 @@ var Engine = { autoSaveCounter: 300, //Autosave every minute updateSkillLevelsCounter: 10, //Only update skill levels every 2 seconds. Might improve performance updateDisplays: 10, //Update displays such as Active Scripts display and character display + serverGrowth: 450, //Process server growth every minute and a half }, decrementAllCounters: function(numCycles = 1) { @@ -317,6 +328,12 @@ var Engine = { Engine.Counters.updateDisplays = 10; } + + if (Engine.Counters.serverGrowth <= 0) { + var numCycles = Math.floor((450 - Engine.Counters.serverGrowth)); + processServerGrowth(numCycles); + Engine.Counters.serverGrowth = 450; + } }, /* Calculates the hack progress for a manual (non-scripted) hack and updates the progress bar/time accordingly */ @@ -363,7 +380,14 @@ var Engine = { if (Engine.loadSave()) { console.log("Loaded game from save"); CompanyPositions.init(); - loadAllRunningScripts(); //This also takes care of offline production + + //Calculate the number of cycles have elapsed while offline + var thisUpdate = new Date().getTime(); + var lastUpdate = Player.lastUpdate; + var numCyclesOffline = Math.floor((thisUpdate - lastUpdate) / Engine._idleSpeed); + + processServerGrowth(numCyclesOffline); //Should be done before offline production for scripts + loadAllRunningScripts(); //This also takes care of offline production for those scripts } else { //No save found, start new game console.log("Initializing new game");