Add MPS calculation function

This commit is contained in:
Isaac Shoebottom 2023-11-03 17:01:47 -03:00
parent 536eebed56
commit f32ae59522

View File

@ -131,4 +131,19 @@ export function executeScriptOnServerFromAnother(ns: NS, server: string, script:
ns.rm(script, server);
}
)
}
/**
* Calculates the money per second the player is making
* @param ns Global NS object
* @param time=5 The number of seconds to calculate the MPS over
*/
export async function calculateMPS(ns: NS, time: number = 5) {
let start = ns.getServerMoneyAvailable("home");
let data: number[] = [];
for (let i = 0; i < time; i++) {
await ns.sleep(1000);
data.push(ns.getServerMoneyAvailable("home") - start);
}
return data.reduce((a, b) => a + b, 0) / time;
}