diff options
| author | John Holiver <none@none> | 2010-06-09 19:38:15 -0300 |
|---|---|---|
| committer | John Holiver <none@none> | 2010-06-09 19:38:15 -0300 |
| commit | 5dff68e457f6c0111acfc4c55b0dfba464ca72df (patch) | |
| tree | 1a2caa57f1600a4e631bbecb0e2e4e525c3ec95f /src/server/game/Entities | |
| parent | 410eb3d1b6483d5e2ff984d431bafeec419aa6ee (diff) | |
Allow to sell item for: money, extendedCost or money+extendedCost.
The new method (money+extende) can be used by using negative values on npc_vendor.ExtendedCost.
This one goes dedicated to ZxBiohazardZx.
Tnx also to VladimirMangos.
--HG--
branch : trunk
Diffstat (limited to 'src/server/game/Entities')
| -rw-r--r-- | src/server/game/Entities/Creature/Creature.cpp | 2 | ||||
| -rw-r--r-- | src/server/game/Entities/Creature/Creature.h | 12 | ||||
| -rw-r--r-- | src/server/game/Entities/Player/Player.cpp | 27 |
3 files changed, 23 insertions, 18 deletions
diff --git a/src/server/game/Entities/Creature/Creature.cpp b/src/server/game/Entities/Creature/Creature.cpp index 71461f94949..c9c9775c04a 100644 --- a/src/server/game/Entities/Creature/Creature.cpp +++ b/src/server/game/Entities/Creature/Creature.cpp @@ -76,7 +76,7 @@ bool VendorItemData::RemoveItem(uint32 item_id) return found; } -VendorItem const* VendorItemData::FindItemCostPair(uint32 item_id, uint32 extendedCost) const +VendorItem const* VendorItemData::FindItemCostPair(uint32 item_id, int32 extendedCost) const { for (VendorItemList::const_iterator i = m_items.begin(); i != m_items.end(); ++i) if((*i)->item == item_id && (*i)->ExtendedCost == extendedCost) diff --git a/src/server/game/Entities/Creature/Creature.h b/src/server/game/Entities/Creature/Creature.h index c19187f2770..a7c17561516 100644 --- a/src/server/game/Entities/Creature/Creature.h +++ b/src/server/game/Entities/Creature/Creature.h @@ -307,13 +307,17 @@ enum ChatType // Vendors struct VendorItem { - VendorItem(uint32 _item, int32 _maxcount, uint32 _incrtime, uint32 _ExtendedCost) + VendorItem(uint32 _item, int32 _maxcount, uint32 _incrtime, int32 _ExtendedCost) : item(_item), maxcount(_maxcount), incrtime(_incrtime), ExtendedCost(_ExtendedCost) {} uint32 item; int32 maxcount; // 0 for infinity item amount uint32 incrtime; // time for restore items amount if maxcount != 0 - uint32 ExtendedCost; + int32 ExtendedCost; + + //helpers + bool IsExcludeMoneyPrice() const { return ExtendedCost > 0; } + uint32 GetExtendedCostId() const { return std::abs(ExtendedCost); } }; typedef std::vector<VendorItem*> VendorItemList; @@ -328,12 +332,12 @@ struct VendorItemData } bool Empty() const { return m_items.empty(); } uint8 GetItemCount() const { return m_items.size(); } - void AddItem(uint32 item, int32 maxcount, uint32 ptime, uint32 ExtendedCost) + void AddItem(uint32 item, int32 maxcount, uint32 ptime, int32 ExtendedCost) { m_items.push_back(new VendorItem(item, maxcount, ptime, ExtendedCost)); } bool RemoveItem(uint32 item_id); - VendorItem const* FindItemCostPair(uint32 item_id, uint32 extendedCost) const; + VendorItem const* FindItemCostPair(uint32 item_id, int32 extendedCost) const; void Clear() { for (VendorItemList::const_iterator itr = m_items.begin(); itr != m_items.end(); ++itr) diff --git a/src/server/game/Entities/Player/Player.cpp b/src/server/game/Entities/Player/Player.cpp index c79ce17f40e..faeb676c21a 100644 --- a/src/server/game/Entities/Player/Player.cpp +++ b/src/server/game/Entities/Player/Player.cpp @@ -19573,12 +19573,12 @@ bool Player::BuyItemFromVendorSlot(uint64 vendorguid, uint32 vendorslot, uint32 return false; } - if (crItem->ExtendedCost) + if (uint32 extendedCostId = crItem->GetExtendedCostId()) { - ItemExtendedCostEntry const* iece = sItemExtendedCostStore.LookupEntry(crItem->ExtendedCost); + ItemExtendedCostEntry const* iece = sItemExtendedCostStore.LookupEntry(extendedCostId); if (!iece) { - sLog.outError("Item %u have wrong ExtendedCost field value %u", pProto->ItemId, crItem->ExtendedCost); + sLog.outError("Item %u have wrong ExtendedCost field value %u", pProto->ItemId, extendedCostId); return false; } @@ -19615,10 +19615,11 @@ bool Player::BuyItemFromVendorSlot(uint64 vendorguid, uint32 vendorslot, uint32 } } - int32 price = pProto->BuyPrice * count; + int32 price = crItem->IsExcludeMoneyPrice() ? 0 : pProto->BuyPrice * count; // reputation discount - price = uint32(floor(price * GetReputationPriceDiscount(pCreature))); + if (price) + price = uint32(floor(price * GetReputationPriceDiscount(pCreature))); if (GetMoney() < price) { @@ -19638,9 +19639,9 @@ bool Player::BuyItemFromVendorSlot(uint64 vendorguid, uint32 vendorslot, uint32 ModifyMoney(-(int32)price); - if (crItem->ExtendedCost) // case for new honor system + if (uint32 extendedCostId = crItem->GetExtendedCostId()) // case for new honor system { - ItemExtendedCostEntry const* iece = sItemExtendedCostStore.LookupEntry(crItem->ExtendedCost); + ItemExtendedCostEntry const* iece = sItemExtendedCostStore.LookupEntry(extendedCostId); if (iece->reqhonorpoints) ModifyHonorPoints(- int32(iece->reqhonorpoints * count)); @@ -19666,11 +19667,11 @@ bool Player::BuyItemFromVendorSlot(uint64 vendorguid, uint32 vendorslot, uint32 GetSession()->SendPacket(&data); SendNewItem(it, pProto->BuyCount*count, true, false, false); - if (it->HasFlag(ITEM_FIELD_FLAGS, ITEM_FLAGS_REFUNDABLE) && crItem->ExtendedCost) + if (it->HasFlag(ITEM_FIELD_FLAGS, ITEM_FLAGS_REFUNDABLE) && crItem->GetExtendedCostId()) { it->SetRefundRecipient(GetGUIDLow()); it->SetPaidMoney(price); - it->SetPaidExtendedCost(crItem->ExtendedCost); + it->SetPaidExtendedCost(crItem->GetExtendedCostId()); it->SaveRefundDataToDB(); AddRefundReference(it->GetGUID()); } @@ -19693,9 +19694,9 @@ bool Player::BuyItemFromVendorSlot(uint64 vendorguid, uint32 vendorslot, uint32 } ModifyMoney(-(int32)price); - if (crItem->ExtendedCost) // case for new honor system + if (uint32 extendedCostId = crItem->GetExtendedCostId()) // case for new honor system { - ItemExtendedCostEntry const* iece = sItemExtendedCostStore.LookupEntry(crItem->ExtendedCost); + ItemExtendedCostEntry const* iece = sItemExtendedCostStore.LookupEntry(extendedCostId); if (iece->reqhonorpoints) ModifyHonorPoints(- int32(iece->reqhonorpoints * count)); @@ -19724,11 +19725,11 @@ bool Player::BuyItemFromVendorSlot(uint64 vendorguid, uint32 vendorslot, uint32 AutoUnequipOffhandIfNeed(); - if (it->HasFlag(ITEM_FIELD_FLAGS, ITEM_FLAGS_REFUNDABLE) && crItem->ExtendedCost) + if (it->HasFlag(ITEM_FIELD_FLAGS, ITEM_FLAGS_REFUNDABLE) && crItem->GetExtendedCostId()) { it->SetRefundRecipient(GetGUIDLow()); it->SetPaidMoney(price); - it->SetPaidExtendedCost(crItem->ExtendedCost); + it->SetPaidExtendedCost(crItem->GetExtendedCostId()); it->SaveRefundDataToDB(); AddRefundReference(it->GetGUID()); } |
