Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

helpers.js: Measure rep gains since last tick #395

Open
alainbryden opened this issue Oct 21, 2024 · 0 comments
Open

helpers.js: Measure rep gains since last tick #395

alainbryden opened this issue Oct 21, 2024 · 0 comments
Assignees
Labels
enhancement New feature or request

Comments

@alainbryden
Copy link
Owner

In order to help with issues like #353 and #388, we need a consistent way of measuring current gain rates that any script can use.

While there are formulas APIs that let us get expected gain rates, there will not always be available, and it would be nice to have something that works for new players from the very start (before they have the SF that auto-grants formulas.exe). It would also be nice not to have to pay the price of formulas.exe and/or resort to ram-dodging, at least for now.

One idea I had was to take the "measureRepGainRate" function that work-for-factions.js uses, and expand on it:

/** Measure our rep gain rate (per second)
 * TODO: Move this to helpers.js, measure all rep gain rates over a parameterizable number of game ticks (default 1) and return them all.
 * @param {NS} ns
 * @param {() => Promise<number>} fnSampleReputation - An async function that samples the reputation at a current point in time */
async function measureRepGainRate(ns, fnSampleReputation) {
    //return (await getPlayerInfo(ns)).workRepGainRate;
    // The game no longer provides the rep gain rate for a given work type, so we must measure it
    const initialReputation = await fnSampleReputation();
    let nextTickReputation;
    let start = Date.now();
    while (initialReputation == (nextTickReputation = await fnSampleReputation()) && Date.now() - start < 450)
        await ns.sleep(50);
    return (nextTickReputation - initialReputation) * 5; // Assume this rep gain was for a 200 tick
}
/** Measure our faction rep gain rate (per second)
 * @param {NS} ns */
async function measureFactionRepGainRate(ns, factionName) {
    return await measureRepGainRate(ns, async () => await getFactionReputation(ns, factionName));
}
/** Measure our company rep gain rate (per second)
 * @param {NS} ns */
async function measureCompanyRepGainRate(ns, companyName) {
    return await measureRepGainRate(ns, async () => await getCompanyReputation(ns, companyName));
}

Currently, it supports getting faction or company reputation, but we could have other variations that measure changes in all player stats between ticks, and also get a more "stable" view of gains by measuring over several ticks and returning only the smallest gain for each stat (removing noise from occasional sporadic earnings)

@alainbryden alainbryden self-assigned this Oct 21, 2024
@alainbryden alainbryden added the enhancement New feature or request label Oct 21, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant