Advertisement
Guest User

Untitled

a guest
Nov 22nd, 2014
154
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.43 KB | None | 0 0
  1. void WorldSession::SendListInventory(ObjectGuid vendorGuid)
  2. {
  3. TC_LOG_DEBUG(LOG_FILTER_NETWORKIO, "WORLD: Sent SMSG_LIST_INVENTORY");
  4.  
  5. Creature* vendor = GetPlayer()->GetNPCIfCanInteractWith(vendorGuid, UNIT_NPC_FLAG_VENDOR);
  6.  
  7. if (!vendor)
  8. {
  9. TC_LOG_DEBUG(LOG_FILTER_NETWORKIO, "WORLD: SendListInventory - Unit (GUID: %u) not found or you can not interact with him.", vendorGuid.dbID);
  10. _player->SendSellError(SELL_ERR_CANT_FIND_VENDOR, NULL, ObjectGuid::Null);
  11. return;
  12. }
  13.  
  14. // remove fake death
  15. if (GetPlayer()->HasUnitState(UNIT_STATE_DIED))
  16. GetPlayer()->RemoveAurasByType(SPELL_AURA_FEIGN_DEATH);
  17.  
  18. // Stop the npc if moving
  19. if (vendor->HasUnitState(UNIT_STATE_MOVING))
  20. vendor->StopMoving();
  21.  
  22. WorldPacket data(SMSG_LIST_INVENTORY);
  23.  
  24. data["guid"] = vendorGuid;
  25.  
  26. VendorItemData const* vendorItems = vendor->GetVendorItems();
  27. uint32 rawItemCount = vendorItems ? vendorItems->GetItemCount() : 0;
  28. float const discount = GetPlayer()->GetReputationPriceDiscount(vendor);
  29. uint32 itemsSent = 0;
  30.  
  31. for (uint32 slot = 0; slot < rawItemCount; ++slot)
  32. {
  33. VendorItem const* vendorItem = vendorItems->GetItem(slot);
  34.  
  35. if (!vendorItems) continue;
  36.  
  37. LuaPacketItem& item = data["items"][itemsSent];
  38.  
  39. uint32 availableInStock = !vendorItem->maxcount ? 0xFFFFFFFF : vendor->GetVendorItemCurrentCount(vendorItem);
  40.  
  41. switch (vendorItem->Type)
  42. {
  43. case ITEM_VENDOR_TYPE_ITEM:
  44. {
  45. ItemTemplate const* it = sObjectMgr->GetItemTemplate(vendorItem->item);
  46. if (!it) continue;
  47.  
  48. if (!GetPlayer()->IsGameMaster())
  49. {
  50. // Respect allowed class
  51. if (!(it->AllowableClass & _player->getClassMask()) && it->Bonding == BIND_WHEN_PICKED_UP)
  52. continue;
  53.  
  54. // Only display items in vendor lists for the team the player is on
  55. if ((it->Flags2 & ITEM_FLAGS_EXTRA_HORDE_ONLY && _player->GetTeam() == ALLIANCE) ||
  56. (it->Flags2 & ITEM_FLAGS_EXTRA_ALLIANCE_ONLY && _player->GetTeam() == HORDE))
  57. continue;
  58.  
  59. // Items sold out are not displayed in list
  60. if (availableInStock == 0)
  61. continue;
  62. }
  63.  
  64. ConditionList conditions = sConditionMgr->GetConditionsForNpcVendorEvent(vendor->GetEntry(), vendorItem->item);
  65. if (!sConditionMgr->IsObjectMeetToConditions(_player, vendor, conditions))
  66. {
  67. TC_LOG_DEBUG(LOG_FILTER_CONDITIONSYS, "SendListInventory: conditions not met for creature entry %u item %u", vendor->GetEntry(), vendorItem->item);
  68. continue;
  69. }
  70.  
  71. int32 finalPrice = vendorItem->IsGoldRequired(it) ? uint32(floor(it->BuyPrice * discount)) : 0;
  72. int32 priceMod = GetPlayer()->GetTotalAuraModifier(SPELL_AURA_MOD_VENDOR_ITEMS_PRICES);
  73. AddPct(finalPrice, -priceMod);
  74.  
  75. item["price"] = finalPrice;
  76. item["durability"] = it->MaxDurability;
  77. item["stackCount"] = it->MaxCount;
  78.  
  79. item["itemInf"]["RandomPropSeed"] = it->RandomSuffix;
  80. item["itemInf"]["RandomPropID"] = it->RandomProperty;
  81.  
  82. break;
  83. }
  84. case ITEM_VENDOR_TYPE_CURRENCY:
  85. {
  86. CurrencyTypesEntry const* ct = sCurrencyTypesStore.LookupEntry(vendorItem->item);
  87.  
  88. if (!ct) continue;
  89.  
  90. /// There's no price defined for currencies, only extendedcost is used
  91. if (vendorItem->ExtendedCost == 0) continue;
  92.  
  93. item["stackCount"] = vendorItem->maxcount;
  94.  
  95. break;
  96. }
  97. }
  98.  
  99. item["slot"] = (slot + 1);
  100. item["type"] = vendorItem->Type;
  101.  
  102. item["qty"] = availableInStock;
  103. item["extendedCost"] = vendorItem->ExtendedCost;
  104.  
  105. item["itemInf"]["itemId"] = vendorItem->item;
  106.  
  107. itemsSent++;
  108. }
  109.  
  110. data["count"] = itemsSent;
  111.  
  112. if (itemsSent)
  113. data["reason"] = itemsSent;
  114. else
  115. data["reason"] = vendor->IsArmorer();
  116.  
  117. SendPacket(&data);
  118. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement