mirror of
https://github.com/EQEmu/Server.git
synced 2026-05-17 03:08:26 +00:00
Refactoring
This commit is contained in:
+49
-23
@@ -33,36 +33,62 @@ EQEmu::Inventory::~Inventory() {
|
||||
delete impl_;
|
||||
}
|
||||
|
||||
std::shared_ptr<EQEmu::ItemInstance> EQEmu::Inventory::Get(int container_id, int slot_id) {
|
||||
auto iter = impl_->containers_.find(container_id);
|
||||
std::shared_ptr<EQEmu::ItemInstance> EQEmu::Inventory::Get(const InventorySlot &slot) {
|
||||
auto iter = impl_->containers_.find(slot.type_);
|
||||
if(iter != impl_->containers_.end()) {
|
||||
return iter->second.Get(slot_id);
|
||||
}
|
||||
|
||||
return std::shared_ptr<ItemInstance>(nullptr);
|
||||
}
|
||||
|
||||
std::shared_ptr<EQEmu::ItemInstance> EQEmu::Inventory::Get(int container_id, int slot_id, int bag_idx) {
|
||||
auto iter = impl_->containers_.find(container_id);
|
||||
if(iter != impl_->containers_.end()) {
|
||||
auto item = iter->second.Get(slot_id);
|
||||
auto item = iter->second.Get(slot.slot_);
|
||||
if(item) {
|
||||
return item->GetItem(bag_idx);
|
||||
if(slot.bag_index_ > -1) {
|
||||
auto sub_item = item->Get(slot.bag_index_);
|
||||
if(sub_item) {
|
||||
if(slot.aug_index_ > -1) {
|
||||
return sub_item->Get(slot.aug_index_);
|
||||
} else {
|
||||
return sub_item;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
return item;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return std::shared_ptr<ItemInstance>(nullptr);
|
||||
}
|
||||
|
||||
bool EQEmu::Inventory::Put(int container_id, int slot_id, std::shared_ptr<ItemInstance> inst) {
|
||||
if(impl_->containers_.count(container_id) == 0) {
|
||||
auto &container = impl_->containers_[container_id];
|
||||
return container.Put(slot_id, inst);
|
||||
} else {
|
||||
ItemContainer container;
|
||||
bool v = container.Put(slot_id, inst);
|
||||
impl_->containers_[container_id] = container;
|
||||
|
||||
return v;
|
||||
bool EQEmu::Inventory::Put(const InventorySlot &slot, std::shared_ptr<ItemInstance> inst) {
|
||||
if(impl_->containers_.count(slot.type_) == 0) {
|
||||
impl_->containers_.insert(std::pair<int, ItemContainer>(slot.type_, ItemContainer()));
|
||||
}
|
||||
|
||||
auto &container = impl_->containers_[slot.type_];
|
||||
if(slot.bag_index_ > -1) {
|
||||
auto item = container.Get(slot.slot_);
|
||||
if(!item)
|
||||
return false;
|
||||
|
||||
if(slot.aug_index_ > -1) {
|
||||
auto bag_item = item->Get(slot.bag_index_);
|
||||
if(!bag_item) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return bag_item->Put(slot.aug_index_, inst);
|
||||
} else {
|
||||
return item->Put(slot.bag_index_, inst);
|
||||
}
|
||||
} else {
|
||||
if(slot.aug_index_ > -1) {
|
||||
auto item = container.Get(slot.slot_);
|
||||
if(!item)
|
||||
return false;
|
||||
|
||||
return item->Put(slot.aug_index_, inst);
|
||||
}
|
||||
|
||||
return container.Put(slot.slot_, inst);
|
||||
}
|
||||
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
+18
-3
@@ -23,6 +23,21 @@
|
||||
|
||||
namespace EQEmu
|
||||
{
|
||||
struct InventorySlot
|
||||
{
|
||||
InventorySlot(int type, int slot)
|
||||
: type_(type), slot_(slot), bag_index_(-1), aug_index_(-1) { }
|
||||
InventorySlot(int type, int slot, int bag_index)
|
||||
: type_(type), slot_(slot), bag_index_(bag_index), aug_index_(-1) { }
|
||||
InventorySlot(int type, int slot, int bag_index, int aug_index)
|
||||
: type_(type), slot_(slot), bag_index_(bag_index), aug_index_(aug_index) { }
|
||||
|
||||
int type_;
|
||||
int slot_;
|
||||
int bag_index_;
|
||||
int aug_index_;
|
||||
};
|
||||
|
||||
enum InventoryType : int
|
||||
{
|
||||
InvTypePersonal = 0,
|
||||
@@ -42,9 +57,9 @@ namespace EQEmu
|
||||
Inventory();
|
||||
~Inventory();
|
||||
|
||||
std::shared_ptr<ItemInstance> Get(int container_id, int slot_id);
|
||||
std::shared_ptr<ItemInstance> Get(int container_id, int slot_id, int bag_idx);
|
||||
bool Put(int container_id, int slot_id, std::shared_ptr<ItemInstance> inst);
|
||||
std::shared_ptr<ItemInstance> Get(const InventorySlot &slot);
|
||||
bool Put(const InventorySlot &slot, std::shared_ptr<ItemInstance> inst);
|
||||
bool Swap(const InventorySlot &src, const InventorySlot &dest);
|
||||
private:
|
||||
struct impl;
|
||||
impl *impl_;
|
||||
|
||||
+1
-1
@@ -1994,7 +1994,7 @@ void ItemInst::PutAugment(SharedDatabase *db, uint8 slot, uint32 item_id)
|
||||
if (item_id == NO_ITEM) { return; }
|
||||
if (db == nullptr) { return; /* TODO: add log message for nullptr */ }
|
||||
|
||||
const ItemInst* aug = db->CreateItem(item_id);
|
||||
const ItemInst* aug = db->CreateItemOld(item_id);
|
||||
if (aug) {
|
||||
PutAugment(slot, *aug);
|
||||
safe_delete(aug);
|
||||
|
||||
@@ -9,12 +9,18 @@ struct EQEmu::ItemContainer::impl
|
||||
|
||||
EQEmu::ItemContainer::ItemContainer()
|
||||
{
|
||||
impl_ = new impl;
|
||||
impl_ = new impl();
|
||||
}
|
||||
|
||||
EQEmu::ItemContainer::~ItemContainer()
|
||||
{
|
||||
delete impl_;
|
||||
if(impl_)
|
||||
delete impl_;
|
||||
}
|
||||
|
||||
EQEmu::ItemContainer::ItemContainer(ItemContainer &&other) {
|
||||
impl_ = other.impl_;
|
||||
other.impl_ = nullptr;
|
||||
}
|
||||
|
||||
std::shared_ptr<EQEmu::ItemInstance> EQEmu::ItemContainer::Get(int slot_id) {
|
||||
|
||||
@@ -29,11 +29,15 @@ namespace EQEmu
|
||||
public:
|
||||
ItemContainer();
|
||||
~ItemContainer();
|
||||
ItemContainer(ItemContainer &&other);
|
||||
|
||||
std::shared_ptr<ItemInstance> Get(int slot_id);
|
||||
bool Put(int slot_id, std::shared_ptr<ItemInstance> inst);
|
||||
bool Delete(int slot_id);
|
||||
private:
|
||||
ItemContainer(const ItemContainer &other);
|
||||
ItemContainer& operator=(const ItemContainer &other);
|
||||
|
||||
struct impl;
|
||||
impl *impl_;
|
||||
};
|
||||
|
||||
@@ -81,7 +81,7 @@ const ItemData *EQEmu::ItemInstance::GetItem() {
|
||||
return impl_->modified_item_ ? impl_->modified_item_ : impl_->base_item_;
|
||||
}
|
||||
|
||||
std::shared_ptr<EQEmu::ItemInstance> EQEmu::ItemInstance::GetItem(int index) {
|
||||
std::shared_ptr<EQEmu::ItemInstance> EQEmu::ItemInstance::Get(int index) {
|
||||
if(EQEmu::ValueWithin(index, 0, 255)) {
|
||||
return impl_->contents_.Get(index);
|
||||
}
|
||||
@@ -89,7 +89,7 @@ std::shared_ptr<EQEmu::ItemInstance> EQEmu::ItemInstance::GetItem(int index) {
|
||||
return std::shared_ptr<EQEmu::ItemInstance>(nullptr);
|
||||
}
|
||||
|
||||
bool EQEmu::ItemInstance::PutItem(int index, std::shared_ptr<ItemInstance> inst) {
|
||||
bool EQEmu::ItemInstance::Put(int index, std::shared_ptr<ItemInstance> inst) {
|
||||
if(!inst || !inst->GetItem()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -33,8 +33,8 @@ namespace EQEmu
|
||||
~ItemInstance();
|
||||
|
||||
const ItemData *GetItem();
|
||||
std::shared_ptr<ItemInstance> GetItem(int index);
|
||||
bool PutItem(int index, std::shared_ptr<ItemInstance> inst);
|
||||
std::shared_ptr<ItemInstance> Get(int index);
|
||||
bool Put(int index, std::shared_ptr<ItemInstance> inst);
|
||||
private:
|
||||
struct impl;
|
||||
impl *impl_;
|
||||
|
||||
+28
-11
@@ -371,7 +371,7 @@ bool SharedDatabase::SetStartingItems(PlayerProfile_Struct* pp, InventoryOld* in
|
||||
if(!myitem)
|
||||
continue;
|
||||
|
||||
ItemInst* myinst = CreateBaseItem(myitem, charges);
|
||||
ItemInst* myinst = CreateBaseItemOld(myitem, charges);
|
||||
|
||||
if(slot < 0)
|
||||
slot = inv->FindFreeSlot(0, 0);
|
||||
@@ -433,7 +433,7 @@ bool SharedDatabase::GetSharedBank(uint32 id, InventoryOld *inv, bool is_charid)
|
||||
|
||||
int16 put_slot_id = INVALID_INDEX;
|
||||
|
||||
ItemInst *inst = CreateBaseItem(item, charges);
|
||||
ItemInst *inst = CreateBaseItemOld(item, charges);
|
||||
if (inst && item->ItemClass == ItemClassCommon) {
|
||||
for (int i = AUG_BEGIN; i < EmuConstants::ITEM_COMMON_SIZE; i++) {
|
||||
if (aug[i])
|
||||
@@ -536,7 +536,7 @@ bool SharedDatabase::GetInventory(uint32 char_id, EQEmu::Inventory *inv)
|
||||
//
|
||||
// int16 put_slot_id = INVALID_INDEX;
|
||||
//
|
||||
// ItemInst *inst = CreateBaseItem(item, charges);
|
||||
// ItemInst *inst = CreateBaseItemOld(item, charges);
|
||||
//
|
||||
// if (inst == nullptr)
|
||||
// continue;
|
||||
@@ -671,7 +671,7 @@ bool SharedDatabase::GetInventory(uint32 account_id, char *name, InventoryOld *i
|
||||
if (!item)
|
||||
continue;
|
||||
|
||||
ItemInst *inst = CreateBaseItem(item, charges);
|
||||
ItemInst *inst = CreateBaseItemOld(item, charges);
|
||||
|
||||
if (inst == nullptr)
|
||||
continue;
|
||||
@@ -1257,14 +1257,14 @@ bool SharedDatabase::LoadNPCFactionLists() {
|
||||
}
|
||||
|
||||
// Create appropriate ItemInst class
|
||||
ItemInst* SharedDatabase::CreateItem(uint32 item_id, int16 charges, uint32 aug1, uint32 aug2, uint32 aug3, uint32 aug4, uint32 aug5, uint32 aug6, uint8 attuned)
|
||||
ItemInst* SharedDatabase::CreateItemOld(uint32 item_id, int16 charges, uint32 aug1, uint32 aug2, uint32 aug3, uint32 aug4, uint32 aug5, uint32 aug6, uint8 attuned)
|
||||
{
|
||||
const ItemData* item = nullptr;
|
||||
ItemInst* inst = nullptr;
|
||||
|
||||
item = GetItem(item_id);
|
||||
if (item) {
|
||||
inst = CreateBaseItem(item, charges);
|
||||
inst = CreateBaseItemOld(item, charges);
|
||||
|
||||
if (inst == nullptr) {
|
||||
Log.Out(Logs::General, Logs::Error, "Error: valid item data returned a null reference for ItemInst creation in SharedDatabase::CreateItem()");
|
||||
@@ -1286,14 +1286,14 @@ ItemInst* SharedDatabase::CreateItem(uint32 item_id, int16 charges, uint32 aug1,
|
||||
|
||||
|
||||
// Create appropriate ItemInst class
|
||||
ItemInst* SharedDatabase::CreateItem(const ItemData* item, int16 charges, uint32 aug1, uint32 aug2, uint32 aug3, uint32 aug4, uint32 aug5, uint32 aug6, uint8 attuned)
|
||||
ItemInst* SharedDatabase::CreateItemOld(const ItemData* item, int16 charges, uint32 aug1, uint32 aug2, uint32 aug3, uint32 aug4, uint32 aug5, uint32 aug6, uint8 attuned)
|
||||
{
|
||||
ItemInst* inst = nullptr;
|
||||
if (item) {
|
||||
inst = CreateBaseItem(item, charges);
|
||||
inst = CreateBaseItemOld(item, charges);
|
||||
|
||||
if (inst == nullptr) {
|
||||
Log.Out(Logs::General, Logs::Error, "Error: valid item data returned a null reference for ItemInst creation in SharedDatabase::CreateItem()");
|
||||
Log.Out(Logs::General, Logs::Error, "Error: valid item data returned a null reference for ItemInst creation in SharedDatabase::CreateItemOld()");
|
||||
Log.Out(Logs::General, Logs::Error, "Item Data = ID: %u, Name: %s, Charges: %i", item->ID, item->Name, charges);
|
||||
return nullptr;
|
||||
}
|
||||
@@ -1310,7 +1310,7 @@ ItemInst* SharedDatabase::CreateItem(const ItemData* item, int16 charges, uint32
|
||||
return inst;
|
||||
}
|
||||
|
||||
ItemInst* SharedDatabase::CreateBaseItem(const ItemData* item, int16 charges) {
|
||||
ItemInst* SharedDatabase::CreateBaseItemOld(const ItemData* item, int16 charges) {
|
||||
ItemInst* inst = nullptr;
|
||||
if (item) {
|
||||
// if maxcharges is -1 that means it is an unlimited use item.
|
||||
@@ -1324,7 +1324,7 @@ ItemInst* SharedDatabase::CreateBaseItem(const ItemData* item, int16 charges) {
|
||||
inst = new ItemInst(item, charges);
|
||||
|
||||
if (inst == nullptr) {
|
||||
Log.Out(Logs::General, Logs::Error, "Error: valid item data returned a null reference for ItemInst creation in SharedDatabase::CreateBaseItem()");
|
||||
Log.Out(Logs::General, Logs::Error, "Error: valid item data returned a null reference for ItemInst creation in SharedDatabase::CreateBaseItemOld()");
|
||||
Log.Out(Logs::General, Logs::Error, "Item Data = ID: %u, Name: %s, Charges: %i", item->ID, item->Name, charges);
|
||||
return nullptr;
|
||||
}
|
||||
@@ -1336,6 +1336,23 @@ ItemInst* SharedDatabase::CreateBaseItem(const ItemData* item, int16 charges) {
|
||||
return inst;
|
||||
}
|
||||
|
||||
std::shared_ptr<EQEmu::ItemInstance> SharedDatabase::CreateItem(uint32 item_id, int16 charges) {
|
||||
const ItemData* item = GetItem(item_id);
|
||||
if(item) {
|
||||
if(charges == 0 && item->MaxCharges == -1) {
|
||||
charges = 1;
|
||||
}
|
||||
|
||||
if(charges <= 0 && item->Stackable) {
|
||||
charges = 1;
|
||||
}
|
||||
|
||||
return std::shared_ptr<EQEmu::ItemInstance>(new EQEmu::ItemInstance(item, charges));
|
||||
}
|
||||
|
||||
return std::shared_ptr<EQEmu::ItemInstance>(nullptr);
|
||||
}
|
||||
|
||||
int32 SharedDatabase::DeleteStalePlayerCorpses() {
|
||||
if(RuleB(Zone, EnableShadowrest)) {
|
||||
std::string query = StringFormat(
|
||||
|
||||
+4
-3
@@ -82,9 +82,10 @@ class SharedDatabase : public Database
|
||||
/*
|
||||
Item Methods
|
||||
*/
|
||||
ItemInst* CreateItem(uint32 item_id, int16 charges = 0, uint32 aug1 = 0, uint32 aug2 = 0, uint32 aug3 = 0, uint32 aug4 = 0, uint32 aug5 = 0, uint32 aug6 = 0, uint8 attuned = 0);
|
||||
ItemInst* CreateItem(const ItemData* item, int16 charges = 0, uint32 aug1 = 0, uint32 aug2 = 0, uint32 aug3 = 0, uint32 aug4 = 0, uint32 aug5 = 0, uint32 aug6 = 0, uint8 attuned = 0);
|
||||
ItemInst* CreateBaseItem(const ItemData* item, int16 charges = 0);
|
||||
ItemInst* CreateItemOld(uint32 item_id, int16 charges = 0, uint32 aug1 = 0, uint32 aug2 = 0, uint32 aug3 = 0, uint32 aug4 = 0, uint32 aug5 = 0, uint32 aug6 = 0, uint8 attuned = 0);
|
||||
ItemInst* CreateItemOld(const ItemData* item, int16 charges = 0, uint32 aug1 = 0, uint32 aug2 = 0, uint32 aug3 = 0, uint32 aug4 = 0, uint32 aug5 = 0, uint32 aug6 = 0, uint8 attuned = 0);
|
||||
ItemInst* CreateBaseItemOld(const ItemData* item, int16 charges = 0);
|
||||
std::shared_ptr<EQEmu::ItemInstance> CreateItem(uint32 item_id, int16 charges = 0);
|
||||
|
||||
/*
|
||||
Shared Memory crap
|
||||
|
||||
Reference in New Issue
Block a user