载入中...
搜索中...
未找到
InventoryControl.cpp
浏览该文件的文档.
23 return failure<const Value::Object*>(DiagnosticCode::InvalidArgument, "inventory parameters must be an object",
28Result<std::string> text(const Value::Object& value, std::string_view name, std::string fallback = {}) {
32 return failure<std::string>(DiagnosticCode::InvalidArgument, "inventory parameter must be a string",
65Result<void> InventoryControl::publish(SubjectRef instance, SubjectRef owner, Bag& bag, EquipmentSet* equipment) {
68 DiagnosticCode::InvalidArgument, "inventory publication needs valid instance and owner ids", "instance"));
71 DiagnosticCode::Conflict, "a gameplay control already owns that inventory instance", "instance"));
86 Diagnostic::error(DiagnosticCode::NotFound, "that inventory instance is not published", "instance"));
166 slot.emplace("quantity", Value(static_cast<std::int64_t>(equipment->getSlotQuantity(slotName))));
167 slot.emplace("instanceId", Value(static_cast<std::int64_t>(equipment->getSlotInstanceId(slotName))));
179 return failure<GameplayObservation>(DiagnosticCode::NotFound, "inventory gameplay instance was not found",
193Result<std::vector<GameplayActionDescriptor>> InventoryControl::availableGameplayActions(const GameplaySession& session,
197 if (!observed) return Result<std::vector<GameplayActionDescriptor>>::failure(observed.status());
211 Value(Value::Object{{"fromSlot", integerType}, {"toSlot", integerType}, {"quantity", integerType}})},
216 actions.push_back({id(kEquip), Value(Value::Object{{"bagSlot", integerType}, {"equipSlot", stringType}})});
223 actions.push_back({id(kAddItem), Value(Value::Object{{"itemId", stringType}, {"quantity", integerType}})});
228Result<GameplayCommandReceipt> InventoryControl::submitGameplay(const GameplaySession& session, SubjectRef instance,
232 return failure<GameplayCommandReceipt>(DiagnosticCode::NotFound, "inventory gameplay instance was not found",
238 return failure<GameplayCommandReceipt>(DiagnosticCode::InvalidArgument, "command id must not be empty",
242 DiagnosticCode::Conflict, "inventory command was based on a stale observation", "command.expectedRevision");
250 return failure<GameplayCommandReceipt>(DiagnosticCode::Failed, "inventory instance lost its container",
279 return failure<GameplayCommandReceipt>(DiagnosticCode::Failed, "bag rejected the granted items",
295 return failure<GameplayCommandReceipt>(DiagnosticCode::PreconditionViolation, "bag does not hold that item",
314 detail = "moved " + std::to_string(quantity.value()) + " from slot " + std::to_string(fromSlot.value());
332 return failure<GameplayCommandReceipt>(DiagnosticCode::Failed, "equip was rejected by the equipment set",
344 return failure<GameplayCommandReceipt>(DiagnosticCode::PreconditionViolation, "equipment slot is empty",
348 return failure<GameplayCommandReceipt>(DiagnosticCode::Failed, "unequip was rejected by the equipment set",
354 return failure<GameplayCommandReceipt>(DiagnosticCode::Unsupported, "unsupported inventory action",
367 {"instance", Value(entry->instance.format())}, {"detail", Value(detail)}, {"quantity", Value(applied)}});
376 Value(Value::Object{{"action", Value(action)}, {"detail", Value(detail)}, {"quantity", Value(applied)}});
377 return Result<GameplayCommandReceipt>::success(std::move(receipt), Status::success(StatusCode::Applied));
380Result<GameplayObservation> InventoryControl::advanceGameplay(const GameplaySession& session, SubjectRef instance,
384 return failure<GameplayObservation>(DiagnosticCode::NotFound, "inventory gameplay instance was not found",
387 return failure<GameplayObservation>(DiagnosticCode::Conflict, "inventory simulation tick must increase",
static Diagnostic error(DiagnosticCode code, std::string message, std::string path={}, DiagnosticDetails details={}, std::string source={})
Construct an error diagnostic with the standard error severity.
Definition Diagnostic.h:125
const std::string & format() const noexcept
Returns the canonical namespace:name representation.
Definition Identity.h:436
static std::optional< LogicalId > parse(std::string_view text)
Parses a scoped logical name.
Definition Identity.cpp:36
static Result failure(Status status)
Construct a failed result from a structured status.
Definition Result.h:175
static Status success(StatusCode code=StatusCode::Ok)
Construct a successful status with an explicit non-error outcome.
Definition Status.h:81
bool isValid() const noexcept
Return whether this reference is valid and non-nil.
Definition SubjectRef.h:38
std::string canAddItemReason(const std::string &itemId, int quantity)
Can add item reason.
Definition Bag.cpp:61
bool canAddItem(const std::string &itemId, int quantity)
便捷操作(转发 InventorySystem):增删 / 移动 / 查询。
Definition Bag.cpp:57
Result< GameplayCommandReceipt > submitGameplay(const GameplaySession &session, SubjectRef instance, const GameplayCommand &command) override
Validate authority and atomically submit one domain command.
Definition InventoryControl.cpp:228
Result< std::vector< GameplayEvent > > gameplayEvents(const GameplaySession &session, SubjectRef instance, std::uint64_t afterSequence) const override
Return events strictly newer than an instance-local sequence cursor.
Definition InventoryControl.cpp:395
Result< GameplayObservation > observeGameplay(const GameplaySession &session, SubjectRef instance) const override
Observe one provider-owned gameplay instance without mutation.
Definition InventoryControl.cpp:175
~InventoryControl() override
Unpublish every instance without destroying borrowed authorities.
Definition InventoryControl.cpp:60
std::vector< SubjectRef > gameplayInstances() const override
Instances currently served, in publication order.
Definition InventoryControl.cpp:116
InventoryControl()
Create an unpublished adapter and register it as the inventory domain.
Definition InventoryControl.cpp:55
std::string_view gameplayDomain() const noexcept override
Stable provider domain used for discovery and routing.
Definition InventoryControl.cpp:114
void clear()
Drop every publication without destroying borrowed containers.
Definition InventoryControl.cpp:91
Result< std::vector< GameplayActionDescriptor > > availableGameplayActions(const GameplaySession &session, SubjectRef instance, SubjectRef subject) const override
Discover currently legal player-semantic actions for one subject.
Definition InventoryControl.cpp:193
Result< GameplayObservation > advanceGameplay(const GameplaySession &session, SubjectRef instance, const SimulationStep &step) override
Advance one provider-owned instance using injected deterministic time.
Definition InventoryControl.cpp:380
std::vector< SubjectRef > instances() const
Published instance identities, in publication order.
Definition InventoryControl.cpp:95
Result< void > publish(SubjectRef instance, SubjectRef owner, Bag &bag, EquipmentSet *equipment)
Publish one borrowed inventory instance under a stable identity.
Definition InventoryControl.cpp:65
Result< void > unpublish(SubjectRef instance)
Drop one publication; NotFound when that instance is not published.
Definition InventoryControl.cpp:81
std::variant< std::monostate, std::int64_t, double, std::string, bool > Value
Definition Database.h:26
运行时容器:固定格数的背包 / 箱子 / 商店栏等。 行为由 InventorySystem 提供;本类暴露便于脚本绑定的薄封装方法。
Definition AvatarInstance.h:37
@ InvalidArgument
@ NotFound
@ PreconditionViolation
@ Unsupported
@ Failed
@ Conflict
@ NoOp
@ Applied
@ PlayerEquivalent
Definition Container.h:602
Owning evidence that a gameplay authority accepted one command.
Definition GameplayControl.h:62
std::uint64_t resultingRevision
Definition GameplayControl.h:66
One player-semantic command submitted to a domain authority.
Definition GameplayControl.h:52
Owning event projection safe across frames and process boundaries.
Definition GameplayControl.h:71
Immutable owning observation of one authoritative gameplay instance.
Definition GameplayControl.h:43
Owning authorization context shared by player, script and automation adapters.
Definition GameplayControl.h:30