danielyxie / bitburner

Bitburner Game
https://danielyxie.github.io/bitburner/
2.81k stars 767 forks source link

NETSCRIPT: Expose additional corporation data to player netscripts #4216

Closed Draco18s closed 2 years ago

Draco18s commented 2 years ago

Linked issues

closes #4202 partially addresses #4199

Documentation

All player-facing information available in the UI (somewhere) is now accessible to netscripts. This includes:

Sample code

The following shows an example of the kind of thing that would now be possible with the changes in this PR

/** @param {NS} ns */
export async function main(ns) {
    const ind = "Food"; //industry to query
    const city = "Aevum"; //city to query
    const mat = "Robots"; //material to query
    const buffer = 0.25; //percentage of warehouse to keep empty (for purchases and production)

    const div = ns.corporation.getCorporation().divisions.filter(d => d.type == ind)[0].name;

    const availableSpace = ns.corporation.getWarehouse(div,city).size;
    const usedSpace = ns.corporation.getWarehouse(div,city).sizeUsed;
    const coreSize = ns.corporation.getMaterialSize(mat);
    const re = ns.corporation.getMaterial(div,city,"RealEstate").qty;
    const hd = ns.corporation.getMaterial(div,city,"Hardware").qty;
    const ro = ns.corporation.getMaterial(div,city,"Robots").qty;
    const ai = ns.corporation.getMaterial(div,city,"AI Cores").qty;

    const canHold = ((availableSpace-usedSpace) * (1-buffer))/coreSize;
    const buyAmt = canHold;

    ns.tprint(`${div} in ${city} can buy ${buyAmt} more ${mat}`);

    const oldMulti = ns.formulas.corp.calculateProductionMultiplier(ind,re,hd,ro,ai);
    const newMulti = ns.formulas.corp.calculateProductionMultiplier(ind,re,hd,ro+buyAmt,ai);

    ns.tprint(`This would improve production from ${oldMulti} to ${newMulti}`);
}
hydroflame commented 2 years ago

Not a bug fix.

https://github.com/danielyxie/bitburner/blob/dev/.github/PULL_REQUEST_TEMPLATE#L1

https://github.com/danielyxie/bitburner/blob/dev/doc/CONTRIBUTING.md#only-bugfix-are-accepted

Draco18s commented 2 years ago

https://github.com/danielyxie/bitburner/blob/dev/doc/CONTRIBUTING.md#only-bugfix-are-accepted

Didn't see that update. :\