Changeset 177 for trunk/src/game/Bag.cpp
- Timestamp:
- 11/19/08 13:43:30 (17 years ago)
- Files:
-
- 1 modified
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/game/Bag.cpp
r102 r177 40 40 Bag::~Bag() 41 41 { 42 for(int i = 0; i<MAX_BAG_SIZE; i++) 43 { 44 if(m_bagslot[i]) delete m_bagslot[i]; 45 } 42 for(int i = 0; i < MAX_BAG_SIZE; ++i) 43 if (m_bagslot[i]) 44 delete m_bagslot[i]; 46 45 } 47 46 … … 50 49 Item::AddToWorld(); 51 50 52 for(int i = 0; i<MAX_BAG_SIZE; i++) 53 { 51 for(uint32 i = 0; i < GetBagSize(); ++i) 54 52 if(m_bagslot[i]) 55 53 m_bagslot[i]->AddToWorld(); 56 }57 54 } 58 55 59 56 void Bag::RemoveFromWorld() 60 57 { 61 for(int i = 0; i<MAX_BAG_SIZE; i++) 62 { 58 for(uint32 i = 0; i < GetBagSize(); ++i) 63 59 if(m_bagslot[i]) 64 60 m_bagslot[i]->RemoveFromWorld(); 65 }66 61 67 62 Item::RemoveFromWorld(); … … 112 107 113 108 // cleanup bag content related item value fields (its will be filled correctly from `character_inventory`) 114 for ( uint32 i = 0; i < GetProto()->ContainerSlots; i++)109 for (int i = 0; i < MAX_BAG_SIZE; ++i) 115 110 { 116 111 SetUInt64Value(CONTAINER_FIELD_SLOT_1 + (i*2), 0); … … 128 123 { 129 124 for (int i = 0; i < MAX_BAG_SIZE; i++) 130 { 131 if (m_bagslot[i]) 132 { 125 if (m_bagslot[i]) 133 126 m_bagslot[i]->DeleteFromDB(); 134 }135 }136 127 137 128 Item::DeleteFromDB(); … … 140 131 uint32 Bag::GetFreeSlots() const 141 132 { 142 uint32 ContainerSlots=GetProto()->ContainerSlots;143 133 uint32 slots = 0; 144 for (uint 8 i=0; i <ContainerSlots; i++)134 for (uint32 i=0; i < GetBagSize(); i++) 145 135 if (!m_bagslot[i]) 146 136 ++slots; … … 179 169 Item::BuildCreateUpdateBlockForPlayer( data, target ); 180 170 181 for (int i = 0; i < MAX_BAG_SIZE; i++) 182 { 171 for (uint32 i = 0; i < GetBagSize(); ++i) 183 172 if(m_bagslot[i]) 184 173 m_bagslot[i]->BuildCreateUpdateBlockForPlayer( data, target ); 185 }186 174 } 187 175 … … 189 177 bool Bag::IsEmpty() const 190 178 { 191 uint32 ContainerSlots=GetProto()->ContainerSlots;192 for(uint32 i=0; i < ContainerSlots; i++)193 if (m_bagslot[i])return false;179 for(uint32 i = 0; i < GetBagSize(); ++i) 180 if (m_bagslot[i]) 181 return false; 194 182 195 183 return true; … … 198 186 uint32 Bag::GetItemCount( uint32 item, Item* eItem ) const 199 187 { 200 uint32 ContainerSlots=GetProto()->ContainerSlots;201 202 188 Item *pItem; 203 189 uint32 count = 0; 204 for(uint32 i=0; i < ContainerSlots; i++)190 for(uint32 i=0; i < GetBagSize(); ++i) 205 191 { 206 192 pItem = m_bagslot[i]; … … 211 197 if(eItem && eItem->GetProto()->GemProperties) 212 198 { 213 for(uint32 i=0; i < ContainerSlots; i++)199 for(uint32 i=0; i < GetBagSize(); ++i) 214 200 { 215 201 pItem = m_bagslot[i]; … … 224 210 uint8 Bag::GetSlotByItemGUID(uint64 guid) const 225 211 { 226 uint32 ContainerSlots=GetProto()->ContainerSlots; 227 228 for(uint32 i=0;i<ContainerSlots;i++) 229 { 212 for(uint32 i = 0; i < GetBagSize(); ++i) 230 213 if(m_bagslot[i] != 0) 231 214 if(m_bagslot[i]->GetGUID() == guid) 232 215 return i; 233 }234 216 return NULL_SLOT; 235 217 } 236 218 237 // Adds an item to a bag slot238 // - slot can be NULL_SLOT, in that case function searchs for a free slot239 // - Return values: 0 - item not added240 // 1 - item added to a free slot (and perhaps to a stack)241 // 2 - item added to a stack (item should be deleted)242 219 Item* Bag::GetItemByPos( uint8 slot ) const 243 220 { 244 ItemPrototype const *pBagProto = GetProto(); 245 if( pBagProto ) 246 { 247 if( slot < pBagProto->ContainerSlots ) 248 return m_bagslot[slot]; 249 } 221 if( slot < GetBagSize() ) 222 return m_bagslot[slot]; 223 250 224 return NULL; 251 225 }