Guest User

Untitled

a guest
May 25th, 2018
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.51 KB | None | 0 0
  1. sLog->outDebug(LOG_FILTER_NETWORKIO, "WORLD: Sent SMSG_LIST_INVENTORY");
  2.  
  3. Creature* vendor = GetPlayer()->GetNPCIfCanInteractWith(vendorGuid, UNIT_NPC_FLAG_VENDOR);
  4. if (!vendor)
  5. {
  6. sLog->outDebug(LOG_FILTER_NETWORKIO, "WORLD: SendListInventory - Unit (GUID: %u) not found or you can not interact with him.", uint32(GUID_LOPART(vendorGuid)));
  7. _player->SendSellError(SELL_ERR_CANT_FIND_VENDOR, NULL, 0, 0);
  8. return;
  9. }
  10.  
  11. // remove fake death
  12. if (GetPlayer()->HasUnitState(UNIT_STAT_DIED))
  13. GetPlayer()->RemoveAurasByType(SPELL_AURA_FEIGN_DEATH);
  14.  
  15. // Stop the npc if moving
  16. if (vendor->HasUnitState(UNIT_STAT_MOVING))
  17. vendor->StopMoving();
  18.  
  19. uint8 bytes[8] = { };
  20. *(uint64*)bytes = vendorGuid;
  21.  
  22. VendorItemData const* items = vendor->GetVendorItems();
  23. if (!items)
  24. {
  25. WorldPacket data(SMSG_LIST_INVENTORY, 8 + 1 + 1);
  26. data.WriteByteMask(bytes[5]);
  27. data.WriteByteMask(bytes[6]);
  28. data.WriteByteMask(bytes[1]);
  29. data.WriteByteMask(bytes[2]);
  30. data.WriteByteMask(bytes[3]);
  31. data.WriteByteMask(bytes[0]);
  32. data.WriteByteMask(bytes[7]);
  33. data.WriteByteMask(bytes[4]);
  34.  
  35. data.WriteByteSeq(bytes[2]);
  36. data.WriteByteSeq(bytes[3]);
  37.  
  38. data << uint8(0); // count == 0, next will be error code
  39. data << uint8(0xA0); // Only seen 0xA0 (160) so far ( should we send 0 here?)
  40.  
  41. data.WriteByteSeq(bytes[4]);
  42. data.WriteByteSeq(bytes[7]);
  43. data.WriteByteSeq(bytes[6]);
  44. SendPacket(&data);
  45. return;
  46. }
  47.  
  48. uint8 itemCount = items->GetItemCount();
  49. uint8 count = 0;
  50.  
  51. WorldPacket data(SMSG_LIST_INVENTORY, 8 + 1 + itemCount * 8 * 4);
  52.  
  53. data.WriteByteMask(bytes[5]);
  54. data.WriteByteMask(bytes[6]);
  55. data.WriteByteMask(bytes[1]);
  56. data.WriteByteMask(bytes[2]);
  57. data.WriteByteMask(bytes[3]);
  58. data.WriteByteMask(bytes[0]);
  59. data.WriteByteMask(bytes[7]);
  60. data.WriteByteMask(bytes[4]);
  61.  
  62. data.WriteByteSeq(bytes[2]);
  63. data.WriteByteSeq(bytes[3]);
  64.  
  65. size_t countPos = data.wpos();
  66. data << uint32(count);
  67.  
  68. data.WriteByteSeq(bytes[5]);
  69. data.WriteByteSeq(bytes[0]);
  70. data.WriteByteSeq(bytes[1]);
  71.  
  72. data << uint8(0xA0); // Only seen 0xA0 (160) so far
  73.  
  74. data.WriteByteSeq(bytes[4]);
  75. data.WriteByteSeq(bytes[7]);
  76. data.WriteByteSeq(bytes[6]);
  77.  
  78. float discountMod = _player->GetReputationPriceDiscount(vendor);
  79.  
  80. for (uint8 slot = 0; slot < itemCount; ++slot)
  81. {
  82. if (VendorItem const* item = items->GetItem(slot))
  83. {
  84. if (ItemTemplate const* itemTemplate = sObjectMgr->GetItemTemplate(item->item))
  85. {
  86. if (!(itemTemplate->AllowableClass & _player->getClassMask()) && itemTemplate->Bonding == BIND_WHEN_PICKED_UP && !_player->isGameMaster())
  87. continue;
  88. // Only display items in vendor lists for the team the
  89. // player is on. If GM on, display all items.
  90. if (!_player->isGameMaster() && ((itemTemplate->Flags2 & ITEM_FLAGS_EXTRA_HORDE_ONLY && _player->GetTeam() == ALLIANCE) || (itemTemplate->Flags2 == ITEM_FLAGS_EXTRA_ALLIANCE_ONLY && _player->GetTeam() == HORDE)))
  91. continue;
  92.  
  93. // Items sold out are not displayed in list
  94. uint32 leftInStock = !item->maxcount ? 0xFFFFFFFF : vendor->GetVendorItemCurrentCount(item);
  95. if (!_player->isGameMaster() && !leftInStock)
  96. continue;
  97.  
  98. // reputation discount
  99. int32 price = item->IsGoldRequired(itemTemplate) ? uint32(floor(itemTemplate->BuyPrice * discountMod)) : 0;
  100.  
  101. data << uint32(itemTemplate->MaxDurability);
  102. data << uint32(slot + 1); // client expects counting to start at 1
  103. data << uint32(item->item);
  104. data << uint32(0);
  105. data << uint32(itemTemplate->DisplayInfoID);
  106. data << uint32(leftInStock);
  107. data << uint32(itemTemplate->BuyCount);
  108. data << uint32(item->ExtendedCost);
  109. data << uint32(1);
  110. data << uint32(price);
  111. }
  112. }
  113. }
  114.  
  115. if (count == 0)
  116. {
  117. SendPacket(&data);
  118. return;
  119. }
  120.  
  121. data.put<uint32>(countPos, count);
  122. SendPacket(&data);
Add Comment
Please, Sign In to add comment