Repository navigation
Expand file tree
/
Copy pathNeglectedGear.lua
More file actions
232 lines (176 loc) · 6.83 KB
/
Copy pathNeglectedGear.lua
File metadata and controls
232 lines (176 loc) · 6.83 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
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
-- Neglected Gear Copyright 2017 JontomXire@hushmail.com
NeglectedGear = {}
local NeglectedGear = _G.NeglectedGear
NeglectedGear.event_queue = {};
function NeglectedGear:TestItem(item)
if strsub(item, 1, 5) ~= "item:"
then
item = "item:" .. tostring(tonumber(item));
end
if not IsEquippableItem(item)
then
NeglectedGear:ChatMessage("Error: " .. item .. " is not equippable.");
return;
end
local name, _, _, _, _, _, _, _, loc = GetItemInfo(item);
if nil == name
then
NeglectedGear:ChatMessage("Error: " .. item .. " is not a valid item link.");
return;
end
NeglectedGear:Initialise(name);
local _, old_item_1, diff_1, old_item_2, diff_2 = NeglectedGear:GetItemValues(item, "player");
NeglectedGear:AddRow(GetUnitName('player'), old_item_1, diff_1, old_item_2, diff_2)
SendAddonMessage("NG_QUERY", item, "RAID");
end
function SlashCmdList.NG(msg, editbox)
local cmd, rest = msg:match("^(%S*)%s*(.-)$");
if cmd:lower() == "test"
then
NeglectedGear:TestItem(rest);
elseif cmd:lower() == "check"
then
if strsub(rest, 1, 5) ~= "item:"
then
rest = "item:" .. tostring(tonumber(rest));
end
if IsUsableItem(rest)
then
NeglectedGear:DebugMessage(3, "You can use that.");
else
NeglectedGear:DebugMessage(3, "You cannot use that.");
end
elseif cmd:lower() == "warn"
then
NeglectedGear:ShowWarning(rest);
elseif cmd:lower() == "findapi"
then
for key, _ in pairs(_G)
do
if string.find(key, rest)
then
NeglectedGear:DebugMessage(1, key);
end
end
elseif cmd:lower() == "hide"
then
NeglectedGear.frame:Hide();
else
NeglectedGear:DebugMessage(3, "Invalid command \""..(cmd or "NIL").."\".");
end
end
function NeglectedGear_OnLoad(self)
NeglectedGear:InitSettings();
self:RegisterEvent("PLAYER_LOGIN");
self:RegisterEvent("PLAYER_REGEN_ENABLED");
self:RegisterEvent("PLAYER_REGEN_DISABLED");
self:RegisterEvent("CHAT_MSG_ADDON");
self:RegisterEvent("OPEN_MASTER_LOOT_LIST");
self:RegisterEvent("UPDATE_MASTER_LOOT_LIST");
GameTooltip:HookScript("OnTooltipSetItem", NeglectedGear_HookSetItem)
ShoppingTooltip1:HookScript("OnTooltipSetItem", NeglectedGear_HookCompareItem)
ShoppingTooltip2:HookScript("OnTooltipSetItem", NeglectedGear_HookCompareItem2)
ItemRefTooltip:HookScript("OnTooltipSetItem", NeglectedGear_HookRefItem)
NeglectedGear:CreateFrame();
-- Set up CLI.
_G["SLASH_NG1"] = "/ng";
NeglectedGear:ChatMessage("Welcome to the Neglected Gear add-on version "..NeglectedGear.major_version.."."..NeglectedGear.minor_version..".");
end
function NeglectedGear_OnEvent(self, event, ...)
local arg1, arg2, arg3, arg4, arg5, arg6 = ...;
local timestamp = GetTime();
NeglectedGear:DebugMessage(1, "Event \""..event.."\" received.");
if event == "PLAYER_LOGIN"
then
NeglectedGear:UpdateSettings();
NeglectedGear.in_combat = false;
elseif event == "PLAYER_REGEN_ENABLED"
then
NeglectedGear.in_combat = false;
elseif event == "PLAYER_REGEN_DISABLED"
then
NeglectedGear.in_combat = true;
elseif event == "CHAT_MSG_ADDON"
then
if arg1 == "NG_QUERY"
then
if not UnitIsUnit(arg4, "player")
then
local name, old_item_1, diff_1, old_item_2, diff_2 = NeglectedGear:GetItemValues(arg2, "player");
if name
then
if old_item_2
then
SendAddonMessage("NG_REPLY", old_item_1 .. "@" .. tostring(diff_1) .. "@" .. old_item_2 .. "@" .. tostring(diff_2), "WHISPER", arg4);
else
SendAddonMessage("NG_REPLY", old_item_1 .. "@" .. tostring(diff_1), "WHISPER", arg4);
end
end
end
elseif arg1 == "NG_REPLY"
then
local old_item_1, diff_1, rest = arg2:match("^([^@]*)@([^@]*)@*(.-)$");
local old_item_2 = nil;
local diff_2 = nil;
if rest
then
old_item_2, diff_2, rest = rest:match("^([^@]*)@([^@]*)@*(.-)$");
end
NeglectedGear:AddRow(GetUnitName(arg4), old_item_1, diff_1, old_item_2, diff_2)
end
elseif (event == "OPEN_MASTER_LOOT_LIST") or (event == "UPDATE_MASTER_LOOT_LIST")
then
item = GetLootSlotLink(LootFrame.selectedSlot);
item = item:match("^.*(item:[0-9]*):.*");
if IsEquippableItem(item)
then
NeglectedGear:ChatMessage("Item is " .. item .. ".");
NeglectedGear:Initialise(LootFrame.selectedItemName);
local i = 1;
local candidate = GetMasterLootCandidate(i);
while nil ~= candidate
do
if UnitIsUnit(candidate, "player")
then
local _, old_item_1, diff_1, old_item_2, diff_2 = NeglectedGear:GetItemValues(item, "player");
NeglectedGear:AddRow(GetUnitName('player'), old_item_1, diff_1, old_item_2, diff_2)
else
SendAddonMessage("NG_QUERY", item, "WHISPER", candidate);
end
i = i + 1;
candidate = GetMasterLootCandidate(i);
end
end
elseif event == "HIDE_WARNING"
then
NeglectedGear:HideWarning();
else
NeglectedGear:ChatMessage("Event "..event.."("..GetTime().."). Args are "..(arg1 or "nil")..", "..(arg2 or "nil")..", "..(arg3 or "nil")..".");
end
end
function NeglectedGear:PostEvent(event, delay)
local entry = {};
entry.event = event;
entry.remaining = delay;
NeglectedGear:DebugMessage(2, "Posting event "..event.." with "..string.format("%0.03f", entry.remaining).." seconds delay.");
NeglectedGear.event_queue[event] = entry;
end
function NeglectedGear:CancelPostedEvent(event)
NeglectedGear.event_queue[event] = nil;
end
function NeglectedGear_OnUpdate(self, elapsed)
local event, entry;
if(NeglectedGear.event_queue)
then
for event,entry in pairs(NeglectedGear.event_queue)
do
entry.remaining = entry.remaining - elapsed;
if(0 >= entry.remaining)
then
NeglectedGear.event_queue[event] = nil;
NeglectedGear:DebugMessage(2, "Posting event "..event);
NeglectedGear_OnEvent(self, event);
end
end
end
end