This repository was archived by the owner on Jan 5, 2021. It is now read-only.
forked from suspectz/Corruption-Tooltips
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCorruptionTooltips.lua
More file actions
195 lines (172 loc) · 5.96 KB
/
CorruptionTooltips.lua
File metadata and controls
195 lines (172 loc) · 5.96 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
local addonName, addon = ...
local R = addon.R
local L = LibStub("AceLocale-3.0"):GetLocale("CorruptionTooltips")
CorruptionTooltips = LibStub("AceAddon-3.0"):NewAddon("CorruptionTooltips", "AceEvent-3.0", "AceConsole-3.0", "AceHook-3.0")
local defaults = {
profile = {
append = true,
summary = true,
english = false,
icon = true,
}
}
function CorruptionTooltips:OnInitialize()
CorruptionTooltips.db = LibStub("AceDB-3.0"):New("CorruptionTooltipsDB", defaults)
end
function CorruptionTooltips:OnEnable()
self:SecureHookScript(GameTooltip, 'OnTooltipSetItem', 'TooltipHook')
self:SecureHookScript(ItemRefTooltip, 'OnTooltipSetItem', 'TooltipHook')
self:SecureHookScript(ShoppingTooltip1, 'OnTooltipSetItem', 'TooltipHook')
self:SecureHookScript(ShoppingTooltip2, 'OnTooltipSetItem', 'TooltipHook')
self:SecureHookScript(EmbeddedItemTooltip, 'OnTooltipSetItem', 'TooltipHook')
self:SecureHookScript(CharacterStatsPane.ItemLevelFrame.Corruption, 'OnEnter', 'SummaryHook')
end
local function GetItemSplit(itemLink)
local itemString = string.match(itemLink, "item:([%-?%d:]+)")
local itemSplit = {}
-- Split data into a table
for _, v in ipairs({strsplit(":", itemString)}) do
if v == "" then
itemSplit[#itemSplit + 1] = 0
else
itemSplit[#itemSplit + 1] = tonumber(v)
end
end
return itemSplit
end
function CorruptionTooltips:CreateTooltip(tooltip)
local name, item = tooltip:GetItem()
if not name then return end
if IsCorruptedItem(item) then
local itemSplit = GetItemSplit(item)
local bonuses = {}
for index=1, itemSplit[13] do
bonuses[#bonuses + 1] = itemSplit[13 + index]
end
local corruption = CorruptionTooltips:GetCorruption(bonuses)
if corruption then
local name = corruption[1]
local icon = corruption[2]
local line = '|T'..icon..':0|t '..'|cff956dd1'..name..'|r'
if CorruptionTooltips.db.profile.icon ~= true then
line = '|cff956dd1'..name..'|r'
end
if CorruptionTooltips:Append(tooltip, line) ~= true then
tooltip:AddLine(" ")
tooltip:AddLine(line)
end
end
end
end
function CorruptionTooltips:GetCorruption(bonuses)
if #bonuses > 0 then
for i, bonus_id in pairs(bonuses) do
bonus_id = tostring(bonus_id)
if R[bonus_id] ~= nil then
local name, rank, icon, castTime, minRange, maxRange = GetSpellInfo(R[bonus_id][3])
if R[bonus_id][2] ~= "" then
rank = L[R[bonus_id][2]]
else
rank = ""
end
if CorruptionTooltips.db.profile.english then
name = R[bonus_id][1]
rank = R[bonus_id][2]
end
return {
name.." "..rank,
icon,
}
end
end
end
end
function CorruptionTooltips:Append(tooltip, line)
if CorruptionTooltips.db.profile.append then
local detected
for i = 1, tooltip:NumLines() do
local left = _G[tooltip:GetName().."TextLeft"..i]
local text = left:GetText()
if text ~= nil and strsub(text, 1, 1) == "+" then
detected = string.find(text, ITEM_MOD_CORRUPTION)
if detected ~= nil then
left:SetText(left:GetText().." / "..line)
return true
end
end
end
end
end
function CorruptionTooltips:TooltipHook(frame)
self:CreateTooltip(frame)
end
function CorruptionTooltips:SummaryHook(frame)
if CorruptionTooltips.db.profile.summary then
local corruptions = CorruptionTooltips:GetCorruptions()
if #corruptions > 0 then
GameTooltip:AddLine(" ")
local buckets = {}
for i=1, #corruptions do
local name = corruptions[i][1]
local icon = corruptions[i][2]
local line = '|T'..icon..':0|t '..'|cff956dd1'..name..'|r'
if CorruptionTooltips.db.profile.icon ~= true then
line = '|cff956dd1'..name..'|r'
end
if buckets[name] == nil then
buckets[name] = {
1,
line,
}
else
buckets[name][1]= buckets[name][1] + 1
end
end
table.sort(buckets)
for name, _ in pairs(buckets) do
GameTooltip:AddLine("|cff956dd1"..buckets[name][1]..' x '..buckets[name][2].."|r")
end
GameTooltip:Show()
end
end
end
function CorruptionTooltips:GetCorruptions()
local corruptions = {}
local slotNames = {
"HeadSlot", -- [1]
"NeckSlot", -- [2]
"ShoulderSlot", -- [3]
"BackSlot", -- [4]
"ChestSlot", -- [5]
"ShirtSlot", -- [6]
"TabardSlot", -- [7]
"WristSlot", -- [8]
"HandsSlot", -- [9]
"WaistSlot", -- [10]
"LegsSlot", -- [11]
"FeetSlot", -- [12]
"Finger0Slot", -- [13]
"Finger1Slot", -- [14]
"Trinket0Slot", -- [15]
"Trinket1Slot", -- [16]
"MainHandSlot", -- [17]
"SecondaryHandSlot", -- [18]
"AmmoSlot" -- [19]
}
for slotNum=1, #slotNames do
local slotId = GetInventorySlotInfo(slotNames[slotNum])
local itemLink = GetInventoryItemLink('player', slotId)
if itemLink then
local itemSplit = GetItemSplit(itemLink)
local bonuses = {}
for index=1, itemSplit[13] do
bonuses[#bonuses + 1] = itemSplit[13 + index]
end
local corruption = CorruptionTooltips:GetCorruption(bonuses)
if corruption then
corruptions[#corruptions + 1] = corruption
end
end
end
return corruptions
end