Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ---------
- local session = SuperMeter.Session(true) ---- Current running session
- local range = SuperMeter.Range ---- Table of units flagged as blocked
- local send = SuperMeter.Send ---- Super Meter's message send function
- local sync = SuperMeter.Sync ---- Table of addon sync capable players
- for k,v in pairs(session.units) do
- local unit = (sync[k] and v.player and v.name) ---- Using brakets here means all results must be present, then return the last result, the units name
- if range[k] and unit and (params.caster == player.id or params.target == player.id) and not (event == "absorb") then ---- Using brackets to match true/false
- send(params, event, unit)
- end
- end
- ---------
- function SuperMeter.Send(params, event, unit)
- if not SuperMeter_enabled or params.sync or params.sent or not unit then return end
- if params then params.ability = nil end ---- Remove old unused data
- local debug = SuperMeter.Debug ---- Debug/Callback
- local format = string.format
- local data = {}
- if not data.text then
- data.text = format("<event> <%0s>%0s", event, (data.text or ""))
- end
- for k,v in pairs(params) do
- data.text = format("%0s <%0s> <%0s>", (data.text or ""), k, v)
- end
- if data.text then
- Command.Message.Send(unit, "sync", data.text, debug)
- params.sent = true
- end
- end
- Short output example: "<abilityName> <Shock Pulse> <damage> <5184>" ---- Using <> as a wall function for use later
- ---------
- function SuperMeter.Receive(from, type, channel, identifier, text)
- if not SuperMeter_enabled or not SuperMeter_instance then return end
- if not (identifier == "sync") then return end ---- Match 'Super Meter Sync' via boolean
- local events = {damage = 0, damageAbsorbed = 0, damageAvoided = 0, damageBlocked = 0, damageDeflected = 0, damageIntercepted = 0, damageModified = 0, heal = 0, overheal = 0, overkill = 0} ---- Table of events to id
- local dummy = SuperMeter.Unit(events, "caster") ---- Create a dummy unit for use later
- local session = SuperMeter.Session(true) ---- Current running session
- local gather = SuperMeter.Gather ---- Super Meter's Gathering function
- local format = string.format ---- Its always faster to premap globals, including global functions, first
- local match = string.match
- local find = string.find
- local integer = tonumber
- local sub = string.gsub
- local caster = false
- local target = false
- local event = false
- local data = {}
- ---- Here we simply match the wall (<>) then the data of the next wall, and build an event table with the results
- for k,v in pairs(events) do ---- Match events from the local table with the incomming string
- data[k] = integer(match(text, format("<%0s> <(%%d+)>", k))) ---- Here I defined numbers for a match as well as a string, this includes negative numbers, Returns the result: number or -number
- end
- if not data.abilityName and text then
- data.abilityName = match(text, "<abilityName> <(.-)>") ---- This pattern matches the wall then anything between the next wall, Returns the result: any result
- data.abilityNew = match(text, "<abilityNew> <(.-)>")
- data.casterName = match(text, "<casterName> <(.-)>")
- data.targetName = match(text, "<targetName> <(.-)>")
- data.caster = match(text, "<caster> <(.-)>")
- data.target = match(text, "<target> <(.-)>")
- data.type = match(text, "<type> <(.-)>")
- end
- if data.abilityName and text then
- data.crit = match(text, "<crit> <(true)>")
- data.sync = not not next(data) ---- The event table has fully built and was received
- end
- if not event and text then ---- Do/Dont do is always faster, Tip: everything is a boolean
- caster = (session.units[data.caster] or dummy)
- target = (session.units[data.target] or dummy)
- event = match(text, "<event> <(.-)>")
- end
- if caster and target then ---- Build a table of sync capable players by sending and receiving a message via combat, run only if no errors
- local unit = match(text, "<syncable> <(.-)>")
- if unit and not SuperMeter.Sync[unit] then
- SuperMeter.Sync[unit] = 0
- end
- end
- if caster and target then ---- Gather if no errors
- gather(data, event, caster, target)
- end
- end
- ---------
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement