diff options
author | maximius <none@none> | 2009-10-17 15:35:07 -0700 |
---|---|---|
committer | maximius <none@none> | 2009-10-17 15:35:07 -0700 |
commit | 26b5e033ffde3d161382fc9addbfa99738379641 (patch) | |
tree | a344f369ca32945f787a02dee35c3dbe342bed7e /src/game/Bag.cpp | |
parent | f21f47005dcb6b76e1abc9f35fbcd03eed191bff (diff) |
*Massive cleanup (\n\n -> \n, *\n -> \n, cleanup for(...) to for (...), and some other cleanups by hand)
*Fix a possible crash in Spell::DoAllEffectOnTarget
--HG--
branch : trunk
Diffstat (limited to 'src/game/Bag.cpp')
-rw-r--r-- | src/game/Bag.cpp | 43 |
1 files changed, 0 insertions, 43 deletions
diff --git a/src/game/Bag.cpp b/src/game/Bag.cpp index 2d58b63c0a9..5b406c2eb08 100644 --- a/src/game/Bag.cpp +++ b/src/game/Bag.cpp @@ -17,25 +17,19 @@ * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ - #include "Common.h" #include "ObjectMgr.h" #include "Database/DatabaseEnv.h" - #include "Bag.h" #include "Log.h" #include "UpdateData.h" - Bag::Bag( ): Item() { m_objectType |= TYPEMASK_CONTAINER; m_objectTypeId = TYPEID_CONTAINER; - m_valuesCount = CONTAINER_END; - memset(m_bagslot, 0, sizeof(Item *) * MAX_BAG_SIZE); } - Bag::~Bag() { for(uint8 i = 0; i < MAX_BAG_SIZE; ++i) @@ -51,68 +45,52 @@ Bag::~Bag() delete m_bagslot[i]; } } - void Bag::AddToWorld() { Item::AddToWorld(); - for(uint32 i = 0; i < GetBagSize(); ++i) if(m_bagslot[i]) m_bagslot[i]->AddToWorld(); } - void Bag::RemoveFromWorld() { for(uint32 i = 0; i < GetBagSize(); ++i) if(m_bagslot[i]) m_bagslot[i]->RemoveFromWorld(); - Item::RemoveFromWorld(); } - bool Bag::Create(uint32 guidlow, uint32 itemid, Player const* owner) { ItemPrototype const * itemProto = objmgr.GetItemPrototype(itemid); - if(!itemProto || itemProto->ContainerSlots > MAX_BAG_SIZE) return false; - Object::_Create( guidlow, 0, HIGHGUID_CONTAINER ); - SetEntry(itemid); SetFloatValue(OBJECT_FIELD_SCALE_X, 1.0f); - SetUInt64Value(ITEM_FIELD_OWNER, owner ? owner->GetGUID() : 0); SetUInt64Value(ITEM_FIELD_CONTAINED, owner ? owner->GetGUID() : 0); - SetUInt32Value(ITEM_FIELD_MAXDURABILITY, itemProto->MaxDurability); SetUInt32Value(ITEM_FIELD_DURABILITY, itemProto->MaxDurability); SetUInt32Value(ITEM_FIELD_FLAGS, itemProto->Flags); SetUInt32Value(ITEM_FIELD_STACK_COUNT, 1); - // Setting the number of Slots the Container has SetUInt32Value(CONTAINER_FIELD_NUM_SLOTS, itemProto->ContainerSlots); - // Cleaning 20 slots for (uint8 i = 0; i < MAX_BAG_SIZE; ++i) { SetUInt64Value(CONTAINER_FIELD_SLOT_1 + (i*2), 0); m_bagslot[i] = NULL; } - return true; } - void Bag::SaveToDB() { Item::SaveToDB(); } - bool Bag::LoadFromDB(uint32 guid, uint64 owner_guid, QueryResult *result) { if(!Item::LoadFromDB(guid, owner_guid, result)) return false; - // cleanup bag content related item value fields (its will be filled correctly from `character_inventory`) for (uint8 i = 0; i < MAX_BAG_SIZE; ++i) { @@ -123,44 +101,34 @@ bool Bag::LoadFromDB(uint32 guid, uint64 owner_guid, QueryResult *result) m_bagslot[i] = NULL; } } - return true; } - void Bag::DeleteFromDB() { for (uint8 i = 0; i < MAX_BAG_SIZE; ++i) if (m_bagslot[i]) m_bagslot[i]->DeleteFromDB(); - Item::DeleteFromDB(); } - uint32 Bag::GetFreeSlots() const { uint32 slots = 0; for (uint32 i=0; i < GetBagSize(); ++i) if (!m_bagslot[i]) ++slots; - return slots; } - void Bag::RemoveItem( uint8 slot, bool /*update*/ ) { assert(slot < MAX_BAG_SIZE); - if (m_bagslot[slot]) m_bagslot[slot]->SetContainer(NULL); - m_bagslot[slot] = NULL; SetUInt64Value( CONTAINER_FIELD_SLOT_1 + (slot * 2), 0 ); } - void Bag::StoreItem( uint8 slot, Item *pItem, bool /*update*/ ) { assert(slot < MAX_BAG_SIZE); - if( pItem ) { m_bagslot[slot] = pItem; @@ -171,26 +139,21 @@ void Bag::StoreItem( uint8 slot, Item *pItem, bool /*update*/ ) pItem->SetSlot(slot); } } - void Bag::BuildCreateUpdateBlockForPlayer( UpdateData *data, Player *target ) const { Item::BuildCreateUpdateBlockForPlayer( data, target ); - 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 { for(uint32 i = 0; i < GetBagSize(); ++i) if (m_bagslot[i]) return false; - return true; } - uint32 Bag::GetItemCount( uint32 item, Item* eItem ) const { Item *pItem; @@ -201,7 +164,6 @@ uint32 Bag::GetItemCount( uint32 item, Item* eItem ) const if( pItem && pItem != eItem && pItem->GetEntry() == item ) count += pItem->GetCount(); } - if(eItem && eItem->GetProto()->GemProperties) { for(uint32 i=0; i < GetBagSize(); ++i) @@ -211,25 +173,20 @@ uint32 Bag::GetItemCount( uint32 item, Item* eItem ) const count += pItem->GetGemCountWithID(item); } } - return count; } - uint8 Bag::GetSlotByItemGUID(uint64 guid) const { for(uint32 i = 0; i < GetBagSize(); ++i) if(m_bagslot[i] != 0) if(m_bagslot[i]->GetGUID() == guid) return i; - return NULL_SLOT; } - Item* Bag::GetItemByPos( uint8 slot ) const { if( slot < GetBagSize() ) return m_bagslot[slot]; - return NULL; } |