Item system update

- Set ITEM_FIELD_CREATE_PLAYED_TIME to 0 in Item::Create, should fix crash described in issue 1199
- Change some function calls so on Player::_saveInventory the core doesn't have to check for existance of item anymore when iterating over m_refundableItems. The loop will now only update played time, removal of items from this set is done in other functions.
- Cleanup in affected functions.

--HG--
branch : trunk
This commit is contained in:
Machiavelli
2010-03-20 16:26:16 +01:00
parent 10417f1e6d
commit a0d8b0be48
5 changed files with 95 additions and 103 deletions
+23 -33
View File
@@ -11580,7 +11580,7 @@ void Player::DestroyItem(uint8 bag, uint8 slot, bool update)
RemoveItemDurations(pItem);
if (pItem->HasFlag(ITEM_FIELD_FLAGS, ITEM_FLAGS_REFUNDABLE))
DeleteRefundReference(pItem);
pItem->SetNotRefundable(this);
ItemRemovedQuestCheck( pItem->GetEntry(), pItem->GetCount() );
@@ -16409,11 +16409,9 @@ void Player::_LoadInventory(QueryResult_AutoPtr result, uint32 timediff)
else
{
fields = result2->Fetch();
ItemRefund* RefundData = new ItemRefund();
RefundData->eligibleFor = fields[0].GetUInt32();
RefundData->paidMoney = fields[1].GetUInt32();
RefundData->paidExtendedCost = fields[2].GetUInt32();
item->SetRefundData(RefundData);
item->SetRefundRecipient(fields[0].GetUInt32());
item->SetPaidMoney(fields[1].GetUInt32());
item->SetPaidExtendedCost(fields[2].GetUInt32());
AddRefundReference(item);
}
}
@@ -17497,21 +17495,15 @@ void Player::_SaveInventory()
m_items[i]->FSetState(ITEM_NEW);
}
// Updated played time for refundable items
for (std::set<Item*>::iterator itr = m_refundableItems.begin(); itr!= m_refundableItems.end();)
// Updated played time for refundable items. We don't do this in Player::Update because there's simply no need for it,
// the client auto counts down in real time after having received the initial played time on the first
// SMSG_ITEM_REFUND_INFO_RESPONSE packet.
// Item::UpdatePlayedTime is only called when needed, which is in DB saves, and item refund info requests.
for (std::set<Item*>::iterator itr = m_refundableItems.begin(); itr!= m_refundableItems.end(); ++itr)
{
// Item could be deleted, or traded.
// In the first case, DeleteRefundDataFromDB() was already called in Item::SaveToDB()
Item* iPtr = (*itr);
if (!iPtr)
m_refundableItems.erase(itr++);
else
{
iPtr->UpdatePlayedTime(this);
if (iPtr->GetPlayedTime() > (2*HOUR))
iPtr->SetNotRefundable(this);
++itr;
}
Item* iPtr = *itr;
ASSERT(iPtr); // Sanity check, if this assertion is hit then the item wasn't removed from the set correctly./
iPtr->UpdatePlayedTime(this);
}
// update enchantment durations
@@ -17527,14 +17519,16 @@ void Player::_SaveInventory()
for (size_t i = 0; i < m_itemUpdateQueue.size(); ++i)
{
Item *item = m_itemUpdateQueue[i];
if(!item || item->GetState() == ITEM_REMOVED) continue;
Item *test = GetItemByPos( item->GetBagSlot(), item->GetSlot());
if (!item || item->GetState() == ITEM_REMOVED)
continue;
Item *test = GetItemByPos(item->GetBagSlot(), item->GetSlot());
if (test == NULL)
{
sLog.outCrash("Player(GUID: %u Name: %s)::_SaveInventory - the bag(%d) and slot(%d) values for the item with guid %d (state %d) are incorrect, the player doesn't have an item at that position!", GetGUIDLow(), GetName(), item->GetBagSlot(), item->GetSlot(), item->GetGUIDLow(), (int32)item->GetState());
//error = true;
//now some items in bags cannot be saved but after cleansup they appear again
//Should the above line really be commented out?
}
else if (test != item)
{
@@ -19364,11 +19358,9 @@ bool Player::BuyItemFromVendor(uint64 vendorguid, uint32 item, uint8 count, uint
if (it->HasFlag(ITEM_FIELD_FLAGS, ITEM_FLAGS_REFUNDABLE) && crItem->ExtendedCost)
{
ItemRefund* RefundData = new ItemRefund();
RefundData->eligibleFor = GetGUIDLow();
RefundData->paidMoney = price;
RefundData->paidExtendedCost = crItem->ExtendedCost;
it->SetRefundData(RefundData);
it->SetRefundRecipient(GetGUIDLow());
it->SetPaidMoney(price);
it->SetPaidExtendedCost(crItem->ExtendedCost);
it->SaveRefundDataToDB();
AddRefundReference(it);
}
@@ -19424,11 +19416,9 @@ bool Player::BuyItemFromVendor(uint64 vendorguid, uint32 item, uint8 count, uint
if (it->HasFlag(ITEM_FIELD_FLAGS, ITEM_FLAGS_REFUNDABLE) && crItem->ExtendedCost)
{
ItemRefund* RefundData = new ItemRefund();
RefundData->eligibleFor = GetGUIDLow();
RefundData->paidMoney = price;
RefundData->paidExtendedCost = crItem->ExtendedCost;
it->SetRefundData(RefundData);
it->SetRefundRecipient(GetGUIDLow());
it->SetPaidMoney(price);
it->SetPaidExtendedCost(crItem->ExtendedCost);
it->SaveRefundDataToDB();
AddRefundReference(it);
}