Clean up in item refund related code.

--HG--
branch : trunk
This commit is contained in:
Machiavelli committed 2010-04-30 19:20:59 +02:00
1 parent 31113370b3
commit 4b1a9916ac
6 files changed
+185 -188

No files matched your search

+2 -145
View File
@@ -1372,44 +1372,7 @@ void WorldSession::HandleItemRefundInfoRequest(WorldPacket& recv_data)
return;
}
// This function call unsets ITEM_FLAGS_REFUNDABLE if played time is over 2 hours.
item->UpdatePlayedTime(GetPlayer());
if (!item->HasFlag(ITEM_FIELD_FLAGS, ITEM_FLAGS_REFUNDABLE))
{
sLog.outDebug("Item refund: item not refundable!");
return;
}
if (GetPlayer()->GetGUIDLow() != item->GetRefundRecipient()) // Formerly refundable item got traded
{
sLog.outDebug("Item refund: item was traded!");
item->SetNotRefundable(GetPlayer());
return;
}
ItemExtendedCostEntry const* iece = sItemExtendedCostStore.LookupEntry(item->GetPaidExtendedCost());
if (!iece)
{
sLog.outDebug("Item refund: cannot find extendedcost data.");
return;
}
uint32 itemCount = item->GetCount();
WorldPacket data(SMSG_ITEM_REFUND_INFO_RESPONSE, 8+4+4+4+4*4+4*4+4+4);
data << uint64(guid); // item guid
data << uint32(item->GetPaidMoney() * itemCount); // money cost
data << uint32(iece->reqhonorpoints * itemCount); // honor point cost
data << uint32(iece->reqarenapoints * itemCount); // arena point cost
for (uint8 i = 0; i < 5; ++i) // item cost data
{
data << iece->reqitem[i];
data << (iece->reqitemcount[i] * itemCount);
}
data << uint32(0);
data << uint32(GetPlayer()->GetTotalPlayedTime() - item->GetPlayedTime());
SendPacket(&data);
GetPlayer()->SendRefundInfo(item);
}
void WorldSession::HandleItemRefund(WorldPacket &recv_data)
@@ -1425,113 +1388,7 @@ void WorldSession::HandleItemRefund(WorldPacket &recv_data)
return;
}
if (!item->HasFlag(ITEM_FIELD_FLAGS, ITEM_FLAGS_REFUNDABLE))
{
sLog.outDebug("Item refund: item not refundable!");
return;
}
if (item->IsRefundExpired()) // item refund has expired
{
item->SetNotRefundable(GetPlayer());
WorldPacket data(SMSG_ITEM_REFUND_RESULT, 8+4);
data << uint64(guid); // Guid
data << uint32(10); // Error!
SendPacket(&data);
return;
}
if (GetPlayer()->GetGUIDLow() != item->GetRefundRecipient()) // Formerly refundable item got traded
{
sLog.outDebug("Item refund: item was traded!");
item->SetNotRefundable(GetPlayer());
return;
}
ItemExtendedCostEntry const* iece = sItemExtendedCostStore.LookupEntry(item->GetPaidExtendedCost());
if (!iece)
{
sLog.outDebug("Item refund: cannot find extendedcost data.");
return;
}
uint32 itemCount = item->GetCount(); // stacked refundable items.
uint32 moneyRefund = item->GetPaidMoney()*itemCount;
bool store_error = false;
for (uint8 i = 0; i < 5; ++i)
{
uint32 count = iece->reqitemcount[i] * itemCount;
uint32 itemid = iece->reqitem[i];
if (count && itemid)
{
ItemPosCountVec dest;
uint8 msg = _player->CanStoreNewItem(NULL_BAG, NULL_SLOT, dest, itemid, count);
if (msg != EQUIP_ERR_OK)
{
store_error = true;
break;
}
}
}
if (store_error)
{
WorldPacket data(SMSG_ITEM_REFUND_RESULT, 8+4);
data << uint64(guid); // Guid
data << uint32(10); // Error!
SendPacket(&data);
return;
}
WorldPacket data(SMSG_ITEM_REFUND_RESULT, 8+4+4+4+4+4*4+4*4);
data << uint64(guid); // item guid
data << uint32(0); // 0, or error code
data << uint32(moneyRefund); // money cost
data << uint32(iece->reqhonorpoints * itemCount); // honor point cost
data << uint32(iece->reqarenapoints * itemCount); // arena point cost
for (uint8 i = 0; i < 5; ++i) // item cost data
{
data << iece->reqitem[i];
data << (iece->reqitemcount[i] * itemCount);
}
SendPacket(&data);
// Delete any references to the refund data
item->SetNotRefundable(GetPlayer());
// Destroy item
_player->DestroyItem(item->GetBagSlot(), item->GetSlot(), true);
// Grant back extendedcost items
for (uint8 i = 0; i < 5; ++i)
{
uint32 count = iece->reqitemcount[i] * itemCount;
uint32 itemid = iece->reqitem[i];
if (count && itemid)
{
ItemPosCountVec dest;
uint8 msg = _player->CanStoreNewItem(NULL_BAG, NULL_SLOT, dest, itemid, count);
ASSERT(msg == EQUIP_ERR_OK) /// Already checked before
Item* it = _player->StoreNewItem(dest, itemid, true);
_player->SendNewItem(it, count, true, false, true);
}
}
// Grant back money
if (moneyRefund)
_player->ModifyMoney(moneyRefund);
// Grant back Honor points
uint32 honorRefund = iece->reqhonorpoints * itemCount;
if (honorRefund)
_player->ModifyHonorPoints(honorRefund);
// Grant back Arena points
uint32 arenaRefund = iece->reqarenapoints * itemCount;
if (arenaRefund)
_player->ModifyArenaPoints(arenaRefund);
GetPlayer()->RefundItem(item);
}
/**