Re=load everything problem when importing game

This commit is contained in:
Daniel Xie 2017-06-08 10:59:22 -05:00
parent b7b4617cee
commit 005216d664
2 changed files with 58 additions and 1 deletions

@ -541,7 +541,7 @@ CONSTANTS = {
"-Declining a faction invite will stop you from receiving invitations from that faction for the rest of the run<br>" + "-Declining a faction invite will stop you from receiving invitations from that faction for the rest of the run<br>" +
"-(BETA) Added functionality to export/import saves. WARNING This is only lightly tested. You cannot choose where to save your file " + "-(BETA) Added functionality to export/import saves. WARNING This is only lightly tested. You cannot choose where to save your file " +
"it just goes to the default save location. Also I have no idea what will happen if you try to import a file " + "it just goes to the default save location. Also I have no idea what will happen if you try to import a file " +
"that is not a valid save. I will address these in later updates<br>" + "that is not a valid save. I will address these in later updates<br><br>" +
"v0.20.0<br>" + "v0.20.0<br>" +
"-Refactored Netscript Interpreter code. Operations in Netscript should now run significantly faster (Every operation " + "-Refactored Netscript Interpreter code. Operations in Netscript should now run significantly faster (Every operation " +
"such as a variable assignment, a function call, a binary operator, getting a variable's value, etc. used to take up to several seconds, " + "such as a variable assignment, a function call, a binary operator, getting a variable's value, etc. used to take up to several seconds, " +
@ -652,6 +652,13 @@ CONSTANTS = {
"-You can now see what an Augmentation does and its price even while its locked<br><br>", "-You can now see what an Augmentation does and its price even while its locked<br><br>",
LatestUpdate: LatestUpdate:
"v0.20.1<br>" +
"-Fixed bug where sometimes scripts would crash without showing the error<br>" +
"-Added Deepscan programs to Dark Web<br>" +
"-Declining a faction invite will stop you from receiving invitations from that faction for the rest of the run<br>" +
"-(BETA) Added functionality to export/import saves. WARNING This is only lightly tested. You cannot choose where to save your file " +
"it just goes to the default save location. Also I have no idea what will happen if you try to import a file " +
"that is not a valid save. I will address these in later updates<br><br>" +
"v0.20.0<br>" + "v0.20.0<br>" +
"-Refactored Netscript Interpreter code. Operations in Netscript should now run significantly faster (Every operation " + "-Refactored Netscript Interpreter code. Operations in Netscript should now run significantly faster (Every operation " +
"such as a variable assignment, a function call, a binary operator, getting a variable's value, etc. used to take up to several seconds, " + "such as a variable assignment, a function call, a binary operator, getting a variable's value, etc. used to take up to several seconds, " +

@ -154,6 +154,56 @@ loadImportedGame = function(saveObj, saveString) {
dialogBoxCreate("Imported game"); dialogBoxCreate("Imported game");
gameOptionsBoxClose(); gameOptionsBoxClose();
//Re-start game
console.log("Importing game");
Engine.setDisplayElements(); //Sets variables for important DOM elements
Engine.init(); //Initialize buttons, work, etc.
CompanyPositions.init();
//Calculate the number of cycles have elapsed while offline
Engine._lastUpdate = new Date().getTime();
var lastUpdate = Player.lastUpdate;
var numCyclesOffline = Math.floor((Engine._lastUpdate - lastUpdate) / Engine._idleSpeed);
/* Process offline progress */
var offlineProductionFromScripts = loadAllRunningScripts(); //This also takes care of offline production for those scripts
if (Player.isWorking) {
console.log("work() called in load() for " + numCyclesOffline * Engine._idleSpeed + " milliseconds");
if (Player.workType == CONSTANTS.WorkTypeFaction) {
Player.workForFaction(numCyclesOffline);
} else if (Player.workType == CONSTANTS.WorkTypeCreateProgram) {
Player.createProgramWork(numCyclesOffline);
} else if (Player.workType == CONSTANTS.WorkTypeStudyClass) {
Player.takeClass(numCyclesOffline);
} else if (Player.workType == CONSTANTS.WorkTypeCrime) {
Player.commitCrime(numCyclesOffline);
} else if (Player.workType == CONSTANTS.WorkTypeCompanyPartTime) {
Player.workPartTime(numCyclesOffline);
} else {
Player.work(numCyclesOffline);
}
}
//Hacknet Nodes offline progress
var offlineProductionFromHacknetNodes = processAllHacknetNodeEarnings(numCyclesOffline);
//Passive faction rep gain offline
processPassiveFactionRepGain(numCyclesOffline);
//Update total playtime
var time = numCyclesOffline * Engine._idleSpeed;
if (Player.totalPlaytime == null) {Player.totalPlaytime = 0;}
Player.totalPlaytime += time;
//Re-apply augmentations
Player.reapplyAllAugmentations();
Player.lastUpdate = Engine._lastUpdate;
Engine.start(); //Run main game loop and Scripts loop
dialogBoxCreate("While you were offline, your scripts generated $" +
formatNumber(offlineProductionFromScripts, 2) + " and your Hacknet Nodes generated $" +
formatNumber(offlineProductionFromHacknetNodes, 2));
return true; return true;
} }