Advertisement
Guest User

Super Meter Raid Sync

a guest
Oct 20th, 2013
52
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 4.11 KB | None | 0 0
  1. ---------
  2.  
  3.     local session = SuperMeter.Session(true) ---- Current running session
  4.     local range = SuperMeter.Range ---- Table of units flagged as blocked
  5.     local send = SuperMeter.Send ---- Super Meter's message send function
  6.     local sync = SuperMeter.Sync ---- Table of addon sync capable players
  7.  
  8.     for k,v in pairs(session.units) do
  9.         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
  10.         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
  11.             send(params, event, unit)
  12.         end
  13.     end
  14.  
  15. ---------
  16.  
  17. function SuperMeter.Send(params, event, unit)
  18.     if not SuperMeter_enabled or params.sync or params.sent or not unit then return end
  19.     if params then params.ability = nil end ---- Remove old unused data
  20.  
  21.     local debug = SuperMeter.Debug ---- Debug/Callback
  22.     local format = string.format
  23.  
  24.     local data = {}
  25.  
  26.     if not data.text then
  27.         data.text = format("<event> <%0s>%0s", event, (data.text or ""))
  28.     end
  29.  
  30.     for k,v in pairs(params) do
  31.         data.text = format("%0s <%0s> <%0s>", (data.text or ""), k, v)
  32.     end
  33.  
  34.     if data.text then
  35.         Command.Message.Send(unit, "sync", data.text, debug)
  36.         params.sent = true
  37.     end
  38. end
  39.  
  40. Short output example: "<abilityName> <Shock Pulse> <damage> <5184>" ---- Using <> as a wall function for use later
  41.  
  42. ---------
  43.  
  44. function SuperMeter.Receive(from, type, channel, identifier, text)
  45.     if not SuperMeter_enabled or not SuperMeter_instance then return end
  46.     if not (identifier == "sync") then return end ---- Match 'Super Meter Sync' via boolean
  47.  
  48.     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
  49.  
  50.     local dummy = SuperMeter.Unit(events, "caster") ---- Create a dummy unit for use later
  51.     local session = SuperMeter.Session(true) ---- Current running session
  52.     local gather = SuperMeter.Gather ---- Super Meter's Gathering function
  53.  
  54.     local format = string.format ---- Its always faster to premap globals, including global functions, first
  55.     local match = string.match
  56.     local find = string.find
  57.     local integer = tonumber
  58.     local sub = string.gsub
  59.  
  60.     local caster = false
  61.     local target = false
  62.     local event = false
  63.  
  64.     local data = {}
  65.  
  66.     ---- Here we simply match the wall (<>) then the data of the next wall, and build an event table with the results
  67.  
  68.     for k,v in pairs(events) do ---- Match events from the local table with the incomming string
  69.         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
  70.     end
  71.  
  72.     if not data.abilityName and text then
  73.         data.abilityName = match(text, "<abilityName> <(.-)>") ---- This pattern matches the wall then anything between the next wall, Returns the result: any result
  74.         data.abilityNew = match(text, "<abilityNew> <(.-)>")
  75.         data.casterName = match(text, "<casterName> <(.-)>")
  76.         data.targetName = match(text, "<targetName> <(.-)>")
  77.         data.caster = match(text, "<caster> <(.-)>")
  78.         data.target = match(text, "<target> <(.-)>")
  79.         data.type = match(text, "<type> <(.-)>")
  80.     end
  81.  
  82.     if data.abilityName and text then
  83.         data.crit = match(text, "<crit> <(true)>")
  84.         data.sync = not not next(data) ---- The event table has fully built and was received
  85.     end
  86.  
  87.     if not event and text then ---- Do/Dont do is always faster, Tip: everything is a boolean
  88.         caster = (session.units[data.caster] or dummy)
  89.         target = (session.units[data.target] or dummy)
  90.         event = match(text, "<event> <(.-)>")
  91.     end
  92.  
  93.     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
  94.         local unit = match(text, "<syncable> <(.-)>")
  95.         if unit and not SuperMeter.Sync[unit] then
  96.             SuperMeter.Sync[unit] = 0
  97.         end
  98.     end
  99.  
  100.     if caster and target then ---- Gather if no errors
  101.         gather(data, event, caster, target)
  102.     end
  103. end
  104.  
  105. ---------
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement