Publish authoritative consumable action state
This commit is contained in:
parent
9ead85539f
commit
4f1d490915
4 changed files with 163 additions and 14 deletions
|
|
@ -181,6 +181,7 @@ internal sealed class AetheriaDaemonYmirSmokeChecks
|
|||
ResourceBehaviorsStopEquipmentChainsInAuthoredOrder,
|
||||
ThermotoggleSeedsAndGatesFromDaemonOwnedTarget,
|
||||
InputCapabilityPublishesExactBehaviorLevers,
|
||||
InputCapabilityPublishesConsumableActionBarState,
|
||||
InputCapabilityPublishesHeldWeaponGroupLever,
|
||||
ReflectorUsesSharedStellarLightFieldWithoutAccumulating,
|
||||
SensorPingIsActorScopedEnergyGatedAndReconnectable,
|
||||
|
|
@ -616,6 +617,81 @@ internal sealed class AetheriaDaemonYmirSmokeChecks
|
|||
"offline equipment must retain stable action identity while advertising current unavailability");
|
||||
}
|
||||
|
||||
private static void InputCapabilityPublishesConsumableActionBarState()
|
||||
{
|
||||
var repairGel = CatalogItem("repair-gel");
|
||||
repairGel.Name = "Repair Gel";
|
||||
repairGel.Category = AetheriaRuntimeItemCategories.Consumable;
|
||||
repairGel.Duration = 4;
|
||||
repairGel.Stackable = false;
|
||||
var ore = CatalogItem("ore");
|
||||
ore.Category = AetheriaRuntimeItemCategories.SimpleCommodity;
|
||||
var catalog = new AetheriaRuntimeCatalogSnapshot([repairGel, ore], [], []);
|
||||
var entity = Entity(0, 0, "player");
|
||||
entity.CargoContents =
|
||||
[
|
||||
new AetheriaRuntimeCargoBayLoadoutCommit
|
||||
{
|
||||
Items =
|
||||
[
|
||||
new AetheriaRuntimeLoadoutItemSlotCommit
|
||||
{
|
||||
Item = new AetheriaRuntimeLoadoutItemCommit { ItemKey = "repair-gel", Quantity = 3 }
|
||||
},
|
||||
new AetheriaRuntimeLoadoutItemSlotCommit
|
||||
{
|
||||
Item = new AetheriaRuntimeLoadoutItemCommit { ItemKey = "ore", Quantity = 7 }
|
||||
}
|
||||
]
|
||||
}
|
||||
];
|
||||
var run = new AetheriaRuntimeRunCheckpointCommit
|
||||
{
|
||||
RunId = "consumable-input-smoke",
|
||||
CurrentZoneIndex = 0,
|
||||
Zones = [new AetheriaRuntimeZoneSnapshotCommit { ZoneIndex = 0, Entities = [entity] }]
|
||||
};
|
||||
run.CurrentEntityKey = run.EntityRecordKey(0, entity.EntityIndex);
|
||||
var frame = AetheriaRuntimeDaemonFrameDocument.Create(run, "smoke", "consumable-input", 1, 0.1, 0.1);
|
||||
var capability = AetheriaRuntimeInputCapabilityDocument.FromFrame(frame, catalog: catalog);
|
||||
var action = capability.Actions.Single(value => value.Category == "consumable");
|
||||
RequireEqual("3", action.Payload["quantityRemaining"],
|
||||
"consumable action bars must derive quantity from daemon cargo truth");
|
||||
RequireEqual("0", action.Payload["fillValue"],
|
||||
"inactive consumables must advertise an empty remaining-duration fill");
|
||||
RequireEqual("remaining-ratio.v1", action.Payload["fillModel"],
|
||||
"generic lowerers must receive the fossil action-bar fill semantics explicitly");
|
||||
RequireEqual("available", action.Availability,
|
||||
"a valid consumable in cargo must advertise current command availability");
|
||||
Require(!capability.Actions.Any(value => value.Category == "consumable" && value.Payload["itemKey"] == "ore"),
|
||||
"non-consumable cargo must not become an action-bar command");
|
||||
|
||||
entity.CargoContents = Array.Empty<AetheriaRuntimeCargoBayLoadoutCommit>();
|
||||
entity.ActiveConsumables =
|
||||
[
|
||||
new AetheriaRuntimeActiveConsumableCommit
|
||||
{
|
||||
ItemKey = "repair-gel",
|
||||
Duration = 4,
|
||||
RemainingDuration = 1
|
||||
}
|
||||
];
|
||||
var activeAction = AetheriaRuntimeInputCapabilityDocument.FromFrame(frame, catalog: catalog)
|
||||
.ToEveDocument().Actions.Single(value => value.Category == "consumable");
|
||||
RequireEqual("0", activeAction.Payload["quantityRemaining"],
|
||||
"the action must survive depletion while its daemon-owned effect remains active");
|
||||
RequireEqual("1", activeAction.Payload["activeEffectCount"],
|
||||
"the portable Eve action must expose daemon-owned active effect state");
|
||||
RequireEqual("1", activeAction.Payload["remainingDurationSeconds"],
|
||||
"generic clients must receive exact remaining duration without querying a Unity effect object");
|
||||
RequireEqual("4", activeAction.Payload["durationSeconds"],
|
||||
"generic clients must receive exact authored consumable duration");
|
||||
RequireEqual("0.25", activeAction.Payload["fillValue"],
|
||||
"remaining duration must lower to the fossil action-bar ratio exactly");
|
||||
RequireEqual("unavailable", activeAction.Availability,
|
||||
"a depleted non-stackable active consumable must remain visible but reject activation");
|
||||
}
|
||||
|
||||
private static void InputCapabilityPublishesHeldWeaponGroupLever()
|
||||
{
|
||||
var entity = Entity(0, 0, "player");
|
||||
|
|
|
|||
|
|
@ -5301,7 +5301,7 @@ public class DaemonRuntimeDocumentTests
|
|||
}
|
||||
|
||||
[Test]
|
||||
public void InputCapabilitiesAdvertiseOnlyCurrentlyActivatableConsumables()
|
||||
public void InputCapabilitiesPublishAuthoritativeConsumableActionBarState()
|
||||
{
|
||||
var run = RunWithTwoEntities();
|
||||
run.CurrentEntityKey = run.EntityRecordKey(0, 0);
|
||||
|
|
@ -5312,7 +5312,7 @@ public class DaemonRuntimeDocumentTests
|
|||
{
|
||||
Items = new[]
|
||||
{
|
||||
new AetheriaRuntimeLoadoutItemSlotCommit { Item = new AetheriaRuntimeLoadoutItemCommit { ItemKey = "repair-gel", Quantity = 1 } },
|
||||
new AetheriaRuntimeLoadoutItemSlotCommit { Item = new AetheriaRuntimeLoadoutItemCommit { ItemKey = "repair-gel", Quantity = 3 } },
|
||||
new AetheriaRuntimeLoadoutItemSlotCommit { Item = new AetheriaRuntimeLoadoutItemCommit { ItemKey = "ore", Quantity = 4 } }
|
||||
}
|
||||
}
|
||||
|
|
@ -5329,8 +5329,33 @@ public class DaemonRuntimeDocumentTests
|
|||
|
||||
var capability = AetheriaRuntimeInputCapabilityDocument.FromFrame(frame, catalog: catalog);
|
||||
|
||||
Assert.IsTrue(capability.Actions.Any(action => action.Operation.EndsWith("ActivateConsumable", StringComparison.Ordinal) && action.Payload["itemKey"] == "repair-gel"));
|
||||
var repair = capability.Actions.Single(action => action.Operation.EndsWith("ActivateConsumable", StringComparison.Ordinal));
|
||||
Assert.AreEqual("repair-gel", repair.Payload["itemKey"]);
|
||||
Assert.AreEqual("3", repair.Payload["quantityRemaining"]);
|
||||
Assert.AreEqual("0", repair.Payload["activeEffectCount"]);
|
||||
Assert.AreEqual("0", repair.Payload["fillValue"]);
|
||||
Assert.AreEqual("remaining-ratio.v1", repair.Payload["fillModel"]);
|
||||
Assert.AreEqual("available", repair.Availability);
|
||||
Assert.IsFalse(capability.Actions.Any(action => action.Operation.EndsWith("ActivateConsumable", StringComparison.Ordinal) && action.Payload["itemKey"] == "ore"));
|
||||
|
||||
actor.CargoContents = Array.Empty<AetheriaRuntimeCargoBayLoadoutCommit>();
|
||||
actor.ActiveConsumables = new[]
|
||||
{
|
||||
new AetheriaRuntimeActiveConsumableCommit
|
||||
{
|
||||
ItemKey = "repair-gel",
|
||||
Duration = 2,
|
||||
RemainingDuration = 0.5
|
||||
}
|
||||
};
|
||||
var activeCapability = AetheriaRuntimeInputCapabilityDocument.FromFrame(frame, catalog: catalog).ToEveDocument();
|
||||
var activeRepair = activeCapability.Actions.Single(action => action.Operation.EndsWith("ActivateConsumable", StringComparison.Ordinal));
|
||||
Assert.AreEqual("0", activeRepair.Payload["quantityRemaining"]);
|
||||
Assert.AreEqual("1", activeRepair.Payload["activeEffectCount"]);
|
||||
Assert.AreEqual("0.5", activeRepair.Payload["remainingDurationSeconds"]);
|
||||
Assert.AreEqual("2", activeRepair.Payload["durationSeconds"]);
|
||||
Assert.AreEqual("0.25", activeRepair.Payload["fillValue"]);
|
||||
Assert.AreEqual("unavailable", activeRepair.Availability);
|
||||
}
|
||||
|
||||
[Test]
|
||||
|
|
|
|||
|
|
@ -93,21 +93,69 @@ namespace GameCult.Aetheria.State.Verse
|
|||
{
|
||||
actions.AddRange((entity.WeaponGroups ?? Array.Empty<IReadOnlyList<int>>()).Select((_, index) => WeaponGroupAction(run, entity, index)));
|
||||
actions.AddRange(EquipmentBehaviorActions(run, entity, catalog));
|
||||
actions.AddRange((entity.CargoContents ?? Array.Empty<AetheriaRuntimeCargoBayLoadoutCommit>())
|
||||
.SelectMany(bay => bay.Items)
|
||||
.Where(slot => slot?.Item != null && AetheriaRuntimeConsumableSimulation.CanActivate(entity, catalog, slot.Item.ItemKey))
|
||||
.GroupBy(slot => slot.Item.ItemKey, StringComparer.Ordinal)
|
||||
.Select((group, index) =>
|
||||
{
|
||||
var itemKey = group.Key;
|
||||
var item = catalog?.FindItem(itemKey);
|
||||
return Action($"cargo.{itemKey}.use", $"Use {item?.Name ?? itemKey}", "ActivateConsumable", "consumable", $"{run.CurrentEntityKey}#cargo/{index}", ("itemKey", itemKey));
|
||||
}));
|
||||
actions.AddRange(ConsumableActions(run, entity, catalog));
|
||||
actions.AddRange(TradeActions(run, entity, catalog));
|
||||
}
|
||||
return new AetheriaRuntimeInputCapabilityDocument { Version = frame?.FrameId ?? 0, Actions = actions.ToArray(), DefaultProfiles = BuildDefaultProfiles(actions) };
|
||||
}
|
||||
|
||||
private static IEnumerable<AetheriaRuntimeInputActionDocument> ConsumableActions(
|
||||
AetheriaRuntimeRunCheckpointCommit run,
|
||||
AetheriaRuntimeEntitySnapshotCommit entity,
|
||||
AetheriaRuntimeCatalogSnapshot? catalog)
|
||||
{
|
||||
if (catalog == null)
|
||||
yield break;
|
||||
|
||||
var cargoItems = (entity.CargoContents ?? Array.Empty<AetheriaRuntimeCargoBayLoadoutCommit>())
|
||||
.SelectMany(bay => bay?.Items ?? Array.Empty<AetheriaRuntimeLoadoutItemSlotCommit>())
|
||||
.Where(slot => slot?.Item != null)
|
||||
.Select(slot => slot.Item)
|
||||
.ToArray();
|
||||
var activeEffects = (entity.ActiveConsumables ?? Array.Empty<AetheriaRuntimeActiveConsumableCommit>())
|
||||
.Where(effect => effect != null)
|
||||
.ToArray();
|
||||
var itemKeys = cargoItems.Select(item => item.ItemKey)
|
||||
.Concat(activeEffects.Select(effect => effect.ItemKey))
|
||||
.Where(itemKey => !string.IsNullOrWhiteSpace(itemKey))
|
||||
.Distinct(StringComparer.Ordinal);
|
||||
|
||||
foreach (var itemKey in itemKeys)
|
||||
{
|
||||
var item = catalog.FindItem(itemKey);
|
||||
if (item == null || !string.Equals(item.Category, AetheriaRuntimeItemCategories.Consumable, StringComparison.Ordinal))
|
||||
continue;
|
||||
|
||||
var quantity = cargoItems
|
||||
.Where(candidate => string.Equals(candidate.ItemKey, itemKey, StringComparison.Ordinal))
|
||||
.Sum(candidate => Math.Max(1, candidate.Quantity));
|
||||
var matchingEffects = activeEffects
|
||||
.Where(effect => string.Equals(effect.ItemKey, itemKey, StringComparison.Ordinal))
|
||||
.ToArray();
|
||||
var active = matchingEffects.FirstOrDefault();
|
||||
var remainingRatio = active == null || active.Duration <= 0
|
||||
? 0
|
||||
: Math.Max(0, Math.Min(1, active.RemainingDuration / active.Duration));
|
||||
var action = Action(
|
||||
$"cargo.{itemKey}.use",
|
||||
$"Use {item.Name ?? itemKey}",
|
||||
"ActivateConsumable",
|
||||
"consumable",
|
||||
$"{run.CurrentEntityKey}#consumable/{itemKey}",
|
||||
("itemKey", itemKey),
|
||||
("quantityRemaining", quantity.ToString(System.Globalization.CultureInfo.InvariantCulture)),
|
||||
("activeEffectCount", matchingEffects.Length.ToString(System.Globalization.CultureInfo.InvariantCulture)),
|
||||
("remainingDurationSeconds", (active?.RemainingDuration ?? 0).ToString("R", System.Globalization.CultureInfo.InvariantCulture)),
|
||||
("durationSeconds", (active?.Duration ?? item.Duration).ToString("R", System.Globalization.CultureInfo.InvariantCulture)),
|
||||
("fillValue", remainingRatio.ToString("R", System.Globalization.CultureInfo.InvariantCulture)),
|
||||
("fillModel", "remaining-ratio.v1"));
|
||||
action.Availability = AetheriaRuntimeConsumableSimulation.CanActivate(entity, catalog, itemKey)
|
||||
? "available"
|
||||
: "unavailable";
|
||||
yield return action;
|
||||
}
|
||||
}
|
||||
|
||||
private static IEnumerable<AetheriaRuntimeInputActionDocument> EquipmentBehaviorActions(
|
||||
AetheriaRuntimeRunCheckpointCommit run,
|
||||
AetheriaRuntimeEntitySnapshotCommit entity,
|
||||
|
|
|
|||
|
|
@ -31,7 +31,7 @@ validation proves contract shape, not wiring, exclusivity, lowering, or parity.
|
|||
| Wormhole travel | `ActionGameManager.EnterWormhole` plus `Ship` enter/exit state | daemon fixed-step transition plus Ymir exclusion | current-entity transition state and feedback chronology | provider-selected generic transition lowering | command acceptance no longer moves an entity immediately; player interact, explicit travel, and agent routing derive the same canonical adjacent-zone wormhole and proximity gate, then persist four-second `entering`, authoritative transfer, four-second `exiting`, and one-frame `completed` phases. The daemon owns smootherstep XZ motion, the fossil 1000-unit visual-depth lever, deterministic 20-unit exit direction, 50-unit exit radius, target-adjacency discovery, and exactly-once start/transfer/completion events. Flight and every world-physics implementation receive no transitioning body; Ymir resumes on the tick after completion. Smoke serializes and rehydrates mid-entry and proves agents traverse multi-edge routes through the same command boundary | generic provider transition effect/camera lowering and live multi-zone pilot witness |
|
||||
| Inventory/equipment | `Entity.ItemFits`, `TryEquip`, `TryUnequip`, `EquippedCargoBay.ItemFits`/`TryStore`, inventory panels + ServerShared | daemon atomic inventory transactions | typed inventory/equipment state, commands, exact receipts | generic UI | generated cargo and docking bays now occupy their typed collections instead of masquerading as ordinary equipment; docked equip/reposition/store validates the complete destination on cloned state before committing either side, uses authored hull interior and hardpoint geometry, forces hardpoint rotation, rejects occupied cells and deployed ships, preserves exact item instance fields and weapon-group membership, routes bay categories with aligned content/assignment arrays, and refuses to unequip nonempty/occupied bays. Cargo transfer now uses the same plan-first rule with typed bay interiors, rotated item footprints, deterministic free-cell search, exact stack maxima, and no partial source/destination mutation on rejection; exact reasons reach generic Eve receipts | live generic refit controls, reconnect after accepted and rejected moves, commodity multi-stack chronology, and full fossil inventory feedback parity |
|
||||
| Trade | trade UI/economy | daemon | stock, quote, purchase/sale commands | generic UI | daemon derives station, stock row, catalog item, current price, quantity, credits, target capacity, and hull-vs-cargo result; purchases ignore client opinions about price and destination kind. Docked sales identify only the source stack and quantity: the daemon derives station, instance-sensitive value, payout, deterministic typed stock placement, and commits cargo/credits atomically; generic Eve advertises available buy and sell actions. The generic Unity live witness receives an authoritative purchase receipt while paused | live sale receipt witness, quote expiry, contested stock, and full trade surface parity |
|
||||
| Action bar/input | input shell and rebinding UI | daemon advertises actions; client owns bindings | input capability and action descriptors | universal binding UI | contracts wired; cargo actions are catalog-filtered to consumables the current actor can actually activate, including suppression of active non-stackable items. Weapon groups advertise the fossil press/release lifecycle as generic `button-hold.v1` values routed to `SetWeaponGroupActive`; daemon entity state persists the active-group latch, press edges pulse instant/charged weapons once, constant weapons remain selected without client keepalives, release clears the latch, and the one-shot compatibility command is not the public input contract. Equipment actions derive from exact installed catalog payload/state pairs instead of blindly activating behavior zero: Switch and Trigger expose generic hold values, adjustable Thermotoggle exposes a scalar Kelvin target/current value, fixed/non-interactive rows are omitted, and offline rows retain identity as unavailable. Every value form translates through generic Eve requests into typed daemon commands under provider identity `aetheria` | runtime action-bar quantity/fill proof and generic scalar-control lowering |
|
||||
| Action bar/input | input shell and rebinding UI | daemon advertises actions; client owns bindings | input capability and action descriptors | universal binding UI | contracts wired; consumable rows are catalog-filtered, expose daemon-owned cargo quantity, active-effect count, exact duration/remaining duration, and the fossil `remaining / duration` fill as `remaining-ratio.v1`. A depleted or non-stackable active consumable remains visible with unavailable command state until its effect ends, so a lowerer never queries Unity gameplay objects. Weapon groups advertise the fossil press/release lifecycle as generic `button-hold.v1` values routed to `SetWeaponGroupActive`; daemon entity state persists the active-group latch, press edges pulse instant/charged weapons once, constant weapons remain selected without client keepalives, release clears the latch, and the one-shot compatibility command is not the public input contract. Equipment actions derive from exact installed catalog payload/state pairs instead of blindly activating behavior zero: Switch and Trigger expose generic hold values, adjustable Thermotoggle exposes a scalar Kelvin target/current value, fixed/non-interactive rows are omitted, and offline rows retain identity as unavailable. Every value form translates through generic Eve requests into typed daemon commands under provider identity `aetheria` | generic scalar-control and action-bar presentation lowering |
|
||||
| Pilot camera | ARPG follow/dock cameras | Eve view semantics + runtime | camera rig and semantic view id | EveUnity camera rig | daemon dock state selects distinct contracts instead of collapsing both fossil cameras: undocked flight advertises the entity-forward `Third Person Rig` framing (distance 30, screen 0.64/0.19, FOV 60, lens 1-4096) and the shared `aim.presentation` convergence point as its look-at; Aetheria translates the fossil Cinemachine top-origin screen Y of `0.81` to Eve's bottom-origin viewport Y of `0.19`; EveUnity solves native pose while preserving both optical aim and advertised entity framing, without provider types; the retained dock projection remains separate | reproduce the dock camera's separate follow/look-at subjects, blend timeline, noise, and reconnect state |
|
||||
| Render channels | Unity layers/culling masks | provider surface policy + runtime asset variant | semantic channel exclusions | EveUnity native layer mapping | wired, exclusive, and lowered: the pilot surface excludes the semantic `map` channel; the Unity asset variant maps `map` to its authored native layer; EveUnity subtracts that layer from the configured camera mask; portable state contains no Unity layer or mask; provider conversion preserves the source icon shader's unlit lighting model; the released witness proves the pilot camera excludes map glyphs while the map camera retains readable white glyphs without a scene light | preserve the channel proof while world presentation and transport continue to evolve |
|
||||
| Minimap/tactical map | `ZoneRenderer`, map cameras | daemon world facts | explicit map projections | Unity and Electron | facts fragmented; generic lowerers absent | same state in both runtimes |
|
||||
|
|
|
|||
Loading…
Reference in a new issue