121 lines
4.4 KiB
JavaScript
121 lines
4.4 KiB
JavaScript
/** @param {NS} ns */
|
|
export async function main(ns) {
|
|
let aCitites = ["Sector-12", "Aevum", "Volhaven", "Chongqing", "New Tokyo", "Ishima"];
|
|
let sCorpName = "RM Enterprises";
|
|
let sDivisionName = "Agri-Ram";
|
|
let reset = ns.args[0];
|
|
if (reset === true || !ns.fileExists("CorpStatus.txt")) {
|
|
ns.write("CorpStatus.txt", JSON.stringify({ nStep: 0 }), "w");
|
|
};
|
|
let oCorpStatus = JSON.parse(ns.read("CorpStatus.txt")) || { nStep: 0 };
|
|
let nStep = oCorpStatus.nStep;
|
|
let nListenPID = 0;
|
|
let oCorpData = {};
|
|
let oDivisionData = {};
|
|
let oOfficeData = {};
|
|
let oWarehouseData = {};
|
|
let bUnlockStatus = false;
|
|
nListenPID = ns.run("/corp/HasCorp.js");
|
|
await ns.nextPortWrite(nListenPID);
|
|
let bCorpExists = ns.readPort(nListenPID);
|
|
if (!bCorpExists) {
|
|
nListenPID = ns.run("/corp/CreateCorp.js", 1, sCorpName);
|
|
await ns.nextPortWrite(nListenPID);
|
|
}
|
|
if (!ns.readPort(nListenPID)) { ns.tprint("Error! Couldn't start Corporation!"); return };
|
|
ns.tprint(oCorpStatus);
|
|
while (nStep < 199) {
|
|
nStep = oCorpStatus.nStep;
|
|
ns.tprint(nStep);
|
|
nListenPID = ns.run("/corp/GetCorpData.js");
|
|
await ns.nextPortWrite(nListenPID);
|
|
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);
|
|
};
|
|
oCorpStatus.nStep = 10;
|
|
break;
|
|
case 10:
|
|
for (let sCity of aCitites) {
|
|
nListenPID = ns.run("/corp/GetDivisionsData.js", 1, sDivisionName);
|
|
await ns.nextPortWrite(nListenPID);
|
|
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);
|
|
}
|
|
}
|
|
oCorpStatus.nStep = 20;
|
|
break;
|
|
case 20:
|
|
nListenPID = ns.run("/corp/HasUnlock.js", 1, "Smart Supply");
|
|
await ns.nextPortWrite(nListenPID);
|
|
bUnlockStatus = ns.readPort(nListenPID);
|
|
if (!bUnlockStatus) {
|
|
await ns.nextPortWrite(ns.run("/corp/BuyUnlock.js", 1, "Smart Supply"));
|
|
}
|
|
for (let sCity of aCitites) {
|
|
nListenPID = ns.run("/corp/GetWarehouseData.js", 1, sDivisionName, sCity);
|
|
await ns.nextPortWrite(nListenPID);
|
|
oWarehouseData = ns.readPort(nListenPID);
|
|
if (!oWarehouseData) {
|
|
await ns.nextPortWrite(ns.run("/corp/PurchaseWarehouses.js", 1, sDivisionName, sCity));
|
|
}
|
|
await ns.nextPortWrite(ns.run("/corp/SetSmartSupply.js", 1, sDivisionName, sCity));
|
|
};
|
|
|
|
oCorpStatus.nStep = 30;
|
|
break;
|
|
case 30:
|
|
let nTargetSize = 4;
|
|
for (let sCity of aCitites) {
|
|
nListenPID = ns.run("/corp/GetOfficeData.js", 1, sDivisionName, sCity);
|
|
await ns.nextPortWrite(nListenPID);
|
|
oOfficeData = ns.readPort(nListenPID);
|
|
await ns.nextPortWrite(ns.run("/corp/UpgradeOffice.js", 1, sDivisionName, sCity, nTargetSize, oOfficeData.size))
|
|
}
|
|
oCorpStatus.nStep = 40;
|
|
break;
|
|
case 40:
|
|
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));
|
|
await ns.nextPortWrite(nListenPID);
|
|
}
|
|
oCorpStatus.nStep = 50;
|
|
break;
|
|
case 50:
|
|
let aCurrentGoods = [
|
|
{ "sMaterialName": "Food", "yAmount": "MAX", "yPrice": "MP-1" },
|
|
{ "sMaterialName": "Plants", "yAmount": "MAX", "yPrice": "MP-1" }
|
|
]
|
|
for (let sCity of aCitites) {
|
|
aCurrentGoods.forEach(async (entry) => {
|
|
nListenPID = ns.run("/corp/SetSalePrices.js", 1, sDivisionName, sCity, JSON.stringify(entry));
|
|
await ns.nextPortWrite(nListenPID);
|
|
})
|
|
}
|
|
oCorpStatus.nStep = 200;
|
|
break;
|
|
case 60:
|
|
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)
|
|
}
|
|
} |