13 if (slotName.empty())
return;
14 if (slots_.find(slotName) == slots_.end()) {
15 slots_.emplace(slotName, Slot{});
16 order_.push_back(slotName);
21 auto it = slots_.find(slotName);
22 if (it == slots_.end())
return;
23 it->second.allowedTags.clear();
28 if (
tag.empty())
return;
29 auto &tags = slots_[slotName].allowedTags;
30 if (std::find(tags.begin(), tags.end(),
tag) == tags.end()) tags.push_back(
tag);
34 return slots_.find(slotName) != slots_.end();
40 if (index < 0 || index >=
int(order_.size()))
return {};
41 return order_[size_t(
index)];
45 auto it = slots_.find(slotName);
46 if (it == slots_.end())
return true;
47 return it->second.stack.empty();
51 auto it = slots_.find(slotName);
52 if (it == slots_.end())
return {};
53 return it->second.stack.itemId;
57 auto it = slots_.find(slotName);
58 if (it == slots_.end())
return 0;
59 return it->second.stack.quantity;
63 auto it = slots_.find(slotName);
64 if (it == slots_.end())
return 0;
65 return it->second.stack.instanceId;
69 auto it = slots_.find(slotName);
70 return it == slots_.end() ? nullptr : &it->second.stack;
74 auto it = slots_.find(slotName);
75 return it == slots_.end() ? nullptr : &it->second.stack;
79 auto it = slots_.find(slotName);
80 return it == slots_.end() ? nullptr : &it->second.allowedTags;
84 std::string *reason)
const {
85 if (!bag || equipSlot.empty()) {
86 if (reason) *reason =
"invalid_args";
89 auto it = slots_.find(equipSlot);
90 if (it == slots_.end()) {
91 if (reason) *reason =
"unknown_slot";
95 if (reason) *reason =
"bad_bag_slot";
98 const auto &bs = bag->
slots()[size_t(bagSlot)];
100 if (reason) *reason =
"empty_bag_slot";
105 if (reason) *reason =
"unknown_item";
109 if (reason) *reason =
"equip_slot_mismatch";
112 const auto &allowed = it->second.allowedTags;
113 if (!allowed.empty()) {
115 for (
const auto &
t : allowed) {
116 if (def->
hasTag(
t) || bs.hasTag(
t)) {
122 if (reason) *reason =
"tag_mismatch";
140 auto it = slots_.find(slotName);
141 if (it == slots_.end() || it->second.stack.empty())
return false;
142 std::string
itemId = it->second.stack.itemId;
143 int qty = it->second.stack.quantity;
144 it->second.stack.clear();
const std::vector< ItemStack > & slots() const
Slots.
int getSlotCount() const
格数。
const std::vector< std::string > * allowedTags(const std::string &slotName) const
Allowed tags.
void clearSlotAllowedTags(const std::string &slotName)
Clears slot allowed tags.
bool hasSlot(const std::string &slotName) const
True when slot.
int getSlotInstanceId(const std::string &slotName) const
Returns the slot instance id.
void addSlotAllowedTag(const std::string &slotName, const std::string &tag)
Adds slot allowed tag.
void defineSlot(const std::string &slotName)
声明一个装备槽;已存在则保留当前物品,仅更新允许标签。
std::string getSlotName(int index) const
Returns the slot name.
void destroy()
Destroys destroy.
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.
std::string getSlotItemId(const std::string &slotName) const
Returns the slot item id.
const ItemStack * stackAt(const std::string &slotName) const
Stack at.
int getSlotCount() const
Returns the slot count.
int getSlotQuantity(const std::string &slotName) const
Returns the slot quantity.
bool unequipToBag(const std::string &equipSlot, Bag *bag)
Unequip to bag.
bool canEquipFromBag(Bag *bag, int bagSlot, const std::string &equipSlot, std::string *reason=nullptr) const
Can equip from bag.
static bool equipFromBag(EquipmentSet *eq, const std::string &equipSlot, Bag *bag, int bagSlot)
Equip from bag.
static bool unequipToBag(EquipmentSet *eq, const std::string &equipSlot, Bag *bag)
Unequip to bag.
static void pushEvent(InventoryChangeEvent ev)
Pushes event.
static const ItemDefinition * find(const std::string &id)
Finds find.
运行时容器:固定格数的背包 / 箱子 / 商店栏等。 行为由 InventorySystem 提供;本类暴露便于脚本绑定的薄封装方法。
一次成功库存变更的事件(供脚本 poll / C++ hook)。
std::string action
add/remove/move/swap/split/merge/transfer/equip/unequip
物品模板(进程级注册表中的定义,不含运行时数量)。
std::string equipSlot
非空表示建议装备槽名;是否可装备由 EquipmentSet 槽位配置最终决定。
bool hasTag(const std::string &tag) const
True when tag.
容器中的一格堆叠(空槽:itemId 为空或 quantity <= 0)。