Core/Cleanup: remove C-style cast to (Bag*):

* add ToBag() methods for Item class;
* add GetBagByPos() method for Player class.
This commit is contained in:
Azazel
2011-03-18 15:58:08 +06:00
parent 90a3fee232
commit e49b5b44d6
9 changed files with 156 additions and 183 deletions
+9 -15
View File
@@ -516,22 +516,17 @@ public:
if (i >= BUYBACK_SLOT_START && i < BUYBACK_SLOT_END)
continue;
Item *item = player->GetItemByPos(INVENTORY_SLOT_BAG_0, i);
if (!item) continue;
if (!item->IsBag())
if (Item *item = player->GetItemByPos(INVENTORY_SLOT_BAG_0, i))
{
if (item->GetState() == state)
handler->PSendSysMessage("bag: 255 slot: %d guid: %d owner: %d", item->GetSlot(), item->GetGUIDLow(), GUID_LOPART(item->GetOwnerGUID()));
}
else
{
Bag *bag = (Bag*)item;
for (uint8 j = 0; j < bag->GetBagSize(); ++j)
if (Bag* bag = item->ToBag())
{
Item* item2 = bag->GetItemByPos(j);
if (item2 && item2->GetState() == state)
handler->PSendSysMessage("bag: 255 slot: %d guid: %d owner: %d", item2->GetSlot(), item2->GetGUIDLow(), GUID_LOPART(item2->GetOwnerGUID()));
for (uint8 j = 0; j < bag->GetBagSize(); ++j)
if (Item* item2 = bag->GetItemByPos(j))
if (item2->GetState() == state)
handler->PSendSysMessage("bag: 255 slot: %d guid: %d owner: %d", item2->GetSlot(), item2->GetGUIDLow(), GUID_LOPART(item2->GetOwnerGUID()));
}
else if (item->GetState() == state)
handler->PSendSysMessage("bag: 255 slot: %d guid: %d owner: %d", item->GetSlot(), item->GetGUIDLow(), GUID_LOPART(item->GetOwnerGUID()));
}
}
}
@@ -619,9 +614,8 @@ public:
error = true; continue;
}
if (item->IsBag())
if (Bag* bag = item->ToBag())
{
Bag *bag = (Bag*)item;
for (uint8 j = 0; j < bag->GetBagSize(); ++j)
{
Item* item2 = bag->GetItemByPos(j);