载入中...
搜索中...
未找到
ShopCatalogue.cpp
浏览该文件的文档.
36 return eve::Result<int>::failure(eve::Diagnostic::error(eve::DiagnosticCode::InvalidArgument, std::move(message),
41 static const std::unordered_set<std::string> known = {"id", "itemId", "name", "desc", "buyPrice", "sellPrice"};
54 if (!root.isArray() || root.size() == 0) return failure("shop catalogue must be a non-empty array", "$");
83 return failure("sellPrice must be a non-negative integer no greater than buyPrice", path + ".sellPrice");
124 return eve::Result<int>::failure(eve::Diagnostic::error(code, std::move(message), std::move(path),
128eve::Result<double> validateTrade(const GameState &gameState, const std::string ¤cyId, const std::string &itemId,
130 if (currencyId.empty() || itemId.empty() || quantity <= 0 || !std::isfinite(unitPrice) || unitPrice < 0.0)
133 "shop trade requires currency/item ids, positive quantity, and finite non-negative unit price", "trade",
140 eve::DiagnosticCode::InvalidArgument, "shop trade would produce a non-finite currency value", "unitPrice",
144 eve::DiagnosticCode::PreconditionViolation, "shop purchase has insufficient currency", "currency",
149eve::Result<int> rollbackFailure(GameState &gameState, const std::string &snapshot, const eve::Status &commitStatus,
153 return tradeFailure(eve::DiagnosticCode::InvariantViolation, "shop trade rollback could not restore GameState",
160eve::Result<int> ShopTransaction::buyOffer(GameState &gameState, inventory::Bag &bag, const std::string ¤cyId,
164 return tradeFailure(eve::DiagnosticCode::NotFound, "shop purchase references an unknown offer", "offerId",
169eve::Result<int> ShopTransaction::sellOffer(GameState &gameState, inventory::Bag &bag, const std::string ¤cyId,
173 return tradeFailure(eve::DiagnosticCode::NotFound, "shop sale references an unknown offer", "offerId", offerId);
177eve::Result<int> ShopTransaction::buy(GameState &gameState, inventory::Bag &bag, const std::string ¤cyId,
194eve::Result<int> ShopTransaction::sell(GameState &gameState, inventory::Bag &bag, const std::string ¤cyId,
全局游戏状态:开关(bool)、变量(数字)、独立变量(按作用域)。
Strict, atomically replaceable RPG shop content.
Atomic RPG currency and inventory purchase/sale orchestration.
static Diagnostic error(DiagnosticCode code, std::string message, std::string path={})
Construct an error diagnostic with the standard error severity.
Definition Diagnostic.cpp:21
static Result failure(Status status)
Construct a failed result from a structured status.
Definition Result.h:196
static eve::Result< int > commitRemove(PreparedInventoryRemove prepared)
Commit a prepared removal and publish its event after the no-fail slot swap.
Definition InventorySystem.cpp:538
static eve::Result< int > commitAddBatch(PreparedInventoryAdd prepared)
Commit one prepared addition and then publish its change events.
Definition InventorySystem.cpp:481
static eve::Result< PreparedInventoryAdd > prepareAddBatch(Bag *bag, const std::vector< InventoryItemGrant > &grants)
Validate a multi-item addition against a private candidate Bag.
Definition InventorySystem.cpp:437
static eve::Result< PreparedInventoryRemove > prepareRemove(Bag *bag, const std::string &itemId, int quantity)
Prepare removal of one exact item quantity without mutation or events.
Definition InventorySystem.cpp:500
static Document parse(const std::string &text, std::string *error=nullptr)
Parse.
Definition Json.cpp:623
eve::Result< std::string > snapshotJson() const
Serialize this state as the canonical versioned RPG game-state JSON document.
Definition GameState.cpp:122
static eve::Result< int > replaceFromJsonStrict(const std::string &json)
Strictly validate and atomically replace the entire offer catalogue.
Definition ShopCatalogue.cpp:49
static const ShopOffer * find(const std::string &id)
Find an offer by stable offer id, or null when absent.
Definition ShopCatalogue.cpp:107
static const ShopOffer * at(int index)
Return an offer by deterministic source index, or null when out of range.
Definition ShopCatalogue.cpp:112
static void clear()
Remove all offers. Intended for teardown and isolated tests.
Definition ShopCatalogue.cpp:100
static int count()
Return the number of committed offers in deterministic source order.
Definition ShopCatalogue.cpp:105
static eve::Result< int > sell(GameState &gameState, inventory::Bag &bag, const std::string ¤cyId, const std::string &itemId, int quantity, double unitPrice)
Atomically remove an item quantity and credit its sale proceeds.
Definition ShopCatalogue.cpp:194
static eve::Result< int > sellOffer(GameState &gameState, inventory::Bag &bag, const std::string ¤cyId, const std::string &offerId, int quantity)
Sell a quantity using the authoritative price and item in ShopCatalogue.
Definition ShopCatalogue.cpp:169
static eve::Result< int > buyOffer(GameState &gameState, inventory::Bag &bag, const std::string ¤cyId, const std::string &offerId, int quantity)
Buy a quantity using the authoritative price and item in ShopCatalogue.
Definition ShopCatalogue.cpp:160
static eve::Result< int > buy(GameState &gameState, inventory::Bag &bag, const std::string ¤cyId, const std::string &itemId, int quantity, double unitPrice)
Atomically debit currency and add the purchased item quantity.
Definition ShopCatalogue.cpp:177
void keys(const Value &value, std::initializer_list< const char * > names)
Definition OceanCodecInternal.h:8
@ InvalidArgument
@ NotFound
@ PreconditionViolation
@ InvariantViolation
One immutable offer in the process-local shop catalogue.
Definition ShopCatalogue.h:14