Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /** @param {NS} ns */
- import * as ports from "/functions/ports.js";
- export async function main(ns) {
- const port = ns.getPortHandle(ports.CORPORATION_QUERY);
- /*while (ns.corporation.getCorporation().state != "EXPORT") {
- await ns.sleep(200);
- if (!port.empty()) {
- ProduceOutput(ns, port.read());
- }
- }
- await ns.sleep(500);
- PrintResults(ns);
- await ns.sleep(500);
- PrintResults(ns);
- await ns.sleep(500);
- PrintResults(ns);
- await ns.sleep(500);
- PrintResults(ns);
- await ns.sleep(500);
- PrintResults(ns);*/
- let lastState = ns.corporation.getCorporation().state;
- while(true) {
- PrintResults(ns);
- lastState = ns.corporation.getCorporation().state;
- while (ns.corporation.getCorporation().state == lastState) {
- await ns.sleep(200);
- if (!port.empty()) {
- ProduceOutput(ns, port.read());
- }
- }
- }
- }
- function PrintResults(ns) {
- ns.tprint(`CURRENT STATE: ${ns.corporation.getCorporation().state}`);
- const divisionName = "Computer";
- const cityName = "Ishima";
- var wh = ns.corporation.getWarehouse(divisionName, cityName);
- ns.tprint(`Computers in Ishima fill: ${Math.round(wh.sizeUsed)}/${Math.round(wh.size)}`);
- var re = Math.round(ns.corporation.getMaterial(divisionName, cityName, "RealEstate").qty);
- var hd = Math.round(ns.corporation.getMaterial(divisionName, cityName, "Hardware").qty);
- var ro = Math.round(ns.corporation.getMaterial(divisionName, cityName, "Robots").qty);
- var ai = Math.round(ns.corporation.getMaterial(divisionName, cityName, "AI Cores").qty);
- var en = Math.round(ns.corporation.getMaterial(divisionName, cityName, "Energy").qty);
- var me = Math.round(ns.corporation.getMaterial(divisionName, cityName, "Metal").qty);
- var po = 0;
- for(var prod of ['Gaming Rig', 'Gaming on the Go', 'Servers for Days', 'Cave Lighting', 'Exotic Sculpture']) {
- po += ns.corporation.getProduct(divisionName, prod).cityData[cityName][0];
- }
- ns.tprint(` Contents:\n - ${en} Energy\n - ${me} Metal\n - ${hd} Hardware\n`+
- ` - ${ro} Robots\n - ${ai} AI Cores\n - ${re} Real Estate\n` +
- ` - ${po} Product`);
- }
- let commands = ['restart', 'reboot', 'exit'];
- function ProduceOutput(ns, portVal) {
- var port = ns.getPortHandle(ports.CORPORATION_QUERY);
- if (commands.includes(portVal)) {
- switch (portVal) {
- case 'exit':
- ns.exit();
- break;
- case 'restart':
- ns.closeTail();
- ns.spawn('corp/autocorp.js');
- break;
- case 'reboot':
- break;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment