Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- void WorldSession::SendListInventory(ObjectGuid vendorGuid)
- {
- TC_LOG_DEBUG(LOG_FILTER_NETWORKIO, "WORLD: Sent SMSG_LIST_INVENTORY");
- Creature* vendor = GetPlayer()->GetNPCIfCanInteractWith(vendorGuid, UNIT_NPC_FLAG_VENDOR);
- if (!vendor)
- {
- TC_LOG_DEBUG(LOG_FILTER_NETWORKIO, "WORLD: SendListInventory - Unit (GUID: %u) not found or you can not interact with him.", vendorGuid.dbID);
- _player->SendSellError(SELL_ERR_CANT_FIND_VENDOR, NULL, ObjectGuid::Null);
- return;
- }
- // remove fake death
- if (GetPlayer()->HasUnitState(UNIT_STATE_DIED))
- GetPlayer()->RemoveAurasByType(SPELL_AURA_FEIGN_DEATH);
- // Stop the npc if moving
- if (vendor->HasUnitState(UNIT_STATE_MOVING))
- vendor->StopMoving();
- WorldPacket data(SMSG_LIST_INVENTORY);
- data["guid"] = vendorGuid;
- VendorItemData const* vendorItems = vendor->GetVendorItems();
- uint32 rawItemCount = vendorItems ? vendorItems->GetItemCount() : 0;
- float const discount = GetPlayer()->GetReputationPriceDiscount(vendor);
- uint32 itemsSent = 0;
- for (uint32 slot = 0; slot < rawItemCount; ++slot)
- {
- VendorItem const* vendorItem = vendorItems->GetItem(slot);
- if (!vendorItems) continue;
- LuaPacketItem& item = data["items"][itemsSent];
- uint32 availableInStock = !vendorItem->maxcount ? 0xFFFFFFFF : vendor->GetVendorItemCurrentCount(vendorItem);
- switch (vendorItem->Type)
- {
- case ITEM_VENDOR_TYPE_ITEM:
- {
- ItemTemplate const* it = sObjectMgr->GetItemTemplate(vendorItem->item);
- if (!it) continue;
- if (!GetPlayer()->IsGameMaster())
- {
- // Respect allowed class
- if (!(it->AllowableClass & _player->getClassMask()) && it->Bonding == BIND_WHEN_PICKED_UP)
- continue;
- // Only display items in vendor lists for the team the player is on
- if ((it->Flags2 & ITEM_FLAGS_EXTRA_HORDE_ONLY && _player->GetTeam() == ALLIANCE) ||
- (it->Flags2 & ITEM_FLAGS_EXTRA_ALLIANCE_ONLY && _player->GetTeam() == HORDE))
- continue;
- // Items sold out are not displayed in list
- if (availableInStock == 0)
- continue;
- }
- ConditionList conditions = sConditionMgr->GetConditionsForNpcVendorEvent(vendor->GetEntry(), vendorItem->item);
- if (!sConditionMgr->IsObjectMeetToConditions(_player, vendor, conditions))
- {
- TC_LOG_DEBUG(LOG_FILTER_CONDITIONSYS, "SendListInventory: conditions not met for creature entry %u item %u", vendor->GetEntry(), vendorItem->item);
- continue;
- }
- int32 finalPrice = vendorItem->IsGoldRequired(it) ? uint32(floor(it->BuyPrice * discount)) : 0;
- int32 priceMod = GetPlayer()->GetTotalAuraModifier(SPELL_AURA_MOD_VENDOR_ITEMS_PRICES);
- AddPct(finalPrice, -priceMod);
- item["price"] = finalPrice;
- item["durability"] = it->MaxDurability;
- item["stackCount"] = it->MaxCount;
- item["itemInf"]["RandomPropSeed"] = it->RandomSuffix;
- item["itemInf"]["RandomPropID"] = it->RandomProperty;
- break;
- }
- case ITEM_VENDOR_TYPE_CURRENCY:
- {
- CurrencyTypesEntry const* ct = sCurrencyTypesStore.LookupEntry(vendorItem->item);
- if (!ct) continue;
- /// There's no price defined for currencies, only extendedcost is used
- if (vendorItem->ExtendedCost == 0) continue;
- item["stackCount"] = vendorItem->maxcount;
- break;
- }
- }
- item["slot"] = (slot + 1);
- item["type"] = vendorItem->Type;
- item["qty"] = availableInStock;
- item["extendedCost"] = vendorItem->ExtendedCost;
- item["itemInf"]["itemId"] = vendorItem->item;
- itemsSent++;
- }
- data["count"] = itemsSent;
- if (itemsSent)
- data["reason"] = itemsSent;
- else
- data["reason"] = vendor->IsArmorer();
- SendPacket(&data);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement