2024-10-17 15:49:55 +02:00
8 changed files with 105 additions and 54 deletions

View File

@@ -30,14 +30,34 @@ export async function main(ns) {
if (!ns.readPort(nListenPID)) { ns.tprint("Error! Couldn't start Corporation!"); return }; if (!ns.readPort(nListenPID)) { ns.tprint("Error! Couldn't start Corporation!"); return };
ns.tprint(oCorpStatus); ns.tprint(oCorpStatus);
while (nStep < 199) { 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; nStep = oCorpStatus.nStep;
ns.tprint(nStep); ns.tprint(nStep);
nListenPID = ns.run("/corp/GetCorpData.js");
await ns.nextPortWrite(nListenPID);
await ns.sleep(1);
oCorpData = ns.readPort(nListenPID);
switch (nStep) { switch (nStep) {
case 0: 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) { if (!oCorpData.divisions.length > 0) {
nListenPID = ns.run("/corp/CorpStart.js", 1, sDivisionName, "Agriculture"); nListenPID = ns.run("/corp/CorpStart.js", 1, sDivisionName, "Agriculture");
await ns.nextPortWrite(nListenPID); await ns.nextPortWrite(nListenPID);
@@ -60,14 +80,14 @@ export async function main(ns) {
oCorpStatus.nStep = 20; oCorpStatus.nStep = 20;
break; break;
case 20: 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.nextPortWrite(nListenPID);
await ns.sleep(1); await ns.sleep(1);
bUnlockStatus = ns.readPort(nListenPID); bUnlockStatus = ns.readPort(nListenPID);
if (!bUnlockStatus) { if (!bUnlockStatus) {
await ns.nextPortWrite(ns.run("/corp/BuyUnlock.js", 1, "Smart Supply")); await ns.nextPortWrite(ns.run("/corp/BuyUnlock.js", 1, "Smart Supply"));
await ns.sleep(1); await ns.sleep(1);
} }*/
for (let sCity of aCitites) { for (let sCity of aCitites) {
nListenPID = ns.run("/corp/GetWarehouseData.js", 1, sDivisionName, sCity); nListenPID = ns.run("/corp/GetWarehouseData.js", 1, sDivisionName, sCity);
await ns.nextPortWrite(nListenPID); 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.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);
}; };
oCorpStatus.nStep = 30; oCorpStatus.nStep = 30;
break; break;
case 30: case 30:
@@ -101,13 +118,49 @@ export async function main(ns) {
await ns.nextPortWrite(nListenPID); await ns.nextPortWrite(nListenPID);
await ns.sleep(1); await ns.sleep(1);
oOfficeData = ns.readPort(nListenPID); 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.nextPortWrite(nListenPID);
await ns.sleep(1); await ns.sleep(1);
} }
oCorpStatus.nStep = 50; oCorpStatus.nStep = 45;
break; 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 = [ let aCurrentGoods = [
{ "sMaterialName": "Food", "yAmount": "MAX", "yPrice": "MP-5" }, { "sMaterialName": "Food", "yAmount": "MAX", "yPrice": "MP-5" },
{ "sMaterialName": "Plants", "yAmount": "MAX", "yPrice": "MP-5" } { "sMaterialName": "Plants", "yAmount": "MAX", "yPrice": "MP-5" }
@@ -150,19 +203,5 @@ export async function main(ns) {
} }
oCorpStatus.nStep = 70; oCorpStatus.nStep = 70;
break; 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)
}
}

View File

@@ -1 +1 @@
{"nStep":200} {"nStep":70}

View File

@@ -190,6 +190,9 @@ export async function purchaseAndUpgradeServers(ns) {
minHackLvl: 1, minHackLvl: 1,
rootAccess: true, rootAccess: true,
openPorts: 0, openPorts: 0,
serverOrgs: "",
serverCores: 1,
serverFiles: []
}); });
ns.write("serverList.txt", JSON.stringify(serverList), "w"); ns.write("serverList.txt", JSON.stringify(serverList), "w");
continue continue
@@ -208,10 +211,10 @@ export async function purchaseAndUpgradeServers(ns) {
if (ns.upgradePurchasedServer(currentServer, targetRam)) { if (ns.upgradePurchasedServer(currentServer, targetRam)) {
ns.print(currentServer + " upgraded to " + targetRam + " GB RAM"); ns.print(currentServer + " upgraded to " + targetRam + " GB RAM");
serverList = JSON.parse(ns.read("serverList.txt")); 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.write("serverList.txt", JSON.stringify(newServerList), "w");
ns.tprint(cCyan + "Server: " + currentServer + " upgraded to: " + targetRam.toLocaleString() + " GB" + cReset); 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 { } else {
await ns.sleep(5000); await ns.sleep(5000);

View File

@@ -1,9 +1,6 @@
/** @param {NS} ns */ /** @param {NS} ns */
export async function main(ns) { export async function main(ns) {
let [sDivName, sCity] = ns.args; let [sDivName, sCity] = ns.args;
//ns.tprint("sDivName = " + sDivName); let bSuccess = ns.corporation.buyTea(sDivName, sCity);
//ns.tprint("sCity = " + sCity);
let bSuccess = ns.corporation.buyTea(sDivName, sCity)
//ns.tprint("bSuccess = " + bSuccess);
ns.writePort(ns.pid, bSuccess); ns.writePort(ns.pid, bSuccess);
} }

View File

@@ -1,5 +1,6 @@
/** @param {NS} ns */ /** @param {NS} ns */
export async function main(ns) { export async function main(ns) {
let [sDivName, sCity] = ns.args; let [sDivName, sCity] = ns.args;
//ns.tprint(ns.corporation.getOffice(sDivName, sCity))
ns.writePort(ns.pid, ns.corporation.getOffice(sDivName, sCity)) ns.writePort(ns.pid, ns.corporation.getOffice(sDivName, sCity))
} }

View File

@@ -1,21 +1,10 @@
/** @param {NS} ns */ /** @param {NS} ns */
export async function main(ns) { export async function main(ns) {
let [sDivName, sCity, oCurrentOffice, oWorkerDistribution] = ns.args; let [sDivName, sCity, oCurrentOffice] = ns.args;
oCurrentOffice = JSON.parse(oCurrentOffice); oCurrentOffice = JSON.parse(oCurrentOffice);
let aWorkerDistribution = JSON.parse(oWorkerDistribution).nWorkerNumbers; if (oCurrentOffice.numEmployees < oCurrentOffice.size) {
let nTotalWorkers = 0; ns.corporation.hireEmployee(sDivName, sCity, "Research & Development");
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) await ns.sleep(1)
i += 1;
}; };
ns.writePort(ns.pid, true); ns.writePort(ns.pid, true);
} }

View File

@@ -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);
}

View File

@@ -1,10 +1,6 @@
/** @param {NS} ns */ /** @param {NS} ns */
export async function main(ns) { export async function main(ns) {
let [sDivName, sCity, nSpend] = ns.args; let [sDivName, sCity, nSpend] = ns.args;
//ns.tprint("sDivName = " + sDivName); let nMoraleMultiplier = ns.corporation.throwParty(sDivName, sCity, nSpend);
//ns.tprint("sCity = " + sCity);
//ns.tprint("nSpend = " + nSpend);
let nMoraleMultiplier = ns.corporation.throwParty(sDivName, sCity, nSpend)
//ns.tprint("nMoraleMultiplier = " + nMoraleMultiplier);
ns.writePort(ns.pid, nMoraleMultiplier); ns.writePort(ns.pid, nMoraleMultiplier);
} }