WoWInterface

WoWInterface (https://www.wowinterface.com/forums/index.php)
-   Lua/XML Help (https://www.wowinterface.com/forums/forumdisplay.php?f=16)
-   -   Tracking debuffs on multiple units affected by AoE spells (https://www.wowinterface.com/forums/showthread.php?t=57872)

FranekW 03-11-20 05:23 AM

Tracking debuffs on multiple units affected by AoE spells
 
Hello,

What would be the best way to track multiple targets affected by multiple AoE spells?

Each AoE spell applies the same debuff to all units within the area of effect e.g. Druid Feral's Thrash is a multitarget spell which doesn't need a valid single target but applies DoTs to all non-friendly units including invisible units. Similarly, Primal Wrath does the same with a different debuff.

I made a simple function with Thrash. It is logged by CLEU using subevents such as "SPELL_DAMAGE", "SPELL_CAST_SUCCESS", "SPELL_CAST_FAILED", etc. I tried the following code:

Lua Code:
  1. -- spellID, sourceGUID etc. comes from CLEU
  2.  
  3. if sourceGUID ~= UnitGUID("player") then return end
  4.  
  5. -- Thrash spellID: 106830
  6. if subevent == "SPELL_CAST_SUCCESS" and spellID == 106830 then
  7.     local spellName = GetSpellInfo(spellID)
  8.     for i = 1,40 do
  9.         local unit = "nameplate"..i
  10.         if UnitExists(unit)
  11.                 and not UnitIsFriend("player", unit)
  12.                 and IsSpellInRange(spellName, unit) then
  13.             tinsert(auratable.targets, UnitGUID(unit))
  14.         end
  15.     end
  16.     ViragDevTool_AddData(auratable.targets, "Encounter"..encounter)
  17.     auratable.encounter = auratable.encounter + 1
  18. end

but the table auratable.targets is empty after each combat session.

I thought about catching the "UNIT_AURA" event and if a nameplate gains a debuff but having to test 40 units and checking 40 indices of possible debuff per unit each time I apply one of the AoE spells seems like a lot of loops to do.

jeruku 03-11-20 09:37 AM

The IDs referenced in the CLEU are GUIDs. Any ID used for a unit frame is a Unit ID(or token) which normally refers to a frame that can be referenced, or created securely.

You can cache the GUIDs when nameplates are added/removed and use those to check applicable units in the CLEU so you can avoid multiplicative aura scans, especially if you'd be scanning nameplates and raid frames.

Performance tip: Cache the player GUID in the frame your using for the CLEU event and put the IF statements inside the player check.
Lua Code:
  1. frame.playerGUID = UnitGUID('player')
  2. frame.AuraList = { -- skip this if you're not planning on adding more de/buffs
  3.     106830 = true,
  4. }
  5.  
  6. -- CLEU code with assuming your function is passed the frame as self
  7. if sourceGUID == self.playerGUID then
  8.    if subevent == "SPELL_CAST_SUCCESS" and frame.AuraList[spellList] then
  9.        -- some more code
  10.    end
  11. end

Seerah 03-11-20 11:36 AM

And move that player GUID check outside of your OnEvent function. You should just need to grab it once.

FranekW 03-12-20 05:54 AM

First of all, thanks for the performance tip.

Second, I should have mentioned that the function is a part of a lua code inside WeakAuras. I don't fully understand the bit with frame reference. I think you are just pointing out the difference between UnitID related to a frame and unitGUID in CLEU. If I query a unit using `UnitGUID` I should get the unit's GUID. Is that correct?

Regarding the second point, is my approach with for loop good enough for adding / removing nameplates from cache? I am thinking about something like event where a player gets new nameplate etc.

Thanks.


All times are GMT -6. The time now is 02:15 AM.

vBulletin © 2020, Jelsoft Enterprises Ltd
© 2004 - 2020 MMOUI