载入中...
搜索中...
未找到
Bag.h
浏览该文件的文档.
1#pragma once
2#include "common/Export.h"
4
5
11#include "inventory/ItemTypes.h"
12
13#include <string>
14#include <unordered_map>
15#include <vector>
16
17namespace eve::inventory {
18
19class InventorySaveSession;
20
23public:
25 Bag(int slotCount);
27 ~Bag() = default;
28
29 Bag(const Bag &) = delete;
30 Bag &operator=(const Bag &) = delete;
31
33 void destroy();
34
36 std::string getId() const { return id_; }
38 void setId(const std::string &id) { id_ = id; }
39
41 std::string getKind() const { return kind_; }
43 void setKind(const std::string &kind) { kind_ = kind; }
44
46 int getSlotCount() const { return int(slots_.size()); }
48 void setSlotCount(int slotCount);
49
51 float getMaxWeight() const { return maxWeight_; }
53 void setMaxWeight(float w) { maxWeight_ = w; }
55 float getMaxVolume() const { return maxVolume_; }
57 void setMaxVolume(float v) { maxVolume_ = v; }
58
60 std::string getAcceptRule() const { return acceptRule_; }
62 void setAcceptRule(const std::string &name) { acceptRule_ = name; }
64 std::string getCapacityPolicy() const { return capacityPolicy_; }
66 void setCapacityPolicy(const std::string &name) { capacityPolicy_ = name; }
68 std::string getStackRule() const { return stackRule_; }
70 void setStackRule(const std::string &name) { stackRule_ = name; }
71
73 void clearAcceptTags();
75 void addAcceptTag(const std::string &tag);
77 int getAcceptTagCount() const;
79 std::string getAcceptTag(int index) const;
80
82 void clearRejectTags();
84 void addRejectTag(const std::string &tag);
86 int getRejectTagCount() const;
88 std::string getRejectTag(int index) const;
89
91 void setExtra(const std::string &key, const std::string &value);
93 std::string getExtra(const std::string &key, const std::string &fallback = {}) const;
94
96 bool canAddItem(const std::string &itemId, int quantity);
98 std::string canAddItemReason(const std::string &itemId, int quantity);
100 int addItem(const std::string &itemId, int quantity);
102 int removeItem(const std::string &itemId, int quantity);
104 int removeAt(int slot, int quantity);
106 bool swapSlots(int slotA, int slotB);
108 bool moveSlot(int fromSlot, int toSlot);
110 bool splitStack(int slot, int quantity, int toSlot);
112 int countItem(const std::string &itemId) const;
114 int findItem(const std::string &itemId) const;
116 int findItemByTag(const std::string &tag) const;
118 float getUsedWeight() const;
120 float getUsedVolume() const;
122 int getUsedSlotCount() const;
124 void clear();
125
126 // ---- 槽位查询 ----
128 bool isSlotEmpty(int slot) const;
130 std::string getSlotItemId(int slot) const;
132 int getSlotQuantity(int slot) const;
134 int getSlotInstanceId(int slot) const;
136 float getSlotDurability(int slot) const;
138 void setSlotDurability(int slot, float durability);
140 std::string getSlotProp(int slot, const std::string &key, const std::string &fallback = {}) const;
142 void setSlotProp(int slot, const std::string &key, const std::string &value);
144 bool slotHasTag(int slot, const std::string &tag) const;
146 void addSlotTag(int slot, const std::string &tag);
147
148 // ---- 供 System 直接访问 ----
150 const std::vector<ItemStack> &slots() const { return slots_; }
152 std::vector<ItemStack> &slots() { return slots_; }
154 const std::vector<std::string> &acceptTags() const { return acceptTags_; }
156 const std::vector<std::string> &rejectTags() const { return rejectTags_; }
157
158private:
159 friend class InventorySystem;
161
162 std::string id_;
163 std::string kind_ = "backpack";
164 float maxWeight_ = 0.f;
165 float maxVolume_ = 0.f;
166 std::string acceptRule_ = "default";
167 std::string capacityPolicy_ = "slotsAndWeight";
168 std::string stackRule_ = "sameItem";
169 std::vector<std::string> acceptTags_;
170 std::vector<std::string> rejectTags_;
171 std::vector<ItemStack> slots_;
172 std::unordered_map<std::string, std::string> extra_;
173};
174
175} // namespace eve::inventory
LogicalId itemId
float w
Definition AnimClip.cpp:738
SQObjectPtr key
Definition ECS.cpp:155
std::string name
Definition ECS.cpp:154
#define EVENGINE_API_FOUNDATION
每个链接组(link group)各自的导出宏。
Definition Export.h:106
float v
void(* destroy)(void *)
std::string id
const std::string * tag
Object::Ptr value
std::string slot
std::string kind
Share string attribute map operations through the Windows Foundation DLL.
uint32_t index
格子型物品容器(脚本可直接操作)。
Definition Bag.h:22
std::string getId() const
容器 id(变更事件定位用)。
Definition Bag.h:36
~Bag()=default
Bag.
float getMaxVolume() const
Returns the max volume.
Definition Bag.h:55
const std::vector< ItemStack > & slots() const
Slots.
Definition Bag.h:150
const std::vector< std::string > & rejectTags() const
Reject tags.
Definition Bag.h:156
std::vector< ItemStack > & slots()
Slots.
Definition Bag.h:152
float getMaxWeight() const
重量 / 体积上限(容量策略用)。
Definition Bag.h:51
const std::vector< std::string > & acceptTags() const
Accept tags.
Definition Bag.h:154
std::string getStackRule() const
Returns the stack rule.
Definition Bag.h:68
void setCapacityPolicy(const std::string &name)
Sets the capacity policy.
Definition Bag.h:66
void setKind(const std::string &kind)
Sets the kind.
Definition Bag.h:43
std::string getKind() const
容器种类(bag / chest / shop 等)。
Definition Bag.h:41
void setAcceptRule(const std::string &name)
Sets the accept rule.
Definition Bag.h:62
void setId(const std::string &id)
Sets the id.
Definition Bag.h:38
int getSlotCount() const
格数。
Definition Bag.h:46
Bag(const Bag &)=delete
std::string getAcceptRule() const
接受规则 / 容量策略 / 堆叠规则名。
Definition Bag.h:60
void setMaxVolume(float v)
Sets the max volume.
Definition Bag.h:57
void setMaxWeight(float w)
Sets the max weight.
Definition Bag.h:53
std::string getCapacityPolicy() const
Returns the capacity policy.
Definition Bag.h:64
Bag & operator=(const Bag &)=delete
void setStackRule(const std::string &name)
Sets the stack rule.
Definition Bag.h:70
Coordinates persistent inventory owners without duplicating their live state.
EVENGINE_API_FOUNDATION public API.
运行时容器:固定格数的背包 / 箱子 / 商店栏等。 行为由 InventorySystem 提供;本类暴露便于脚本绑定的薄封装方法。