From fe910c6878bc0acccb0bd68d75e9a74cf509cd86 Mon Sep 17 00:00:00 2001 From: Mizzajl Date: Wed, 16 Oct 2024 10:23:57 +0200 Subject: [PATCH] fixed my corp stuff --- Mizzajl/home/CorpControl.js | 79 ++++++++++++----------- Mizzajl/home/corp/CreateCorp.js | 3 +- Mizzajl/home/corp/GetCorpData.js | 2 +- Mizzajl/home/corp/HireWorkers.js | 23 +++++-- Mizzajl/home/corp/PriceCalcCheatsheet.txt | 3 + Mizzajl/home/corp/SetMaterialLimit.js | 2 +- Mizzajl/home/corptest.js | 4 -- 7 files changed, 65 insertions(+), 51 deletions(-) create mode 100644 Mizzajl/home/corp/PriceCalcCheatsheet.txt delete mode 100644 Mizzajl/home/corptest.js diff --git a/Mizzajl/home/CorpControl.js b/Mizzajl/home/CorpControl.js index ef3da28..71c02b0 100644 --- a/Mizzajl/home/CorpControl.js +++ b/Mizzajl/home/CorpControl.js @@ -1,6 +1,5 @@ /** @param {NS} ns */ export async function main(ns) { - ns.tail(); let aCitites = ["Sector-12", "Aevum", "Volhaven", "Chongqing", "New Tokyo", "Ishima"]; let sCorpName = "RM Enterprises"; let sDivisionName = "Agri-Ram"; @@ -17,14 +16,16 @@ export async function main(ns) { let oWarehouseData = {}; let bUnlockStatus = false; let nTargetSize = 0; + let oNewOfficeData = {}; + let oWorkerNumbers = {}; nListenPID = ns.run("/corp/HasCorp.js"); await ns.nextPortWrite(nListenPID); - await ns.sleep(1) + await ns.sleep(1); let bCorpExists = ns.readPort(nListenPID); if (!bCorpExists) { nListenPID = ns.run("/corp/CreateCorp.js", 1, sCorpName); await ns.nextPortWrite(nListenPID); - await ns.sleep(1) + await ns.sleep(1); } if (!ns.readPort(nListenPID)) { ns.tprint("Error! Couldn't start Corporation!"); return }; ns.tprint(oCorpStatus); @@ -33,14 +34,14 @@ export async function main(ns) { ns.tprint(nStep); nListenPID = ns.run("/corp/GetCorpData.js"); await ns.nextPortWrite(nListenPID); - await ns.sleep(1) + await ns.sleep(1); oCorpData = ns.readPort(nListenPID); switch (nStep) { case 0: if (!oCorpData.divisions.length > 0) { nListenPID = ns.run("/corp/CorpStart.js", 1, sDivisionName, "Agriculture"); await ns.nextPortWrite(nListenPID); - await ns.sleep(1) + await ns.sleep(1); }; oCorpStatus.nStep = 10; break; @@ -48,12 +49,12 @@ export async function main(ns) { for (let sCity of aCitites) { nListenPID = ns.run("/corp/GetDivisionsData.js", 1, sDivisionName); await ns.nextPortWrite(nListenPID); - await ns.sleep(1) + await ns.sleep(1); oDivisionData = ns.readPort(nListenPID); if (sCity !== "Sector-12" && !oDivisionData.cities.includes(sCity)) { nListenPID = ns.run("/corp/CorpExpandCity.js", 1, sDivisionName, sCity); await ns.nextPortWrite(nListenPID); - await ns.sleep(1) + await ns.sleep(1); } } oCorpStatus.nStep = 20; @@ -61,23 +62,23 @@ export async function main(ns) { case 20: nListenPID = ns.run("/corp/HasUnlock.js", 1, "Smart Supply"); await ns.nextPortWrite(nListenPID); - await ns.sleep(1) + 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) + await ns.sleep(1); } for (let sCity of aCitites) { nListenPID = ns.run("/corp/GetWarehouseData.js", 1, sDivisionName, sCity); await ns.nextPortWrite(nListenPID); - await ns.sleep(1) + await ns.sleep(1); oWarehouseData = ns.readPort(nListenPID); if (!oWarehouseData) { await ns.nextPortWrite(ns.run("/corp/PurchaseWarehouses.js", 1, sDivisionName, sCity)); - await ns.sleep(1) + await ns.sleep(1); } await ns.nextPortWrite(ns.run("/corp/SetSmartSupply.js", 1, sDivisionName, sCity)); - await ns.sleep(1) + await ns.sleep(1); }; oCorpStatus.nStep = 30; @@ -87,10 +88,10 @@ export async function main(ns) { for (let sCity of aCitites) { nListenPID = ns.run("/corp/GetOfficeData.js", 1, sDivisionName, sCity); await ns.nextPortWrite(nListenPID); - await ns.sleep(1) + await ns.sleep(1); oOfficeData = ns.readPort(nListenPID); await ns.nextPortWrite(ns.run("/corp/UpgradeOffice.js", 1, sDivisionName, sCity, nTargetSize, oOfficeData.size)) - await ns.sleep(1) + await ns.sleep(1); } oCorpStatus.nStep = 40; break; @@ -98,11 +99,11 @@ export async function main(ns) { for (let sCity of aCitites) { nListenPID = ns.run("/corp/GetOfficeData.js", 1, sDivisionName, sCity); await ns.nextPortWrite(nListenPID); - await ns.sleep(1) + 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), JSON.stringify({ nWorkerNumbers: [1, 1, 1, 1, 0, 0] })); await ns.nextPortWrite(nListenPID); - await ns.sleep(1) + await ns.sleep(1); } oCorpStatus.nStep = 50; break; @@ -113,37 +114,43 @@ export async function main(ns) { ] for (let sCity of aCitites) { aCurrentGoods.forEach(async (entry) => { - nListenPID = ns.run("/corp/SetSalePrices.js", 1, sDivisionName, sCity, JSON.stringify(entry)); nListenPID = ns.run("/corp/SetMaterialLimit.js", 1, sDivisionName, sCity, JSON.stringify(entry)); - - ns.tprint(sCity, entry) }) } oCorpStatus.nStep = 60; break; case 60: - nTargetSize = 12; 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); - await ns.nextPortWrite(ns.run("/corp/UpgradeOffice.js", 1, sDivisionName, sCity, nTargetSize, oOfficeData.size)) - await ns.sleep(1) + nTargetSize = sCity === "Sector-12" ? 12 : 4; + oWorkerNumbers = sCity === "Sector-12" ? { nWorkerNumbers: [2, 2, 2, 2, 2, 2] } : { nWorkerNumbers: [1, 1, 1, 1, 0, 0] } + let running = true; + while (running) { + nListenPID = ns.run("/corp/GetOfficeData.js", 1, sDivisionName, sCity); + await ns.nextPortWrite(nListenPID); + await ns.sleep(1); + oOfficeData = ns.readPort(nListenPID); + await ns.nextPortWrite(ns.run("/corp/UpgradeOffice.js", 1, sDivisionName, sCity, nTargetSize, oOfficeData.size)); + await ns.sleep(1); + nListenPID = ns.run("/corp/GetOfficeData.js", 1, sDivisionName, sCity); + await ns.nextPortWrite(nListenPID); + await ns.sleep(1); + oNewOfficeData = ns.readPort(nListenPID); + if (oNewOfficeData.size < nTargetSize) { + await ns.sleep(10000); + ns.tprint("Waiting for money"); + continue; + } else { + nListenPID = ns.run("/corp/HireWorkers.js", 1, sDivisionName, sCity, JSON.stringify(oOfficeData), JSON.stringify(oWorkerNumbers)); + await ns.nextPortWrite(nListenPID); + await ns.sleep(1); + running = false; + } + } } oCorpStatus.nStep = 70; break; case 70: - 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/HireWorkers.js", 1, sDivisionName, sCity, JSON.stringify(oOfficeData), JSON.stringify({nWorkerNumbers: [2, 2, 2, 2, 2, 2]})); - await ns.nextPortWrite(nListenPID); - await ns.sleep(1) - } oCorpStatus.nStep = 200; break; case 80: diff --git a/Mizzajl/home/corp/CreateCorp.js b/Mizzajl/home/corp/CreateCorp.js index 39295b4..8c89283 100644 --- a/Mizzajl/home/corp/CreateCorp.js +++ b/Mizzajl/home/corp/CreateCorp.js @@ -1,7 +1,6 @@ /** @param {NS} ns */ export async function main(ns) { let [sCorpName] = ns.args; - ns.corporation.createCorporation(sCorpName,true) - ns.writePort(ns.pid, true); + ns.writePort(ns.pid, ns.corporation.createCorporation(sCorpName,false)); } \ No newline at end of file diff --git a/Mizzajl/home/corp/GetCorpData.js b/Mizzajl/home/corp/GetCorpData.js index e433075..5333f72 100644 --- a/Mizzajl/home/corp/GetCorpData.js +++ b/Mizzajl/home/corp/GetCorpData.js @@ -1,4 +1,4 @@ /** @param {NS} ns */ export async function main(ns) { - ns.writePort(ns.pid,ns.corporation.getCorporation()) + ns.writePort(ns.pid, ns.corporation.getCorporation()); } \ No newline at end of file diff --git a/Mizzajl/home/corp/HireWorkers.js b/Mizzajl/home/corp/HireWorkers.js index 69195e6..5033276 100644 --- a/Mizzajl/home/corp/HireWorkers.js +++ b/Mizzajl/home/corp/HireWorkers.js @@ -1,12 +1,21 @@ /** @param {NS} ns */ export async function main(ns) { - let [sDivName, sCity, oCurrentOffice] = ns.args; - oCurrentOffice = JSON.parse(oCurrentOffice) - if (oCurrentOffice.numEmployees < oCurrentOffice.size) { - (oCurrentOffice.employeeJobs.Operations < 1) ? ns.corporation.hireEmployee(sDivName, sCity, "Operations") : ""; - (oCurrentOffice.employeeJobs.Engineer < 1) ? ns.corporation.hireEmployee(sDivName, sCity, "Engineer") : ""; - (oCurrentOffice.employeeJobs.Business < 1) ? ns.corporation.hireEmployee(sDivName, sCity, "Business") : ""; - (oCurrentOffice.employeeJobs.Management < 1) ? ns.corporation.hireEmployee(sDivName, sCity, "Management") : ""; + 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]; + 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") : ""; + await ns.sleep(1); + i += 1; }; ns.writePort(ns.pid, true); } \ No newline at end of file diff --git a/Mizzajl/home/corp/PriceCalcCheatsheet.txt b/Mizzajl/home/corp/PriceCalcCheatsheet.txt new file mode 100644 index 0000000..a01d466 --- /dev/null +++ b/Mizzajl/home/corp/PriceCalcCheatsheet.txt @@ -0,0 +1,3 @@ +getMaterial() -> material.marketPrice + +ns.corporation.getMaterialData() -> baseMarkup \ No newline at end of file diff --git a/Mizzajl/home/corp/SetMaterialLimit.js b/Mizzajl/home/corp/SetMaterialLimit.js index 2f3e7b0..54ebeff 100644 --- a/Mizzajl/home/corp/SetMaterialLimit.js +++ b/Mizzajl/home/corp/SetMaterialLimit.js @@ -4,4 +4,4 @@ export async function main(ns) { oCurrentGoods = JSON.parse(oCurrentGoods); ns.corporation.limitMaterialProduction(sDivName, sCity, oCurrentGoods.sMaterialName,50); ns.writePort(ns.pid, true); - } \ No newline at end of file + } diff --git a/Mizzajl/home/corptest.js b/Mizzajl/home/corptest.js deleted file mode 100644 index 6e51c16..0000000 --- a/Mizzajl/home/corptest.js +++ /dev/null @@ -1,4 +0,0 @@ -/** @param {NS} ns */ -export async function main(ns) { - ns.corporation.hasWarehouse(); -} \ No newline at end of file