namespace NeonSprawl.Server.Game.Gathering; /// Registry-backed lazy init and atomic depletion commits for world node instances (NEO-61). public static class ResourceNodeInstanceOperations { /// /// Decrements remaining gathers by one after lazy-init from catalog maxGathers. Interact wiring (NEO-63) /// maps to denied interact responses. /// public static ResourceNodeInstanceMutationOutcome TryCommitSuccessfulGatherDecrement( string interactableId, IResourceNodeDefinitionRegistry registry, IResourceNodeInstanceStore store) { var key = InMemoryResourceNodeInstanceStore.NormalizeInteractableId(interactableId); if (key.Length == 0 || !registry.TryGetDefinition(key, out var definition)) { return new ResourceNodeInstanceMutationOutcome( ResourceNodeInstanceMutationKind.Denied, ResourceNodeInstanceReasonCodes.UnknownNode, null); } if (!store.TryGetRemainingGathers(key, out _)) { if (!store.TryEnsureInitialized(key, definition.MaxGathers)) { return new ResourceNodeInstanceMutationOutcome( ResourceNodeInstanceMutationKind.Denied, ResourceNodeInstanceReasonCodes.UnknownNode, null); } } if (store.TryDecrementRemainingGathers(key, out _, out var remaining)) { return new ResourceNodeInstanceMutationOutcome( ResourceNodeInstanceMutationKind.Applied, null, new ResourceNodeInstanceSnapshot(key, remaining)); } store.TryGetRemainingGathers(key, out var current); return new ResourceNodeInstanceMutationOutcome( ResourceNodeInstanceMutationKind.Denied, ResourceNodeInstanceReasonCodes.NodeDepleted, current.InteractableId.Length > 0 ? current : new ResourceNodeInstanceSnapshot(key, 0)); } }