From 005216d66451df869e103abac7897c5eee4498ee Mon Sep 17 00:00:00 2001 From: Daniel Xie Date: Thu, 8 Jun 2017 10:59:22 -0500 Subject: [PATCH] Re=load everything problem when importing game --- src/Constants.js | 9 ++++++++- src/SaveObject.js | 50 +++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 58 insertions(+), 1 deletion(-) diff --git a/src/Constants.js b/src/Constants.js index fbaa5119a..8c66dcd4e 100644 --- a/src/Constants.js +++ b/src/Constants.js @@ -541,7 +541,7 @@ CONSTANTS = { "-Declining a faction invite will stop you from receiving invitations from that faction for the rest of the run
" + "-(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
" + + "that is not a valid save. I will address these in later updates

" + "v0.20.0
" + "-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, " + @@ -652,6 +652,13 @@ CONSTANTS = { "-You can now see what an Augmentation does and its price even while its locked

", LatestUpdate: + "v0.20.1
" + + "-Fixed bug where sometimes scripts would crash without showing the error
" + + "-Added Deepscan programs to Dark Web
" + + "-Declining a faction invite will stop you from receiving invitations from that faction for the rest of the run
" + + "-(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

" + "v0.20.0
" + "-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, " + diff --git a/src/SaveObject.js b/src/SaveObject.js index 0f3129018..0197f49e7 100644 --- a/src/SaveObject.js +++ b/src/SaveObject.js @@ -154,6 +154,56 @@ loadImportedGame = function(saveObj, saveString) { dialogBoxCreate("Imported game"); 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; }