-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathHealBot_BonusScanner.lua
227 lines (205 loc) · 5.87 KB
/
HealBot_BonusScanner.lua
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
--------------------------------------------------
-- This is a cut version on BonusScanner
-- Healbot only cares about heals and although BonusScanner is a great addon, it lags when everts are fired.
--
-- Original BonusScanner here:
-- http://www.curse-gaming.com/mod.php?addid=2384
--------------------------------------------------
HB_BONUSSCANNER_PATTERN_SETNAME = "^(.*) %(%d/%d%)$";
HB_BONUSSCANNER_PATTERN_GENERIC_PREFIX = "^%+(%d+)%%?(.*)$";
HB_BONUSSCANNER_PATTERN_GENERIC_SUFFIX = "^(.*)%+(%d+)%%?$";
HealBot_BonusScanner = {
bonuses = 0;
IsUpdating = false;
ShowDebug = false; -- tells when the equipment is scanned
active = nil;
temp = {
sets = {},
set = "",
slot = "",
bonuses = 0,
details = {}
};
types = {
"HEAL", -- healing
};
slots = {
"Head",
"Neck",
"Shoulder",
"Shirt",
"Chest",
"Waist",
"Legs",
"Feet",
"Wrist",
"Hands",
"Finger0",
"Finger1",
"Trinket0",
"Trinket1",
"Back",
"MainHand",
"SecondaryHand",
"Ranged",
"Tabard",
};
}
function HealBot_BonusScanner:GetBonus()
if(HealBot_BonusScanner.bonuses) then
return HealBot_BonusScanner.bonuses;
end;
return 0;
end
function HealBot_BonusScanner_Update()
if (HealBot_BonusScanner.IsUpdating) then
return;
else
HealBot_BonusScanner.IsUpdating = true;
HealBot_BonusScanner:ScanEquipment();
end
HealBot_BonusScanner.IsUpdating = false;
end
function HealBot_BonusScanner:ScanEquipment()
local slotid, slotname, hasItem, i;
HealBot_BonusTooltip:SetOwner(HealBot_BonusTooltip, "ANCHOR_NONE");
HealBot_BonusScanner.temp.bonuses = 0;
HealBot_BonusScanner.temp.sets = {};
HealBot_BonusScanner.temp.set = "";
for i, slotname in ipairs(HealBot_BonusScanner.slots) do
slotid, _ = GetInventorySlotInfo(slotname.. "Slot");
hasItem = HealBot_BonusTooltip:SetInventoryItem("player", slotid);
if ( hasItem ) then
HealBot_BonusScanner.temp.slot = slotname;
HealBot_BonusScanner:ScanTooltip();
if(HealBot_BonusScanner.temp.set ~= "") then
HealBot_BonusScanner.temp.sets[HealBot_BonusScanner.temp.set] = 1;
end;
end
end
HealBot_BonusScanner.bonuses = HealBot_BonusScanner.temp.bonuses;
end
function HealBot_BonusScanner:ScanTooltip()
local tmpTxt, line;
local lines = HealBot_BonusTooltip:NumLines();
for i=2, lines, 1 do
tmpText = getglobal("HealBot_BonusTooltipTextLeft"..i);
val = nil;
if (tmpText:GetText()) then
line = tmpText:GetText();
HealBot_BonusScanner:ScanLine(line);
end
end
end
function HealBot_BonusScanner:AddValue(effect, value)
local i,e;
if(type(effect) == "string") then
if effect=="HEAL" then
if(HealBot_BonusScanner.temp.bonuses) then
HealBot_BonusScanner.temp.bonuses = HealBot_BonusScanner.temp.bonuses + value;
else
HealBot_BonusScanner.temp.bonuses = value;
end
end
else
if(type(value) == "table") then
for i,e in ipairs(effect) do
HealBot_BonusScanner:AddValue(e, value[i]);
end
else
for i,e in ipairs(effect) do
HealBot_BonusScanner:AddValue(e, value);
end
end
end
end;
function HealBot_BonusScanner:ScanLine(line)
local tmpStr, found;
if(string.sub(line,0,string.len(HB_BONUSSCANNER_PREFIX_EQUIP)) == HB_BONUSSCANNER_PREFIX_EQUIP) then
tmpStr = string.sub(line,string.len(HB_BONUSSCANNER_PREFIX_EQUIP)+1);
HealBot_BonusScanner:CheckPassive(tmpStr);
elseif(string.sub(line,0,string.len(HB_BONUSSCANNER_PREFIX_SET)) == HB_BONUSSCANNER_PREFIX_SET
and HealBot_BonusScanner.temp.set ~= ""
and not HealBot_BonusScanner.temp.sets[HealBot_BonusScanner.temp.set]) then
tmpStr = string.sub(line,string.len(HB_BONUSSCANNER_PREFIX_SET)+1);
HealBot_BonusScanner.temp.slot = "Set";
HealBot_BonusScanner:CheckPassive(tmpStr);
else
_, _, tmpStr = string.find(line, HB_BONUSSCANNER_PATTERN_SETNAME);
if(tmpStr) then
HealBot_BonusScanner.temp.set = tmpStr;
else
found = HealBot_BonusScanner:CheckGeneric(line);
if(not found) then
HealBot_BonusScanner:CheckOther(line);
end;
end
end
end;
function HealBot_BonusScanner:CheckPassive(line)
local i, p, value, found;
found = nil;
for i,p in ipairs(HB_BONUSSCANNER_PATTERNS_PASSIVE) do
_, _, value = string.find(line, "^" .. p.pattern);
if(value) then
HealBot_BonusScanner:AddValue(p.effect, value)
found = 1;
end
end
if(not found) then
HealBot_BonusScanner:CheckGeneric(line);
end
end
function HealBot_BonusScanner:CheckGeneric(line)
local value, token, pos, tmpStr, found;
found = false;
while(string.len(line) > 0) do
pos = string.find(line, "/", 1, true);
if(pos) then
tmpStr = string.sub(line,1,pos-1);
line = string.sub(line,pos+1);
else
tmpStr = line;
line = "";
end
tmpStr = string.gsub( tmpStr, "^%s+", "" );
tmpStr = string.gsub( tmpStr, "%s+$", "" );
tmpStr = string.gsub( tmpStr, "%.$", "" );
_, _, value, token = string.find(tmpStr, HB_BONUSSCANNER_PATTERN_GENERIC_PREFIX);
if(not value) then
_, _, token, value = string.find(tmpStr, HB_BONUSSCANNER_PATTERN_GENERIC_SUFFIX);
end
if(token and value) then
token = string.gsub( token, "^%s+", "" );
token = string.gsub( token, "%s+$", "" );
token = string.gsub( token, "%.$", "" );
if(HealBot_BonusScanner:CheckToken(token,value)) then
found = true;
end
end
end
return found;
end
function HealBot_BonusScanner:CheckToken(token, value)
local i, p, s1, s2;
if(HB_BONUSSCANNER_PATTERNS_GENERIC_LOOKUP[token]) then
HealBot_BonusScanner:AddValue(HB_BONUSSCANNER_PATTERNS_GENERIC_LOOKUP[token], value);
return true;
end
return false;
end
function HealBot_BonusScanner:CheckOther(line)
local i, p, value, start, found;
for i,p in ipairs(HB_BONUSSCANNER_PATTERNS_OTHER) do
start, _, value = string.find(line, "^" .. p.pattern);
if(start) then
if(p.value) then
HealBot_BonusScanner:AddValue(p.effect, p.value)
elseif(value) then
HealBot_BonusScanner:AddValue(p.effect, value)
end
return true;
end
end
return false;
end