Draco18s

showWarehouseContents.js

Oct 15th, 2022
1,260
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /** @param {NS} ns */
  2. import * as ports from "/functions/ports.js";
  3.  
  4. export async function main(ns) {
  5.     const port = ns.getPortHandle(ports.CORPORATION_QUERY);
  6.     /*while (ns.corporation.getCorporation().state != "EXPORT") {
  7.         await ns.sleep(200);
  8.         if (!port.empty()) {
  9.             ProduceOutput(ns, port.read());
  10.         }
  11.     }
  12.     await ns.sleep(500);
  13.     PrintResults(ns);
  14.     await ns.sleep(500);
  15.     PrintResults(ns);
  16.     await ns.sleep(500);
  17.     PrintResults(ns);
  18.     await ns.sleep(500);
  19.     PrintResults(ns);
  20.     await ns.sleep(500);
  21.     PrintResults(ns);*/
  22.     let lastState = ns.corporation.getCorporation().state;
  23.     while(true) {
  24.         PrintResults(ns);
  25.         lastState = ns.corporation.getCorporation().state;
  26.         while (ns.corporation.getCorporation().state == lastState) {
  27.             await ns.sleep(200);
  28.             if (!port.empty()) {
  29.                 ProduceOutput(ns, port.read());
  30.             }
  31.         }
  32.     }
  33. }
  34.  
  35. function PrintResults(ns) {
  36.     ns.tprint(`CURRENT STATE: ${ns.corporation.getCorporation().state}`);
  37.     const divisionName = "Computer";
  38.     const cityName = "Ishima";
  39.     var wh = ns.corporation.getWarehouse(divisionName, cityName);
  40.     ns.tprint(`Computers in Ishima fill: ${Math.round(wh.sizeUsed)}/${Math.round(wh.size)}`);
  41.  
  42.     var re = Math.round(ns.corporation.getMaterial(divisionName, cityName, "RealEstate").qty);
  43.     var hd = Math.round(ns.corporation.getMaterial(divisionName, cityName, "Hardware").qty);
  44.     var ro = Math.round(ns.corporation.getMaterial(divisionName, cityName, "Robots").qty);
  45.     var ai = Math.round(ns.corporation.getMaterial(divisionName, cityName, "AI Cores").qty);
  46.     var en = Math.round(ns.corporation.getMaterial(divisionName, cityName, "Energy").qty);
  47.     var me = Math.round(ns.corporation.getMaterial(divisionName, cityName, "Metal").qty);
  48.  
  49.     var po = 0;
  50.     for(var prod of ['Gaming Rig', 'Gaming on the Go', 'Servers for Days', 'Cave Lighting', 'Exotic Sculpture']) {
  51.         po += ns.corporation.getProduct(divisionName, prod).cityData[cityName][0];
  52.     }
  53.  
  54.     ns.tprint(`  Contents:\n - ${en} Energy\n - ${me} Metal\n - ${hd} Hardware\n`+
  55.                 ` - ${ro} Robots\n - ${ai} AI Cores\n - ${re} Real Estate\n` +
  56.                 ` - ${po} Product`);
  57. }
  58.  
  59. let commands = ['restart', 'reboot', 'exit'];
  60. function ProduceOutput(ns, portVal) {
  61.     var port = ns.getPortHandle(ports.CORPORATION_QUERY);
  62.     if (commands.includes(portVal)) {
  63.         switch (portVal) {
  64.             case 'exit':
  65.                 ns.exit();
  66.                 break;
  67.             case 'restart':
  68.                 ns.closeTail();
  69.                 ns.spawn('corp/autocorp.js');
  70.                 break;
  71.             case 'reboot':
  72.                 break;
  73.         }
  74.     }
  75. }
Advertisement
Add Comment
Please, Sign In to add comment