mirror of
https://github.com/mangosfour/server.git
synced 2025-12-16 04:37:00 +00:00
Avoid access to bag item prototype for getting bag size, use related item update field instead as more fast source.
This commit is contained in:
parent
99ff9ab5d9
commit
aaddf4b51b
5 changed files with 112 additions and 202 deletions
|
|
@ -37,30 +37,25 @@ Bag::Bag( ): Item()
|
|||
|
||||
Bag::~Bag()
|
||||
{
|
||||
for(int i = 0; i<MAX_BAG_SIZE; i++)
|
||||
{
|
||||
if(m_bagslot[i]) delete m_bagslot[i];
|
||||
}
|
||||
for(int i = 0; i < MAX_BAG_SIZE; ++i)
|
||||
if (m_bagslot[i])
|
||||
delete m_bagslot[i];
|
||||
}
|
||||
|
||||
void Bag::AddToWorld()
|
||||
{
|
||||
Item::AddToWorld();
|
||||
|
||||
for(int i = 0; i<MAX_BAG_SIZE; i++)
|
||||
{
|
||||
for(uint32 i = 0; i < GetBagSize(); ++i)
|
||||
if(m_bagslot[i])
|
||||
m_bagslot[i]->AddToWorld();
|
||||
}
|
||||
}
|
||||
|
||||
void Bag::RemoveFromWorld()
|
||||
{
|
||||
for(int i = 0; i<MAX_BAG_SIZE; i++)
|
||||
{
|
||||
for(uint32 i = 0; i < GetBagSize(); ++i)
|
||||
if(m_bagslot[i])
|
||||
m_bagslot[i]->RemoveFromWorld();
|
||||
}
|
||||
|
||||
Item::RemoveFromWorld();
|
||||
}
|
||||
|
|
@ -109,7 +104,7 @@ bool Bag::LoadFromDB(uint32 guid, uint64 owner_guid, QueryResult *result)
|
|||
return false;
|
||||
|
||||
// cleanup bag content related item value fields (its will be filled correctly from `character_inventory`)
|
||||
for (uint32 i = 0; i < GetProto()->ContainerSlots; i++)
|
||||
for (int i = 0; i < MAX_BAG_SIZE; ++i)
|
||||
{
|
||||
SetUInt64Value(CONTAINER_FIELD_SLOT_1 + (i*2), 0);
|
||||
if (m_bagslot[i])
|
||||
|
|
@ -125,21 +120,16 @@ bool Bag::LoadFromDB(uint32 guid, uint64 owner_guid, QueryResult *result)
|
|||
void Bag::DeleteFromDB()
|
||||
{
|
||||
for (int i = 0; i < MAX_BAG_SIZE; i++)
|
||||
{
|
||||
if (m_bagslot[i])
|
||||
{
|
||||
m_bagslot[i]->DeleteFromDB();
|
||||
}
|
||||
}
|
||||
|
||||
Item::DeleteFromDB();
|
||||
}
|
||||
|
||||
uint32 Bag::GetFreeSlots() const
|
||||
{
|
||||
uint32 ContainerSlots=GetProto()->ContainerSlots;
|
||||
uint32 slots = 0;
|
||||
for (uint8 i=0; i <ContainerSlots; i++)
|
||||
for (uint32 i=0; i < GetBagSize(); i++)
|
||||
if (!m_bagslot[i])
|
||||
++slots;
|
||||
|
||||
|
|
@ -176,30 +166,26 @@ void Bag::BuildCreateUpdateBlockForPlayer( UpdateData *data, Player *target ) co
|
|||
{
|
||||
Item::BuildCreateUpdateBlockForPlayer( data, target );
|
||||
|
||||
for (int i = 0; i < MAX_BAG_SIZE; i++)
|
||||
{
|
||||
for (uint32 i = 0; i < GetBagSize(); ++i)
|
||||
if(m_bagslot[i])
|
||||
m_bagslot[i]->BuildCreateUpdateBlockForPlayer( data, target );
|
||||
}
|
||||
}
|
||||
|
||||
// If the bag is empty returns true
|
||||
bool Bag::IsEmpty() const
|
||||
{
|
||||
uint32 ContainerSlots=GetProto()->ContainerSlots;
|
||||
for(uint32 i=0; i < ContainerSlots; i++)
|
||||
if (m_bagslot[i]) return false;
|
||||
for(uint32 i = 0; i < GetBagSize(); ++i)
|
||||
if (m_bagslot[i])
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
uint32 Bag::GetItemCount( uint32 item, Item* eItem ) const
|
||||
{
|
||||
uint32 ContainerSlots=GetProto()->ContainerSlots;
|
||||
|
||||
Item *pItem;
|
||||
uint32 count = 0;
|
||||
for(uint32 i=0; i < ContainerSlots; i++)
|
||||
for(uint32 i=0; i < GetBagSize(); ++i)
|
||||
{
|
||||
pItem = m_bagslot[i];
|
||||
if( pItem && pItem != eItem && pItem->GetEntry() == item )
|
||||
|
|
@ -208,7 +194,7 @@ uint32 Bag::GetItemCount( uint32 item, Item* eItem ) const
|
|||
|
||||
if(eItem && eItem->GetProto()->GemProperties)
|
||||
{
|
||||
for(uint32 i=0; i < ContainerSlots; i++)
|
||||
for(uint32 i=0; i < GetBagSize(); ++i)
|
||||
{
|
||||
pItem = m_bagslot[i];
|
||||
if( pItem && pItem != eItem && pItem->GetProto()->Socket[0].Color )
|
||||
|
|
@ -221,29 +207,18 @@ uint32 Bag::GetItemCount( uint32 item, Item* eItem ) const
|
|||
|
||||
uint8 Bag::GetSlotByItemGUID(uint64 guid) const
|
||||
{
|
||||
uint32 ContainerSlots=GetProto()->ContainerSlots;
|
||||
|
||||
for(uint32 i=0;i<ContainerSlots;i++)
|
||||
{
|
||||
for(uint32 i = 0; i < GetBagSize(); ++i)
|
||||
if(m_bagslot[i] != 0)
|
||||
if(m_bagslot[i]->GetGUID() == guid)
|
||||
return i;
|
||||
}
|
||||
|
||||
return NULL_SLOT;
|
||||
}
|
||||
|
||||
// Adds an item to a bag slot
|
||||
// - slot can be NULL_SLOT, in that case function searchs for a free slot
|
||||
// - Return values: 0 - item not added
|
||||
// 1 - item added to a free slot (and perhaps to a stack)
|
||||
// 2 - item added to a stack (item should be deleted)
|
||||
Item* Bag::GetItemByPos( uint8 slot ) const
|
||||
{
|
||||
ItemPrototype const *pBagProto = GetProto();
|
||||
if( pBagProto )
|
||||
{
|
||||
if( slot < pBagProto->ContainerSlots )
|
||||
return m_bagslot[slot];
|
||||
}
|
||||
if( slot < GetBagSize() )
|
||||
return m_bagslot[slot];
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue