From cae28e2d250ec15441caf7f43c55675d4e5b5987 Mon Sep 17 00:00:00 2001 From: Olivier Gagnon Date: Thu, 11 Mar 2021 20:37:58 -0500 Subject: [PATCH] softReset now accepts a callback script like installAugmentations --- src/Augmentation/AugmentationHelpers.jsx | 20 +------------- src/Constants.ts | 7 ++++- src/NetscriptFunctions.js | 33 ++++++++++++++++++++++-- 3 files changed, 38 insertions(+), 22 deletions(-) diff --git a/src/Augmentation/AugmentationHelpers.jsx b/src/Augmentation/AugmentationHelpers.jsx index fe82cf539..53f417c91 100644 --- a/src/Augmentation/AugmentationHelpers.jsx +++ b/src/Augmentation/AugmentationHelpers.jsx @@ -2054,7 +2054,7 @@ function applyAugmentation(aug, reapply=false) { } } -function installAugmentations(cbScript=null) { +function installAugmentations() { if (Player.queuedAugmentations.length == 0) { dialogBoxCreate("You have not purchased any Augmentations to install!"); return false; @@ -2074,24 +2074,6 @@ function installAugmentations(cbScript=null) { "to install the following Augmentations:
" + augmentationList + "
You wake up in your home...you feel different..."); prestigeAugmentation(); - - //Run a script after prestiging - if (cbScript && isString(cbScript)) { - var home = Player.getHomeComputer(); - for (const script of home.scripts) { - if (script.filename === cbScript) { - const ramUsage = script.ramUsage; - const ramAvailable = home.maxRam - home.ramUsed; - if (ramUsage > ramAvailable) { - return; // Not enough RAM - } - const runningScriptObj = new RunningScript(script, []); // No args - runningScriptObj.threads = 1; // Only 1 thread - - startWorkerScript(runningScriptObj, home); - } - } - } } function augmentationExists(name) { diff --git a/src/Constants.ts b/src/Constants.ts index 7120d6594..099b4f038 100644 --- a/src/Constants.ts +++ b/src/Constants.ts @@ -228,19 +228,24 @@ export let CONSTANTS: IMap = { LatestUpdate: ` - v0.49.0 - 2021-XX-XX Source-File -1 + v0.49.0 - 2021-03-11 Source-File -1 ------- Source-File -1 * For advanced players: The game now embraces exploits and will reward players for doing so. + Gang + * ascension is less effective as the ascension multiplier goes up. + * territory gain scales with power difference. + Netscript * 'gang.getEquipmentStats' returns the stats of the equipment. * 'gang.getTaskStats' returns the stats of a task. * 'getCrimeStats' returns the stats of a crime. * Crashes should now print the ns stack trace. * Log messages are now more consistent. + * 'softReset' now accepts a callback script like 'installAugmentations' Misc. * Minor formatting under Hacking>Active Scripts diff --git a/src/NetscriptFunctions.js b/src/NetscriptFunctions.js index 7bca5fc5a..8200244eb 100644 --- a/src/NetscriptFunctions.js +++ b/src/NetscriptFunctions.js @@ -74,6 +74,8 @@ import { AddToAllServers, createUniqueRandomIp, } from "./Server/AllServers"; +import { RunningScript } from "./Script/RunningScript"; +import { startWorkerScript } from "./NetscriptWorker"; import { Server } from "./Server/Server"; import { GetServerByHostname, @@ -529,6 +531,31 @@ function NetscriptFunctions(workerScript) { return Augmentations[name]; } + const runAfterReset = function(cbScript=null) { + //Run a script after reset + console.log(cbScript); + if (cbScript && isString(cbScript)) { + console.log('here'); + const home = Player.getHomeComputer(); + for (const script of home.scripts) { + console.log('here 2'+script); + if (script.filename === cbScript) { + console.log('here 3'); + const ramUsage = script.ramUsage; + const ramAvailable = home.maxRam - home.ramUsed; + if (ramUsage > ramAvailable) { + console.log('here 4'); + return; // Not enough RAM + } + const runningScriptObj = new RunningScript(script, []); // No args + runningScriptObj.threads = 1; // Only 1 thread + console.log('running!'); + startWorkerScript(runningScriptObj, home); + } + } + } + } + return { hacknet : { numNodes : function() { @@ -3242,7 +3269,8 @@ function NetscriptFunctions(workerScript) { workerScript.log("softReset", "Soft resetting. This will cause this script to be killed"); setTimeoutRef(() => { - prestigeAugmentation(cbScript); + prestigeAugmentation(); + runAfterReset(cbScript); }, 0); // Prevent workerScript from "finishing execution naturally" @@ -3260,7 +3288,8 @@ function NetscriptFunctions(workerScript) { Player.gainIntelligenceExp(CONSTANTS.IntelligenceSingFnBaseExpGain); workerScript.log("installAugmentations", "Installing Augmentations. This will cause this script to be killed"); setTimeoutRef(() => { - installAugmentations(cbScript); + installAugmentations(); + runAfterReset(cbScript); }, 0); workerScript.running = false; // Prevent workerScript from "finishing execution naturally"