vanilla-wow-addons – Blame information for rev 1

Subversion Repositories:
Rev:
Rev Author Line No. Line
1 office 1  
2 local mod = klhtm
3 local me = {}
4 local petthreat
5 local petincombat = false
6 mod.pet = me
7  
8 --[[
9 PetMod.lua
10 v1.0 by Ghost, public domain
11  
12 An extension to measure pet threat for warlocks (maybe hunters?) while solo
13 playing. Just proof-of-concept code, based on the klhtm framework for making
14 extensions. It seems to work with DE and EN client voidwalker, on levels 10-60,
15 assuming all books have been bought. Have fun, but don't expect updates :-)
16  
17 Known bugs:
18 -"prin" statements are for debugging purpose only but should not be executed
19 -target of the pet is ignored
20 -pet aggro display is not deleted when pet leaves combat
21 -no talents or whatever are taken into account, only Damage+Torment+Suffering
22 -no character can use the name Pet
23 ]]
24  
25  
26 ------------------------------------------------------------------------
27 -- Aggro for Warlocks Voidwalker --
28 ------------------------------------------------------------------------
29  
30 me.myevents = { "CHAT_MSG_SPELL_PET_DAMAGE", "CHAT_MSG_COMBAT_PET_HITS", "CHAT_MSG_COMBAT_HOSTILE_DEATH", "PET_ATTACK_START"}
31  
32 --[[
33 onupdate() function, called from Core.lua
34 ]]
35 me.onupdate = function()
36 -- update combat state
37 if UnitAffectingCombat("pet") then
38 if petincombat == false then
39 petincombat = true
40 end
41 else
42 if petincombat == true then
43 petincombat = false
44 mod.table.raiddata[UnitName("pet")] = nil
45 KLHTM_RequestRedraw("raid")
46 end
47 end
48 end
49  
50 me.onevent = function()
51  
52 --prin(string.format("Received the event %s: %s", event, arg1))
53  
54 -- if (mod.my.states.incombat.value == false) then
55 -- mod.table.raiddata["Pet"] = nil
56 -- end
57  
58 -- This is stage one:
59 local output = mod.regex.parse(me.parserset, arg1, event)
60  
61 if output.hit == nil then
62 return
63 end
64  
65 if output.final[1] ~= UnitName("pet") then
66 return
67 end
68  
69  
70 if output.parser.identifier == "petattack" then
71 me.addpetthreat(output.final[3])
72 elseif output.parser.identifier == "petcastaggro" then
73 if me.getenglishspell(output.final[2]) == "Torment" then
74 me.addpetthreat(me.getthreatvalue(output.final[2]))
75 elseif me.getenglishspell(output.final[2]) == "Suffering" then
76 if UnitName("target") == output.final[3] then
77 me.addpetthreat(me.getthreatvalue(output.final[2]))
78 end
79 elseif me.getenglishspell(output.final[2]) == "Growl" then
80 me.addpetthreat(me.getthreatvalue(output.final[2]))
81 elseif me.getenglishspell(output.final[2]) == "Intimidation" then
82 me.addpetthreat(me.getthreatvalue(output.final[2]),True)
83 end
84 elseif output.parser.identifier == "petspell" then
85 me.addpetthreat(output.final[4])
86 end
87  
88 end
89  
90 --me.onloadcomplete = function()
91 -- prin("KTM PetMod loaded!!")
92 --end
93  
94 -- show pet threat value in raid display
95 me.addpetthreat = function(value)
96 -- if not value then prin("no pet threat value to add"); return; end
97 if mod.table.raiddata[UnitName("pet")] == nil then
98 petthreat = 0
99 end
100  
101 petthreat = petthreat + value
102 mod.table.updateplayerthreat(UnitName("pet"), petthreat)
103 KLHTM_RequestRedraw("raid")
104 return
105 end
106  
107 ---- BEGIN spell data
108 -- minimum player level for each rank
109 local spellaggrolevel = {
110 ["Torment"] = {
111 60, 50, 40, 30, 20, 10
112 },
113 ["Suffering"] = {
114 60, 48, 36, 24
115 },
116 ["Growl"] = {
117 60, 50, 40, 30, 20, 10, 1
118 },
119 ["Intimidation"] = {
120 1
121 }
122 }
123 -- aggro value for each rank
124 local spellaggro = {
125 ["Torment"] = {
126 395, 300, 215, 125, 75, 45
127 },
128 ["Suffering"] = {
129 600, 450, 300, 150
130 },
131 ["Growl"] = {
132 415, 320, 240, 170, 110, 65, 50
133 },
134 ["Intimidation"] = {
135 580
136 }
137 }
138  
139 me.getthreatvalue = function(spellname)
140 spellname = me.getenglishspell(spellname)
141 if not spellaggrolevel[spellname] then prin("key not found in spelldata "..spellname); return 0; end
142 local i = 1
143 while UnitLevel('pet') < spellaggrolevel[spellname][i] do
144 i = i + 1
145 end
146 return spellaggro[spellname][i]
147 end
148  
149 me.getenglishspell = function(spellname)
150 -- translate localised spell name to english version, to match spellaggro data above
151 if GetLocale() == "deDE" then
152 if spellname == "Qual" then return "Torment"
153 elseif spellname == "Leiden" then return "Suffering"
154 -- additional translations could be added
155 end
156 end
157 if GetLocale() == "koKR" then
158 if spellname == "고문" then return "Torment"
159 elseif spellname == "고통" then return "Suffering"
160 elseif spellname == "포효" then return "Growl"
161 elseif spellname == "위협" then return "Intimidation"
162 -- additional translations could be added
163 end
164 end
165 return spellname
166 end
167 ---- END spell data
168  
169 me.parserset = { }
170 me.onload = function()
171  
172 local parserdata
173  
174 for _, parserdata in me.parserconstructor do
175 mod.regex.addparsestring(me.parserset, parserdata[1], parserdata[2], parserdata[3])
176 end
177  
178 end
179  
180 --[[
181 List of all the parsers we use. The first value is the identifier, the second value is the name of the variable
182 defined in GlobalStrings.lua, and the third variable is the event the parser works on.
183 ]]
184 me.parserconstructor =
185 {
186 {"petcastaggro", "SPELLCASTGOOTHERTARGETTED", "CHAT_MSG_SPELL_PET_DAMAGE"}, -- %1$s wirkt %2$s auf %3$s. "You hit %s for %d."
187 {"petcastaggro", "SIMPLECASTOTHEROTHER", "CHAT_MSG_SPELL_PET_DAMAGE"},
188  
189 {"petattack", "COMBATHITCRITOTHEROTHER", "CHAT_MSG_COMBAT_PET_HITS"}, -- %1$s trifft %2$s fA¼r %3$d Schaden. "You crit %s for %d."
190 {"petattack", "COMBATHITOTHEROTHER", "CHAT_MSG_COMBAT_PET_HITS"}, -- %1$s trifft %2$s fA¼r %3$d Schaden. "You crit %s for %d."
191  
192 {"petspell", "SPELLLOGCRITSCHOOLOTHEROTHER", "CHAT_MSG_SPELL_PET_DAMAGE"}, -- "%ss %s trifft %s kritisch fA¼r %d %s Schaden."
193 {"petspell", "SPELLLOGSCHOOLOTHEROTHER", "CHAT_MSG_SPELL_PET_DAMAGE"},
194  
195 {"petspell", "SPELLLOGOTHEROTHER", "CHAT_MSG_SPELL_PET_DAMAGE"}, -- "%ss %s trifft %s kritisch fA¼r %d %s Schaden."
196 {"petspell", "SPELLLOGCRITOTHEROTHER", "CHAT_MSG_SPELL_PET_DAMAGE"},
197  
198 -- {"abilityhit", "SPELLLOGSELFOTHER", "CHAT_MSG_SPELL_SELF_DAMAGE"}, -- "Your %s hits %s for %d."
199 -- {"abilitycrit", "SPELLLOGCRITSELFOTHER", "CHAT_MSG_SPELL_SELF_DAMAGE"}, -- "Your %s crits %s for %d."
200 }
201  
202