载入中...
搜索中...
未找到
Bag.h
浏览该文件的文档.
1#pragma once
2#include "common/Export.h"
3
4
10#include "inventory/ItemTypes.h"
11
12#include <string>
13#include <unordered_map>
14#include <vector>
15
16namespace eve::inventory {
17
18class InventorySaveSession;
19
22public:
24 Bag(int slotCount);
26 ~Bag() = default;
27
28 Bag(const Bag &) = delete;
29 Bag &operator=(const Bag &) = delete;
30
32 void destroy();
33
35 std::string getId() const { return id_; }
37 void setId(const std::string &id) { id_ = id; }
38
40 std::string getKind() const { return kind_; }
42 void setKind(const std::string &kind) { kind_ = kind; }
43
45 int getSlotCount() const { return int(slots_.size()); }
47 void setSlotCount(int slotCount);
48
50 float getMaxWeight() const { return maxWeight_; }
52 void setMaxWeight(float w) { maxWeight_ = w; }
54 float getMaxVolume() const { return maxVolume_; }
56 void setMaxVolume(float v) { maxVolume_ = v; }
57
59 std::string getAcceptRule() const { return acceptRule_; }
61 void setAcceptRule(const std::string &name) { acceptRule_ = name; }
63 std::string getCapacityPolicy() const { return capacityPolicy_; }
65 void setCapacityPolicy(const std::string &name) { capacityPolicy_ = name; }
67 std::string getStackRule() const { return stackRule_; }
69 void setStackRule(const std::string &name) { stackRule_ = name; }
70
72 void clearAcceptTags();
74 void addAcceptTag(const std::string &tag);
76 int getAcceptTagCount() const;
78 std::string getAcceptTag(int index) const;
79
81 void clearRejectTags();
83 void addRejectTag(const std::string &tag);
85 int getRejectTagCount() const;
87 std::string getRejectTag(int index) const;
88
90 void setExtra(const std::string &key, const std::string &value);
92 std::string getExtra(const std::string &key, const std::string &fallback = {}) const;
93
95 bool canAddItem(const std::string &itemId, int quantity);
97 std::string canAddItemReason(const std::string &itemId, int quantity);
99 int addItem(const std::string &itemId, int quantity);
101 int removeItem(const std::string &itemId, int quantity);
103 int removeAt(int slot, int quantity);
105 bool swapSlots(int slotA, int slotB);
107 bool moveSlot(int fromSlot, int toSlot);
109 bool splitStack(int slot, int quantity, int toSlot);
111 int countItem(const std::string &itemId) const;
113 int findItem(const std::string &itemId) const;
115 int findItemByTag(const std::string &tag) const;
117 float getUsedWeight() const;
119 float getUsedVolume() const;
121 int getUsedSlotCount() const;
123 void clear();
124
125 // ---- 槽位查询 ----
127 bool isSlotEmpty(int slot) const;
129 std::string getSlotItemId(int slot) const;
131 int getSlotQuantity(int slot) const;
133 int getSlotInstanceId(int slot) const;
135 float getSlotDurability(int slot) const;
137 void setSlotDurability(int slot, float durability);
139 std::string getSlotProp(int slot, const std::string &key, const std::string &fallback = {}) const;
141 void setSlotProp(int slot, const std::string &key, const std::string &value);
143 bool slotHasTag(int slot, const std::string &tag) const;
145 void addSlotTag(int slot, const std::string &tag);
146
147 // ---- 供 System 直接访问 ----
149 const std::vector<ItemStack> &slots() const { return slots_; }
151 std::vector<ItemStack> &slots() { return slots_; }
153 const std::vector<std::string> &acceptTags() const { return acceptTags_; }
155 const std::vector<std::string> &rejectTags() const { return rejectTags_; }
156
157private:
158 friend class InventorySystem;
160
161 std::string id_;
162 std::string kind_ = "backpack";
163 float maxWeight_ = 0.f;
164 float maxVolume_ = 0.f;
165 std::string acceptRule_ = "default";
166 std::string capacityPolicy_ = "slotsAndWeight";
167 std::string stackRule_ = "sameItem";
168 std::vector<std::string> acceptTags_;
169 std::vector<std::string> rejectTags_;
170 std::vector<ItemStack> slots_;
171 std::unordered_map<std::string, std::string> extra_;
172};
173
174} // namespace eve::inventory
double value
LogicalId itemId
float w
Definition AnimClip.cpp:738
#define EVENGINE_API_FOUNDATION
每个链接组(link group)各自的导出宏。
Definition Export.h:106
std::uint32_t key
float v
void(* destroy)(void *)
TokenKind kind
std::string name
const std::string * tag
std::string id
Definition PlayHost.cpp:108
uint32_t index
格子型物品容器(脚本可直接操作)。
Definition Bag.h:21
std::string getId() const
容器 id(变更事件定位用)。
Definition Bag.h:35
~Bag()=default
Bag.
float getMaxVolume() const
Returns the max volume.
Definition Bag.h:54
const std::vector< ItemStack > & slots() const
Slots.
Definition Bag.h:149
const std::vector< std::string > & rejectTags() const
Reject tags.
Definition Bag.h:155
std::vector< ItemStack > & slots()
Slots.
Definition Bag.h:151
float getMaxWeight() const
重量 / 体积上限(容量策略用)。
Definition Bag.h:50
const std::vector< std::string > & acceptTags() const
Accept tags.
Definition Bag.h:153
std::string getStackRule() const
Returns the stack rule.
Definition Bag.h:67
void setCapacityPolicy(const std::string &name)
Sets the capacity policy.
Definition Bag.h:65
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
void setId(const std::string &id)
Sets the id.
Definition Bag.h:37
int getSlotCount() const
格数。
Definition Bag.h:45
Bag(const Bag &)=delete
std::string getAcceptRule() const
接受规则 / 容量策略 / 堆叠规则名。
Definition Bag.h:59
void setMaxVolume(float v)
Sets the max volume.
Definition Bag.h:56
void setMaxWeight(float w)
Sets the max weight.
Definition Bag.h:52
std::string getCapacityPolicy() const
Returns the capacity policy.
Definition Bag.h:63
Bag & operator=(const Bag &)=delete
void setStackRule(const std::string &name)
Sets the stack rule.
Definition Bag.h:69
Coordinates persistent inventory owners without duplicating their live state.
EVENGINE_API_FOUNDATION public API.
运行时容器:固定格数的背包 / 箱子 / 商店栏等。 行为由 InventorySystem 提供;本类暴露便于脚本绑定的薄封装方法。