9 if (slotCount < 0) slotCount = 0;
10 slots_.assign(
size_t(slotCount),
ItemStack{});
16 if (slotCount < 0) slotCount = 0;
17 slots_.resize(
size_t(slotCount));
23 if (
tag.empty())
return;
24 if (std::find(acceptTags_.begin(), acceptTags_.end(),
tag) == acceptTags_.end())
25 acceptTags_.push_back(
tag);
31 if (index < 0 || index >=
int(acceptTags_.size()))
return {};
32 return acceptTags_[size_t(
index)];
38 if (
tag.empty())
return;
39 if (std::find(rejectTags_.begin(), rejectTags_.end(),
tag) == rejectTags_.end())
40 rejectTags_.push_back(
tag);
46 if (index < 0 || index >=
int(rejectTags_.size()))
return {};
47 return rejectTags_[size_t(
index)];
53 auto it = extra_.find(
key);
54 return it == extra_.end() ? fallback : it->second;
109 return slots_[size_t(slot)].empty();
114 return slots_[size_t(slot)].itemId;
119 return slots_[size_t(slot)].quantity;
124 return slots_[size_t(slot)].instanceId;
129 return slots_[size_t(slot)].durability;
134 if (!slots_[
size_t(slot)].empty()) slots_[size_t(slot)].durability = durability;
138 if (slot < 0 || slot >=
getSlotCount())
return fallback;
139 return slots_[size_t(slot)].getProp(
key, fallback);
144 if (!slots_[
size_t(slot)].empty()) slots_[size_t(slot)].setProp(
key,
value);
149 return slots_[size_t(slot)].hasTag(
tag);
154 auto &
s = slots_[size_t(slot)];
155 if (
s.empty())
return;
156 if (!
s.hasTag(
tag))
s.tags.push_back(
tag);
int getSlotInstanceId(int slot) const
Returns the slot instance id.
float getUsedWeight() const
Returns the used weight.
void setSlotCount(int slotCount)
调整格数:扩容追加空槽;缩容会丢弃被裁掉的槽(不自动转移)。
std::string canAddItemReason(const std::string &itemId, int quantity)
Can add item reason.
std::string getAcceptTag(int index) const
Returns the accept tag.
bool canAddItem(const std::string &itemId, int quantity)
便捷操作(转发 InventorySystem):增删 / 移动 / 查询。
void setSlotDurability(int slot, float durability)
Sets the slot durability.
std::string getSlotProp(int slot, const std::string &key, const std::string &fallback={}) const
Returns the slot prop.
int addItem(const std::string &itemId, int quantity)
Adds item.
int getRejectTagCount() const
Returns the reject tag count.
void addSlotTag(int slot, const std::string &tag)
Adds slot tag.
bool slotHasTag(int slot, const std::string &tag) const
Slot has tag.
bool splitStack(int slot, int quantity, int toSlot)
Split stack.
int removeItem(const std::string &itemId, int quantity)
Removes item.
void clearRejectTags()
Clears reject tags.
int findItem(const std::string &itemId) const
Finds item.
void addRejectTag(const std::string &tag)
Adds reject tag.
std::string getSlotItemId(int slot) const
Returns the slot item id.
bool moveSlot(int fromSlot, int toSlot)
Moves slot.
int getSlotCount() const
格数。
int countItem(const std::string &itemId) const
Returns the number of item.
float getUsedVolume() const
Returns the used volume.
int getAcceptTagCount() const
Returns the accept tag count.
bool swapSlots(int slotA, int slotB)
Swap slots.
std::string getExtra(const std::string &key, const std::string &fallback={}) const
Returns the extra.
int getSlotQuantity(int slot) const
Returns the slot quantity.
void setExtra(const std::string &key, const std::string &value)
容器级额外属性(键值)。
int removeAt(int slot, int quantity)
Removes at.
void clear()
Clears clear.
bool isSlotEmpty(int slot) const
True when slot empty.
float getSlotDurability(int slot) const
Returns the slot durability.
void setSlotProp(int slot, const std::string &key, const std::string &value)
Sets the slot prop.
void clearAcceptTags()
可接受 / 拒绝的标签过滤。
int findItemByTag(const std::string &tag) const
Finds item by tag.
void addAcceptTag(const std::string &tag)
Adds accept tag.
Bag(int slotCount)
创建指定格数的空容器。
int getUsedSlotCount() const
Returns the used slot count.
std::string getRejectTag(int index) const
Returns the reject tag.
static int addItem(Bag *bag, const std::string &itemId, int quantity)
返回实际放入数量(可能部分成功)。
static bool canAdd(Bag *bag, const std::string &itemId, int quantity, std::string *reason=nullptr)
Can add.
static bool swapSlots(Bag *bag, int slotA, int slotB)
Swap slots.
static float usedWeight(const Bag *bag)
Used weight.
static float usedVolume(const Bag *bag)
Used volume.
static bool splitStack(Bag *bag, int slot, int quantity, int toSlot)
Split stack.
static int countItem(const Bag *bag, const std::string &itemId)
Returns the number of item.
static int usedSlotCount(const Bag *bag)
Used slot count.
static void clearBag(Bag *bag)
Clears bag.
static int removeAt(Bag *bag, int slot, int quantity)
Removes at.
static int removeItem(Bag *bag, const std::string &itemId, int quantity)
static bool moveSlot(Bag *bag, int fromSlot, int toSlot)
Moves slot.
static int findItemByTag(const Bag *bag, const std::string &tag)
Finds item by tag.
static int findItem(const Bag *bag, const std::string &itemId)
Finds item.
运行时容器:固定格数的背包 / 箱子 / 商店栏等。 行为由 InventorySystem 提供;本类暴露便于脚本绑定的薄封装方法。
容器中的一格堆叠(空槽:itemId 为空或 quantity <= 0)。