faction-manager.js: Problem with rep cost estimates
Sometimes when i let the scripts run by themselves, i go back to them having quit to an error message that goes like this (copied from this line): (CONTEXT: BN: 4.3, SF:1.1, 4.2)
ERROR: We were only able to purchase ${purchased} of our ${purchaseableAugs.length} augmentations. Expected cost was ${getCostString(totalAugCost, totalRepCost)}. Player money was ${formatMoney(playerData.money)} right before purchase, is now ${formatMoney(await getNsDataThroughFile(ns, 'ns.getPlayer().money'))}
So I looked into it and it seems like there is a problem when estimating the money needed to buy the rep for an aug because the expected cost is always smaller than the player money and when the script uses the estimated money to buy the rep, it ends up with less rep than needed to get the wanted aug.
If this ever happens again, it would be helpful to:
- Copy+Paste or take a screenshot of the actual error message you received so that I can see what the values of the variables
${purchased},${purchaseableAugs.length},playerData.moneyetc... were when you encountered the error (I put them in the log message because they are essential to figuring out which of a myriad of possible things went wrong) - Export and attach your save file so that I can load it up, reproduce, and step through the code
As is, I can't reproduce the conditions that led to the error you saw, or even begin to speculate on what scenario you encountered. The only thing I can think is that perhaps you were playing the unstable DEV version of the game (e.g. https://bitburner-official.github.io/bitburner-src/) which sometimes contains temporary backwards-incompatible changes to the game logic, and which don't always make their way to the main (steam-release) branch.
Oh... that's because the function to get bitnode multipliers in a script is only available once you have SF-5.1... otherwise it calculates as if faction rep multiplier is 1... which it isn't in bitnode 4.
Oh... that's because the function to get bitnode multipliers in a script is only available once you have SF-5.1... otherwise it calculates as if faction rep multiplier is 1... which it isn't in bitnode 4.
That is a phenomenal catch! Next time I'm working on this I'll hard-code this bitnode mult into faction manager as a fall-back for when SF5.1 isn't available
Hiya;
I've been having this same issues sporadically and I've come to realize it's because managePurchaseableAugs generally makes our list of purchasables without NFG; then adds in NFG after. The issue itself comes from it adding NFG after all augs cheaper than first NF, but before all augs more expensive than first NF. So, as a result, if we happen to be able to afford 4 augs more expensive than NF, and then be able to afford a few levels of NF, adding the NF aug purchases with change the actual purchase price of the more expensive augs (making them even more expensive) due to the aug purchase count multiplier.
If we simply push the NF purchases (instead of splicing them in) then the total costs should remain as expected and we shouldn't have any issues in the purchase logic (unless there's some other logical reason for not doing this).
I wouldn't think it's sorting them from cheapest to most expensive as you're suspecting - it should be the exact opposite - its always optimal to buy augs in order of most expensive, to cheapest.
The algorithm gets more complex when you consider that some augs depend on one another, so the code performs a greedy sort to determine what purchase order minimizes the cost.
I'm more inclined to think the first theory above is accurate - if the game alters the formula for the cost of reputation (which it does in some bitnodes), but you don't have SF5.1 to get the multipliers, then we're now no longer buying sufficient rep, then that would explain why all the subsequent purchase attempts failed.
If the rep is only off by a small amount (e.g. <1) due to a rounding error, then that could explain why some report that the initial run fails to buy anything, but then re-running works (because in that time their rep with that faction might have creeped ever so slightly higher)
Current formula for getting the required donation amount (in dollars) for reputation with a faction is:
let getReqDonationForRep = (rep, faction) => Math.ceil(1e6 * (Math.max(0, rep - (faction.name ? faction : factionData[faction]).reputation)) / (playerData.mults.faction_rep));
It already takes into account the player faction rep multiplier (e.g. from a prior install), which acts as a divisor to the cost of buying additional reputation. My guess is that value 1e6 is what is changing in BN 4 and needs to be adjusted based on some currently unknown bitnode multiplier.
Hmm, I don't think this has always been here:
Looks like the "FactionWorkRepGain" mult (which affects how fast you gain reputation from working) also affects how much reputation you get from donating.
This was added Oct 7, 2022: https://github.com/bitburner-official/bitburner-src/commit/ea39e5e1f46ddc962a7463d09b646d80ca83a059 which is probably around the time I stopped agressively playing / maintaining these scripts.