cleanup, download lit, log function
This commit is contained in:
+14
-5
@@ -3,8 +3,18 @@
|
||||
export async function main(ns) {
|
||||
ns.disableLog('ALL');
|
||||
|
||||
async function writeLog(obj) {
|
||||
await ns.tryWritePort(1, obj + '\n');
|
||||
async function writeLog(type, obj) {
|
||||
let timeNow = new Date();
|
||||
let year = timeNow.getFullYear().toString().substring(2);
|
||||
let month = (timeNow.getMonth() < 9 ? '0' : '') + (timeNow.getMonth() + 1);
|
||||
let day = (timeNow.getDate() < 10 ? '0' : '') + timeNow.getDate();
|
||||
let hour = (timeNow.getHours() < 10 ? '0' : '') + timeNow.getHours();
|
||||
let minute = (timeNow.getMinutes() < 10 ? '0' : '') + timeNow.getMinutes();
|
||||
let second = (timeNow.getSeconds() < 10 ? '0' : '') + timeNow.getSeconds();
|
||||
let timestamp = `${year}${month}${day}_${hour}${minute}${second}`;
|
||||
await ns.tryWritePort(1, `t${timestamp}_${type} = ${obj};\n`);
|
||||
|
||||
if (['ERROR', 'TERMINAL'].indexOf(type) != -1) ns.tprint(`${timestamp} ${type} = ${obj}`);
|
||||
}
|
||||
|
||||
let server = ns.args[0];
|
||||
@@ -38,8 +48,7 @@ export async function main(ns) {
|
||||
currentSecurity = ns.getServerSecurityLevel(server);
|
||||
}
|
||||
|
||||
await writeLog(`${server.replaceAll('-', '_')} = {loop: ${++loop}, hack: ${Math.floor(hackedMoney)}, money: ${Math.floor(currentMoney)} / ${Math.floor(maxMoney)} == ${((currentMoney / maxMoney) * 100).toFixed(2)}, security: ${currentSecurity.toFixed(2)} / ${Math.floor(minSecurity)} == ${((currentSecurity / minSecurity) * 100).toFixed(4)}};`);
|
||||
await ns.sleep(10);
|
||||
await writeLog('LOG', `${server.replaceAll('-', '_')} = {loop: ${++loop}, hack: ${Math.floor(hackedMoney)}, money: ${Math.floor(currentMoney)} / ${Math.floor(maxMoney)} == ${((currentMoney / maxMoney) * 100).toFixed(2)}, security: ${currentSecurity.toFixed(2)} / ${Math.floor(minSecurity)} == ${((currentSecurity / minSecurity) * 100).toFixed(4)}};`);
|
||||
await ns.sleep(50);
|
||||
}
|
||||
await ns.sleep(10);
|
||||
}
|
||||
Reference in New Issue
Block a user