Store alternate currency spent on an item by Item ExtendedCost entry instead of honorPts/arenaPts/items seperately. Thanks to Opterman for the idea.

--HG--
branch : trunk
This commit is contained in:
Machiavelli
2010-03-18 22:56:48 +01:00
parent ef57a96cce
commit 35a7f4849e
6 changed files with 76 additions and 97 deletions
+1 -10
View File
@@ -1059,16 +1059,7 @@ void Item::SaveRefundDataToDB()
ss << GetGUIDLow() << ",";
ss << RefundData->eligibleFor << ",";
ss << RefundData->paidMoney << ",";
ss << RefundData->paidHonorPoints << ",";
ss << RefundData->paidArenaPoints << ",";
for (uint8 i=0; i<5; ++i)
{
ss << RefundData->paidItemId[i] << ",";
ss << RefundData->paidItemCount[i];
if (i < 4)
ss << ",";
}
ss << RefundData->paidExtendedCost;
ss << ")";
CharacterDatabase.Execute(ss.str().c_str());
+2 -15
View File
@@ -220,23 +220,10 @@ bool ItemCanGoIntoBag(ItemPrototype const *proto, ItemPrototype const *pBagProto
struct ItemRefund
{
ItemRefund()
{
paidMoney = 0;
paidHonorPoints = 0;
paidArenaPoints = 0;
for (uint8 i=0;i<5;++i)
{
paidItemId[i] = 0;
paidItemCount[i] = 0;
}
}
ItemRefund() : paidMoney(0), paidExtendedCost(0) {}
uint32 eligibleFor;
uint32 paidMoney;
uint32 paidHonorPoints;
uint32 paidArenaPoints;
uint32 paidItemId[5];
uint32 paidItemCount[5];
uint32 paidExtendedCost;
};
class Item : public Object
+28 -15
View File
@@ -1382,18 +1382,24 @@ void WorldSession::HandleItemRefundInfoRequest(WorldPacket& recv_data)
item->SetNotRefundable(GetPlayer());
return;
}
ItemExtendedCostEntry const* iece = sItemExtendedCostStore.LookupEntry(RefundData->paidExtendedCost);
if (!iece)
{
sLog.outDebug("Item refund: cannot find extendedcost data.");
return;
}
item->UpdatePlayedTime(GetPlayer());
WorldPacket data(SMSG_ITEM_REFUND_INFO_RESPONSE, 8+4+4+4+4*4+4*4+4+4);
data << uint64(guid); // item guid
data << uint32(RefundData->paidMoney); // money cost
data << uint32(RefundData->paidHonorPoints); // honor point cost
data << uint32(RefundData->paidArenaPoints); // arena point cost
data << uint32(iece->reqhonorpoints); // honor point cost
data << uint32(iece->reqarenapoints); // arena point cost
for (uint8 i = 0; i < 5; ++i) // item cost data
{
data << RefundData->paidItemId[i];
data << RefundData->paidItemCount[i];
data << iece->reqitem[i];
data << iece->reqitemcount[i];
}
data << uint32(0);
data << uint32(GetPlayer()->GetTotalPlayedTime() - item->GetPlayedTime());
@@ -1444,11 +1450,18 @@ void WorldSession::HandleItemRefund(WorldPacket &recv_data)
return;
}
ItemExtendedCostEntry const* iece = sItemExtendedCostStore.LookupEntry(RefundData->paidExtendedCost);
if (!iece)
{
sLog.outDebug("Item refund: cannot find extendedcost data.");
return;
}
bool store_error = false;
for (uint8 i = 0; i < 5; ++i)
{
uint32 count = RefundData->paidItemCount[i];
uint32 itemid = RefundData->paidItemId[i];
uint32 count = iece->reqitemcount[i];
uint32 itemid = iece->reqitem[i];
if (count && itemid)
{
@@ -1475,12 +1488,12 @@ void WorldSession::HandleItemRefund(WorldPacket &recv_data)
data << uint64(guid); // item guid
data << uint32(0); // 0, or error code
data << uint32(RefundData->paidMoney); // money cost
data << uint32(RefundData->paidHonorPoints); // honor point cost
data << uint32(RefundData->paidArenaPoints); // arena point cost
data << uint32(iece->reqhonorpoints); // honor point cost
data << uint32(iece->reqarenapoints); // arena point cost
for (uint8 i = 0; i < 5; ++i) // item cost data
{
data << RefundData->paidItemId[i];
data << RefundData->paidItemCount[i];
data << iece->reqitem[i];
data << iece->reqitemcount[i];
}
SendPacket(&data);
@@ -1493,8 +1506,8 @@ void WorldSession::HandleItemRefund(WorldPacket &recv_data)
// Grant back extendedcost items
for (uint8 i = 0; i < 5; ++i)
{
uint32 count = RefundData->paidItemCount[i];
uint32 itemid = RefundData->paidItemId[i];
uint32 count = iece->reqitemcount[i];
uint32 itemid = iece->reqitem[i];
if (count && itemid)
{
ItemPosCountVec dest;
@@ -1511,12 +1524,12 @@ void WorldSession::HandleItemRefund(WorldPacket &recv_data)
_player->ModifyMoney(moneyRefund);
// Grant back Honor points
uint32 honorRefund = RefundData->paidHonorPoints;
uint32 honorRefund = iece->reqhonorpoints;
if (honorRefund)
_player->ModifyHonorPoints(honorRefund);
// Grant back Arena points
uint32 arenaRefund = RefundData->paidArenaPoints;
uint32 arenaRefund = iece->reqarenapoints;
if (arenaRefund)
_player->ModifyArenaPoints(arenaRefund);
+15 -57
View File
@@ -16389,10 +16389,7 @@ void Player::_LoadInventory(QueryResult_AutoPtr result, uint32 timediff)
else
{
QueryResult_AutoPtr result2 = CharacterDatabase.PQuery(
"SELECT player_guid,paidMoney,paidHonor,paidArena,"
"paidItem_1,paidItemCount_1,paidItem_2,paidItemCount_2,paidItem_3,paidItemCount_3,paidItem_4,paidItemCount_4,"
"paidItem_5,paidItemCount_5 FROM item_refund_instance WHERE item_guid = '%u' LIMIT 1",
item->GetGUIDLow());
"SELECT player_guid,paidMoney,paidExtendedCost FROM `item_refund_instance` WHERE item_guid = '%u' LIMIT 1", item->GetGUIDLow());
if (!result2)
{
sLog.outDebug("Item::LoadFromDB, "
@@ -16406,13 +16403,7 @@ void Player::_LoadInventory(QueryResult_AutoPtr result, uint32 timediff)
ItemRefund* RefundData = new ItemRefund();
RefundData->eligibleFor = fields[0].GetUInt32();
RefundData->paidMoney = fields[1].GetUInt32();
RefundData->paidHonorPoints = fields[2].GetUInt32();
RefundData->paidArenaPoints = fields[3].GetUInt32();
for (uint8 i=0, j=4; i<5; ++i, j+=2)
{
RefundData->paidItemId[i] = fields[j].GetUInt32();
RefundData->paidItemCount[i] = fields[j+1].GetUInt32();
}
RefundData->paidExtendedCost = fields[2].GetUInt32();
item->SetRefundData(RefundData);
AddRefundReference(item);
}
@@ -19322,11 +19313,6 @@ bool Player::BuyItemFromVendor(uint64 vendorguid, uint32 item, uint8 count, uint
return false;
}
uint32 honorPoints = 0;
uint32 arenaPoints = 0;
uint32 itemCostId[5] = {0,0,0,0,0};
uint32 itemCostCount[5] = {0,0,0,0,0};
if ((bag == NULL_BAG && slot == NULL_SLOT) || IsInventoryPos(bag, slot))
{
ItemPosCountVec dest;
@@ -19343,23 +19329,15 @@ bool Player::BuyItemFromVendor(uint64 vendorguid, uint32 item, uint8 count, uint
{
ItemExtendedCostEntry const* iece = sItemExtendedCostStore.LookupEntry(crItem->ExtendedCost);
if (iece->reqhonorpoints)
{
honorPoints = iece->reqhonorpoints;
ModifyHonorPoints( - int32(honorPoints) );
}
ModifyHonorPoints( - int32(iece->reqhonorpoints * count) );
if (iece->reqarenapoints)
{
arenaPoints = iece->reqarenapoints;
ModifyArenaPoints( - int32(arenaPoints) );
}
ModifyArenaPoints( - int32(iece->reqarenapoints * count) );
for (uint8 i = 0; i < 5; ++i)
{
if (iece->reqitem[i])
{
DestroyItemCount(iece->reqitem[i], (iece->reqitemcount[i] * count), true);
itemCostId[i] = iece->reqitem[i];
itemCostCount[i] = iece->reqitemcount[i];
}
}
}
@@ -19375,18 +19353,12 @@ bool Player::BuyItemFromVendor(uint64 vendorguid, uint32 item, uint8 count, uint
GetSession()->SendPacket(&data);
SendNewItem(it, pProto->BuyCount*count, true, false, false);
if (it->HasFlag(ITEM_FIELD_FLAGS, ITEM_FLAGS_REFUNDABLE))
if (it->HasFlag(ITEM_FIELD_FLAGS, ITEM_FLAGS_REFUNDABLE) && crItem->ExtendedCost)
{
ItemRefund* RefundData = new ItemRefund();
RefundData->eligibleFor = GetGUIDLow();
RefundData->paidMoney = price;
RefundData->paidHonorPoints = honorPoints;
RefundData->paidArenaPoints = arenaPoints;
for (uint8 i=0; i<5; ++i)
{
RefundData->paidItemId[i] = itemCostId[i];
RefundData->paidItemCount[i] = itemCostCount[i] ;
}
RefundData->paidExtendedCost = crItem->ExtendedCost;
it->SetRefundData(RefundData);
it->SaveRefundDataToDB();
AddRefundReference(it);
@@ -19414,23 +19386,15 @@ bool Player::BuyItemFromVendor(uint64 vendorguid, uint32 item, uint8 count, uint
{
ItemExtendedCostEntry const* iece = sItemExtendedCostStore.LookupEntry(crItem->ExtendedCost);
if (iece->reqhonorpoints)
{
honorPoints = iece->reqhonorpoints;
ModifyHonorPoints( - int32(honorPoints) );
}
ModifyHonorPoints( - int32(iece->reqhonorpoints * count) );
if (iece->reqarenapoints)
{
arenaPoints = iece->reqarenapoints;
ModifyArenaPoints( - int32(arenaPoints));
}
ModifyArenaPoints( - int32(iece->reqarenapoints * count) );
for (uint8 i = 0; i < 5; ++i)
{
if(iece->reqitem[i])
{
DestroyItemCount(iece->reqitem[i], iece->reqitemcount[i], true);
itemCostId[i] = iece->reqitem[i];
itemCostCount[i] = iece->reqitemcount[i];
}
DestroyItemCount(iece->reqitem[i], iece->reqitemcount[i] * count, true);
}
}
@@ -19449,18 +19413,12 @@ bool Player::BuyItemFromVendor(uint64 vendorguid, uint32 item, uint8 count, uint
AutoUnequipOffhandIfNeed();
if (it->HasFlag(ITEM_FIELD_FLAGS, ITEM_FLAGS_REFUNDABLE))
if (it->HasFlag(ITEM_FIELD_FLAGS, ITEM_FLAGS_REFUNDABLE) && crItem->ExtendedCost)
{
ItemRefund* RefundData = new ItemRefund();
RefundData->eligibleFor = GetGUIDLow();
RefundData->paidMoney = price;
RefundData->paidHonorPoints = honorPoints;
RefundData->paidArenaPoints = arenaPoints;
for (uint8 i=0; i<5; ++i)
{
RefundData->paidItemId[i] = itemCostId[i];
RefundData->paidItemCount[i] = itemCostCount[i] ;
}
RefundData->paidExtendedCost = crItem->ExtendedCost;
it->SetRefundData(RefundData);
it->SaveRefundDataToDB();
AddRefundReference(it);