[11209] Some refactoring in Player::BuyItemFromVendorSlot

This commit is contained in:
zergtmn 2011-02-28 01:47:04 +05:00
parent d1370941ca
commit 65b631a8e4
4 changed files with 75 additions and 79 deletions

View file

@ -1072,14 +1072,16 @@ struct ItemDisplayInfoEntry
// uint32 arenaseason; // arena season number(1-4)
//};
#define MAX_EXTENDED_COST_ITEMS 5
struct ItemExtendedCostEntry
{
uint32 ID; // 0 extended-cost entry id
uint32 reqhonorpoints; // 1 required honor points
uint32 reqarenapoints; // 2 required arena points
uint32 reqarenaslot; // 4 arena slot restrctions (min slot value)
uint32 reqitem[5]; // 5-8 required item id
uint32 reqitemcount[5]; // 9-13 required count of 1st item
uint32 reqarenaslot; // 4 arena slot restrictions (min slot value)
uint32 reqitem[MAX_EXTENDED_COST_ITEMS]; // 5-8 required item id
uint32 reqitemcount[MAX_EXTENDED_COST_ITEMS]; // 9-13 required count of 1st item
uint32 reqpersonalarenarating; // 14 required personal arena rating
};

View file

@ -18818,6 +18818,22 @@ void Player::InitDisplayIds()
}
}
void Player::TakeExtendedCost(uint32 extendedCostId, uint32 count)
{
ItemExtendedCostEntry const* extendedCost = sItemExtendedCostStore.LookupEntry(extendedCostId);
if (extendedCost->reqhonorpoints)
ModifyHonorPoints(-int32(extendedCost->reqhonorpoints * count));
if (extendedCost->reqarenapoints)
ModifyArenaPoints(-int32(extendedCost->reqarenapoints * count));
for (uint8 i = 0; i < MAX_EXTENDED_COST_ITEMS; ++i)
{
if (extendedCost->reqitem[i])
DestroyItemCount(extendedCost->reqitem[i], extendedCost->reqitemcount[i] * count, true);
}
}
// 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)
{
@ -18874,7 +18890,7 @@ bool Player::BuyItemFromVendorSlot(ObjectGuid vendorGuid, uint32 vendorslot, uin
ItemPrototype const* crProto = ObjectMgr::GetItemPrototype(crItem->item);
if (crProto->Flags & ITEM_FLAG_BOA && crProto->RequiredReputationFaction &&
uint32(GetReputationRank(crProto->RequiredReputationFaction)) >= crProto->RequiredReputationRank)
converted = item == sObjectMgr.GetItemConvert(crItem->item, getRaceMask());;
converted = item == sObjectMgr.GetItemConvert(crItem->item, getRaceMask());
if (!converted)
{
@ -18883,10 +18899,12 @@ bool Player::BuyItemFromVendorSlot(ObjectGuid vendorGuid, uint32 vendorslot, uin
}
}
uint32 totalCount = pProto->BuyCount * count;
// check current item amount if it limited
if (crItem->maxcount != 0)
{
if (pCreature->GetVendorItemCurrentCount(crItem) < pProto->BuyCount * count )
if (pCreature->GetVendorItemCurrentCount(crItem) < totalCount)
{
SendBuyError(BUY_ERR_ITEM_ALREADY_SOLD, pCreature, item, 0);
return false;
@ -18923,9 +18941,9 @@ bool Player::BuyItemFromVendorSlot(ObjectGuid vendorGuid, uint32 vendorslot, uin
}
// item base price
for (uint8 i = 0; i < 5; ++i)
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] * count))
{
SendEquipError(EQUIP_ERR_VENDOR_MISSING_TURNINS, NULL, NULL);
return false;
@ -18953,48 +18971,28 @@ bool Player::BuyItemFromVendorSlot(ObjectGuid vendorGuid, uint32 vendorslot, uin
return false;
}
Item* pItem = NULL;
if ((bag == NULL_BAG && slot == NULL_SLOT) || IsInventoryPos(bag, slot))
{
ItemPosCountVec dest;
uint8 msg = CanStoreNewItem( bag, slot, dest, item, pProto->BuyCount * count );
uint8 msg = CanStoreNewItem(bag, slot, dest, item, totalCount);
if (msg != EQUIP_ERR_OK)
{
SendEquipError(msg, NULL, NULL, item);
return false;
}
ModifyMoney( -(int32)price );
if (uint32 extendedCostId = crItem->ExtendedCost)
{
ItemExtendedCostEntry const* iece = sItemExtendedCostStore.LookupEntry(extendedCostId);
if (iece->reqhonorpoints)
ModifyHonorPoints( - int32(iece->reqhonorpoints * count));
if (iece->reqarenapoints)
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);
}
}
ModifyMoney(-int32(price));
if (Item *it = StoreNewItem( dest, item, true ))
{
uint32 new_count = pCreature->UpdateVendorItemCurrentCount(crItem,pProto->BuyCount * count);
if (crItem->ExtendedCost)
TakeExtendedCost(crItem->ExtendedCost, count);
WorldPacket data(SMSG_BUY_ITEM, (8+4+4+4));
data << pCreature->GetObjectGuid();
data << uint32(vendorslot+1); // numbered from 1 at client
data << uint32(crItem->maxcount > 0 ? new_count : 0xFFFFFFFF);
data << uint32(count);
GetSession()->SendPacket(&data);
SendNewItem(it, pProto->BuyCount*count, true, false, false);
}
pItem = StoreNewItem(dest, item, true);
}
else if (IsEquipmentPos(bag, slot))
{
if (pProto->BuyCount * count != 1)
if (totalCount != 1)
{
SendEquipError(EQUIP_ERR_ITEM_CANT_BE_EQUIPPED, NULL, NULL);
return false;
@ -19008,43 +19006,36 @@ bool Player::BuyItemFromVendorSlot(ObjectGuid vendorGuid, uint32 vendorslot, uin
return false;
}
ModifyMoney( -(int32)price );
if (uint32 extendedCostId = crItem->ExtendedCost)
{
ItemExtendedCostEntry const* iece = sItemExtendedCostStore.LookupEntry(extendedCostId);
if (iece->reqhonorpoints)
ModifyHonorPoints( - int32(iece->reqhonorpoints));
if (iece->reqarenapoints)
ModifyArenaPoints( - int32(iece->reqarenapoints));
for (uint8 i = 0; i < 5; ++i)
{
if(iece->reqitem[i])
DestroyItemCount(iece->reqitem[i], iece->reqitemcount[i], true);
}
}
ModifyMoney(-int32(price));
if (Item *it = EquipNewItem( dest, item, true ))
{
uint32 new_count = pCreature->UpdateVendorItemCurrentCount(crItem,pProto->BuyCount * count);
if (crItem->ExtendedCost)
TakeExtendedCost(crItem->ExtendedCost, count);
WorldPacket data(SMSG_BUY_ITEM, (8+4+4+4));
data << pCreature->GetObjectGuid();
data << uint32(vendorslot + 1); // numbered from 1 at client
data << uint32(crItem->maxcount > 0 ? new_count : 0xFFFFFFFF);
data << uint32(count);
GetSession()->SendPacket(&data);
SendNewItem(it, pProto->BuyCount*count, true, false, false);
pItem = EquipNewItem(dest, item, true);
if (pItem)
AutoUnequipOffhandIfNeed();
}
}
else
{
SendEquipError(EQUIP_ERR_ITEM_DOESNT_GO_TO_SLOT, NULL, NULL);
return false;
}
if (!pItem)
return false;
uint32 new_count = pCreature->UpdateVendorItemCurrentCount(crItem, totalCount);
WorldPacket data(SMSG_BUY_ITEM, 8+4+4+4);
data << pCreature->GetObjectGuid();
data << uint32(vendorslot + 1); // numbered from 1 at client
data << uint32(crItem->maxcount > 0 ? new_count : 0xFFFFFFFF);
data << uint32(count);
GetSession()->SendPacket(&data);
SendNewItem(pItem, totalCount, true, false, false);
return crItem->maxcount != 0;
}

View file

@ -1330,6 +1330,9 @@ class MANGOS_DLL_SPEC Player : public Unit
void AddItemToBuyBackSlot( Item *pItem );
Item* GetItemFromBuyBackSlot( uint32 slot );
void RemoveItemFromBuyBackSlot( uint32 slot, bool del );
void TakeExtendedCost(uint32 extendedCostId, uint32 count);
uint32 GetMaxKeyringSize() const { return KEYRING_SLOT_END-KEYRING_SLOT_START; }
void SendEquipError( uint8 msg, Item* pItem, Item *pItem2 = NULL, uint32 itemid = 0 ) const;
void SendBuyError( uint8 msg, Creature* pCreature, uint32 item, uint32 param );

View file

@ -1,4 +1,4 @@
#ifndef __REVISION_NR_H__
#define __REVISION_NR_H__
#define REVISION_NR "11208"
#define REVISION_NR "11209"
#endif // __REVISION_NR_H__