vanilla-wow-addons – Blame information for rev 1

Subversion Repositories:
Rev:
Rev Author Line No. Line
1 office 1 -- This lua file is mostly used for initialization
2  
3 TheoryCraft_TooltipData = {}
4 TheoryCraft_OldText = {}
5 TheoryCraft_Data = {}
6 TheoryCraft_Data.armormult = 1
7 TheoryCraft_Data.armormultinternal = 1
8 TheoryCraft_Data.Target = {}
9 TheoryCraft_Data.BaseData = {}
10 TheoryCraft_Data.BaseData["Allcritbonus"] = 0.5
11 TheoryCraft_Data.BaseData["Allthreat"] = 1
12 TheoryCraft_Data.BaseData["Allmodifier"] = 1
13 TheoryCraft_Data.BaseData["Allbaseincrease"] = 1
14 TheoryCraft_Data.BaseData["Huntercritbonus"] = 0.5
15 TheoryCraft_Data.BaseData["Rangedcritbonus"] = 1
16 TheoryCraft_Data.BaseData["Rangedmodifier"] = 1
17 TheoryCraft_Data.BaseData["Rangedbaseincrease"] = 1
18 TheoryCraft_Data.BaseData["Meleecritbonus"] = 1
19 TheoryCraft_Data.BaseData["Meleemodifier"] = 1
20 TheoryCraft_Data.BaseData["Meleebaseincrease"] = 1
21 TheoryCraft_Data.BaseData["AllUpFrontmodifier"] = 1
22 TheoryCraft_Data.BaseData["AllUpFrontbaseincrease"] = 1
23 TheoryCraft_Data.BaseData["manacostall"] = 1
24 TheoryCraft_Data.Talents = {}
25 TheoryCraft_Data.Talents["strmultiplier"] = 1
26 TheoryCraft_Data.Talents["agimultiplier"] = 1
27 TheoryCraft_Data.Talents["stammultiplier"] = 1
28 TheoryCraft_Data.Talents["intmultiplier"] = 1
29 TheoryCraft_Data.Talents["spiritmultiplier"] = 1
30 TheoryCraft_Data.Talents["manamultiplier"] = 1
31 TheoryCraft_Data.Talents["healthmultiplier"] = 1
32 local _, class = UnitClass("player")
33 local _, race = UnitRace("player")
34 if (race == "Gnome") then
35 TheoryCraft_Data.Talents["intmultiplier"] = 1.05
36 end
37 if (race == "Human") then
38 TheoryCraft_Data.Talents["spiritmultiplier"] = 1.05
39 end
40 if (race == "Tauren") then
41 TheoryCraft_Data.Talents["healthmultiplier"] = 1.05
42 end
43 TheoryCraft_Data.Talents["strmultiplierreal"] = 1
44 TheoryCraft_Data.Talents["agimultiplierreal"] = 1
45 TheoryCraft_Data.Talents["stammultiplierreal"] = 1
46 TheoryCraft_Data.Talents["intmultiplierreal"] = TheoryCraft_Data.Talents["intmultiplier"]
47 TheoryCraft_Data.Talents["spiritmultiplierreal"] = TheoryCraft_Data.Talents["spiritmultiplier"]
48 TheoryCraft_Data.Talents["manamultiplierreal"] = 1
49 TheoryCraft_Data.Talents["healthmultiplierreal"] = TheoryCraft_Data.Talents["healthmultiplier"]
50 TheoryCraft_Data.Stats = {}
51  
52 TheoryCraft_UpdatedButtons = {}
53  
54 function Print(text, begin, spaces)
55 if spaces and string.len(spaces) > 10 then
56 return
57 end
58 if text == nil then text = "nil" end
59 if text == true then text = "true" end
60 if text == false then text = "false" end
61 if type(text) == "function" then
62 text = "function ("..tostring(text)..")"
63 end
64 if type(text) == "table" then
65 for k, v in pairs(text) do
66 if type(v) == "table" then
67 Print(k..": (Table)", "", (spaces or "").." ")
68 end
69 Print(v, k..": ", (spaces or "").." ")
70 end
71 return
72 end
73 text = (spaces or "")..(begin or "")..text
74 DEFAULT_CHAT_FRAME:AddMessage(text)
75 end
76  
77 function TheoryCraft_CopyTable(tab1, tab2)
78 for k, v in pairs(tab1) do
79 if type(v) == "table" then
80 tab2[k] = {}
81 TheoryCraft_CopyTable(v, tab2[k])
82 else
83 tab2[k] = v
84 end
85 end
86 end
87  
88 function TheoryCraft_DeleteTable(tab1)
89 for k, v in pairs(tab1) do
90 if type(v) == "table" then
91 TheoryCraft_DeleteTable(v)
92 else
93 tab1[k] = nil
94 end
95 end
96 end
97  
98 function TheoryCraftCast(spellname, overheal)
99 if UnitHealthMax("target") == 100 then
100 CastSpellByName(spellname)
101 return
102 end
103 if overheal == nil then overheal = 1 end
104 local u, highest, s = UnitHealthMax("target")-UnitHealth("target"), 1
105 u = u * overheal
106 for i = 1,20 do
107 s = TheoryCraft_GetSpellDataByName(spellname, i)
108 if (s) and (s.averagehealnocrit) and (s.averagehealnocrit > u) then
109 CastSpellByName(spellname.."(Rank "..i..")")
110 return
111 end
112 end
113 CastSpellByName(spellname)
114 end
115  
116 local function round(arg1, decplaces)
117 if (decplaces == nil) then decplaces = 0 end
118 if arg1 == nil then arg1 = 0 end
119 return string.format ("%."..decplaces.."f", arg1)
120 end
121  
122 function TheoryCraft_WatchCritRate(arg1)
123 local _, _, hit = strfind(arg1, "Your (.+) heals ")
124 local _, _, crit= strfind(arg1, "Your (.+) critically")
125 if (not hit) and (not crit) then return end
126 if crit then hit = crit end
127 local foundcc
128 for k = 1,20 do
129 if TheoryCraft_TooltipData[hit.."("..k..")"] then
130 foundcc = TheoryCraft_TooltipData[TheoryCraft_TooltipData[hit.."("..k..")"]]["crithealchance"]
131 end
132 end
133 if foundcc == nil then
134 return
135 end
136 if not TheoryCraft_Settings["critchancedata"] then
137 TheoryCraft_Settings["critchancedata"] = {}
138 end
139 if (TheoryCraft_Data.outfit) and (TheoryCraft_Data.outfit ~= -1) and (TheoryCraft_Data.outfit ~= 1) then
140 return
141 end
142 local _, tmp2 = UnitStat("player", 4)
143 local tmp = tmp2..":"..(foundcc-TheoryCraft_Data.Stats["critchance"])
144 if not TheoryCraft_Settings["critchancedata"][tmp] then
145 TheoryCraft_Settings["critchancedata"][tmp] = {}
146 TheoryCraft_Settings["critchancedata"][tmp].casts = 0
147 TheoryCraft_Settings["critchancedata"][tmp].crits = 0
148 end
149 TheoryCraft_Settings["critchancedata"][tmp].casts = TheoryCraft_Settings["critchancedata"][tmp].casts+1
150 if crit then
151 TheoryCraft_Settings["critchancedata"][tmp].crits = TheoryCraft_Settings["critchancedata"][tmp].crits+1
152 end
153 if class == "PALADIN" then
154 if (TheoryCraft_Settings["critchancedata"][tmp].casts == 15000) or ((TheoryCraft_Settings["critchancedata"][tmp].casts > 15000) and (math.floor(TheoryCraft_Settings["critchancedata"][tmp].casts/100) == TheoryCraft_Settings["critchancedata"][tmp].casts/100)) then
155 if TheoryCraft_Settings["hidecritdata"] then return end
156 local cc = (TheoryCraft_Settings["critchancedata"][tmp].crits/TheoryCraft_Settings["critchancedata"][tmp].casts-(foundcc-TheoryCraft_Data.Stats["critchance"])/100)*100
157 Print("You've cast "..TheoryCraft_Settings["critchancedata"][tmp].casts.." heals with "..tmp2.." intellect and +"..(foundcc-TheoryCraft_Data.Stats["critchance"]).." crit chance.")
158 Print("Over this you had a base crit rate of "..round((TheoryCraft_Settings["critchancedata"][tmp].crits/TheoryCraft_Settings["critchancedata"][tmp].casts-(foundcc-TheoryCraft_Data.Stats["critchance"])/100)*100,4).."%")
159 Print("TC was expecting a base crit rate of "..TheoryCraft_Data.Stats["critchance"].."%")
160 Print("*Please* post this info on the Curse Gaming message board for TheoryCraft, as this is a very significant amount of casts,")
161 Print("and currently the correct crit formula for Paladins is not known.")
162 Print("This message will show every 100 heals from now on. To hide it, type")
163 Print("/tc hidecritdata")
164 end
165 end
166 end
167  
168 local function findpattern(text, pattern, start)
169 if (text and pattern and (string.find(text, pattern, start))) then
170 return string.sub(text, string.find(text, pattern, start))
171 else
172 return ""
173 end
174 end
175  
176 function TheoryCraft_UpdateArmor()
177 local oldmit = TheoryCraft_Data.armormultinternal
178 TheoryCraft_Data.armormultinternal = 1
179 local armor
180 if UnitIsPlayer("target") then
181 if (TheoryCraft_MitigationPlayers[UnitName("target")]) and (TheoryCraft_MitigationPlayers[UnitName("target")][1]) then
182 armor = TheoryCraft_MitigationPlayers[UnitName("target")][1]-TheoryCraft_GetStat("Sunder")
183 else
184 local unitlevel = UnitLevel("target")
185 if unitlevel == -1 then unitlevel = 60 end
186 local uc = UnitClass("target")
187 if UnitClass("target") == nil then
188 return
189 end
190 for i = 0,60 do
191 if (TheoryCraft_MitigationPlayers[uc..":"..unitlevel+i]) and (TheoryCraft_MitigationPlayers[uc..":"..unitlevel+i][1]) then
192 armor = TheoryCraft_MitigationPlayers[uc..":"..unitlevel+i][1]-TheoryCraft_GetStat("Sunder")
193 break
194 end
195 if (TheoryCraft_MitigationPlayers[uc..":"..unitlevel-i]) and (TheoryCraft_MitigationPlayers[uc..":"..unitlevel-i][1]) then
196 armor = TheoryCraft_MitigationPlayers[uc..":"..unitlevel-i][1]-TheoryCraft_GetStat("Sunder")
197 break
198 end
199 end
200 end
201 else
202 if (TheoryCraft_MitigationMobs[UnitName("target")]) and (TheoryCraft_MitigationMobs[UnitName("target")][1]) then
203 armor = TheoryCraft_MitigationMobs[UnitName("target")][1]-TheoryCraft_GetStat("Sunder")
204 end
205 end
206 if armor then
207 if armor < 0 then armor = 0 end
208 TheoryCraft_Data.armormultinternal = 1 - (armor / (85 * UnitLevel("player") + 400 + armor))
209 end
210 if TheoryCraft_Data.armormultinternal ~= oldmit then
211 TheoryCraft_DeleteTable(TheoryCraft_UpdatedButtons)
212 end
213 end
214  
215 local old = {}
216  
217 function TheoryCraft_UpdateTarget(dontgen)
218 if UnitName("target") == nil and TheoryCraft_Settings["useglock"] then
219 TheoryCraft_Settings["resistscores"]["Arcane"] = 0
220 TheoryCraft_Settings["resistscores"]["Fire"] = 0
221 TheoryCraft_Settings["resistscores"]["Nature"] = 0
222 TheoryCraft_Settings["resistscores"]["Frost"] = 0
223 TheoryCraft_Settings["resistscores"]["Shadow"] = 0
224 TheoryCraftresistArcane:SetText(TheoryCraft_Settings["resistscores"]["Arcane"])
225 TheoryCraftresistFire:SetText(TheoryCraft_Settings["resistscores"]["Fire"])
226 TheoryCraftresistNature:SetText(TheoryCraft_Settings["resistscores"]["Nature"])
227 TheoryCraftresistFrost:SetText(TheoryCraft_Settings["resistscores"]["Frost"])
228 TheoryCraftresistShadow:SetText(TheoryCraft_Settings["resistscores"]["Shadow"])
229 end
230 TheoryCraft_DeleteTable(old)
231 TheoryCraft_CopyTable(TheoryCraft_Data.Target, old)
232 TheoryCraft_DeleteTable(TheoryCraft_Data.Target)
233 local race, raceen = UnitRace("player")
234 local racetar = UnitCreatureType("target")
235 if (raceen == "Troll") and (racetar == TheoryCraft_Locale.ID_Beast) then
236 TheoryCraft_Data.Target["Allbaseincrease"] = 0.05
237 TheoryCraft_Data.Target["Rangedmodifier"] = 0.05
238 TheoryCraft_Data.Target["Meleemodifier"] = 0.05
239 end
240 local slaying = 0
241 if (racetar == TheoryCraft_Locale.ID_Humanoid) then
242 slaying = TheoryCraft_GetStat("humanoidslaying")
243 end
244 if (racetar == TheoryCraft_Locale.ID_Beast) or (racetar == TheoryCraft_Locale.ID_Giant) or (racetar == TheoryCraft_Locale.ID_Dragonkin) then
245 slaying = TheoryCraft_GetStat("monsterslaying")
246 end
247 if racetar then
248 TheoryCraft_Data.Target["All"] = TheoryCraft_GetStat(racetar)
249 end
250 TheoryCraft_Data.Target["Allbaseincrease"] = (TheoryCraft_Data.Target["Allbaseincrease"] or 0)+slaying
251 TheoryCraft_Data.Target["Rangedmodifier"] = (TheoryCraft_Data.Target["Rangedmodifier"] or 0)+slaying
252 TheoryCraft_Data.Target["Meleemodifier"] = (TheoryCraft_Data.Target["Meleemodifier"] or 0)+slaying
253 TheoryCraft_Data.Target["Allcritbonus"] = slaying
254 TheoryCraft_Data.Target["Rangedcritbonus"] = slaying
255 TheoryCraft_Data.Target["Meleecritbonus"] = slaying
256 if (dontgen == nil) and (TheoryCraft_IsDifferent(old, TheoryCraft_Data.Target)) then
257 TheoryCraft_GenerateAll()
258 end
259 if TheoryCraft_Settings["dontresist"] then
260 TheoryCraft_DeleteTable(TheoryCraft_UpdatedButtons)
261 end
262 TheoryCraft_UpdateArmor()
263 end
264  
265 --- IsDifferent, returns true if the two tables are different else nil ---
266  
267 function TheoryCraft_IsDifferent(oldtable, newtable)
268 if newtable == nil then return true end
269 if oldtable == nil then return true end
270 for k,v in pairs(oldtable) do
271 if type(v) == "table" then
272 if TheoryCraft_IsDifferent(v, newtable[k]) then
273 return true
274 end
275 elseif newtable[k] ~= v then
276 if not (((v == nil) and (newtable[k] == 0)) or ((newtable[k] == nil) and (v == 0))) then
277 return true
278 end
279 end
280 end
281 for k,v in pairs(newtable) do
282 if type(v) == "table" then
283 if TheoryCraft_IsDifferent(v, oldtable[k]) then
284 return true
285 end
286 elseif (oldtable[k] ~= v) then
287 if not (((v == nil) and (oldtable[k] == 0)) or ((oldtable[k] == nil) and (v == 0))) then
288 return true
289 end
290 end
291 end
292 end
293  
294 --- OnLoad ---
295  
296 local function SetDefaults()
297 TheoryCraft_Settings = {}
298 TheoryCraft_Settings["embed"] = true
299 TheoryCraft_Settings["combinedot"] = true
300 TheoryCraft_Settings["procs"] = true
301 TheoryCraft_Settings["healanddamage"] = true
302 TheoryCraft_Settings["embedstyle1"] = true
303 TheoryCraft_Settings["buttontext"] = true
304 if TheoryCraft_NotStripped then
305 TheoryCraft_Settings["mitigation"] = true
306 end
307 TheoryCraft_Settings["tryfirst"] = "averagedam"
308 TheoryCraft_Settings["trysecond"] = "averagehealnocrit"
309 TheoryCraft_Settings["tryfirstsfg"] = 0
310 TheoryCraft_Settings["trysecondsfg"] = -1
311 TheoryCraft_Settings["dataversion"] = TheoryCraft_DataVersion
312 TheoryCraft_Settings["GenerateList"] = ""
313 TheoryCraft_Settings["dontresist"] = true
314 if (MobResistDB) and type(MobResistDB) == "table" then
315 TheoryCraft_Settings["useglock"] = true
316 end
317 TheoryCraft_Settings["resistscores"] = {}
318 TheoryCraft_Settings["resistscores"]["Arcane"] = 0
319 TheoryCraft_Settings["resistscores"]["Fire"] = 0
320 TheoryCraft_Settings["resistscores"]["Nature"] = 0
321 TheoryCraft_Settings["resistscores"]["Frost"] = 0
322 TheoryCraft_Settings["resistscores"]["Shadow"] = 0
323 end
324  
325 function TheoryCraft_SetItemRef(link, text, button)
326 if (IsAltKeyDown()) and (string.sub(link, 1, 4) == "item") then
327 TheoryCraft_AddToCustom(link)
328 TheoryCraft_UpdateGear("player", true)
329 TheoryCraft_LoadStats()
330 TheoryCraft_GenerateAll()
331 else
332 TheoryCraft_Data["SetItemRef"](link, text, button)
333 end
334 end
335  
336 function TheoryCraft_ContainerFrameItemButton_OnClick(button, ignoremodifiers)
337 if (IsAltKeyDown()) and (button == "LeftButton") and (not ignoremodifiers) and ((AuctionFrame == nil) or (not AuctionFrame:IsVisible())) then
338 TheoryCraft_AddToCustom(GetContainerItemLink(this:GetParent():GetID(), this:GetID()))
339 TheoryCraft_UpdateGear("player", true)
340 TheoryCraft_LoadStats()
341 TheoryCraft_GenerateAll()
342 end
343 TheoryCraft_Data["ContainerFrameItemButton_OnClick"](button, ignoremodifiers)
344 end
345  
346 function TheoryCraft_PaperDollItemSlotButton_OnClick(arg1)
347 if (arg1 == "LeftButton") and (IsAltKeyDown()) then
348 TheoryCraft_AddToCustom(GetInventoryItemLink("player", this:GetID()))
349 TheoryCraft_UpdateGear("player", true)
350 TheoryCraft_LoadStats()
351 TheoryCraft_GenerateAll()
352 end
353 TheoryCraft_Data["PaperDollItemSlotButton_OnClick"](arg1)
354 end
355  
356 function TheoryCraft_SuperInspect_InspectPaperDollItemSlotButton_OnClick(arg1)
357 if (arg1 == "LeftButton") and (IsAltKeyDown()) then
358 TheoryCraft_AddToCustom(GetInventoryItemLink("target", GetInventorySlotInfo(string.sub(this:GetName(), 21))))
359 TheoryCraft_UpdateGear("player", true)
360 TheoryCraft_LoadStats()
361 TheoryCraft_GenerateAll()
362 end
363 TheoryCraft_Data["SuperInspect_InspectPaperDollItemSlotButton_OnClick"](arg1)
364 end
365  
366  
367 function TheoryCraft_InspectPaperDollItemSlotButton_OnClick(arg1)
368 if (arg1 == "LeftButton") and (IsAltKeyDown()) then
369 Print(this:GetName())
370 TheoryCraft_AddToCustom(GetInventoryItemLink("target", this:GetID()))
371 TheoryCraft_UpdateGear("player", true)
372 TheoryCraft_LoadStats()
373 TheoryCraft_GenerateAll()
374 end
375 TheoryCraft_Data["InspectPaperDollItemSlotButton_OnClick"](arg1)
376 end
377  
378 function TheoryCraft_ISyncButtonClick(arg1, sButton)
379 if (sButton == "LeftButton") and (IsAltKeyDown()) then
380 TheoryCraft_AddToCustom("item:"..this.storeID)
381 TheoryCraft_UpdateGear("player", true)
382 TheoryCraft_LoadStats()
383 TheoryCraft_GenerateAll()
384 end
385 TheoryCraft_Data["ISync:ButtonClick"](arg1, sButton)
386 end
387  
388 function TheoryCraft_OnLoad()
389 if not TheoryCraft_NotStripped then
390 TheoryCraft_Locale.LoadText = string.gsub(TheoryCraft_Locale.LoadText, TheoryCraft_Version, TheoryCraft_Version.." STRIPPED")
391 TheoryCraft_DataVersion = TheoryCraft_DataVersion.." STRIPPED"
392 TheoryCraft_Version = TheoryCraft_Version.." STRIPPED"
393 end
394 TheoryCraft_MitigationMobs = {}
395 TheoryCraft_MitigationPlayers = {}
396 tinsert(UISpecialFrames,"TheoryCraft")
397 SLASH_TheoryCraft1 = "/theorycraft"
398 SLASH_TheoryCraft2 = "/tc"
399 SlashCmdList["TheoryCraft"] = TheoryCraft_Command
400 this:RegisterEvent("VARIABLES_LOADED")
401 this:RegisterEvent("PLAYER_LOGIN")
402 SetDefaults()
403  
404 -- Translates and expands out "schoolname" fields
405  
406 local s
407 local function bothcase(a)
408 return "["..string.upper(a)..string.lower(a).."]"
409 end
410 for k, v in pairs(TheoryCraft_PrimarySchools) do
411 if (type(v) == "table") and v.text then
412 v.text = string.gsub(v.text, "(.)", bothcase)
413 end
414 end
415  
416 local i = 1
417 local s2 = 1
418 local i3 = 1
419 local newones = {}
420 while (TheoryCraft_EquipEveryLine[i]) do
421 s2 = TheoryCraft_EquipEveryLine[i].text
422 if (strfind(TheoryCraft_EquipEveryLine[i].text, "schoolname")) then
423 local i2 = 1
424 local type = 1
425 local s3 = 1
426 while TheoryCraft_PrimarySchools[i2] do
427 s3 = s2
428  
429 s3 = string.gsub(s2, "schoolname", TheoryCraft_PrimarySchools[i2].text)
430 if i2 == 1 then
431 TheoryCraft_EquipEveryLine[i].text = s3
432 TheoryCraft_EquipEveryLine[i].type = TheoryCraft_PrimarySchools[i2].name
433 else
434 newones[i3] = {}
435 newones[i3].me = TheoryCraft_EquipEveryLine[i].me
436 newones[i3].amount = TheoryCraft_EquipEveryLine[i].amount
437 newones[i3].text = s3
438 newones[i3].type = TheoryCraft_PrimarySchools[i2].name
439 i3 = i3 + 1
440 end
441 i2 = i2 + 1
442 end
443 end
444 i = i + 1
445 end
446 i2 = 1
447 while newones[i2] do
448 TheoryCraft_EquipEveryLine[i] = {}
449 TheoryCraft_EquipEveryLine[i].me = newones[i2].me
450 TheoryCraft_EquipEveryLine[i].amount = newones[i2].amount
451 TheoryCraft_EquipEveryLine[i].text = newones[i2].text
452 TheoryCraft_EquipEveryLine[i].type = newones[i2].type
453 i2 = i2 + 1
454 i = i + 1
455 end
456  
457 local i = 1
458 local s2 = 1
459 local i3 = 1
460 local newones = {}
461 while (TheoryCraft_EquipEveryRight[i]) do
462 s2 = TheoryCraft_EquipEveryRight[i].text
463 if (strfind(TheoryCraft_EquipEveryRight[i].text, "schoolname")) then
464 local i2 = 1
465 local type = 1
466 local s3 = 1
467 while TheoryCraft_PrimarySchools[i2] do
468 s3 = s2
469 s3 = string.gsub(s2, "schoolname", TheoryCraft_PrimarySchools[i2].text)
470 if i2 == 1 then
471 TheoryCraft_EquipEveryRight[i].text = s3
472 TheoryCraft_EquipEveryRight[i].type = TheoryCraft_PrimarySchools[i2].name
473 else
474 newones[i3] = {}
475 newones[i3].me = TheoryCraft_EquipEveryRight[i].me
476 newones[i3].amount = TheoryCraft_EquipEveryRight[i].amount
477 newones[i3].text = s3
478 newones[i3].type = TheoryCraft_PrimarySchools[i2].name
479 i3 = i3 + 1
480 end
481 i2 = i2 + 1
482 end
483 end
484 i = i + 1
485 end
486 i2 = 1
487 while newones[i2] do
488 TheoryCraft_EquipEveryRight[i] = {}
489 TheoryCraft_EquipEveryRight[i].me = newones[i2].me
490 TheoryCraft_EquipEveryRight[i].amount = newones[i2].amount
491 TheoryCraft_EquipEveryRight[i].text = newones[i2].text
492 TheoryCraft_EquipEveryRight[i].type = newones[i2].type
493 i2 = i2 + 1
494 i = i + 1
495 end
496  
497 local i = 1
498 local s2 = 1
499 local i3 = 1
500 local newones = {}
501 while (TheoryCraft_Equips[i]) do
502 s2 = TheoryCraft_Equips[i].text
503 if (strfind(TheoryCraft_Equips[i].text, "schoolname")) then
504 local i2 = 1
505 local type = 1
506 local s3 = 1
507 while TheoryCraft_PrimarySchools[i2] do
508 s3 = string.gsub(s2, "schoolname", TheoryCraft_PrimarySchools[i2].text)
509 if i2 == 1 then
510 TheoryCraft_Equips[i].text = s3
511 TheoryCraft_Equips[i].type = TheoryCraft_PrimarySchools[i2].name
512 else
513 newones[i3] = {}
514 newones[i3].me = TheoryCraft_Equips[i].me
515 newones[i3].amount = TheoryCraft_Equips[i].amount
516 newones[i3].text = s3
517 newones[i3].type = TheoryCraft_PrimarySchools[i2].name
518 i3 = i3 + 1
519 end
520 i2 = i2 + 1
521 end
522 end
523 i = i + 1
524 end
525 i2 = 1
526 while newones[i2] do
527 TheoryCraft_Equips[i] = {}
528 TheoryCraft_Equips[i].me = newones[i2].me
529 TheoryCraft_Equips[i].amount = newones[i2].amount
530 TheoryCraft_Equips[i].text = newones[i2].text
531 TheoryCraft_Equips[i].type = newones[i2].type
532 i2 = i2 + 1
533 i = i + 1
534 end
535  
536 i = 1
537 while TheoryCraft_Spells[class][i] do
538 if TheoryCraft_Spells[class][i].id then
539 if TheoryCraft_Spells[class][i].id == "Aimed Shot" then
540 TheoryCraft_Locale.MinMax.aimedshotname = TheoryCraft_Locale.SpellTranslator[TheoryCraft_Spells[class][i].id]
541 elseif TheoryCraft_Spells[class][i].id == "Multi-Shot" then
542 TheoryCraft_Locale.MinMax.multishotname = TheoryCraft_Locale.SpellTranslator[TheoryCraft_Spells[class][i].id]
543 elseif TheoryCraft_Spells[class][i].id == "Arcane Shot" then
544 TheoryCraft_Locale.MinMax.arcaneshotname = TheoryCraft_Locale.SpellTranslator[TheoryCraft_Spells[class][i].id]
545 elseif TheoryCraft_Spells[class][i].id == "Auto Shot" then
546 TheoryCraft_Locale.MinMax.autoshotname = TheoryCraft_Locale.SpellTranslator[TheoryCraft_Spells[class][i].id]
547 end
548 if TheoryCraft_Locale.SpellTranslator[TheoryCraft_Spells[class][i].id] then
549 TheoryCraft_Spells[class][i].name = TheoryCraft_Locale.SpellTranslator[TheoryCraft_Spells[class][i].id]
550 else
551 Print("TheoryCraft error, no translation found for: "..TheoryCraft_Spells[class][i].id)
552 TheoryCraft_Spells[class][i].name = TheoryCraft_Spells[class][i].id
553 end
554 end
555 i = i + 1
556 end
557  
558 Print(TheoryCraft_Locale.LoadText)
559 end
560  
561 --- OnShow ---
562  
563 function TheoryCraft_OnShow()
564 TheoryCraft_AddTooltipInfo(GameTooltip)
565 if (TheoryCraft_OnShow_Save) then
566 TheoryCraft_OnShow_Save()
567 end
568 end
569  
570 function TheoryCraft_GLOCK_UpdateResist(this, arg1)
571 this:OldSetText(arg1)
572 if not TheoryCraft_Settings["useglock"] then
573 return
574 end
575 if strfind(arg1, "I") then
576 TheoryCraft_Settings["resistscores"][this.TCType] = "~"
577 elseif strfind(arg1, "V") then
578 TheoryCraft_Settings["resistscores"][this.TCType] = -50
579 else
580 TheoryCraft_Settings["resistscores"][this.TCType] = tonumber(arg1) or 0
581 end
582 getglobal("TheoryCraftresist"..this.TCType):SetText(TheoryCraft_Settings["resistscores"][this.TCType])
583 end
584  
585 if BActionButton and type(BActionButton) == "table" then
586 TheoryCraft_Data["oldBongo"] = BActionButton.Create
587 function TheoryCraft_BActionButtonCreate(index, bar)
588 local tmp = TheoryCraft_Data["oldBongo"](index, bar)
589 TheoryCraft_SetUpButton(tmp:GetName(), "Normal")
590 return tmp
591 end
592 BActionButton.Create = TheoryCraft_BActionButtonCreate
593 end
594  
595 function TheoryCraft_OnEvent()
596 local UIMem = gcinfo()
597 if event == "VARIABLES_LOADED" then
598 if TheoryCraft_AddButtonText then TheoryCraft_AddButtonText() end
599 TheoryCraft_Mitigation = nil
600 TheoryCraft_Data["SetItemRef"] = SetItemRef
601 SetItemRef = TheoryCraft_SetItemRef
602  
603 if (MobResistDB) and (GLOCK_UIschools) and type(MobResistDB) == "table" then
604 for k, v in TheoryCraft_PrimarySchools do
605 for k, v2 in GLOCK_UIschools do
606 if v2 == v.name then
607 if getglobal("GMin"..v.name.."TxT") and getglobal("GMin"..v.name.."TxT").SetText then
608 getglobal("GMin"..v.name.."TxT").TCType = v.name
609 getglobal("GMin"..v.name.."TxT").OldSetText = getglobal("GMin"..v.name.."TxT").SetText
610 getglobal("GMin"..v.name.."TxT").SetText = TheoryCraft_GLOCK_UpdateResist
611 break
612 end
613 end
614 end
615 end
616 end
617  
618 -- Hooking Nurfed Action Bars onUpdate event for button text purposes
619 TheoryCraft_Data["oldGBMSB"] = GB_Spellbook_UpdatePage
620 GB_Spellbook_UpdatePage = TheoryCraft_GB_Spellbook_UpdatePage
621  
622 TheoryCraft_Data["oldNurfed"] = Nurfed_ActionButton_OnUpdate
623 Nurfed_ActionButton_OnUpdate = TheoryCraft_Nurfed_ActionButton_OnUpdate
624  
625 TheoryCraft_Data["PaperDollItemSlotButton_OnClick"] = PaperDollItemSlotButton_OnClick
626 PaperDollItemSlotButton_OnClick = TheoryCraft_PaperDollItemSlotButton_OnClick
627  
628 TheoryCraft_Data["InspectPaperDollItemSlotButton_OnClick"] = InspectPaperDollItemSlotButton_OnClick
629 InspectPaperDollItemSlotButton_OnClick = TheoryCraft_InspectPaperDollItemSlotButton_OnClick
630  
631 TheoryCraft_Data["SuperInspect_InspectPaperDollItemSlotButton_OnClick"] = SuperInspect_InspectPaperDollItemSlotButton_OnClick
632 SuperInspect_InspectPaperDollItemSlotButton_OnClick = TheoryCraft_SuperInspect_InspectPaperDollItemSlotButton_OnClick
633  
634 TheoryCraft_Data["ContainerFrameItemButton_OnClick"] = ContainerFrameItemButton_OnClick
635 ContainerFrameItemButton_OnClick = TheoryCraft_ContainerFrameItemButton_OnClick
636  
637 if ISync then
638 TheoryCraft_Data["ISync:ButtonClick"] = ISync.ButtonClick
639 ISync.ButtonClick = TheoryCraft_ISyncButtonClick
640 end
641  
642 if TheoryCraft_OnShow_Save ~= nil then
643 return
644 end
645  
646 --hooking GameTooltip's OnShow
647 TheoryCraft_OnShow_Save = GameTooltip:GetScript("OnShow")
648 GameTooltip:SetScript( "OnShow", TheoryCraft_OnShow )
649 if TheoryCraft_Mitigation == nil then
650 TheoryCraft_Mitigation = {}
651 end
652 if (TheoryCraft_Settings["dataversion"] ~= TheoryCraft_DataVersion) then
653 SetDefaults()
654 end
655 if TheoryCraft_Settings["ColR2"] == nil then
656 TheoryCraft_Settings["buttontextx"] = 1.111
657 TheoryCraft_Settings["buttontexty"] = 10.22
658 TheoryCraft_Settings["ColR"] = 1
659 TheoryCraft_Settings["ColG"] = 1
660 TheoryCraft_Settings["ColB"] = 1
661 TheoryCraft_Settings["ColR2"] = 1
662 TheoryCraft_Settings["ColG2"] = 1
663 TheoryCraft_Settings["ColB2"] = 175/255
664 TheoryCraft_Settings["FontSize"] = 12
665 TheoryCraft_Settings["FontPath"] = "Fonts\\ArialN.TTF"
666 end
667 if TheoryCraftGenBox_Text then TheoryCraftGenBox_Text:SetText(TheoryCraft_Settings["GenerateList"]) end
668 if TheoryCraft_Settings["off"] then
669 Print("TheoryCraft is currently switched off, type in '/tc on' to enabled")
670 end
671 elseif event == "PLAYER_LOGIN" then
672 this:RegisterEvent("ACTIONBAR_PAGE_CHANGED")
673 this:RegisterEvent("ACTIONBAR_SLOT_CHANGED")
674 this:RegisterEvent("SPELLS_CHANGED")
675 this:RegisterEvent("UNIT_AURA")
676 this:RegisterEvent("UNIT_INVENTORY_CHANGED")
677 this:RegisterEvent("PLAYER_TARGET_CHANGED")
678 this:RegisterEvent("UNIT_MANA")
679 this:RegisterEvent("CHARACTER_POINTS_CHANGED")
680 this:RegisterEvent("PLAYER_LEAVING_WORLD")
681 this:RegisterEvent("PLAYER_ENTERING_WORLD")
682 this:RegisterEvent("PLAYER_COMBO_POINTS")
683 this:RegisterEvent("CHAT_MSG_SPELL_SELF_DAMAGE")
684 this:RegisterEvent("PLAYER_REGEN_ENABLED")
685 this:RegisterEvent("CHAT_MSG_SPELL_SELF_BUFF")
686 elseif event == "PLAYER_LEAVING_WORLD" then
687 this:UnregisterEvent("ACTIONBAR_PAGE_CHANGED")
688 this:UnregisterEvent("ACTIONBAR_SLOT_CHANGED")
689 this:UnregisterEvent("SPELLS_CHANGED")
690 this:UnregisterEvent("UNIT_AURA")
691 this:UnregisterEvent("UNIT_INVENTORY_CHANGED")
692 this:UnregisterEvent("PLAYER_TARGET_CHANGED")
693 this:UnregisterEvent("UNIT_MANA")
694 this:UnregisterEvent("CHARACTER_POINTS_CHANGED")
695 this:UnregisterEvent("PLAYER_LEAVING_WORLD")
696 this:UnregisterEvent("PLAYER_COMBO_POINTS")
697 this:UnregisterEvent("CHAT_MSG_SPELL_SELF_DAMAGE")
698 this:UnregisterEvent("PLAYER_REGEN_ENABLED")
699 this:UnregisterEvent("CHAT_MSG_SPELL_SELF_BUFF")
700 elseif event == "PLAYER_ENTERING_WORLD" then
701 TheoryCraft_UpdateTalents(true)
702 TheoryCraft_UpdateGear("player", true)
703 TheoryCraft_UpdateBuffs("player", true)
704 TheoryCraft_UpdateBuffs("target", true)
705 TheoryCraft_LoadStats()
706 TheoryCraft_GenerateAll()
707 this:RegisterEvent("ACTIONBAR_PAGE_CHANGED")
708 this:RegisterEvent("ACTIONBAR_SLOT_CHANGED")
709 this:RegisterEvent("SPELLS_CHANGED")
710 this:RegisterEvent("UNIT_AURA")
711 this:RegisterEvent("UNIT_INVENTORY_CHANGED")
712 this:RegisterEvent("PLAYER_TARGET_CHANGED")
713 this:RegisterEvent("UNIT_MANA")
714 this:RegisterEvent("CHARACTER_POINTS_CHANGED")
715 this:RegisterEvent("PLAYER_LEAVING_WORLD")
716 this:RegisterEvent("PLAYER_COMBO_POINTS")
717 this:RegisterEvent("CHAT_MSG_SPELL_SELF_DAMAGE")
718 this:RegisterEvent("PLAYER_REGEN_ENABLED")
719 this:RegisterEvent("CHAT_MSG_SPELL_SELF_BUFF")
720 elseif event == "CHAT_MSG_SPELL_SELF_DAMAGE" then
721 if TheoryCraft_ParseCombat then
722 TheoryCraft_ParseCombat(arg1)
723 end
724 elseif event == "CHAT_MSG_SPELL_SELF_BUFF" then
725 TheoryCraft_WatchCritRate(arg1)
726 elseif event == "UNIT_INVENTORY_CHANGED" then
727 TheoryCraft_UpdateGear(arg1)
728 elseif event == "PLAYER_REGEN_ENABLED" then
729 if TheoryCraft_Data.regenaftercombat then
730 TheoryCraft_Data.regenaftercombat = nil
731 TheoryCraft_UpdateGear("player", nil, true)
732 end
733 elseif event == "SPELLS_CHANGED" then
734 local autoshotname = TheoryCraft_Locale.SpellTranslator["Auto Shot"]
735 if autoshotname then
736 local olddesc = TheoryCraft_TooltipData[autoshotname.."(0)"]
737 if olddesc then
738 TheoryCraft_TooltipData[autoshotname.."(0)"] = nil
739 TheoryCraft_TooltipData[olddesc] = nil
740 end
741 end
742 TheoryCraft_DeleteTable(TheoryCraft_UpdatedButtons)
743 elseif event == "ACTIONBAR_PAGE_CHANGED" then
744 TheoryCraft_DeleteTable(TheoryCraft_UpdatedButtons)
745 elseif event == "ACTIONBAR_SLOT_CHANGED" then
746 TheoryCraft_DeleteTable(TheoryCraft_UpdatedButtons)
747 elseif event == "UNIT_AURA" then
748 TheoryCraft_UpdateBuffs(arg1)
749 elseif event == "CHARACTER_POINTS_CHANGED" then
750 TheoryCraft_UpdateTalents()
751 elseif event == "PLAYER_TARGET_CHANGED" then
752 TheoryCraft_UpdateTarget()
753 TheoryCraft_UpdateBuffs("target")
754 elseif event == "PLAYER_COMBO_POINTS" then
755 TheoryCraft_DeleteTable(TheoryCraft_UpdatedButtons)
756 elseif (event == "UNIT_MANA") and (arg1 == "player") then
757 if UnitClass("player") == "DRUID" then
758 local _, _, catform = GetShapeshiftFormInfo(3)
759 if catform then
760 TheoryCraft_DeleteTable(TheoryCraft_UpdatedButtons)
761 end
762 end
763 if ((string.find(TheoryCraft_Settings["tryfirst"], "remaining")) or (string.find(TheoryCraft_Settings["trysecond"], "remaining"))) or
764 ((TheoryCraft_Settings["tryfirst"] == "spellcasts") or (TheoryCraft_Settings["trysecond"] == "spellcasts")) then
765 TheoryCraft_DeleteTable(TheoryCraft_UpdatedButtons)
766 end
767 end
768 if TheoryCraft_Settings["showmem"] then
769 Print(event..": "..gcinfo()-UIMem)
770 end
771 end
772  
773 function TheoryCraft_CheckBoxShowDescription(arg1)
774 local name = this:GetName()
775 name = string.sub(name, 12)
776 if (TheoryCraft_CheckButtons[name] == nil) then
777 return
778 end
779 local text = 1
780 if (TheoryCraft_CheckButtons[name].descriptionmelee) and ((class == "ROGUE") or (class == "WARRIOR")) then
781 text = TheoryCraft_CheckButtons[name].descriptionmelee
782 else
783 text = TheoryCraft_CheckButtons[name].description
784 end
785 if string.find(text, "$cr") then
786 text = string.gsub(text, "$cr", round(TheoryCraft_intpercrit(), 2))
787 end
788 GameTooltip_SetDefaultAnchor( GameTooltip, UIParent )
789 if TheoryCraft_CheckButtons[name].tooltiptitle then
790 GameTooltip:AddLine(TheoryCraft_CheckButtons[name].tooltiptitle, 1,1,1)
791 else
792 GameTooltip:AddLine(TheoryCraft_CheckButtons[name].short, 1,1,1)
793 end
794 GameTooltip:AddLine(text, 1,1,0)
795 GameTooltip:Show()
796 end
797  
798 function TheoryCraft_SetCheckBox(variablename)
799 if getglobal("TheoryCraft"..variablename) then
800 getglobal("TheoryCraft"..variablename):SetChecked(TheoryCraft_Settings[variablename])
801 end
802 end
803  
804 function TheoryCraft_CheckBoxSetText(arg1)
805 local name = this:GetName()
806 name = string.sub(name, 12)
807 if TheoryCraft_CheckButtons[name] == nil then return end
808 if TheoryCraft_CheckButtons[name].hide then
809 for k,v in pairs(TheoryCraft_CheckButtons[name].hide) do
810 if (class == v) or ((v == "STRIPPED") and (not TheoryCraft_NotStripped)) then
811 getglobal(this:GetName()):Disable()
812 getglobal(this:GetName().."Text"):SetTextColor(0.5, 0.5, 0.5)
813 end
814 end
815 end
816 getglobal(this:GetName().."Text"):SetText(TheoryCraft_CheckButtons[name].short)
817 end
818  
819 function TheoryCraft_CheckBoxToggle(arg1)
820 local onoff
821 if (this:GetChecked()) then
822 onoff = true
823 end
824 local name = this:GetName()
825 name = string.sub(name, 12)
826 if (name == "embedstyle1") or (name == "embedstyle2") or (name == "embedstyle3") then
827 TheoryCraft_Settings["embedstyle1"] = nil
828 TheoryCraft_Settings["embedstyle2"] = nil
829 TheoryCraft_Settings["embedstyle3"] = nil
830 TheoryCraft_Settings[name] = onoff
831 TheoryCraft_SetCheckBox("embedstyle1")
832 TheoryCraft_SetCheckBox("embedstyle2")
833 TheoryCraft_SetCheckBox("embedstyle3")
834 elseif (name == "alignleft") or (name == "alignright") then
835 TheoryCraft_Settings["alignleft"] = nil
836 TheoryCraft_Settings["alignright"] = nil
837 TheoryCraft_Settings[name] = onoff
838 TheoryCraft_SetCheckBox("alignleft")
839 TheoryCraft_SetCheckBox("alignright")
840 TheoryCraft_UpdateDummyButtonText()
841 elseif name == "useglock" then
842 if (MobResistDB) and (type(MobResistDB) == "table") and (onoff == true) then
843 TheoryCraft_Settings[name] = onoff
844 elseif (not MobResistDB) then
845 TheoryCraft_Settings[name] = nil
846 this:SetChecked(false)
847 Print("GLOCK can be found at Curse Gaming. (TC couldn't find it installed)")
848 end
849 else
850 TheoryCraft_Settings[name] = onoff
851 end
852 if name == "dontresist" then
853 if TheoryCraft_Settings["dontresist"] then
854 TheoryCraftresistArcane:Show()
855 TheoryCraftresistFire:Show()
856 TheoryCraftresistNature:Show()
857 TheoryCraftresistFrost:Show()
858 TheoryCraftresistShadow:Show()
859 TheoryCraftuseglock:Show()
860 else
861 TheoryCraftresistArcane:Hide()
862 TheoryCraftresistFire:Hide()
863 TheoryCraftresistNature:Hide()
864 TheoryCraftresistFrost:Hide()
865 TheoryCraftresistShadow:Hide()
866 TheoryCraftuseglock:Hide()
867 end
868 end
869 if (name == "procs") or (name == "rollignites") or (name == "sepignites") or (name == "combinedot") or (name == "dotoverct") or (name == "dontcrit") then
870 TheoryCraft_GenerateAll()
871 end
872 if (name == "buttontext") or (name == "tryfirstlarge") or (name == "trysecondlarge") or (name == "dontresist") or (name == "useglock") then
873 TheoryCraft_DeleteTable(TheoryCraft_UpdatedButtons)
874 end
875 end
876  
877 function TheoryCraft_Command(cmd)
878 if (cmd == "") then
879 if TheoryCraft_Data["firstrun"] == nil then
880 if TheoryCraft_NotStripped then
881 PanelTemplates_SetNumTabs(TheoryCraft, 3)
882 TheoryCraft.selectedTab=1
883 PanelTemplates_UpdateTabs(TheoryCraft)
884 end
885 end
886 TheoryCraft_Data["firstrun"] = 1
887  
888 TheoryCraft_SetCheckBox("embedstyle1")
889 TheoryCraft_SetCheckBox("embedstyle2")
890 TheoryCraft_SetCheckBox("embedstyle3")
891 TheoryCraft_SetCheckBox("titles")
892 TheoryCraft_SetCheckBox("embed")
893 TheoryCraft_SetCheckBox("crit")
894 TheoryCraft_SetCheckBox("critdam")
895 TheoryCraft_SetCheckBox("sepignite")
896 TheoryCraft_SetCheckBox("rollignites")
897 TheoryCraft_SetCheckBox("dps")
898 TheoryCraft_SetCheckBox("combinedot")
899 TheoryCraft_SetCheckBox("dotoverct")
900 TheoryCraft_SetCheckBox("hps")
901 TheoryCraft_SetCheckBox("dpsdam")
902 TheoryCraft_SetCheckBox("averagedam")
903 TheoryCraft_SetCheckBox("procs")
904 TheoryCraft_SetCheckBox("mitigation")
905 TheoryCraft_SetCheckBox("resists")
906 TheoryCraft_SetCheckBox("averagethreat")
907 TheoryCraft_SetCheckBox("plusdam")
908 TheoryCraft_SetCheckBox("damcoef")
909 TheoryCraft_SetCheckBox("dameff")
910 TheoryCraft_SetCheckBox("damfinal")
911 TheoryCraft_SetCheckBox("healanddamage")
912 TheoryCraft_SetCheckBox("nextagi")
913 TheoryCraft_SetCheckBox("nextstr")
914 TheoryCraft_SetCheckBox("nextcrit")
915 TheoryCraft_SetCheckBox("nexthit")
916 TheoryCraft_SetCheckBox("nextpen")
917 TheoryCraft_SetCheckBox("mana")
918 TheoryCraft_SetCheckBox("dpm")
919 TheoryCraft_SetCheckBox("hpm")
920 TheoryCraft_SetCheckBox("max")
921 TheoryCraft_SetCheckBox("maxevoc")
922 TheoryCraft_SetCheckBox("lifetap")
923 TheoryCraft_SetCheckBox("dontcrit")
924 TheoryCraft_SetCheckBox("dontresist")
925 TheoryCraft_SetCheckBox("useglock")
926 TheoryCraft_SetCheckBox("buttontext")
927 TheoryCraft_SetCheckBox("tryfirstlarge")
928 TheoryCraft_SetCheckBox("trysecondlarge")
929 TheoryCraft_SetCheckBox("framebyframe")
930  
931 TheoryCraftresistArcane:SetText(TheoryCraft_Settings["resistscores"]["Arcane"])
932 TheoryCraftresistFire:SetText(TheoryCraft_Settings["resistscores"]["Fire"])
933 TheoryCraftresistNature:SetText(TheoryCraft_Settings["resistscores"]["Nature"])
934 TheoryCraftresistFrost:SetText(TheoryCraft_Settings["resistscores"]["Frost"])
935 TheoryCraftresistShadow:SetText(TheoryCraft_Settings["resistscores"]["Shadow"])
936  
937 if TheoryCraft_Settings["dontresist"] then
938 TheoryCraftresistArcane:Show()
939 TheoryCraftresistFire:Show()
940 TheoryCraftresistNature:Show()
941 TheoryCraftresistFrost:Show()
942 TheoryCraftresistShadow:Show()
943 TheoryCraftuseglock:Show()
944 else
945 TheoryCraftresistArcane:Hide()
946 TheoryCraftresistFire:Hide()
947 TheoryCraftresistNature:Hide()
948 TheoryCraftresistFrost:Hide()
949 TheoryCraftresistShadow:Hide()
950 TheoryCraftuseglock:Hide()
951 end
952  
953 if (TheoryCraft:IsVisible()) then
954 TheoryCraft:Hide()
955 else
956 if TheoryCraft_UpdateDummyButtonText then TheoryCraft_UpdateDummyButtonText() end
957 TheoryCraft:Show()
958 end
959 end
960 local onoff = nil
961 if strfind(cmd, " ") then
962 onoff = string.sub(cmd, strfind(cmd, " ")+1)
963 cmd = string.sub(cmd, 1, strfind(cmd, " ")-1)
964 end
965 if (cmd == "custom") then
966 local linkid = string.sub(onoff, string.find(onoff, "item:%d+:%d+:%d+:%d+"))
967 TheoryCraft_Settings["CustomOutfitName"] = "Custom"
968 TheoryCraft_AddToCustom(linkid)
969 end
970 if (cmd == "calccrits") then
971 if TheoryCraft_Settings["critchancedata"] == nil then
972 Print("No crits found - this feature works for heals only")
973 return
974 end
975 local _, critrate, int, gear
976 local crittable = {}
977 for k, v in pairs(TheoryCraft_Settings["critchancedata"]) do
978 _, _, int, gear = strfind(k, "(.+):(.+)")
979 if crittable[int] == nil then
980 crittable[int] = {}
981 end
982 critrate = v.crits/v.casts-gear/100
983 crittable[int].casts = v.casts+(crittable[int].casts or 0)
984 crittable[int].critrate = v.casts*(v.crits/v.casts-gear/100)/crittable[int].casts
985 end
986 local minint = 1000
987 local maxint = 0
988 local mincrit = 0
989 local maxcrit = 0
990 for k, v in pairs(crittable) do
991 if (tonumber(k) < minint) and (v.casts > 400) then
992 minint = tonumber(k)
993 mincrit = v.critrate
994 end
995 if (tonumber(k) > maxint) and (v.casts > 400) then
996 maxint = tonumber(k)
997 maxcrit = v.critrate
998 end
999 end
1000 mincrit = mincrit * 100
1001 maxcrit = maxcrit * 100
1002 Print("Int | Casts | Crit Chance")
1003 for k, v in crittable do
1004 Print(k.." | "..v.casts.." | "..round(v.critrate*100,4).."%")
1005 end
1006 if minint == 1000 then
1007 Print("Insufficient data to calculate crit rates")
1008 elseif minint == maxint then
1009 Print("Insufficient range to calculate base crit, assuming 0")
1010 Print("Int Per Crit = "..round(maxint/maxcrit,3))
1011 Print("Base Crit = 0")
1012 else
1013 Print("Using this data:")
1014 Print("Int Per Crit = "..round((maxint-minint)/(maxcrit-mincrit),3))
1015 Print("Base Crit = "..round((mincrit-minint/((maxint-minint)/(maxcrit-mincrit))),3).."%")
1016 end
1017 end
1018 if (cmd == "armor") or (cmd == "playerarmor") then
1019 if onoff == nil then onoff = "" end
1020 onoff = string.upper(onoff)
1021 local test = {}
1022 local i = 1
1023 local ul = UnitLevel("player")
1024 Print(" ")
1025 if cmd == "armor" then
1026 for k, v in pairs(TheoryCraft_MitigationMobs) do
1027 if strfind(string.upper(k), onoff) then
1028 test[i] = round((v[1] / (85 * ul + 400 + v[1]))*100,1).." | "..v[1].." | "..k
1029 i = i + 1
1030 if i > 250 then
1031 Print("Please limit your search - more than 250 mobs were found")
1032 return
1033 end
1034 end
1035 end
1036 Print("DR | Armor | Mob Name")
1037 else
1038 local classname, level, _
1039 for k, v in pairs(TheoryCraft_MitigationPlayers) do
1040 if strfind(string.upper(k), onoff) and strfind(string.upper(k), ":") then
1041 _, _, classname, level = strfind(k, "(.+):(.+)")
1042 test[i] = classname.." | "..level.." | "..v[1].." | "..round((v[1] / (85 * ul + 400 + v[1]))*100,1)
1043 i = i + 1
1044 if i > 250 then
1045 Print("Please limit your search - more than 250 mobs were found")
1046 return
1047 end
1048 end
1049 end
1050 Print(" ")
1051 Print("Class | Lvl | Armor | DR")
1052 table.sort(test)
1053 for k, v in pairs(test) do
1054 Print(v)
1055 end
1056 test = {}
1057 for k, v in pairs(TheoryCraft_MitigationPlayers) do
1058 if strfind(string.upper(k), onoff) and (not strfind(k, ":")) then
1059 test[i] = round((v[1] / (85 * ul + 400 + v[1]))*100,1).." | "..v[1].." | "..k
1060 i = i + 1
1061 if i > 250 then
1062 Print("Please limit your search - more than 250 mobs were found")
1063 return
1064 end
1065 end
1066 end
1067 Print(" ")
1068 Print("DR | Armor | Player Name")
1069 end
1070 table.sort(test)
1071 for k, v in pairs(test) do
1072 Print(v)
1073 end
1074 end
1075 if (cmd == "off") then
1076 Print("TheoryCraft is now switched OFF")
1077 TheoryCraft_Settings["off"] = true
1078 end
1079 if (cmd == "on") then
1080 Print("TheoryCraft is now switched ON")
1081 TheoryCraft_Settings["off"] = nil
1082 end
1083 if (cmd == "more") then
1084 Print("/tc showmem")
1085 Print(" Debug infomation, shows the memory usage (in bytes) as each event occurs")
1086 Print("/tc damtodouble")
1087 Print(" Shows how much +damage/+heal is required to double a spells base damage")
1088 Print("/tc dpsmana")
1089 Print(" Adds a dps/mana field to the tooltip")
1090 Print("/tc armorchanges")
1091 Print(" Prints whenever the armor value of the target changes")
1092 Print("/tc armor (mob name)")
1093 Print(" Prints the mobs armor. Leave blank for all.")
1094 Print("/tc playerarmor (player name, or class)")
1095 Print(" Prints a players armor. Leave blank for all.")
1096 Print("/tc calccrits")
1097 Print(" Shows your actual crit rate, from combat. Only works for healers.")
1098 Print("Macro Tooltips")
1099 Print(" If you name a macro the same as the name of the spell, in the format: Pyroblast(x), where x is the rank (or 0 if N/A), TC will show the correct tooltip. If the spell name does not fit, only use as many characters as can fit without leaving the rank off.")
1100 Print('/script TheoryCraftCast("Greater Heal", 1)')
1101 Print(" Casts the lowest rank Greater Heal that'll bring your target to full health. The 1 represents overheal amount, eg change to 1.2 to attempt to overheal by 20% (to account for damage while casting). Can be used in macros.")
1102 end
1103 if (cmd == "titles") or (cmd == "dpsmana") or (cmd == "damtodouble") or (cmd == "hidecritdata") or (cmd == "dpsdampercent") or (cmd == "armorchanges") or (cmd == "procs") or (cmd == "hideadvanced") or (cmd == "showregenheal") or (cmd == "showregendam") or (cmd == "hpm") or (cmd == "dpm") or (cmd == "dontcritdpm") or (cmd == "dontcrithpm") or (cmd == "nextagi") or (cmd == "nextpen") or (cmd == "embed") or (cmd == "dam") or (cmd == "averagedam") or (cmd == "averagedamnocrit") or (cmd == "crit") or (cmd == "critdam") or (cmd == "sepignite") or (cmd == "rollignites") or (cmd == "dps") or (cmd == "dpsdam") or (cmd == "resists") or (cmd == "timeit") or (cmd == "plusdam") or (cmd == "damcoef") or (cmd == "dameff") or (cmd == "damfinal") or (cmd == "nextcrit") or (cmd == "nexthit") or (cmd == "mana") or (cmd == "max") or (cmd == "maxevoc") or (cmd == "maxtime") or (cmd == "averagethreat") or (cmd == "healanddamage") or (cmd == "lifetap") or (cmd == "showmore") or (cmd == "showmem") then
1104 if (TheoryCraft_Settings[cmd]) then
1105 onoff = nil
1106 else
1107 onoff = true
1108 end
1109 if onoff then
1110 DEFAULT_CHAT_FRAME:AddMessage(cmd.." is now set to 'on'")
1111 else
1112 DEFAULT_CHAT_FRAME:AddMessage(cmd.." is now set to 'off'")
1113 end
1114 TheoryCraft_Settings[cmd] = onoff
1115 end
1116 end
1117  
1118 function TheoryCraft_OutfitChange(arg1)
1119 local id = this:GetName()
1120 local name = this:GetText()
1121 if (id == "TheoryCraftSetToAll") then
1122 TheoryCraftGenBox_Text:SetText("")
1123 local spellname, spellrank
1124 local i, i2 = 1
1125 local first = true
1126 while (true) do
1127 spellname, spellrank = GetSpellName(i,BOOKTYPE_SPELL)
1128 if spellname == nil then break end
1129 spellrank = tonumber(findpattern(spellrank, "%d+"))
1130 if spellrank == nil then spellrank = 0 end
1131 i2 = 1
1132 while (TheoryCraft_Spells[class][i2]) and (spellname ~= TheoryCraft_Spells[class][i2].name) do
1133 i2 = i2 + 1
1134 end
1135 if (TheoryCraft_Spells[class][i2] ~= nil) then
1136 if first then
1137 TheoryCraftGenBox_Text:SetText(spellname.."("..spellrank..")")
1138 first = false
1139 else
1140 TheoryCraftGenBox_Text:SetText(TheoryCraftGenBox_Text:GetText().."\n"..spellname.."("..spellrank..")")
1141 end
1142 end
1143 i = i + 1
1144 end
1145 return
1146 end
1147 if (id == "TheoryCraftGenAll") then
1148 local timer = GetTime()
1149 TheoryCraft_UpdateGear("player", true)
1150 TheoryCraft_LoadStats()
1151 timer = round((GetTime()-timer)*1000)
1152 Print(" ")
1153 Print("TheoryCraft takes: "..timer.."ms to read your gear. This will only occur out of combat, and only when your gear changes.")
1154 TheoryCraft_Data["reporttimes"] = true
1155 TheoryCraft_Data["buttonsgenerated"] = 0
1156 TheoryCraft_Data["timetaken"] = 0
1157 TheoryCraft_GenerateAll()
1158 return
1159 end
1160 if (id == "TheoryCraftResetButton") then
1161 TheoryCraft_Data["outfit"] = 1
1162 local i = 1
1163 while (TheoryCraft_Talents[i]) do
1164 TheoryCraft_Talents[i].forceto = -1
1165 i = i + 1
1166 end
1167 TheoryCraft_UpdateGear("player", true)
1168 TheoryCraft_UpdateTalents(true)
1169 TheoryCraft_LoadStats()
1170 TheoryCraft_GenerateAll()
1171 UIDropDownMenu_SetSelectedID(TheoryCraftoutfit, 1)
1172 TheoryCraftCustomOutfit:Hide()
1173 return
1174 end
1175 if (id == "TheoryCraftClearButton") then
1176 TheoryCraft_Settings["CustomOutfitName"] = "Custom"
1177 TheoryCraft_Settings["CustomOutfit"] = nil
1178 TheoryCraft_UpdateGear("player", true)
1179 TheoryCraft_LoadStats()
1180 TheoryCraft_GenerateAll()
1181 return
1182 end
1183 if (id == "TheoryCraftClose") then
1184 TheoryCraft:Hide()
1185 return
1186 end
1187 if (id == "TheoryCraftEquipTargetButton") then
1188 TheoryCraft_Settings["CustomOutfitName"] = UnitName("target")
1189 TheoryCraft_Settings["CustomOutfit"] = nil
1190 TheoryCraft_Data["outfit"] = 2
1191 TheoryCraft_UpdateGear("player", true)
1192 local i = 20
1193 while i > 0 do
1194 TheoryCraft_AddToCustom(GetInventoryItemLink("target", i))
1195 i=i-1
1196 end
1197 TheoryCraft_UpdateGear("player", true)
1198 TheoryCraft_LoadStats()
1199 TheoryCraft_GenerateAll()
1200 return
1201 end
1202 if (id == "TheoryCraftEquipSelfButton") then
1203 TheoryCraft_Settings["CustomOutfitName"] = "Self"
1204 TheoryCraft_Settings["CustomOutfit"] = nil
1205 TheoryCraft_UpdateGear("player", true)
1206 TheoryCraft_LoadStats()
1207 TheoryCraft_GenerateAll()
1208 TheoryCraft_Data["outfit"] = 2
1209 local i = 20
1210 while i > 0 do
1211 TheoryCraft_AddToCustom(GetInventoryItemLink("player", i))
1212 i=i-1
1213 end
1214 TheoryCraft_UpdateGear("player", true)
1215 TheoryCraft_LoadStats()
1216 TheoryCraft_GenerateAll()
1217 return
1218 end
1219 end
1220  
1221 function TheoryCraft_UpdateEditBox()
1222 local s = string.gsub(this:GetName(), "TheoryCraft", "")
1223 local text = this:GetText()
1224 if s ~= "FontPath" then
1225 if text == "~" and strfind(s, "resist") then
1226 TheoryCraft_Settings["resistscores"][string.gsub(s, "resist", "")] = "~"
1227 TheoryCraft_DeleteTable(TheoryCraft_UpdatedButtons)
1228 return
1229 end
1230 text = tonumber(text)
1231 if text == nil then
1232 if strfind(s, "resist") then
1233 TheoryCraft_Settings["resistscores"][string.gsub(s, "resist", "")] = 0
1234 TheoryCraft_DeleteTable(TheoryCraft_UpdatedButtons)
1235 end
1236 return
1237 end
1238 if strfind(s, "Col") then
1239 if text > 255 then
1240 text = 255
1241 end
1242 if text < 0 then
1243 text = 0
1244 end
1245 text = text/255
1246 end
1247 end
1248 if strfind(s, "resist") then
1249 TheoryCraft_Settings["resistscores"][string.gsub(s, "resist", "")] = text
1250 if TheoryCraft_Settings["dontresist"] then
1251 TheoryCraft_DeleteTable(TheoryCraft_UpdatedButtons)
1252 end
1253 else
1254 TheoryCraft_Settings[s] = text
1255 if TheoryCraft_UpdateDummyButtonText then
1256 TheoryCraft_UpdateDummyButtonText(true)
1257 end
1258 end
1259 end