corpSync
This commit is contained in:
@@ -16,12 +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);
|
||||
let bCorpExists = ns.readPort(nListenPID);
|
||||
if (!bCorpExists) {
|
||||
nListenPID = ns.run("/corp/CreateCorp.js", 1, sCorpName);
|
||||
await ns.nextPortWrite(nListenPID);
|
||||
await ns.sleep(1);
|
||||
}
|
||||
if (!ns.readPort(nListenPID)) { ns.tprint("Error! Couldn't start Corporation!"); return };
|
||||
ns.tprint(oCorpStatus);
|
||||
@@ -30,12 +34,14 @@ export async function main(ns) {
|
||||
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:
|
||||
if (!oCorpData.divisions.length > 0) {
|
||||
nListenPID = ns.run("/corp/CorpStart.js", 1, sDivisionName, "Agriculture");
|
||||
await ns.nextPortWrite(nListenPID);
|
||||
await ns.sleep(1);
|
||||
};
|
||||
oCorpStatus.nStep = 10;
|
||||
break;
|
||||
@@ -43,10 +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);
|
||||
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);
|
||||
}
|
||||
}
|
||||
oCorpStatus.nStep = 20;
|
||||
@@ -54,18 +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);
|
||||
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);
|
||||
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.nextPortWrite(ns.run("/corp/SetSmartSupply.js", 1, sDivisionName, sCity));
|
||||
await ns.sleep(1);
|
||||
};
|
||||
|
||||
oCorpStatus.nStep = 30;
|
||||
@@ -75,8 +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);
|
||||
oOfficeData = ns.readPort(nListenPID);
|
||||
await ns.nextPortWrite(ns.run("/corp/UpgradeOffice.js", 1, sDivisionName, sCity, nTargetSize, oOfficeData.size))
|
||||
await ns.sleep(1);
|
||||
}
|
||||
oCorpStatus.nStep = 40;
|
||||
break;
|
||||
@@ -84,9 +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);
|
||||
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] }));
|
||||
await ns.nextPortWrite(nListenPID);
|
||||
await ns.sleep(1);
|
||||
}
|
||||
oCorpStatus.nStep = 50;
|
||||
break;
|
||||
@@ -97,33 +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) {
|
||||
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.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);
|
||||
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);
|
||||
}
|
||||
oCorpStatus.nStep = 200;
|
||||
break;
|
||||
case 80:
|
||||
|
||||
@@ -1 +1 @@
|
||||
{"nStep":70}
|
||||
{"nStep":200}
|
||||
@@ -2,6 +2,4 @@
|
||||
export async function main(ns) {
|
||||
let [sDivName, sCity] = ns.args;
|
||||
ns.writePort(ns.pid, ns.corporation.getOffice(sDivName, sCity))
|
||||
|
||||
ns.tprint(ns.corporation.getOffice(sDivName, sCity))
|
||||
}
|
||||
@@ -3,19 +3,19 @@ export async function main(ns) {
|
||||
let [sDivName, sCity, oCurrentOffice, oWorkerDistribution] = ns.args;
|
||||
oCurrentOffice = JSON.parse(oCurrentOffice);
|
||||
let aWorkerDistribution = JSON.parse(oWorkerDistribution).nWorkerNumbers;
|
||||
ns.tprint(aWorkerDistribution);
|
||||
let nTotalWorkers = 0;
|
||||
const len = aWorkerDistribution.length;
|
||||
for (let i = 0; i < len; i++) nTotalWorkers += aWorkerDistribution[i];
|
||||
ns.tprint(typeof(oCurrentOffice.employeeJobs["Research & Development"]))
|
||||
|
||||
while (oCurrentOffice.numEmployees < oCurrentOffice.size && oCurrentOffice.numEmployees < nTotalWorkers) {
|
||||
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["Research & Development"] < aWorkerDistribution[4]) ? ns.corporation.hireEmployee(sDivName, sCity, "Research & Development") : "";
|
||||
(oCurrentOffice.employeeJobs.Intern < aWorkerDistribution[5]) ? ns.corporation.hireEmployee(sDivName, sCity, "Intern") : "";
|
||||
ns.sleep(1)
|
||||
i += 1;
|
||||
};
|
||||
ns.writePort(ns.pid, true);
|
||||
}
|
||||
3
Ramses/home/corp/PriceCalcCheatsheet.txt
Normal file
3
Ramses/home/corp/PriceCalcCheatsheet.txt
Normal file
@@ -0,0 +1,3 @@
|
||||
getMaterial() -> material.marketPrice
|
||||
|
||||
ns.corporation.getMaterialData() -> baseMarkup
|
||||
@@ -1,9 +1,5 @@
|
||||
/** @param {NS} ns */
|
||||
export async function main(ns) {
|
||||
let [sDivName, sCity] = ns.args;
|
||||
if (ns.corporation.hasWarehouse(sDivName, sCity)) {
|
||||
ns.writePort(ns.pid, ns.corporation.getWarehouse(sDivName, sCity))
|
||||
} else {
|
||||
ns.writePort(ns.pid, false)
|
||||
};
|
||||
let [sMaterial] = ns.args;
|
||||
ns.tprint(ns.corporation.getMaterialData(sMaterial))
|
||||
}
|
||||
Reference in New Issue
Block a user