vanilla-wow-addons – Blame information for rev 1

Subversion Repositories:
Rev:
Rev Author Line No. Line
1 office 1 
2 -- Add the module to the tree
3 local mod = klhtm
4 local me = {}
5 mod.combatparser = me
6  
7 --[[
8 CombatParser.lua
9  
10 This module is the bridge between Regex.lua and Combat.lua. Given a combat log event, it feeds it to the parser.
11 If successful, the parser will return a set of arguments, and an identifier that describes the combat log line, such as "whiteattackhit".
12  
13 CombatParser then works out what to do with the arguments. That is, it massages them into a format for Combat.lua's methods.
14  
15 ]]
16  
17 me.myevents = { "CHAT_MSG_COMBAT_SELF_HITS", "CHAT_MSG_SPELL_DAMAGESHIELDS_ON_SELF", "CHAT_MSG_SPELL_SELF_DAMAGE", "CHAT_MSG_SPELL_PERIODIC_CREATURE_DAMAGE", "CHAT_MSG_SPELL_PERIODIC_FRIENDLYPLAYER_BUFFS", "CHAT_MSG_SPELL_PERIODIC_PARTY_BUFFS", "CHAT_MSG_SPELL_PERIODIC_SELF_BUFFS", "CHAT_MSG_SPELL_SELF_BUFF", "CHAT_MSG_SPELL_CREATURE_VS_SELF_DAMAGE" }
18  
19 -- OnEvent() - called from Core.lua.
20 me.onevent = function()
21  
22 -- This is stage one:
23 local output = mod.regex.parse(me.parserset, arg1, event)
24  
25 if output.hit == nil then
26 return
27 end
28  
29 -- Reset combat args
30 me.action.type = ""
31 me.action.spellname = ""
32 me.action.spellid = ""
33 me.action.damage = 0
34 me.action.target = ""
35 me.action.iscrit = false
36 me.action.spellschool = ""
37  
38 -- check a stage two handler is defined
39 if me.parserstagetwo[output.parser.identifier] == nil then
40 if mod.out.checktrace("error", me, "parser") then
41 mod.out.printtrace(string.format("No handler is defined for a %s parse!", output.parser.identifier))
42 end
43 return
44 end
45  
46 -- run the stage two handler
47 me.parserstagetwo[output.parser.identifier](output.final[1], output.final[2], output.final[3], output.final[4], output.final[5])
48  
49 -- check a stage 3 handler is defined
50 if me.parserstagethree[me.action.type] == nil then
51 if mod.out.checktrace("error", me, "parser") then
52 mod.out.printtrace(string.format("No stage handler is defined for a %s action!", me.action.type))
53 end
54 return
55 end
56  
57 -- run the stage 3 handler
58 me.parserstagethree[me.action.type]()
59  
60 end
61  
62 --[[
63 type can be:
64  
65 attack anything that causes damage
66 heal any source of healing from you
67 powergain you gain x rage / mana / energy
68 nothing actions that don't change threat
69 special non-damaging abilities, e.g. taunt / feint
70  
71 ]]
72  
73 me.action =
74 {
75 type = "",
76 spellname = "",
77 spellid = "",
78 damage = 0,
79 target = "",
80 iscrit = false,
81 spellschool = "",
82 }
83  
84 --[[
85 Combining some parsers is possible. e.g. autoattack hits and crits can go together. Even if in one locale they look completely different, or have different orderings, once they go through stage one they will come out the same. And for an autoattack we don't care whether it's a crit or not (only for abilities, to calculate the rage cost of heroic strike or maul more accurately).
86 ]]
87 me.parserstagetwo =
88 {
89 ["autoattack"] = function(target, damage)
90 me.action.spellid = "whitedamage"
91 me.action.damage = damage
92 me.action.target = target
93 me.action.type = "attack"
94  
95 end,
96  
97 ["damageshield"] = function(damage, school, target)
98 me.action.damage = damage
99 me.action.target = target
100 me.action.spellschool = school
101 me.action.type = "attack"
102 me.action.spellid = "damageshield"
103  
104 end,
105  
106 ["abilityhit"] = function(name, target, damage)
107 me.action.spellname = name
108 me.action.damage = damage
109 me.action.target = target
110 me.action.type = "attack"
111  
112 end,
113  
114 ["abilitycrit"] = function(name, target, damage)
115 me.action.spellname = name
116 me.action.damage = damage
117 me.action.target = target
118 me.action.iscrit = true
119 me.action.type = "attack"
120  
121 end,
122  
123 ["spellhit"] = function(name, target, damage, school)
124 me.action.spellname = name
125 me.action.damage = damage
126 me.action.target = target
127 me.action.spellschool = school
128 me.action.type = "attack"
129  
130 end,
131  
132 ["spellcrit"] = function(name, target, damage, school)
133 me.action.spellname = name
134 me.action.damage = damage
135 me.action.target = target
136 me.action.spellschool = school
137 me.action.iscrit = true
138 me.action.type = "attack"
139  
140 end,
141  
142 ["perform"] = function(name, target)
143 me.action.spellname = name
144 me.action.target = target
145 me.action.type = "special"
146  
147 end,
148  
149 ["spellcast"] = function(name, target)
150 me.action.spellname = name
151 me.action.target = target
152 me.action.type = "special"
153  
154 end,
155  
156 ["othersdotonother"] = function(target, damage, school, author, name)
157 me.action.type = "nothing"
158 if (GetLocale() == "koKR") then
159 local korname = author.."의 "..name
160 if (korname == "어둠의 권능: 고통" or korname == "파멸의 역병" or korname == "정신의 채찍" or
161 korname == "고통의 저주" or korname == "불의 비" or korname == "폭발의 덫" or korname == "제물의 덫") then
162 me.action.spellname = korname
163 me.action.spellid = "dot"
164 me.action.damage = damage
165 me.action.target = target
166 me.action.spellschool = school
167 me.action.type = "attack"
168 end
169 end
170  
171 end,
172  
173 ["dot"] = function(target, damage, school, name)
174 me.action.spellname = name
175 me.action.spellid = "dot"
176 me.action.damage = damage
177 me.action.target = target
178 me.action.spellschool = school
179 me.action.type = "attack"
180  
181 end,
182  
183 ["yourhotonother"] = function(target, damage, name)
184 me.action.spellname = name
185 me.action.damage = damage
186 me.action.target = target
187 me.action.type = "heal"
188  
189 end,
190  
191 -- check that we don't do anything when we get this
192 ["othershotonyou"] = function()
193 me.action.type = "nothing"
194  
195 end,
196  
197 ["othershotonother"] = function()
198 me.action.type = "nothing"
199  
200 end,
201  
202 -- healing on self. Leave target = nil
203 ["hotonself"] = function(damage, name)
204 me.action.spellname = name
205 me.action.damage = damage
206 me.action.type = "heal"
207  
208 end,
209  
210 -- powertype is put in the target section
211 ["powergain"] = function(damage, powertype, name)
212 me.action.spellname = name
213 me.action.damage = damage
214 me.action.target = powertype
215  
216 me.action.type = "powergain"
217  
218 end,
219  
220 ["healonself"] = function(name, damage)
221 me.action.spellname = name
222 me.action.damage = damage
223 me.action.type = "heal"
224  
225 end,
226  
227 ["healonother"] = function(name, target, damage)
228 me.action.spellname = name
229 me.action.damage = damage
230 me.action.target = target
231 me.action.type = "heal"
232  
233 end,
234  
235 }
236  
237 me.parserstagethree =
238 {
239 ["attack"] = function()
240  
241 -- 1) Check for special abilities
242 if me.action.spellid == "" then
243 me.action.spellid = mod.string.unlocalise("spell", me.action.spellname)
244 end
245  
246 if me.action.spellid and mod.data.spells[me.action.spellid] then
247 -- this is a special
248 mod.combat.specialattack(me.action.spellid, me.action.target, me.action.damage, me.action.iscrit, me.action.spellschool)
249  
250 else
251 -- this is a normal attack, or is not modified by threat
252 mod.combat.normalattack(me.action.spellname, me.action.spellid, me.action.damage, nil, me.action.target, me.action.iscrit, me.action.spellschool)
253 end
254  
255 KLHTM_RequestRedraw("self")
256 end,
257  
258 ["heal"] = function()
259 if me.action.target == "" then
260 me.action.target = UnitName("player")
261 end
262  
263 -- check for a spellid
264 me.action.spellid = mod.string.unlocalise("spell", me.action.spellname)
265  
266 mod.combat.possibleoverheal(me.action.spellname, me.action.spellid, me.action.damage, me.action.target)
267  
268 KLHTM_RequestRedraw("self")
269 end,
270  
271 ["nothing"] = function()
272  
273 end,
274  
275 ["powergain"] = function()
276 me.action.spellid = mod.string.unlocalise("spell", me.action.spellname)
277 mod.combat.powergain(me.action.damage, me.action.target, me.action.spellid)
278  
279 KLHTM_RequestRedraw("self")
280 end,
281  
282 ["special"] = function()
283  
284 -- 1) Unlocalise the ability. e.g. "Heroic Strike" -> "heroicstrike", "Heldenhafter Sto\195\159" -> "heroicstrike"
285 me.action.spellid = mod.string.unlocalise("spell", me.action.spellname)
286  
287 -- 2) Taunt / Growl
288 if (me.action.spellid == "taunt") or (me.action.spellid == "growl") then
289 mod.combat.taunt(me.action.target)
290  
291 -- 3) Special Abilities
292 elseif me.action.spellid and mod.data.spells[me.action.spellid] then
293 mod.combat.specialattack(me.action.spellid, me.action.target, 0, nil, nil)
294  
295 -- 4) Unrelated abilities
296 else
297 return
298 end
299  
300 KLHTM_RequestRedraw("self")
301  
302 end,
303  
304 }
305  
306 --[[
307 ------------------------------------------------------------------------------
308 Section B: Creating the Parser Engine at Startup
309 ------------------------------------------------------------------------------
310 ]]
311  
312 me.parserset = { }
313  
314 -- Special OnLoad() method called from Core.lua.
315 me.onload = function()
316  
317 local parserdata
318  
319 for _, parserdata in me.parserconstructor do
320 mod.regex.addparsestring(me.parserset, parserdata[1], parserdata[2], parserdata[3])
321 end
322  
323 end
324  
325 --[[
326 List of all the parsers we use. The first value is the identifier, the second value is the name of the variable
327 defined in GlobalStrings.lua, and the third variable is the event the parser works on.
328 ]]
329 me.parserconstructor =
330 {
331 {"autoattack", "COMBATHITSELFOTHER", "CHAT_MSG_COMBAT_SELF_HITS"}, -- "You hit %s for %d."
332 {"autoattack", "COMBATHITCRITSELFOTHER", "CHAT_MSG_COMBAT_SELF_HITS"}, -- "You crit %s for %d."
333  
334 {"damageshield", "DAMAGESHIELDSELFOTHER", "CHAT_MSG_SPELL_DAMAGESHIELDS_ON_SELF"}, -- "You reflect %d %s damage to %s."
335  
336 {"abilityhit", "SPELLLOGSELFOTHER", "CHAT_MSG_SPELL_SELF_DAMAGE"}, -- "Your %s hits %s for %d."
337 {"abilitycrit", "SPELLLOGCRITSELFOTHER", "CHAT_MSG_SPELL_SELF_DAMAGE"}, -- "Your %s crits %s for %d."
338 {"spellhit", "SPELLLOGSCHOOLSELFOTHER", "CHAT_MSG_SPELL_SELF_DAMAGE"}, -- "Your %s hits %s for %d %s damage."
339 {"spellcrit", "SPELLLOGCRITSCHOOLSELFOTHER", "CHAT_MSG_SPELL_SELF_DAMAGE"}, -- "Your %s crits %s for %d %s damage."
340 {"perform", "SPELLPERFORMGOSELFTARGETTED", "CHAT_MSG_SPELL_SELF_DAMAGE"}, -- "You perform %s on %s."
341 {"spellcast", "SPELLCASTGOSELFTARGETTED", "CHAT_MSG_SPELL_SELF_DAMAGE"}, -- "You cast %s on %s."
342  
343 {"othersdotonother", "PERIODICAURADAMAGEOTHEROTHER", "CHAT_MSG_SPELL_PERIODIC_CREATURE_DAMAGE"}, -- added for korean
344 {"dot", "PERIODICAURADAMAGESELFOTHER", "CHAT_MSG_SPELL_PERIODIC_CREATURE_DAMAGE"}, -- "%s suffers %d %s damage from your %s."
345  
346  
347  
348  
349 {"othershotonother", "PERIODICAURAHEALOTHEROTHER", "CHAT_MSG_SPELL_PERIODIC_FRIENDLYPLAYER_BUFFS"}, -- "%s gains %d health from %s' %s."
350 {"yourhotonother", "PERIODICAURAHEALSELFOTHER", "CHAT_MSG_SPELL_PERIODIC_FRIENDLYPLAYER_BUFFS"}, -- "%s gains %d health from your %s."
351  
352 {"othershotonother", "PERIODICAURAHEALOTHEROTHER", "CHAT_MSG_SPELL_PERIODIC_PARTY_BUFFS"}, -- "%s gains %d health from %s' %s."
353 {"yourhotonother", "PERIODICAURAHEALSELFOTHER", "CHAT_MSG_SPELL_PERIODIC_PARTY_BUFFS"}, -- "%s gains %d health from your %s."
354  
355 {"othershotonyou", "PERIODICAURAHEALOTHERSELF", "CHAT_MSG_SPELL_PERIODIC_SELF_BUFFS"}, -- "You gain %d health from %s's %s."
356 {"othershotonother", "PERIODICAURAHEALOTHEROTHER", "CHAT_MSG_SPELL_PERIODIC_SELF_BUFFS"}, -- "You gain %d health from %s's %s."
357 {"yourhotonother", "PERIODICAURAHEALSELFOTHER", "CHAT_MSG_SPELL_PERIODIC_SELF_BUFFS"}, -- "%s gains %d health from your %s."
358  
359 {"hotonself", "PERIODICAURAHEALSELFSELF", "CHAT_MSG_SPELL_PERIODIC_SELF_BUFFS"},-- "You gain %d health from %s."
360 {"powergain", "POWERGAINSELFSELF", "CHAT_MSG_SPELL_PERIODIC_SELF_BUFFS"}, -- "You gain %d %s from %s."
361  
362 {"healonother", "HEALEDSELFOTHER", "CHAT_MSG_SPELL_SELF_BUFF"}, -- "Your %s heals %s for %d."
363 {"healonother", "HEALEDCRITSELFOTHER", "CHAT_MSG_SPELL_SELF_BUFF"}, -- "Your %s critically heals %s for %d."
364 {"healonself", "HEALEDSELFSELF", "CHAT_MSG_SPELL_SELF_BUFF"}, -- "Your %s heals you for %d."
365 {"healonself", "HEALEDCRITSELFSELF", "CHAT_MSG_SPELL_SELF_BUFF"}, -- "Your %s critically heals you for %d."
366 {"powergain", "POWERGAINSELFSELF", "CHAT_MSG_SPELL_SELF_BUFF"}, -- "You gain %d %s from %s."
367 }