Make a refused summon ledger-neutral: ItemManager.Mark/Rewind restore the stream and the lot ledger together

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
soul 2026-11-20 01:49:18 +01:00
commit 09a1c32560
3 changed files with 28 additions and 5 deletions

View file

@ -45,6 +45,25 @@ public class ItemManager
_logger = logger;
}
// A restore point over everything building items draws or mints: the item stream and the lot ledger, which a run save
// persists. Rewind puts both back, so a refused build is neither a draw nor a lot.
public readonly struct Checkpoint
{
internal readonly Random Stream;
internal readonly int NextLot;
internal Checkpoint(Random stream, int nextLot) { Stream = stream; NextLot = nextLot; }
}
public Checkpoint Mark() => new Checkpoint(Random, Lots.NextLot);
public void Rewind(Checkpoint mark)
{
Random = mark.Stream;
foreach (var id in Lots.Lots.Keys.Where(id => id >= mark.NextLot).ToList()) Lots.Lots.Remove(id);
Lots.NextLot = mark.NextLot;
foreach (var key in _extracted.Where(entry => entry.Value >= mark.NextLot).Select(entry => entry.Key).ToList()) _extracted.Remove(key);
}
public void Log(string s)
{
_logger(s);