NEO-105: Consolidate inventory snapshot clone helper.
Add PlayerInventorySnapshot.Clone() and use it from craft and encounter completion pre-flight paths (Bugbot PR #144).pull/144/head
parent
cbb6f137fd
commit
01bcd7334c
|
|
@ -56,7 +56,7 @@ public static class CraftOperations
|
|||
}
|
||||
}
|
||||
|
||||
var simulated = CloneSnapshot(snapshot);
|
||||
var simulated = snapshot.Clone();
|
||||
foreach (var input in scaledInputs)
|
||||
{
|
||||
if (!PlayerInventoryOperations.TrySimulateRemoveStack(ref simulated, input.ItemId, input.Quantity, itemRegistry))
|
||||
|
|
@ -176,13 +176,6 @@ public static class CraftOperations
|
|||
return scaled;
|
||||
}
|
||||
|
||||
private static PlayerInventorySnapshot CloneSnapshot(PlayerInventorySnapshot snapshot) =>
|
||||
new()
|
||||
{
|
||||
BagSlots = PlayerInventorySnapshot.CloneSlots(snapshot.BagSlots),
|
||||
EquipmentSlots = PlayerInventorySnapshot.CloneSlots(snapshot.EquipmentSlots),
|
||||
};
|
||||
|
||||
private static void CompensatingRestoreInputs(
|
||||
string playerId,
|
||||
IReadOnlyList<CraftIoApplied> inputs,
|
||||
|
|
|
|||
|
|
@ -62,7 +62,7 @@ public static class EncounterCompletionOperations
|
|||
return Deny(EncounterCompletionReasonCodes.InventoryStoreMissing);
|
||||
}
|
||||
|
||||
var simulated = CloneSnapshot(snapshot);
|
||||
var simulated = snapshot.Clone();
|
||||
foreach (var grant in grants)
|
||||
{
|
||||
if (!PlayerInventoryOperations.TrySimulateAddStack(
|
||||
|
|
@ -139,13 +139,6 @@ public static class EncounterCompletionOperations
|
|||
private static string MakeIdempotencyKey(string normalizedPlayerId, string normalizedEncounterId) =>
|
||||
$"{normalizedPlayerId}:{normalizedEncounterId}";
|
||||
|
||||
private static PlayerInventorySnapshot CloneSnapshot(PlayerInventorySnapshot snapshot) =>
|
||||
new()
|
||||
{
|
||||
BagSlots = PlayerInventorySnapshot.CloneSlots(snapshot.BagSlots),
|
||||
EquipmentSlots = PlayerInventorySnapshot.CloneSlots(snapshot.EquipmentSlots),
|
||||
};
|
||||
|
||||
private static void CompensatingRemoveGrants(
|
||||
string playerId,
|
||||
IReadOnlyList<EncounterGrantApplied> grants,
|
||||
|
|
|
|||
|
|
@ -41,6 +41,14 @@ public sealed class PlayerInventorySnapshot
|
|||
return copy;
|
||||
}
|
||||
|
||||
/// <summary>Deep-copies bag and equipment slot arrays (NEO-69 craft pre-flight, NEO-105 encounter grant pre-flight).</summary>
|
||||
public PlayerInventorySnapshot Clone() =>
|
||||
new()
|
||||
{
|
||||
BagSlots = CloneSlots(BagSlots),
|
||||
EquipmentSlots = CloneSlots(EquipmentSlots),
|
||||
};
|
||||
|
||||
public InventorySlotState[] GetSlots(InventoryContainerKind container) =>
|
||||
container == InventoryContainerKind.Equipment ? EquipmentSlots : BagSlots;
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue