This commit is contained in:
Lopin
2011-06-23 21:24:53 +02:00
2 changed files with 39 additions and 30 deletions
@@ -718,12 +718,12 @@ void WorldSession::HandleListInventoryOpcode(WorldPacket & recv_data)
SendListInventory(guid); SendListInventory(guid);
} }
void WorldSession::SendListInventory(uint64 vendorguid) void WorldSession::SendListInventory(uint64 vendorGuid)
{ {
sLog->outDebug(LOG_FILTER_NETWORKIO, "WORLD: Sent SMSG_LIST_INVENTORY"); sLog->outDebug(LOG_FILTER_NETWORKIO, "WORLD: Sent SMSG_LIST_INVENTORY");
Creature *pCreature = GetPlayer()->GetNPCIfCanInteractWith(vendorguid, UNIT_NPC_FLAG_VENDOR); Creature* vendor = GetPlayer()->GetNPCIfCanInteractWith(vendorGuid, UNIT_NPC_FLAG_VENDOR);
if (!pCreature) if (!vendor)
{ {
sLog->outDebug(LOG_FILTER_NETWORKIO, "WORLD: SendListInventory - Unit (GUID: %u) not found or you can not interact with him.", uint32(GUID_LOPART(vendorguid))); sLog->outDebug(LOG_FILTER_NETWORKIO, "WORLD: SendListInventory - Unit (GUID: %u) not found or you can not interact with him.", uint32(GUID_LOPART(vendorguid)));
_player->SendSellError(SELL_ERR_CANT_FIND_VENDOR, NULL, 0, 0); _player->SendSellError(SELL_ERR_CANT_FIND_VENDOR, NULL, 0, 0);
@@ -735,56 +735,65 @@ void WorldSession::SendListInventory(uint64 vendorguid)
GetPlayer()->RemoveAurasByType(SPELL_AURA_FEIGN_DEATH); GetPlayer()->RemoveAurasByType(SPELL_AURA_FEIGN_DEATH);
// Stop the npc if moving // Stop the npc if moving
if (pCreature->HasUnitState(UNIT_STAT_MOVING)) if (vendor->HasUnitState(UNIT_STAT_MOVING))
pCreature->StopMoving(); vendor->StopMoving();
VendorItemData const* vItems = pCreature->GetVendorItems(); VendorItemData const* items = vendor->GetVendorItems();
if (!vItems) if (!items)
{ {
WorldPacket data(SMSG_LIST_INVENTORY, (8+1+1)); WorldPacket data(SMSG_LIST_INVENTORY, 8 + 1 + 1);
data << uint64(vendorguid); data << uint64(vendorGuid);
data << uint8(0); // count==0, next will be error code data << uint8(0); // count == 0, next will be error code
data << uint8(0); // "Vendor has no inventory" data << uint8(0); // "Vendor has no inventory"
SendPacket(&data); SendPacket(&data);
return; return;
} }
uint8 numitems = vItems->GetItemCount(); uint8 itemCount = items->GetItemCount();
uint8 count = 0; uint8 count = 0;
WorldPacket data(SMSG_LIST_INVENTORY, (8+1+numitems*8*4)); WorldPacket data(SMSG_LIST_INVENTORY, 8 + 1 + itemCount * 8 * 4);
data << uint64(vendorguid); data << uint64(vendorGuid);
size_t count_pos = data.wpos(); size_t countPos = data.wpos();
data << uint8(count); data << uint8(count);
float discountMod = _player->GetReputationPriceDiscount(pCreature); float discountMod = _player->GetReputationPriceDiscount(vendor);
for (uint8 vendorslot = 0; vendorslot < numitems; ++vendorslot ) for (uint8 slot = 0; slot < itemCount; ++slot)
{ {
if (VendorItem const* crItem = vItems->GetItem(vendorslot)) if (VendorItem const* item = items->GetItem(slot))
{ {
if (ItemTemplate const *pProto = sObjectMgr->GetItemTemplate(crItem->item)) if (ItemTemplate const* itemTemplate = sObjectMgr->GetItemTemplate(item->item))
{ {
if ((pProto->AllowableClass & _player->getClassMask()) == 0 && pProto->Bonding == BIND_WHEN_PICKED_UP && !_player->isGameMaster()) if (!(itemTemplate->AllowableClass & _player->getClassMask()) && itemTemplate->Bonding == BIND_WHEN_PICKED_UP && !_player->isGameMaster())
continue; continue;
// Only display items in vendor lists for the team the // Only display items in vendor lists for the team the
// player is on. If GM on, display all items. // player is on. If GM on, display all items.
if (!_player->isGameMaster() && ((pProto->Flags2 & ITEM_FLAGS_EXTRA_HORDE_ONLY && _player->GetTeam() == ALLIANCE) || (pProto->Flags2 == ITEM_FLAGS_EXTRA_ALLIANCE_ONLY && _player->GetTeam() == HORDE))) if (!_player->isGameMaster() && ((itemTemplate->Flags2 & ITEM_FLAGS_EXTRA_HORDE_ONLY && _player->GetTeam() == ALLIANCE) || (itemTemplate->Flags2 == ITEM_FLAGS_EXTRA_ALLIANCE_ONLY && _player->GetTeam() == HORDE)))
continue; continue;
// Items sold out are not displayed in list
uint32 leftInStock = !item->maxcount ? 0xFFFFFFFF : vendor->GetVendorItemCurrentCount(item);
if (!leftInStock)
continue;
if (itemTemplate->Class == ITEM_CLASS_QUEST && !_player->HasQuestForItem(item->item))
continue;
++count; ++count;
// reputation discount // reputation discount
int32 price = crItem->IsGoldRequired(pProto) ? uint32(floor(pProto->BuyPrice * discountMod)) : 0; int32 price = item->IsGoldRequired(itemTemplate) ? uint32(floor(itemTemplate->BuyPrice * discountMod)) : 0;
data << uint32(vendorslot+1); // client expects counting to start at 1 data << uint32(slot + 1); // client expects counting to start at 1
data << uint32(crItem->item); data << uint32(item->item);
data << uint32(pProto->DisplayInfoID); data << uint32(itemTemplate->DisplayInfoID);
data << int32(crItem->maxcount <= 0 ? 0xFFFFFFFF : pCreature->GetVendorItemCurrentCount(crItem)); data << int32(leftInStock);
data << uint32(price); data << uint32(price);
data << uint32(pProto->MaxDurability); data << uint32(itemTemplate->MaxDurability);
data << uint32(pProto->BuyCount); data << uint32(itemTemplate->BuyCount);
data << uint32(crItem->ExtendedCost); data << uint32(item->ExtendedCost);
} }
} }
} }
@@ -796,7 +805,7 @@ void WorldSession::SendListInventory(uint64 vendorguid)
return; return;
} }
data.put<uint8>(count_pos, count); data.put<uint8>(countPos, count);
SendPacket(&data); SendPacket(&data);
} }
+1 -1
View File
@@ -284,7 +284,7 @@ class WorldSession
void SendTrainerList(uint64 guid); void SendTrainerList(uint64 guid);
void SendTrainerList(uint64 guid, const std::string& strTitle); void SendTrainerList(uint64 guid, const std::string& strTitle);
void SendListInventory(uint64 guid); void SendListInventory(uint64 vendorGuid);
void SendShowBank(uint64 guid); void SendShowBank(uint64 guid);
void SendTabardVendorActivate(uint64 guid); void SendTabardVendorActivate(uint64 guid);
void SendSpiritResurrect(); void SendSpiritResurrect();