Implemented server growth (might need rebalancing). No wwhen a script is killed it is properly removed from the Active Scripts tab

This commit is contained in:
Daniel Xie
2016-12-20 14:18:34 -06:00
parent e2316e4a1d
commit f1ec376f33
6 changed files with 67 additions and 12 deletions

View File

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

View File

@@ -105,6 +105,9 @@ function runScriptsLoop() {
//Delete script from workerScripts
workerScripts.splice(i, 1);
//Delete script from Active Scripts
Engine.deleteActiveScriptsItem(i);
}
}

View File

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

View File

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

View File

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