From eacf13bc533e2408af896f77e8918b1eb0049c08 Mon Sep 17 00:00:00 2001 From: Philipp Date: Thu, 17 Oct 2024 11:04:00 +0200 Subject: [PATCH] Corp Cleanup --- Ramses/home/CorpControl.js | 95 +++++++++++++++++-------- Ramses/home/CorpStatus.txt | 2 +- Ramses/home/Library.js | 7 +- Ramses/home/corp/BuyTea.js | 5 +- Ramses/home/corp/GetOfficeData.js | 1 + Ramses/home/corp/HireWorkers.js | 17 +---- Ramses/home/corp/SetWorkerOnPosition.js | 26 +++++++ Ramses/home/corp/ThrowParty.js | 6 +- 8 files changed, 105 insertions(+), 54 deletions(-) create mode 100644 Ramses/home/corp/SetWorkerOnPosition.js diff --git a/Ramses/home/CorpControl.js b/Ramses/home/CorpControl.js index 71c02b0..d2f12bf 100644 --- a/Ramses/home/CorpControl.js +++ b/Ramses/home/CorpControl.js @@ -30,14 +30,34 @@ export async function main(ns) { if (!ns.readPort(nListenPID)) { ns.tprint("Error! Couldn't start Corporation!"); return }; ns.tprint(oCorpStatus); while (nStep < 199) { + await ns.corporation.nextUpdate(); + if (nStep > 40) { + for (let sCity of aCitites) { + nListenPID = ns.run("/corp/GetOfficeData.js", 1, sDivisionName, sCity); + await ns.nextPortWrite(nListenPID); + await ns.sleep(1); + oOfficeData = ns.readPort(nListenPID); + if (oOfficeData.avgEnergy < 99.5) { + nListenPID = ns.run("/corp/BuyTea.js", 1, sDivisionName, sCity); + await ns.nextPortWrite(nListenPID); + await ns.sleep(1); + } + if (oOfficeData.avgMorale < 99.5) { + nListenPID = ns.run("/corp/ThrowParty.js", 1, sDivisionName, sCity, 500000); + await ns.nextPortWrite(nListenPID); + await ns.sleep(1); + } + // InsertSmartSupplyHere + } + }; nStep = oCorpStatus.nStep; ns.tprint(nStep); - nListenPID = ns.run("/corp/GetCorpData.js"); - await ns.nextPortWrite(nListenPID); - await ns.sleep(1); - oCorpData = ns.readPort(nListenPID); switch (nStep) { case 0: + nListenPID = ns.run("/corp/GetCorpData.js"); + await ns.nextPortWrite(nListenPID); + await ns.sleep(1); + oCorpData = ns.readPort(nListenPID); if (!oCorpData.divisions.length > 0) { nListenPID = ns.run("/corp/CorpStart.js", 1, sDivisionName, "Agriculture"); await ns.nextPortWrite(nListenPID); @@ -60,14 +80,14 @@ export async function main(ns) { oCorpStatus.nStep = 20; break; case 20: - nListenPID = ns.run("/corp/HasUnlock.js", 1, "Smart Supply"); + /*nListenPID = ns.run("/corp/HasUnlock.js", 1, "Smart Supply"); await ns.nextPortWrite(nListenPID); await ns.sleep(1); bUnlockStatus = ns.readPort(nListenPID); if (!bUnlockStatus) { await ns.nextPortWrite(ns.run("/corp/BuyUnlock.js", 1, "Smart Supply")); await ns.sleep(1); - } + }*/ for (let sCity of aCitites) { nListenPID = ns.run("/corp/GetWarehouseData.js", 1, sDivisionName, sCity); await ns.nextPortWrite(nListenPID); @@ -77,10 +97,7 @@ export async function main(ns) { await ns.nextPortWrite(ns.run("/corp/PurchaseWarehouses.js", 1, sDivisionName, sCity)); await ns.sleep(1); } - await ns.nextPortWrite(ns.run("/corp/SetSmartSupply.js", 1, sDivisionName, sCity)); - await ns.sleep(1); }; - oCorpStatus.nStep = 30; break; case 30: @@ -101,13 +118,49 @@ export async function main(ns) { await ns.nextPortWrite(nListenPID); await ns.sleep(1); oOfficeData = ns.readPort(nListenPID); - nListenPID = ns.run("/corp/HireWorkers.js", 1, sDivisionName, sCity, JSON.stringify(oOfficeData), JSON.stringify({ nWorkerNumbers: [1, 1, 1, 1, 0, 0] })); + nListenPID = ns.run("/corp/HireWorkers.js", 1, sDivisionName, sCity, JSON.stringify(oOfficeData)); await ns.nextPortWrite(nListenPID); await ns.sleep(1); } - oCorpStatus.nStep = 50; + oCorpStatus.nStep = 45; break; - case 50: + case 45: + nListenPID = ns.run("/corp/GetDivisionsData.js", 1, sDivisionName); + await ns.nextPortWrite(nListenPID); + await ns.sleep(1); + oDivisionData = ns.readPort(nListenPID); + if (!oDivisionData.researchPoints > 55) { continue } else { + for (let sCity of aCitites) { + nListenPID = ns.run("/corp/GetOfficeData.js", 1, sDivisionName, sCity); + await ns.nextPortWrite(nListenPID); + await ns.sleep(1); + oOfficeData = ns.readPort(nListenPID); + nListenPID = ns.run("/corp/SetWorkerOnPosition.js", 1, sDivisionName, sCity, JSON.stringify(oOfficeData), JSON.stringify({ nWorkerNumbers: [1, 1, 1, 1, 0, 0] })); + await ns.nextPortWrite(nListenPID); + await ns.sleep(1); + } + oCorpStatus.nStep = 70; + } + break; + case 70: + break; + case 80: + break; + case 90: + break; + case 100: + break; + default: + break; + } + ns.write("CorpStatus.txt", JSON.stringify(oCorpStatus), "w") + await ns.sleep(1) + } +} + +/* + +case 50: let aCurrentGoods = [ { "sMaterialName": "Food", "yAmount": "MAX", "yPrice": "MP-5" }, { "sMaterialName": "Plants", "yAmount": "MAX", "yPrice": "MP-5" } @@ -150,19 +203,5 @@ export async function main(ns) { } oCorpStatus.nStep = 70; break; - case 70: - oCorpStatus.nStep = 200; - break; - case 80: - break; - case 90: - break; - case 100: - break; - default: - break; - } - ns.write("CorpStatus.txt", JSON.stringify(oCorpStatus), "w") - await ns.sleep(1) - } -} \ No newline at end of file + + */ \ No newline at end of file diff --git a/Ramses/home/CorpStatus.txt b/Ramses/home/CorpStatus.txt index 1835133..f122dab 100644 --- a/Ramses/home/CorpStatus.txt +++ b/Ramses/home/CorpStatus.txt @@ -1 +1 @@ -{"nStep":200} \ No newline at end of file +{"nStep":70} \ No newline at end of file diff --git a/Ramses/home/Library.js b/Ramses/home/Library.js index 6612a0c..d5acb6d 100644 --- a/Ramses/home/Library.js +++ b/Ramses/home/Library.js @@ -190,6 +190,9 @@ export async function purchaseAndUpgradeServers(ns) { minHackLvl: 1, rootAccess: true, openPorts: 0, + serverOrgs: "", + serverCores: 1, + serverFiles: [] }); ns.write("serverList.txt", JSON.stringify(serverList), "w"); continue @@ -208,10 +211,10 @@ export async function purchaseAndUpgradeServers(ns) { if (ns.upgradePurchasedServer(currentServer, targetRam)) { ns.print(currentServer + " upgraded to " + targetRam + " GB RAM"); serverList = JSON.parse(ns.read("serverList.txt")); - let newServerList = serverList.map((entry) => { if (entry.serverName === currentServer) { entry.maxRam = targetRam } { entry.serverOrgs = "" } { entry.serverCores = 1 } { entry.serverFiles = [] } return entry }); + let newServerList = serverList.map((entry) => { if (entry.serverName === currentServer) { entry.maxRam = targetRam } return entry }); ns.write("serverList.txt", JSON.stringify(newServerList), "w"); ns.tprint(cCyan + "Server: " + currentServer + " upgraded to: " + targetRam.toLocaleString() + " GB" + cReset); - ns.toast("Server: " + currentServer + " upgraded to: " + targetRam.toLocaleString() + " GB", "info", 10000); + //ns.toast("Server: " + currentServer + " upgraded to: " + targetRam.toLocaleString() + " GB", "info", 10000); } } else { await ns.sleep(5000); diff --git a/Ramses/home/corp/BuyTea.js b/Ramses/home/corp/BuyTea.js index 845783c..5b6538e 100644 --- a/Ramses/home/corp/BuyTea.js +++ b/Ramses/home/corp/BuyTea.js @@ -1,9 +1,6 @@ /** @param {NS} ns */ export async function main(ns) { let [sDivName, sCity] = ns.args; - //ns.tprint("sDivName = " + sDivName); - //ns.tprint("sCity = " + sCity); - let bSuccess = ns.corporation.buyTea(sDivName, sCity) - //ns.tprint("bSuccess = " + bSuccess); + let bSuccess = ns.corporation.buyTea(sDivName, sCity); ns.writePort(ns.pid, bSuccess); } \ No newline at end of file diff --git a/Ramses/home/corp/GetOfficeData.js b/Ramses/home/corp/GetOfficeData.js index bbd219e..e676b76 100644 --- a/Ramses/home/corp/GetOfficeData.js +++ b/Ramses/home/corp/GetOfficeData.js @@ -1,5 +1,6 @@ /** @param {NS} ns */ export async function main(ns) { let [sDivName, sCity] = ns.args; + //ns.tprint(ns.corporation.getOffice(sDivName, sCity)) ns.writePort(ns.pid, ns.corporation.getOffice(sDivName, sCity)) } \ No newline at end of file diff --git a/Ramses/home/corp/HireWorkers.js b/Ramses/home/corp/HireWorkers.js index 4e90be8..2c9cf3c 100644 --- a/Ramses/home/corp/HireWorkers.js +++ b/Ramses/home/corp/HireWorkers.js @@ -1,21 +1,10 @@ /** @param {NS} ns */ export async function main(ns) { - let [sDivName, sCity, oCurrentOffice, oWorkerDistribution] = ns.args; + let [sDivName, sCity, oCurrentOffice] = ns.args; oCurrentOffice = JSON.parse(oCurrentOffice); - let aWorkerDistribution = JSON.parse(oWorkerDistribution).nWorkerNumbers; - let nTotalWorkers = 0; - const len = aWorkerDistribution.length; - for (let i = 0; i < len; i++) nTotalWorkers += aWorkerDistribution[i]; - let i = 0; - while (oCurrentOffice.numEmployees < oCurrentOffice.size && oCurrentOffice.numEmployees < nTotalWorkers && i < 1) { - (oCurrentOffice.employeeJobs.Operations < aWorkerDistribution[0]) ? ns.corporation.hireEmployee(sDivName, sCity, "Operations") : ""; - (oCurrentOffice.employeeJobs.Engineer < aWorkerDistribution[1]) ? ns.corporation.hireEmployee(sDivName, sCity, "Engineer") : ""; - (oCurrentOffice.employeeJobs.Business < aWorkerDistribution[2]) ? ns.corporation.hireEmployee(sDivName, sCity, "Business") : ""; - (oCurrentOffice.employeeJobs.Management < aWorkerDistribution[3]) ? ns.corporation.hireEmployee(sDivName, sCity, "Management") : ""; - (oCurrentOffice.employeeJobs["Research & Development"] < aWorkerDistribution[4]) ? ns.corporation.hireEmployee(sDivName, sCity, "Research & Development") : ""; - (oCurrentOffice.employeeJobs.Intern < aWorkerDistribution[5]) ? ns.corporation.hireEmployee(sDivName, sCity, "Intern") : ""; + if (oCurrentOffice.numEmployees < oCurrentOffice.size) { + ns.corporation.hireEmployee(sDivName, sCity, "Research & Development"); await ns.sleep(1) - i += 1; }; ns.writePort(ns.pid, true); } \ No newline at end of file diff --git a/Ramses/home/corp/SetWorkerOnPosition.js b/Ramses/home/corp/SetWorkerOnPosition.js new file mode 100644 index 0000000..8148a1f --- /dev/null +++ b/Ramses/home/corp/SetWorkerOnPosition.js @@ -0,0 +1,26 @@ +/** @param {NS} ns */ +export async function main(ns) { + let [sDivName, sCity, oCurrentOffice, oWorkerDistribution] = ns.args; + oCurrentOffice = JSON.parse(oCurrentOffice); + let aWorkerDistribution = JSON.parse(oWorkerDistribution).nWorkerNumbers; + let nTotalWorkers = 0; + const len = aWorkerDistribution.length; + for (let i = 0; i < len; i++) nTotalWorkers += aWorkerDistribution[i]; + if (nTotalWorkers <= oCurrentOffice.numEmployees) { + ns.corporation.setAutoJobAssignment(sDivName, sCity, "Operations", 0); + ns.corporation.setAutoJobAssignment(sDivName, sCity, "Engineer", 0); + ns.corporation.setAutoJobAssignment(sDivName, sCity, "Business", 0); + ns.corporation.setAutoJobAssignment(sDivName, sCity, "Management", 0); + ns.corporation.setAutoJobAssignment(sDivName, sCity, "Research & Development", 0); + ns.corporation.setAutoJobAssignment(sDivName, sCity, "Intern", 0); + + ns.corporation.setAutoJobAssignment(sDivName, sCity, "Operations", aWorkerDistribution[0]); + ns.corporation.setAutoJobAssignment(sDivName, sCity, "Engineer", aWorkerDistribution[1]); + ns.corporation.setAutoJobAssignment(sDivName, sCity, "Business", aWorkerDistribution[2]); + ns.corporation.setAutoJobAssignment(sDivName, sCity, "Management", aWorkerDistribution[3]); + ns.corporation.setAutoJobAssignment(sDivName, sCity, "Research & Development", aWorkerDistribution[4]); + ns.corporation.setAutoJobAssignment(sDivName, sCity, "Intern", aWorkerDistribution[5]); + await ns.sleep(1) + }; + ns.writePort(ns.pid, true); +} \ No newline at end of file diff --git a/Ramses/home/corp/ThrowParty.js b/Ramses/home/corp/ThrowParty.js index 0a7759d..bab217e 100644 --- a/Ramses/home/corp/ThrowParty.js +++ b/Ramses/home/corp/ThrowParty.js @@ -1,10 +1,6 @@ /** @param {NS} ns */ export async function main(ns) { let [sDivName, sCity, nSpend] = ns.args; - //ns.tprint("sDivName = " + sDivName); - //ns.tprint("sCity = " + sCity); - //ns.tprint("nSpend = " + nSpend); - let nMoraleMultiplier = ns.corporation.throwParty(sDivName, sCity, nSpend) - //ns.tprint("nMoraleMultiplier = " + nMoraleMultiplier); + let nMoraleMultiplier = ns.corporation.throwParty(sDivName, sCity, nSpend); ns.writePort(ns.pid, nMoraleMultiplier); } \ No newline at end of file