diff options
Diffstat (limited to 'src/game/Player.cpp')
-rw-r--r-- | src/game/Player.cpp | 146 |
1 files changed, 126 insertions, 20 deletions
diff --git a/src/game/Player.cpp b/src/game/Player.cpp index fa4759dacd1..d53d61581c1 100644 --- a/src/game/Player.cpp +++ b/src/game/Player.cpp @@ -11560,6 +11560,9 @@ void Player::DestroyItem(uint8 bag, uint8 slot, bool update) RemoveEnchantmentDurations(pItem); RemoveItemDurations(pItem); + + if (pItem->HasFlag(ITEM_FIELD_FLAGS, ITEM_FLAGS_REFUNDABLE)) + DeleteRefundReference(pItem); ItemRemovedQuestCheck( pItem->GetEntry(), pItem->GetCount() ); @@ -16366,6 +16369,47 @@ void Player::_LoadInventory(QueryResult_AutoPtr result, uint32 timediff) continue; } + if (item->HasFlag(ITEM_FIELD_FLAGS, ITEM_FLAGS_REFUNDABLE)) + { + if (item->GetPlayedTime() > (2*HOUR)) + { + sLog.outDebug("Item::LoadFromDB, Item GUID: %u: refund time expired, deleting refund data and removing refundable flag.", item->GetGUIDLow()); + CharacterDatabase.PExecute("DELETE FROM item_refund_instance WHERE item_guid = '%u'", item->GetGUIDLow()); + item->RemoveFlag(ITEM_FIELD_FLAGS, ITEM_FLAGS_REFUNDABLE); + } + 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()); + if (!result2) + { + sLog.outDebug("Item::LoadFromDB, " + "Item GUID: %u has field flags & ITEM_FLAGS_REFUNDABLE but has no data in item_refund_instance, removing flag.", + item->GetGUIDLow()); + RemoveFlag(ITEM_FIELD_FLAGS, ITEM_FLAGS_REFUNDABLE); + } + else + { + fields = result2->Fetch(); + 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(); + } + item->SetRefundData(RefundData); + AddRefundReference(item); + } + } + } + bool success = true; if (!bag_guid) @@ -17444,6 +17488,23 @@ 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();) + { + // Item could be deleted, or traded. + // In the first case, DeleteRefundDataFromDB() was already called in Item::SaveToDB() + Item* iPtr = (*itr); + if (!iPtr || iPtr->GetOwner() != this) + m_refundableItems.erase(itr++); + else + { + iPtr->UpdatePlayedTime(this); + if (iPtr->GetPlayedTime() > (2*HOUR)) + iPtr->SetNotRefundable(this); + ++itr; + } + } + // update enchantment durations for (EnchantDurationList::iterator itr = m_enchantDuration.begin(); itr != m_enchantDuration.end(); ++itr) itr->item->SetEnchantmentDuration(itr->slot,itr->leftduration, this); @@ -19252,6 +19313,11 @@ 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; @@ -19263,22 +19329,18 @@ bool Player::BuyItemFromVendor(uint64 vendorguid, uint32 item, uint8 count, uint } ModifyMoney( -(int32)price ); - uint32 arenaPoints = 0; - uint32 honorPoints = 0; - uint32 extendedCost[5] = {0,0,0,0,0}; - uint32 extendedCostCount[5] = {0,0,0,0,0}; - + if (crItem->ExtendedCost) // case for new honor system { ItemExtendedCostEntry const* iece = sItemExtendedCostStore.LookupEntry(crItem->ExtendedCost); if (iece->reqhonorpoints) { - honorPoints = iece->reqhonorpoints * count; + honorPoints = iece->reqhonorpoints; ModifyHonorPoints( - int32(honorPoints) ); } if (iece->reqarenapoints) { - arenaPoints = iece->reqarenapoints * count; + arenaPoints = iece->reqarenapoints; ModifyArenaPoints( - int32(arenaPoints) ); } for (uint8 i = 0; i < 5; ++i) @@ -19286,8 +19348,8 @@ bool Player::BuyItemFromVendor(uint64 vendorguid, uint32 item, uint8 count, uint if (iece->reqitem[i]) { DestroyItemCount(iece->reqitem[i], (iece->reqitemcount[i] * count), true); - extendedCost[i] = iece->reqitem[i]; - extendedCostCount[i] = iece->reqitemcount[i]; + itemCostId[i] = iece->reqitem[i]; + itemCostCount[i] = iece->reqitemcount[i]; } } } @@ -19303,15 +19365,22 @@ bool Player::BuyItemFromVendor(uint64 vendorguid, uint32 item, uint8 count, uint data << uint32(count); GetSession()->SendPacket(&data); SendNewItem(it, pProto->BuyCount*count, true, false, false); - - // Item Refund system, only works for non stackable items with extendedcost - if(count == 1 && crItem->ExtendedCost ) - { - it->SetPaidArenaPoints(arenaPoints); - it->SetPaidHonorPoints(honorPoints); - it->SetRefundExpiryTime( time(NULL)+(HOUR*2) ); - for (uint8 i = 0; i < 5; ++i) - it->SetPaidExtendedCost(i, extendedCost[i], extendedCostCount[i]); + + if (it->HasFlag(ITEM_FIELD_FLAGS, ITEM_FLAGS_REFUNDABLE)) + { + 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] ; + } + it->SetRefundData(RefundData); + it->SaveRefundDataToDB(); + AddRefundReference(it); } } } @@ -19336,13 +19405,23 @@ bool Player::BuyItemFromVendor(uint64 vendorguid, uint32 item, uint8 count, uint { ItemExtendedCostEntry const* iece = sItemExtendedCostStore.LookupEntry(crItem->ExtendedCost); if (iece->reqhonorpoints) - ModifyHonorPoints( - int32(iece->reqhonorpoints)); + { + honorPoints = iece->reqhonorpoints; + ModifyHonorPoints( - int32(honorPoints) ); + } if (iece->reqarenapoints) - ModifyArenaPoints( - int32(iece->reqarenapoints)); + { + arenaPoints = iece->reqarenapoints; + ModifyArenaPoints( - int32(arenaPoints)); + } 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]; + } } } @@ -19360,6 +19439,23 @@ bool Player::BuyItemFromVendor(uint64 vendorguid, uint32 item, uint8 count, uint SendNewItem(it, pProto->BuyCount*count, true, false, false); AutoUnequipOffhandIfNeed(); + + if (it->HasFlag(ITEM_FIELD_FLAGS, ITEM_FLAGS_REFUNDABLE)) + { + 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] ; + } + it->SetRefundData(RefundData); + it->SaveRefundDataToDB(); + AddRefundReference(it); + } } } else @@ -23284,3 +23380,13 @@ void Player::SendDuelCountdown(uint32 counter) data << uint32(counter); // seconds GetSession()->SendPacket(&data); } + +void Player::AddRefundReference(Item* it) +{ + m_refundableItems.insert(it); +} + +void Player::DeleteRefundReference(Item* it) +{ + m_refundableItems.erase(it); +}
\ No newline at end of file |