softReset now accepts a callback script like installAugmentations

This commit is contained in:
Olivier Gagnon 2021-03-11 20:37:58 -05:00
parent 486d025572
commit cae28e2d25
3 changed files with 38 additions and 22 deletions

@ -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:<br>" + augmentationList +
"<br>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) {

@ -228,19 +228,24 @@ export let CONSTANTS: IMap<any> = {
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

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