Advertisement
Guest User

Untitled

a guest
Aug 20th, 2019
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.22 KB | None | 0 0
  1. local _, core = ...; -- Namespace
  2. local events = CreateFrame("Frame");
  3.  
  4. function core:Init(event, name)
  5. if (event == "ADDON_LOADED") then
  6. if (name == "EZJunk") then
  7. events:UnregisterEvent("ADDON_LOADED");
  8.  
  9. events:RegisterEvent("MERCHANT_SHOW");
  10. end
  11. elseif (event == "MERCHANT_SHOW") then
  12. core.OnMerchantShow();
  13. end
  14. end
  15.  
  16. function core:OnMerchantShow()
  17. if ( MerchantFrame:IsVisible() and MerchantFrame.selectedTab == 1 ) then
  18. local link;
  19. local itemInfo;
  20. local containerItemInfo;
  21. local profitInCopper = 0;
  22. local itemsSold = 0;
  23.  
  24. for bag = 0, 4 do
  25. for slot = 1, GetContainerNumSlots(bag) do
  26. link = GetContainerItemLink(bag, slot);
  27.  
  28. if (link) then
  29. itemInfo = core:GetItemInfo(link);
  30. containerItemInfo = core:GetContainerItemInfo(bag, slot);
  31. --print(containerItemInfo.Quality);
  32.  
  33. if core:IsJunk(itemInfo) then
  34. -- DEBUG
  35. --print(itemInfo.Name);
  36. --print(itemInfo.Link);
  37. --print(itemInfo.Rarity);
  38. --print(itemInfo.Level);
  39. --print(itemInfo.MinLevel);
  40. --print(itemInfo.Type);
  41. --print(itemInfo.SubType);
  42. --print(itemInfo.StackCount);
  43. --print(itemInfo.EquipLocation);
  44. --print(itemInfo.Icon);
  45. --print(itemInfo.SellPrice);
  46. --print(itemInfo.ClassId);
  47. --print(itemInfo.SubClassId);
  48. --print(itemInfo.BindType);
  49. --print(itemInfo.ExpacId);
  50. --print(itemInfo.ItemSetId);
  51. --print(itemInfo.IsCraftingReagent);
  52.  
  53. --sell item
  54. UseContainerItem(bag, slot);
  55.  
  56. itemsSold = itemsSold + 1;
  57. profitInCopper = profitInCopper + (itemInfo.SellPrice * containerItemInfo.ItemCount);
  58. end
  59. end
  60. end
  61. end
  62.  
  63. if (profitInCopper > 0 and itemsSold > 0) then
  64. local junkItemText = itemsSold > 1 and "items" or "item";
  65.  
  66. print(GetCoinTextureString(profitInCopper) .. " has been obtained from selling " .. itemsSold .. " junk " .. junkItemText);
  67. end
  68. end
  69. end
  70.  
  71. function core:IsJunk(itemInfo)
  72. if itemInfo.Rarity == 0 then
  73. return true
  74. end
  75.  
  76. return false
  77. end
  78.  
  79. function core:GetItemInfo(link)
  80. local name, link, rarity, level, minLevel, type, subType, stackCount, equipLoc, icon, sellPrice, classId, subClassId, bindType = GetItemInfo(link);
  81.  
  82. return {
  83. Name = name,
  84. Link = link,
  85. Rarity = rarity,
  86. Level = level,
  87. MinLevel = minLevel,
  88. Type = type,
  89. SubType = subType,
  90. StackCount = stackCount,
  91. EquipLocation = equipLoc,
  92. Icon = icon,
  93. SellPrice = sellPrice,
  94. ClassId = classId,
  95. SubClassId = subClassId,
  96. BindType = bindType,
  97. ExpacId = expacId,
  98. ItemSetId = itemSetId,
  99. IsCraftingReagent = IsCraftingReagent,
  100. };
  101. end
  102.  
  103. function core:GetContainerItemInfo(bag, slot)
  104. local icon, itemCount, locked, quality, readable, lootable, itemLink, isFiltered, noValue, itemId = GetContainerItemInfo(bag, slot);
  105.  
  106. return {
  107. Icon = icon,
  108. ItemCount = itemCount,
  109. Locked = locked,
  110. Quality = quality,
  111. Readable = readable,
  112. Lootable = lootable,
  113. ItemLink = itemLink,
  114. IsFiltered = isFiltered,
  115. NoValue = noValue,
  116. ItemId = itemId,
  117. };
  118. end
  119.  
  120. function core:InternalAttachItemValueTooltip(tooltip, checkStack)
  121. local link = select(2, tooltip:GetItem());
  122.  
  123. if (link) then
  124. local itemInfo = core:GetItemInfo(link);
  125.  
  126. if (itemInfo.SellPrice and itemInfo.SellPrice > 0) then
  127. local stackCount = 1;
  128.  
  129. if (checkStack) then
  130. local frame = GetMouseFocus();
  131. local objectType = frame:GetObjectType();
  132.  
  133. if (objectType == "Button") then
  134. stackCount = frame.count or 1;
  135. end
  136. end
  137.  
  138. local totalValue = itemInfo.SellPrice * stackCount;
  139. local displayValue = GetCoinTextureString(totalValue);
  140.  
  141. SetTooltipMoney(tooltip, totalValue, nil, format("%s:", SELL_PRICE));
  142. end
  143. end
  144. end
  145.  
  146. local function AttachItemValueTooltip(tooltip, ...)
  147. if (not MerchantFrame:IsShown()) then
  148. core:InternalAttachItemValueTooltip(tooltip, true);
  149. end
  150. end
  151.  
  152. local function AttachLinkedItemValueTooltip(tooltip, ...)
  153. core:InternalAttachItemValueTooltip(tooltip, false);
  154. end
  155.  
  156. events:RegisterEvent("ADDON_LOADED");
  157. events:SetScript("OnEvent", core.Init);
  158.  
  159. GameTooltip:HookScript("OnTooltipSetItem", AttachItemValueTooltip);
  160. ItemRefTooltip:HookScript("OnTooltipSetItem", AttachLinkedItemValueTooltip);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement