alainbryden / bitburner-scripts

My own scripts for playing bitburner
MIT License
607 stars 272 forks source link

faction-manager.js purchase order error #409

Closed Nifle-CGE closed 3 weeks ago

Nifle-CGE commented 3 weeks ago

I got this error while ascending, it stops all the scripts and i have to rerun autopilot and it does the same. Context : BN 11.3

faction-manager.js: ERROR: Purchase order total cost ($216.5q) is far more than current player money ($162.099q). Your money may have recently changed (It was $162.099q at startup), or there may be a bug in purchasing logic.
ascend.js: ERROR: See above faction-manager.js logs - there are no new purchased augs. Specify --allow-soft-reset to proceed without any purchased augs.

bitburnerSave_1729942446_BN11x3.json.gz

to reproduce:

Nifle-CGE commented 3 weeks ago

Might be related to #406

alainbryden commented 3 weeks ago

Thanks I'll try to get this solved tonight.

I was refactoring faction manager the other day and I tried my best not to change anything material, but I might have scuffed it

alainbryden commented 3 weeks ago

Digging into this now. It looks like the bug is because it inserted the NF purchases too high in the list: image

Augmentations should be purchased from most expensive to cheapest (except when a "dependency" needs to be purchased before its more expensive successor augmentation).

Here we can see that the final purchase order places NF before nextSENS Gene Modification, but it should definitely be after. This might account for the higher final price than expected.

alainbryden commented 3 weeks ago

Figured it out. The cause was "The Red Pill" (free) being cheaper than neuroflux.

When adding NF to the purchase list, I have this logic to insert NF above any augs cheaper than NF (The red pill): image

This would work fine, except for some reason, I also implemented this feature a different way, by temporarily removing augs from the purchase list, and then re-adding them at the end: image ... image

Either one of these implementations on their own would have been fine, but with both, the effect is it's moved up one position more than it should have been 🤦‍♂️

alainbryden commented 3 weeks ago

Actually, I fixed the above and it still didn't work. Certainly, the logic to remove "free" augmentations shouldn't be necessary, since it's taken care of by the insert logic, but there's another problem here:

I'm counting how many augmentations are cheaper than NF, and using that count to decide how far up the list to insert them. What I don't take into account are prerequisites that are cheaper, yes, but they've been inserted higher up the list because they are a prerequisite to a more expensive augmentation.

So the real fix is to not count all cheaper augs, just cheaper augs from the end of the list (until a more expensive aug is encountered)