From 741cd477cb62c5cf9fac8d6e4350b8afdeea5c6d Mon Sep 17 00:00:00 2001 From: Dramacydal Date: Mon, 17 Jun 2013 09:35:29 +0100 Subject: [PATCH] [c12636] Fix buying stackable items for etended cost Fix calculating item price for items with buyout --- src/game/Item.h | 16 ++++++++++------ src/game/ItemHandler.cpp | 4 ++-- src/game/Player.cpp | 38 ++++++++++++++++++++++++++------------ src/game/Player.h | 6 +++--- src/shared/revision_nr.h | 2 +- 5 files changed, 42 insertions(+), 24 deletions(-) diff --git a/src/game/Item.h b/src/game/Item.h index e4c9893ef..66277ce68 100644 --- a/src/game/Item.h +++ b/src/game/Item.h @@ -123,12 +123,16 @@ enum InventoryResult EQUIP_ERR_EVENT_AUTOEQUIP_BIND_CONFIRM = 81, // EQUIP_ERR_OK, EVENT_AUTOEQUIP_BIND_CONFIRM EQUIP_ERR_ARTEFACTS_ONLY_FOR_OWN_CHARACTERS = 82, // ERR_NOT_SAME_ACCOUNT EQUIP_ERR_OK2 = 83, // EQUIP_ERR_OK - EQUIP_ERR_ITEM_MAX_LIMIT_CATEGORY_COUNT_EXCEEDED_IS = 84, - EQUIP_ERR_ITEM_MAX_LIMIT_CATEGORY_SOCKETED_EXCEEDED_IS = 85, - EQUIP_ERR_SCALING_STAT_ITEM_LEVEL_EXCEEDED = 86, - EQUIP_ERR_PURCHASE_LEVEL_TOO_LOW = 87, - EQUIP_ERR_CANT_EQUIP_NEED_TALENT = 88, - EQUIP_ERR_ITEM_MAX_LIMIT_CATEGORY_EQUIPPED_EXCEEDED_IS = 89 + EQUIP_ERR_ITEM_MAX_LIMIT_CATEGORY_COUNT_EXCEEDED_IS = 84, // You can only carry %d %s + EQUIP_ERR_ITEM_MAX_LIMIT_CATEGORY_SOCKETED_EXCEEDED_IS = 85, // You can only equip %d |4item:items in the %s category + EQUIP_ERR_SCALING_STAT_ITEM_LEVEL_EXCEEDED = 86, // Your level is too high to use that item + EQUIP_ERR_PURCHASE_LEVEL_TOO_LOW = 87, // You must reach level %d to purchase that item. + EQUIP_ERR_CANT_EQUIP_NEED_TALENT = 88, // You do not have the required talent to equip that + EQUIP_ERR_ITEM_MAX_LIMIT_CATEGORY_EQUIPPED_EXCEEDED_IS = 89, // You can only equip %d |4item:items in the %s category + EQUIP_ERR_SHAPESHIFT_FORM_CANNOT_EQUIP = 90, // Cannot equip item in this form + EQUIP_ERR_ITEM_INVENTORY_FULL_SATCHEL = 91, // Your inventory is full. Your satchel has been delivered to your mailbox. + EQUIP_ERR_SCALING_STAT_ITEM_LEVEL_TOO_LOW = 92, // Your level is too low to use that item + EQUIP_ERR_CANT_BUY_QUANTITY = 93, // You can't buy the specified quantity of that item. }; enum BuyResult diff --git a/src/game/ItemHandler.cpp b/src/game/ItemHandler.cpp index beaf47ead..b44599db9 100644 --- a/src/game/ItemHandler.cpp +++ b/src/game/ItemHandler.cpp @@ -499,7 +499,7 @@ void WorldSession::HandleBuyItemOpcode(WorldPacket& recv_data) else return; // cheating - switch(type) + switch (type) { case VENDOR_ITEM_TYPE_NONE: break; @@ -530,7 +530,7 @@ void WorldSession::HandleBuyItemOpcode(WorldPacket& recv_data) } case VENDOR_ITEM_TYPE_CURRENCY: { - GetPlayer()->BuyCurrencyFromVendorSlot(vendorGuid, slot, item, 1); + GetPlayer()->BuyCurrencyFromVendorSlot(vendorGuid, slot, item, count); break; } } diff --git a/src/game/Player.cpp b/src/game/Player.cpp index 26af7d888..2fd04a08b 100644 --- a/src/game/Player.cpp +++ b/src/game/Player.cpp @@ -19193,14 +19193,14 @@ void Player::InitDisplayIds() } } -void Player::TakeExtendedCost(uint32 extendedCostId, uint32 count) +void Player::TakeExtendedCost(uint32 extendedCostId) { ItemExtendedCostEntry const* extendedCost = sItemExtendedCostStore.LookupEntry(extendedCostId); for (uint8 i = 0; i < MAX_EXTENDED_COST_ITEMS; ++i) { if (extendedCost->reqitem[i]) - DestroyItemCount(extendedCost->reqitem[i], extendedCost->reqitemcount[i] * count, true); + DestroyItemCount(extendedCost->reqitem[i], extendedCost->reqitemcount[i], true); } for (int i = 0; i < MAX_EXTENDED_COST_CURRENCIES; ++i) @@ -19215,13 +19215,13 @@ void Player::TakeExtendedCost(uint32 extendedCostId, uint32 count) if (!entry) continue; - int32 cost = int32(extendedCost->reqcurrcount[i] * count); + int32 cost = int32(extendedCost->reqcurrcount[i]); ModifyCurrencyCount(entry->ID, -cost); } } // Return true is the bought item has a max count to force refresh of window by caller -bool Player::BuyItemFromVendorSlot(ObjectGuid vendorGuid, uint32 vendorslot, uint32 item, uint8 count, uint8 bag, uint8 slot) +bool Player::BuyItemFromVendorSlot(ObjectGuid vendorGuid, uint32 vendorslot, uint32 item, uint32 count, uint8 bag, uint8 slot) { // cheating attempt if (count < 1) count = 1; @@ -19305,6 +19305,12 @@ bool Player::BuyItemFromVendorSlot(ObjectGuid vendorGuid, uint32 vendorslot, uin if (uint32 extendedCostId = crItem->ExtendedCost) { + if (pProto->BuyCount != count) + { + SendEquipError(EQUIP_ERR_CANT_BUY_QUANTITY, NULL, NULL); + return false; + } + ItemExtendedCostEntry const* iece = sItemExtendedCostStore.LookupEntry(extendedCostId); if (!iece) { @@ -19315,7 +19321,7 @@ bool Player::BuyItemFromVendorSlot(ObjectGuid vendorGuid, uint32 vendorslot, uin // item base price for (uint8 i = 0; i < MAX_EXTENDED_COST_ITEMS; ++i) { - if (iece->reqitem[i] && !HasItemCount(iece->reqitem[i], iece->reqitemcount[i] * count)) + if (iece->reqitem[i] && !HasItemCount(iece->reqitem[i], iece->reqitemcount[i])) { SendEquipError(EQUIP_ERR_VENDOR_MISSING_TURNINS, NULL, NULL); return false; @@ -19335,7 +19341,7 @@ bool Player::BuyItemFromVendorSlot(ObjectGuid vendorGuid, uint32 vendorslot, uin continue; } - int32 cost = int32(iece->reqcurrcount[i] * count); + int32 cost = int32(iece->reqcurrcount[i]); bool hasCount = iece->IsSeasonCurrencyRequirement(i) ? HasCurrencySeasonCount(iece->reqcur[i], cost) : HasCurrencyCount(iece->reqcur[i], cost); if (!hasCount) @@ -19361,6 +19367,8 @@ bool Player::BuyItemFromVendorSlot(ObjectGuid vendorGuid, uint32 vendorslot, uin } uint64 price = (crItem->ExtendedCost == 0 || pProto->Flags2 & ITEM_FLAG2_EXT_COST_REQUIRES_GOLD) ? pProto->BuyPrice * count : 0; + if (pProto->BuyCount > 1) + price = uint64(price / float(pProto->BuyCount) + 0.5f); // reputation discount if (price) @@ -19387,7 +19395,7 @@ bool Player::BuyItemFromVendorSlot(ObjectGuid vendorGuid, uint32 vendorslot, uin ModifyMoney(-int64(price)); if (crItem->ExtendedCost) - TakeExtendedCost(crItem->ExtendedCost, count); + TakeExtendedCost(crItem->ExtendedCost); pItem = StoreNewItem(dest, item, true); } @@ -19410,7 +19418,7 @@ bool Player::BuyItemFromVendorSlot(ObjectGuid vendorGuid, uint32 vendorslot, uin ModifyMoney(-int64(price)); if (crItem->ExtendedCost) - TakeExtendedCost(crItem->ExtendedCost, count); + TakeExtendedCost(crItem->ExtendedCost); pItem = EquipNewItem(dest, item, true); @@ -19440,7 +19448,7 @@ bool Player::BuyItemFromVendorSlot(ObjectGuid vendorGuid, uint32 vendorslot, uin return crItem->maxcount != 0; } -bool Player::BuyCurrencyFromVendorSlot(ObjectGuid vendorGuid, uint32 vendorslot, uint32 currencyId, uint8 count) +bool Player::BuyCurrencyFromVendorSlot(ObjectGuid vendorGuid, uint32 vendorslot, uint32 currencyId, uint32 count) { // cheating attempt if (count < 1) count = 1; @@ -19489,6 +19497,12 @@ bool Player::BuyCurrencyFromVendorSlot(ObjectGuid vendorGuid, uint32 vendorslot, if (uint32 extendedCostId = crItem->ExtendedCost) { + if (crItem->maxcount != count) + { + SendEquipError(EQUIP_ERR_CANT_BUY_QUANTITY, NULL, NULL); + return false; + } + ItemExtendedCostEntry const* iece = sItemExtendedCostStore.LookupEntry(extendedCostId); if (!iece) { @@ -19499,7 +19513,7 @@ bool Player::BuyCurrencyFromVendorSlot(ObjectGuid vendorGuid, uint32 vendorslot, // item base price for (uint8 i = 0; i < MAX_EXTENDED_COST_ITEMS; ++i) { - if (iece->reqitem[i] && !HasItemCount(iece->reqitem[i], iece->reqitemcount[i] * count)) + if (iece->reqitem[i] && !HasItemCount(iece->reqitem[i], iece->reqitemcount[i])) { SendEquipError(EQUIP_ERR_VENDOR_MISSING_TURNINS, NULL, NULL); return false; @@ -19519,7 +19533,7 @@ bool Player::BuyCurrencyFromVendorSlot(ObjectGuid vendorGuid, uint32 vendorslot, continue; } - int32 cost = int32(iece->reqcurrcount[i] * count); + int32 cost = int32(iece->reqcurrcount[i]); bool hasCount = iece->IsSeasonCurrencyRequirement(i) ? HasCurrencySeasonCount(iece->reqcur[i], cost) : HasCurrencyCount(iece->reqcur[i], cost); if (!hasCount) { @@ -19562,7 +19576,7 @@ bool Player::BuyCurrencyFromVendorSlot(ObjectGuid vendorGuid, uint32 vendorslot, } if (crItem->ExtendedCost) - TakeExtendedCost(crItem->ExtendedCost, count); + TakeExtendedCost(crItem->ExtendedCost); ModifyCurrencyCount(currencyId, crItem->maxcount, true, false, true); diff --git a/src/game/Player.h b/src/game/Player.h index 63b20d6a4..04588427b 100644 --- a/src/game/Player.h +++ b/src/game/Player.h @@ -1284,7 +1284,7 @@ class MANGOS_DLL_SPEC Player : public Unit Item* GetItemFromBuyBackSlot(uint32 slot); void RemoveItemFromBuyBackSlot(uint32 slot, bool del); - void TakeExtendedCost(uint32 extendedCostId, uint32 count); + void TakeExtendedCost(uint32 extendedCostId); void SendEquipError(InventoryResult msg, Item* pItem, Item* pItem2 = NULL, uint32 itemid = 0) const; void SendBuyError(BuyResult msg, Creature* pCreature, uint32 item, uint32 param); @@ -1305,8 +1305,8 @@ class MANGOS_DLL_SPEC Player : public Unit return offItem && ((mainItem && mainItem->GetProto()->InventoryType == INVTYPE_2HWEAPON) || offItem->GetProto()->InventoryType == INVTYPE_2HWEAPON); } void SendNewItem(Item* item, uint32 count, bool received, bool created, bool broadcast = false); - bool BuyItemFromVendorSlot(ObjectGuid vendorGuid, uint32 vendorslot, uint32 item, uint8 count, uint8 bag, uint8 slot); - bool BuyCurrencyFromVendorSlot(ObjectGuid vendorGuid, uint32 vendorslot, uint32 currencyId, uint8 count); + bool BuyItemFromVendorSlot(ObjectGuid vendorGuid, uint32 vendorslot, uint32 item, uint32 count, uint8 bag, uint8 slot); + bool BuyCurrencyFromVendorSlot(ObjectGuid vendorGuid, uint32 vendorslot, uint32 currencyId, uint32 count); float GetReputationPriceDiscount(Creature const* pCreature) const; diff --git a/src/shared/revision_nr.h b/src/shared/revision_nr.h index 26b5b616c..2f88007f4 100644 --- a/src/shared/revision_nr.h +++ b/src/shared/revision_nr.h @@ -1,4 +1,4 @@ #ifndef __REVISION_NR_H__ #define __REVISION_NR_H__ - #define REVISION_NR "12635" + #define REVISION_NR "12636" #endif // __REVISION_NR_H__