lua: inventory.clone
This commit is contained in:
@@ -44,6 +44,16 @@ std::shared_ptr<Inventory> Inventories::get(int64_t id) {
|
||||
return found->second;
|
||||
}
|
||||
|
||||
std::shared_ptr<Inventory> Inventories::clone(int64_t id) {
|
||||
auto original = get(id);
|
||||
if (original == nullptr)
|
||||
return nullptr;
|
||||
auto origptr = reinterpret_cast<const Inventory*>(original.get());
|
||||
auto clone = std::make_shared<Inventory>(*origptr);
|
||||
clone->setId(level.getWorld()->getNextInventoryId());
|
||||
return clone;
|
||||
}
|
||||
|
||||
const inventories_map& Inventories::getMap() const {
|
||||
return map;
|
||||
}
|
||||
|
||||
@@ -36,6 +36,8 @@ public:
|
||||
/* Get inventory by id (works with both real and virtual)*/
|
||||
std::shared_ptr<Inventory> get(int64_t id);
|
||||
|
||||
std::shared_ptr<Inventory> clone(int64_t id);
|
||||
|
||||
const inventories_map& getMap() const;
|
||||
};
|
||||
|
||||
|
||||
@@ -40,6 +40,10 @@ public:
|
||||
|
||||
static void convert(dynamic::Map* data, const ContentLUT* lut);
|
||||
|
||||
inline void setId(int64_t id) {
|
||||
this->id = id;
|
||||
}
|
||||
|
||||
inline int64_t getId() const {
|
||||
return id;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user