载入中...
搜索中...
未找到
Inventory.cpp
浏览该文件的文档.
5#include "inventory/Item.h"
6
7#include "common/SubjectRef.h"
8
9#include <simplesquirrel/simplesquirrel.hpp>
10
11namespace eve::inventory {
12
14
15Inventory::Inventory() = default;
16
17int Inventory::registerItemsFromJson(const std::string &json) {
19 return ItemRegistry::loadFromJson(json, nullptr);
20}
21
23
25
26bool Inventory::hasItemDefinition(const std::string &itemId) {
27 return ItemRegistry::find(itemId) != nullptr;
28}
29
30std::string Inventory::getItemDisplayName(const std::string &itemId) {
31 const auto *def = ItemRegistry::find(itemId);
32 return def ? def->displayName : std::string{};
33}
34
35int Inventory::getItemMaxStack(const std::string &itemId) {
36 const auto *def = ItemRegistry::find(itemId);
37 return def ? def->maxStack : 0;
38}
39
40float Inventory::getItemWeight(const std::string &itemId) {
41 const auto *def = ItemRegistry::find(itemId);
42 return def ? def->weight : 0.f;
43}
44
45float Inventory::getItemVolume(const std::string &itemId) {
46 const auto *def = ItemRegistry::find(itemId);
47 return def ? def->volume : 0.f;
48}
49
50std::string Inventory::getItemCategory(const std::string &itemId) {
51 const auto *def = ItemRegistry::find(itemId);
52 return def ? def->category : std::string{};
53}
54
55std::string Inventory::getItemEquipSlot(const std::string &itemId) {
56 const auto *def = ItemRegistry::find(itemId);
57 return def ? def->equipSlot : std::string{};
58}
59
60bool Inventory::itemHasTag(const std::string &itemId, const std::string &tag) {
61 const auto *def = ItemRegistry::find(itemId);
62 return def ? def->hasTag(tag) : false;
63}
64
65std::string Inventory::getItemExtra(const std::string &itemId, const std::string &key,
66 const std::string &fallback) {
67 const auto *def = ItemRegistry::find(itemId);
68 return def ? def->getExtra(key, fallback) : fallback;
69}
70
71Bag *Inventory::newBag(int slotCount) {
73 return new Bag(slotCount);
74}
75
80
81int Inventory::transferItem(Bag *from, Bag *to, const std::string &itemId, int quantity) {
82 return InventorySystem::transfer(from, to, itemId, quantity);
83}
84
85int Inventory::transferSlot(Bag *from, int fromSlot, Bag *to, int quantity) {
86 return InventorySystem::transferSlot(from, fromSlot, to, quantity);
87}
88
89bool Inventory::hasAcceptRule(const std::string &ruleName) {
90 return InventorySystem::hasAcceptRule(ruleName);
91}
92
93bool Inventory::hasCapacityPolicy(const std::string &policyName) {
94 return InventorySystem::hasCapacityPolicy(policyName);
95}
96
97bool Inventory::hasStackRule(const std::string &ruleName) {
98 return InventorySystem::hasStackRule(ruleName);
99}
100
102
104 return int(InventorySystem::events().size());
105}
106
108 const auto &evs = InventorySystem::events();
109 if (index < 0 || size_t(index) >= evs.size()) return {};
110 return evs[size_t(index)].action;
111}
112
113std::string Inventory::getChangeEventBagId(int index) const {
114 const auto &evs = InventorySystem::events();
115 if (index < 0 || size_t(index) >= evs.size()) return {};
116 return evs[size_t(index)].bagId;
117}
118
120 const auto &evs = InventorySystem::events();
121 if (index < 0 || size_t(index) >= evs.size()) return {};
122 return evs[size_t(index)].otherBagId;
123}
124
126 const auto &evs = InventorySystem::events();
127 if (index < 0 || size_t(index) >= evs.size()) return {};
128 return evs[size_t(index)].itemId;
129}
130
132 const auto &evs = InventorySystem::events();
133 if (index < 0 || size_t(index) >= evs.size()) return 0;
134 return evs[size_t(index)].quantity;
135}
136
138 const auto &evs = InventorySystem::events();
139 if (index < 0 || size_t(index) >= evs.size()) return -1;
140 return evs[size_t(index)].slot;
141}
142
144 const auto &evs = InventorySystem::events();
145 if (index < 0 || size_t(index) >= evs.size()) return -1;
146 return evs[size_t(index)].otherSlot;
147}
148
150 const auto &evs = InventorySystem::events();
151 if (index < 0 || size_t(index) >= evs.size()) return {};
152 return evs[size_t(index)].equipSlot;
153}
154
155void Inventory::expose(ssq::Table &table) {
156 auto cls = table.addClass(name, Inventory::create, false);
157 expose(cls);
158
159 auto bag = table.addClass<Bag>(
160 "Bag", std::function<Bag *(int)>([](int slots) -> Bag * { return new Bag(slots); }), true);
161 bag.addFunc("destroy", &Bag::destroy);
162 bag.addFunc("getId", &Bag::getId);
163 bag.addFunc("setId", &Bag::setId);
164 bag.addFunc("getKind", &Bag::getKind);
165 bag.addFunc("setKind", &Bag::setKind);
166 bag.addFunc("getSlotCount", &Bag::getSlotCount);
167 bag.addFunc("setSlotCount", &Bag::setSlotCount);
168 bag.addFunc("getMaxWeight", &Bag::getMaxWeight);
169 bag.addFunc("setMaxWeight", &Bag::setMaxWeight);
170 bag.addFunc("getMaxVolume", &Bag::getMaxVolume);
171 bag.addFunc("setMaxVolume", &Bag::setMaxVolume);
172 bag.addFunc("getAcceptRule", &Bag::getAcceptRule);
173 bag.addFunc("setAcceptRule", &Bag::setAcceptRule);
174 bag.addFunc("getCapacityPolicy", &Bag::getCapacityPolicy);
175 bag.addFunc("setCapacityPolicy", &Bag::setCapacityPolicy);
176 bag.addFunc("getStackRule", &Bag::getStackRule);
177 bag.addFunc("setStackRule", &Bag::setStackRule);
178 bag.addFunc("clearAcceptTags", &Bag::clearAcceptTags);
179 bag.addFunc("addAcceptTag", &Bag::addAcceptTag);
180 bag.addFunc("getAcceptTagCount", &Bag::getAcceptTagCount);
181 bag.addFunc("getAcceptTag", &Bag::getAcceptTag);
182 bag.addFunc("clearRejectTags", &Bag::clearRejectTags);
183 bag.addFunc("addRejectTag", &Bag::addRejectTag);
184 bag.addFunc("getRejectTagCount", &Bag::getRejectTagCount);
185 bag.addFunc("getRejectTag", &Bag::getRejectTag);
186 bag.addFunc("setExtra", &Bag::setExtra);
187 bag.addFunc("getExtra", &Bag::getExtra);
188 bag.addFunc("canAddItem", &Bag::canAddItem);
189 bag.addFunc("canAddItemReason", &Bag::canAddItemReason);
190 bag.addFunc("addItem", &Bag::addItem);
191 bag.addFunc("removeItem", &Bag::removeItem);
192 bag.addFunc("removeAt", &Bag::removeAt);
193 bag.addFunc("swapSlots", &Bag::swapSlots);
194 bag.addFunc("moveSlot", &Bag::moveSlot);
195 bag.addFunc("splitStack", &Bag::splitStack);
196 bag.addFunc("countItem", &Bag::countItem);
197 bag.addFunc("findItem", &Bag::findItem);
198 bag.addFunc("findItemByTag", &Bag::findItemByTag);
199 bag.addFunc("getUsedWeight", &Bag::getUsedWeight);
200 bag.addFunc("getUsedVolume", &Bag::getUsedVolume);
201 bag.addFunc("getUsedSlotCount", &Bag::getUsedSlotCount);
202 bag.addFunc("clear", &Bag::clear);
203 bag.addFunc("isSlotEmpty", &Bag::isSlotEmpty);
204 bag.addFunc("getSlotItemId", &Bag::getSlotItemId);
205 bag.addFunc("getSlotQuantity", &Bag::getSlotQuantity);
206 bag.addFunc("getSlotInstanceId", &Bag::getSlotInstanceId);
207 bag.addFunc("getSlotDurability", &Bag::getSlotDurability);
208 bag.addFunc("setSlotDurability", &Bag::setSlotDurability);
209 bag.addFunc("getSlotProp", &Bag::getSlotProp);
210 bag.addFunc("setSlotProp", &Bag::setSlotProp);
211 bag.addFunc("slotHasTag", &Bag::slotHasTag);
212 bag.addFunc("addSlotTag", &Bag::addSlotTag);
213
214 auto eq = table.addClass<EquipmentSet>(
215 "EquipmentSet", std::function<EquipmentSet *()>([]() { return new EquipmentSet(); }), true);
216 eq.addFunc("destroy", &EquipmentSet::destroy);
217 eq.addFunc("getId", &EquipmentSet::getId);
218 eq.addFunc("setId", &EquipmentSet::setId);
219 eq.addFunc("defineSlot", &EquipmentSet::defineSlot);
220 eq.addFunc("clearSlotAllowedTags", &EquipmentSet::clearSlotAllowedTags);
221 eq.addFunc("addSlotAllowedTag", &EquipmentSet::addSlotAllowedTag);
222 eq.addFunc("hasSlot", &EquipmentSet::hasSlot);
223 eq.addFunc("getSlotCount", &EquipmentSet::getSlotCount);
224 eq.addFunc("getSlotName", &EquipmentSet::getSlotName);
225 eq.addFunc("isSlotEmpty", &EquipmentSet::isSlotEmpty);
226 eq.addFunc("getSlotItemId", &EquipmentSet::getSlotItemId);
227 eq.addFunc("getSlotQuantity", &EquipmentSet::getSlotQuantity);
228 eq.addFunc("getSlotInstanceId", &EquipmentSet::getSlotInstanceId);
229 eq.addFunc("equipFromBag", &EquipmentSet::equipFromBag);
230 eq.addFunc("unequipToBag", &EquipmentSet::unequipToBag);
231 eq.addFunc("clearSlot", &EquipmentSet::clearSlot);
232
233 auto saveSession = table.addClass<InventorySaveSession>(
234 "InventorySaveSession",
235 std::function<InventorySaveSession *()>([]() { return new InventorySaveSession(); }), true);
236 saveSession.addFunc("bind", [](InventorySaveSession *session, Bag *boundBag,
237 EquipmentSet *boundEquipment) -> int {
238 if (!session || !boundBag || !boundEquipment) return 0;
239 session->bind(*boundBag, *boundEquipment);
240 return 1;
241 });
242 saveSession.addFunc("snapshotJson", [](InventorySaveSession *session) -> std::string {
243 if (!session) return {};
244 auto result = session->snapshotJson();
245 return result.ok() ? std::move(result).takeValue() : std::string{};
246 });
247 saveSession.addFunc("restoreSnapshotJson",
248 [](InventorySaveSession *session, const std::string &json) -> int {
249 return session && session->restoreSnapshotJson(json).ok() ? 1 : 0;
250 });
251}
252
253void Inventory::expose(ssq::Class &cls) {
254 cls.addFunc("getName", &Inventory::getName);
255 cls.addFunc("registerItemsFromJson", &Inventory::registerItemsFromJson);
256 cls.addFunc("clearItemDefinitions", &Inventory::clearItemDefinitions);
257 cls.addFunc("getItemDefinitionCount", &Inventory::getItemDefinitionCount);
258 cls.addFunc("hasItemDefinition", &Inventory::hasItemDefinition);
259 cls.addFunc("getItemDisplayName", &Inventory::getItemDisplayName);
260 cls.addFunc("getItemMaxStack", &Inventory::getItemMaxStack);
261 cls.addFunc("getItemWeight", &Inventory::getItemWeight);
262 cls.addFunc("getItemVolume", &Inventory::getItemVolume);
263 cls.addFunc("getItemCategory", &Inventory::getItemCategory);
264 cls.addFunc("getItemEquipSlot", &Inventory::getItemEquipSlot);
265 cls.addFunc("itemHasTag", &Inventory::itemHasTag);
266 cls.addFunc("getItemExtra", &Inventory::getItemExtra);
267 cls.addFunc("newBag", &Inventory::newBag);
268 cls.addFunc("newEquipmentSet", &Inventory::newEquipmentSet);
269 cls.addFunc("transferItem", &Inventory::transferItem);
270 cls.addFunc("transferSlot", &Inventory::transferSlot);
271 cls.addFunc("hasAcceptRule", &Inventory::hasAcceptRule);
272 cls.addFunc("hasCapacityPolicy", &Inventory::hasCapacityPolicy);
273 cls.addFunc("hasStackRule", &Inventory::hasStackRule);
274 cls.addFunc("clearChangeEvents", &Inventory::clearChangeEvents);
275 cls.addFunc("getChangeEventCount", &Inventory::getChangeEventCount);
276 cls.addFunc("getChangeEventAction", &Inventory::getChangeEventAction);
277 cls.addFunc("getChangeEventBagId", &Inventory::getChangeEventBagId);
278 cls.addFunc("getChangeEventOtherBagId", &Inventory::getChangeEventOtherBagId);
279 cls.addFunc("getChangeEventItemId", &Inventory::getChangeEventItemId);
280 cls.addFunc("getChangeEventQuantity", &Inventory::getChangeEventQuantity);
281 cls.addFunc("getChangeEventSlot", &Inventory::getChangeEventSlot);
282 cls.addFunc("getChangeEventOtherSlot", &Inventory::getChangeEventOtherSlot);
283 cls.addFunc("getChangeEventEquipSlot", &Inventory::getChangeEventEquipSlot);
284
285 // 把玩家背包发布到共享玩法协议(`eve_gameplay` / MCP)。返回 {ok, message}:
286 // 失败原因(非规范持久 id、重复实例、空 bag)不被丢弃。equipment 可为 null;
287 // ssq 的默认指针绑定拒绝 Squirrel `null`,故按 Avatar.cpp 的既有做法接收
288 // ssq::Object 并在此翻译 null -> nullptr。
289 cls.addFunc("publishGameplay", [vm = cls.getHandle()](Inventory *self, const std::string &instanceId,
290 const std::string &ownerId, Bag *bag, ssq::Object equipment) {
291 ssq::Table result(vm);
292 if (self == nullptr || bag == nullptr) {
293 result.set("ok", false);
294 result.set("message", std::string("publishGameplay needs the inventory module and a bag"));
295 return result;
296 }
297 EquipmentSet *equipmentSet = equipment.isNull() ? nullptr : equipment.toPtrUnsafe<EquipmentSet *>();
298 const auto published = self->publishGameplay(instanceId, ownerId, bag, equipmentSet);
299 result.set("ok", published.ok());
300 result.set("message", published.ok() ? std::string("published") : published.status().describe());
301 return result;
302 });
303 cls.addFunc("unpublishGameplay", [vm = cls.getHandle()](Inventory *self, const std::string &instanceId) {
304 ssq::Table result(vm);
305 const auto unpublished = self == nullptr
307 eve::DiagnosticCode::Failed, "inventory module unavailable", "self"))
308 : self->unpublishGameplay(instanceId);
309 result.set("ok", unpublished.ok());
310 result.set("message", unpublished.ok() ? std::string("unpublished") : unpublished.status().describe());
311 return result;
312 });
313 cls.addFunc("clearGameplayControls", &Inventory::clearGameplayControls);
314 cls.addFunc("getGameplayControlCount", &Inventory::gameplayControlCount);
315}
316
317Inventory::~Inventory() { clearGameplayControls(); }
318
319eve::Result<void> Inventory::publishGameplay(const std::string &instanceId, const std::string &ownerId, Bag *bag,
320 EquipmentSet *equipment) {
321 if (instanceId.empty() || ownerId.empty() || bag == nullptr)
324 "publishGameplay needs an instance id, an owner id and a bag", "instanceId"));
325 const auto instance = eve::PersistentId::parse(instanceId);
326 const auto owner = eve::PersistentId::parse(ownerId);
327 if (!instance.has_value() || !owner.has_value())
330 "instance and owner ids must be canonical persistent ids", "instanceId"));
331 if (!gameplay_) gameplay_ = std::make_unique<InventoryControl>();
332 return gameplay_->publish(eve::SubjectRef::fromPersistentId(*instance), eve::SubjectRef::fromPersistentId(*owner),
333 *bag, equipment);
334}
335
336eve::Result<void> Inventory::unpublishGameplay(const std::string &instanceId) {
337 if (!gameplay_)
339 eve::Diagnostic::error(eve::DiagnosticCode::NotFound, "no inventory instance is published", "instanceId"));
340 const auto instance = eve::PersistentId::parse(instanceId);
341 if (!instance.has_value())
343 eve::DiagnosticCode::InvalidArgument, "the instance id must be a canonical persistent id", "instanceId"));
344 return gameplay_->unpublish(eve::SubjectRef::fromPersistentId(*instance));
345}
346
347void Inventory::clearGameplayControls() {
348 if (gameplay_) gameplay_->clear();
349}
350
351int Inventory::gameplayControlCount() const { return gameplay_ ? gameplay_->count() : 0; }
352
353std::vector<std::string> Inventory::gameplayInstances() const {
354 std::vector<std::string> result;
355 if (!gameplay_) return result;
356 for (const auto &instance : gameplay_->instances()) result.push_back(instance.format());
357 return result;
358}
359
360} // namespace eve::inventory
LogicalId itemId
std::string from
HSQUIRRELVM vm
Definition ECS.cpp:20
HSQOBJECT cls
Definition ECS.cpp:21
std::uint32_t key
wgpu::PopErrorScopeStatus status
HexCoordinates to
Cell the unit walks towards on this segment.
Definition HexUnits.cpp:64
Versioned atomic persistence boundary for one bag and equipment set.
std::string name
const std::string * tag
#define Module_IMPL(ModuleName, newExpr)
Definition Module.h:26
std::string string
LocalPageCacheEntry slots[ShadowConfig::kLocalSlots]
Stable reference to a runtime gameplay subject.
std::optional< InteractionSession > session
Definition Tactics.cpp:39
float size
Definition TreeMesh.cpp:156
uint32_t index
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
virtual std::string getName() const =0
Returns the name.
Move-only operation result carrying either a value or Status.
Definition Result.h:155
static Result failure(Status status)
Construct a failed result from a structured status.
Definition Result.h:175
static SubjectRef fromPersistentId(PersistentId id) noexcept
Wrap a persistent identity without changing its bytes.
Definition SubjectRef.h:32
static std::optional< Id128 > parse(std::string_view text) noexcept
Parses canonical UUID text.
Definition Identity.h:151
格子型物品容器(脚本可直接操作)。
Definition Bag.h:21
int getSlotInstanceId(int slot) const
Returns the slot instance id.
Definition Bag.cpp:122
std::string getId() const
容器 id(变更事件定位用)。
Definition Bag.h:35
float getUsedWeight() const
Returns the used weight.
Definition Bag.cpp:99
void setSlotCount(int slotCount)
调整格数:扩容追加空槽;缩容会丢弃被裁掉的槽(不自动转移)。
Definition Bag.cpp:15
float getMaxVolume() const
Returns the max volume.
Definition Bag.h:54
std::string canAddItemReason(const std::string &itemId, int quantity)
Can add item reason.
Definition Bag.cpp:61
std::string getAcceptTag(int index) const
Returns the accept tag.
Definition Bag.cpp:30
bool canAddItem(const std::string &itemId, int quantity)
便捷操作(转发 InventorySystem):增删 / 移动 / 查询。
Definition Bag.cpp:57
void setSlotDurability(int slot, float durability)
Sets the slot durability.
Definition Bag.cpp:132
std::string getSlotProp(int slot, const std::string &key, const std::string &fallback={}) const
Returns the slot prop.
Definition Bag.cpp:137
int addItem(const std::string &itemId, int quantity)
Adds item.
Definition Bag.cpp:67
int getRejectTagCount() const
Returns the reject tag count.
Definition Bag.cpp:43
void addSlotTag(int slot, const std::string &tag)
Adds slot tag.
Definition Bag.cpp:152
bool slotHasTag(int slot, const std::string &tag) const
Slot has tag.
Definition Bag.cpp:147
float getMaxWeight() const
重量 / 体积上限(容量策略用)。
Definition Bag.h:50
bool splitStack(int slot, int quantity, int toSlot)
Split stack.
Definition Bag.cpp:83
int removeItem(const std::string &itemId, int quantity)
Removes item.
Definition Bag.cpp:71
std::string getStackRule() const
Returns the stack rule.
Definition Bag.h:67
void clearRejectTags()
Clears reject tags.
Definition Bag.cpp:35
void setCapacityPolicy(const std::string &name)
Sets the capacity policy.
Definition Bag.h:65
int findItem(const std::string &itemId) const
Finds item.
Definition Bag.cpp:91
void addRejectTag(const std::string &tag)
Adds reject tag.
Definition Bag.cpp:37
void setKind(const std::string &kind)
Sets the kind.
Definition Bag.h:42
std::string getKind() const
容器种类(bag / chest / shop 等)。
Definition Bag.h:40
void setAcceptRule(const std::string &name)
Sets the accept rule.
Definition Bag.h:61
std::string getSlotItemId(int slot) const
Returns the slot item id.
Definition Bag.cpp:112
void setId(const std::string &id)
Sets the id.
Definition Bag.h:37
bool moveSlot(int fromSlot, int toSlot)
Moves slot.
Definition Bag.cpp:79
int getSlotCount() const
格数。
Definition Bag.h:45
int countItem(const std::string &itemId) const
Returns the number of item.
Definition Bag.cpp:87
float getUsedVolume() const
Returns the used volume.
Definition Bag.cpp:101
int getAcceptTagCount() const
Returns the accept tag count.
Definition Bag.cpp:28
bool swapSlots(int slotA, int slotB)
Swap slots.
Definition Bag.cpp:77
std::string getExtra(const std::string &key, const std::string &fallback={}) const
Returns the extra.
Definition Bag.cpp:52
std::string getAcceptRule() const
接受规则 / 容量策略 / 堆叠规则名。
Definition Bag.h:59
int getSlotQuantity(int slot) const
Returns the slot quantity.
Definition Bag.cpp:117
void setExtra(const std::string &key, const std::string &value)
容器级额外属性(键值)。
Definition Bag.cpp:50
int removeAt(int slot, int quantity)
Removes at.
Definition Bag.cpp:75
void clear()
Clears clear.
Definition Bag.cpp:105
void setMaxVolume(float v)
Sets the max volume.
Definition Bag.h:56
bool isSlotEmpty(int slot) const
True when slot empty.
Definition Bag.cpp:107
float getSlotDurability(int slot) const
Returns the slot durability.
Definition Bag.cpp:127
void setSlotProp(int slot, const std::string &key, const std::string &value)
Sets the slot prop.
Definition Bag.cpp:142
void setMaxWeight(float w)
Sets the max weight.
Definition Bag.h:52
void clearAcceptTags()
可接受 / 拒绝的标签过滤。
Definition Bag.cpp:20
int findItemByTag(const std::string &tag) const
Finds item by tag.
Definition Bag.cpp:95
std::string getCapacityPolicy() const
Returns the capacity policy.
Definition Bag.h:63
void addAcceptTag(const std::string &tag)
Adds accept tag.
Definition Bag.cpp:22
int getUsedSlotCount() const
Returns the used slot count.
Definition Bag.cpp:103
void destroy()
释放资源并使其失效。
Definition Bag.cpp:13
std::string getRejectTag(int index) const
Returns the reject tag.
Definition Bag.cpp:45
void setStackRule(const std::string &name)
Sets the stack rule.
Definition Bag.h:69
EVENGINE_API_FOUNDATION public API.
Definition Equipment.h:19
void clearSlotAllowedTags(const std::string &slotName)
Clears slot allowed tags.
Definition Equipment.cpp:20
void setId(const std::string &id)
Sets the id.
Definition Equipment.h:35
bool hasSlot(const std::string &slotName) const
True when slot.
Definition Equipment.cpp:33
int getSlotInstanceId(const std::string &slotName) const
Returns the slot instance id.
Definition Equipment.cpp:62
void addSlotAllowedTag(const std::string &slotName, const std::string &tag)
Adds slot allowed tag.
Definition Equipment.cpp:26
void defineSlot(const std::string &slotName)
声明一个装备槽;已存在则保留当前物品,仅更新允许标签。
Definition Equipment.cpp:12
std::string getSlotName(int index) const
Returns the slot name.
Definition Equipment.cpp:39
void destroy()
Destroys destroy.
Definition Equipment.cpp:10
bool clearSlot(const std::string &slotName)
直接清空槽位(物品丢弃,不回背包)。
bool equipFromBag(const std::string &equipSlot, Bag *bag, int bagSlot)
Equip from bag.
bool isSlotEmpty(const std::string &slotName) const
True when slot empty.
Definition Equipment.cpp:44
std::string getSlotItemId(const std::string &slotName) const
Returns the slot item id.
Definition Equipment.cpp:50
int getSlotCount() const
Returns the slot count.
Definition Equipment.cpp:37
int getSlotQuantity(const std::string &slotName) const
Returns the slot quantity.
Definition Equipment.cpp:56
std::string getId() const
Returns the id.
Definition Equipment.h:33
bool unequipToBag(const std::string &equipSlot, Bag *bag)
Unequip to bag.
static void ensureBuiltins()
确保内置规则已注册(模块首次使用时自动调用)。
static const std::vector< InventoryChangeEvent > & events()
Events.
static bool hasStackRule(const std::string &name)
True when stack rule.
static int transfer(Bag *from, Bag *to, const std::string &itemId, int quantity)
Transfer.
static bool hasAcceptRule(const std::string &name)
True when accept rule.
static bool hasCapacityPolicy(const std::string &name)
True when capacity policy.
static int transferSlot(Bag *from, int fromSlot, Bag *to, int quantity)
Transfer slot.
static void clearEvents()
Clears events.
背包模块(eve.Inventory)。
Definition Inventory.h:24
bool hasItemDefinition(const std::string &itemId)
物品定义查询(显示名/堆叠/重量/体积/类别/装备槽/标签/额外属性)。
Definition Inventory.cpp:26
std::string getItemExtra(const std::string &itemId, const std::string &key, const std::string &fallback={})
Returns the item extra.
Definition Inventory.cpp:65
int transferItem(Bag *from, Bag *to, const std::string &itemId, int quantity)
跨容器转移(按物品 id / 按槽位);返回实际转移数量。
Definition Inventory.cpp:81
std::string getChangeEventOtherBagId(int index) const
Returns the change event other bag id.
std::string getChangeEventItemId(int index) const
Returns the change event item id.
int getChangeEventOtherSlot(int index) const
Returns the change event other slot.
EquipmentSet * newEquipmentSet()
Creates a equipment set. @ownership Caller deletes unless documented otherwise.
Definition Inventory.cpp:76
void clearGameplayControls()
取消发布本模块持有的全部玩法实例。
int getItemDefinitionCount()
已注册物品定义数量。
Definition Inventory.cpp:24
bool hasStackRule(const std::string &name)
True when stack rule.
Definition Inventory.cpp:97
std::string getChangeEventAction(int index) const
Returns the change event action.
std::string getItemCategory(const std::string &itemId)
Returns the item category.
Definition Inventory.cpp:50
int getChangeEventSlot(int index) const
Returns the change event slot.
void clearChangeEvents()
变更事件队列(添加/移除/移动/装备)。
int transferSlot(Bag *from, int fromSlot, Bag *to, int quantity)
Transfer slot.
Definition Inventory.cpp:85
void clearItemDefinitions()
清空物品定义。
Definition Inventory.cpp:22
int registerItemsFromJson(const std::string &json)
从 JSON 注册物品定义;返回成功注册数量。
Definition Inventory.cpp:17
Bag * newBag(int slotCount)
工厂:创建容器 / 装备栏。
Definition Inventory.cpp:71
std::string getChangeEventBagId(int index) const
Returns the change event bag id.
int getChangeEventCount() const
Returns the change event count.
int getChangeEventQuantity(int index) const
Returns the change event quantity.
int gameplayControlCount() const
已发布的玩法实例数量。
bool itemHasTag(const std::string &itemId, const std::string &tag)
Item has tag.
Definition Inventory.cpp:60
std::string getItemDisplayName(const std::string &itemId)
Returns the item display name.
Definition Inventory.cpp:30
int getItemMaxStack(const std::string &itemId)
Returns the item max stack.
Definition Inventory.cpp:35
bool hasAcceptRule(const std::string &name)
扩展策略是否存在(接受规则 / 容量策略 / 堆叠规则)。
Definition Inventory.cpp:89
float getItemVolume(const std::string &itemId)
Returns the item volume.
Definition Inventory.cpp:45
std::string getItemEquipSlot(const std::string &itemId)
Returns the item equip slot.
Definition Inventory.cpp:55
bool hasCapacityPolicy(const std::string &name)
True when capacity policy.
Definition Inventory.cpp:93
std::string getChangeEventEquipSlot(int index) const
Returns the change event equip slot.
float getItemWeight(const std::string &itemId)
Returns the item weight.
Definition Inventory.cpp:40
static int loadFromJson(const std::string &json, std::string *error=nullptr)
从 JSON 数组或单对象批量注册,返回成功数量。 元素形如: { "id": "potion.hp", "displayName": "治疗药水", "maxStack": 20,...
Definition Item.cpp:84
static int count()
Returns the number of count.
Definition Item.cpp:63
static void clear()
Clears clear.
Definition Item.cpp:61
static const ItemDefinition * find(const std::string &id)
Finds find.
Definition Item.cpp:53
运行时容器:固定格数的背包 / 箱子 / 商店栏等。 行为由 InventorySystem 提供;本类暴露便于脚本绑定的薄封装方法。