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
View File
@@ -281,6 +281,15 @@ bool Item::Create(uint32 guidlow, uint32 itemid, Player const* owner)
return true;
}
// Returns true if Item is a bag AND it is not empty.
// Returns false if Item is not a bag OR it is an empty bag.
bool Item::IsNotEmptyBag() const
{
if (const Bag* pBag = ToBag())
return !pBag->IsEmpty();
return false;
}
void Item::UpdateDuration(Player* owner, uint32 diff)
{
if (!GetUInt32Value(ITEM_FIELD_DURATION))
+4
View File
@@ -253,8 +253,12 @@ class Item : public Object
void SaveRefundDataToDB();
void DeleteRefundDataFromDB();
Bag* ToBag() { if (IsBag()) return reinterpret_cast<Bag*>(this); else return NULL; }
const Bag* ToBag() const { if (IsBag()) return reinterpret_cast<const Bag*>(this); else return NULL; }
bool IsLocked() const { return !HasFlag(ITEM_FIELD_FLAGS, ITEM_FLAG_UNLOCKED); }
bool IsBag() const { return GetProto()->InventoryType == INVTYPE_BAG; }
bool IsNotEmptyBag() const;
bool IsBroken() const { return GetUInt32Value(ITEM_FIELD_MAXDURABILITY) > 0 && GetUInt32Value(ITEM_FIELD_DURABILITY) == 0; }
bool CanBeTraded(bool mail = false, bool trade = false) const;
void SetInTrade(bool b = true) { mb_in_trade = b; }