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:
parent
0c9ab54048
commit
09a1c32560
3 changed files with 28 additions and 5 deletions
|
|
@ -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);
|
||||
|
|
|
|||
|
|
@ -201,7 +201,7 @@ public class ZoneStage
|
|||
|
||||
// Places ships into a running zone through the admission a run start uses: the script places with the stage's verbs,
|
||||
// and the entities join with their stance toward the player, a pilot when piloted and the knowledge the script stated.
|
||||
// Returns the placed entities in order, or null with every failure listed and the zone and the item stream unchanged.
|
||||
// Returns the placed entities in order, or null with every failure listed and the zone and the item stream and lot ledger unchanged.
|
||||
// It draws from the live item stream and does not reseed (a reseed would give every summon the same fits). The anchor
|
||||
// is the player's ship: the stance is written against it.
|
||||
public static IReadOnlyList<Entity> Summon(ItemManager items, Zone zone, Ship player, Action<ZoneStage> script, List<string> failures)
|
||||
|
|
@ -216,13 +216,13 @@ public class ZoneStage
|
|||
failures.Add("summon: the player is not in this zone");
|
||||
return null;
|
||||
}
|
||||
var stream = items.Random;
|
||||
var mark = items.Mark();
|
||||
var stage = new ZoneStage(items, zone);
|
||||
script(stage);
|
||||
failures.AddRange(stage._failures);
|
||||
if (stage._failures.Count > 0)
|
||||
{
|
||||
items.Random = stream; // a refusal draws nothing: the fits it built are discarded with it
|
||||
items.Rewind(mark); // a refusal draws and mints nothing: the fits it built are discarded with it
|
||||
return null;
|
||||
}
|
||||
stage.StockUnauthoredAmmunition();
|
||||
|
|
|
|||
Loading…
Reference in a new issue