Quantcast
Average damage taken within time period - WoWInterface
Thread Tools Display Modes
08-04-16, 03:12 AM   #1
ZikO
An Aku'mai Servant
Join Date: Jun 2008
Posts: 36
Average damage taken within time period

Hello,

I am trying to calculate an average damage taken within last 5 secs.

The reason for that is I have a Blood DK. The new Death Strike ability can heal me by 20% of amount of damage taken within last 5 secs. That's what it says.


So I would like to do an extra progress bar in Weak Aura 2. Right after I start combat, the bar should start progressing from 0% to 100% and would have text stating an approximation of amount of healing calculated from average damage taken.

After using Death Strike, I would like the progress bar to get empty and begin to fill up (like progress bar) up to 100% within 5 secs when Death Strike has been used. Also, if I use DS withing the period of 5 secs, the bar should get empty and start progressing again.

The main problem I have is I don't know which event I should look for. Is it COPMBAT_LOG_UNFILTERED or anything that triggers when my health bar is reduced?
  Reply With Quote
08-04-16, 12:33 PM   #2
Seerah
Fishing Trainer
 
Seerah's Avatar
WoWInterface Super Mod
Featured
Join Date: Oct 2006
Posts: 10,765
UNIT_HEALTH http://wowprogramming.com/docs/events/UNIT_HEALTH
(or UNIT_HEALTH_FREQUENT)

Also, what would the 100% be of?
__________________
"You'd be surprised how many people violate this simple principle every day of their lives and try to fit square pegs into round holes, ignoring the clear reality that Things Are As They Are." -Benjamin Hoff, The Tao of Pooh

  Reply With Quote
08-04-16, 01:15 PM   #3
ZikO
An Aku'mai Servant
Join Date: Jun 2008
Posts: 36
Originally Posted by Seerah View Post
UNIT_HEALTH http://wowprogramming.com/docs/events/UNIT_HEALTH
(or UNIT_HEALTH_FREQUENT)

Also, what would the 100% be of?
Thanks

It's just a thing with a progress bar which would increase from 0% (Ds is used) to 100% (5 secs passed). 100 % would mean I would potentially benefit from Death Strike in maximal way. Also, I'd prefer progress bars from icons.
  Reply With Quote
08-04-16, 02:55 PM   #4
Kanegasi
A Molten Giant
 
Kanegasi's Avatar
AddOn Author - Click to view addons
Join Date: Apr 2007
Posts: 506
I don't think Death Strike cuts you off from healing already given. If you DS 2 seconds after a DS, both will still give healing based on the 5 seconds of previous damage, even if you were already healed based on the overlapping 3 seconds.
  Reply With Quote
08-04-16, 08:28 PM   #5
Phanx
Cat.
 
Phanx's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2006
Posts: 5,617
I'm also pretty sure (I don't play a DK, but the tooltip wording seems pretty clear, especially considering how other abilities with similar wording work or have worked) that it's a sliding 5-second window. It doesn't reset to zero every 5 seconds. It just keeps a rolling record of all the damage you take, so that at any given moment, it can calculate how much damage you took between "now" and "5 seconds before now".

That said, UNIT_HEALTH isn't what you want here, because not every health change -- not even every health reduction -- is due to taking damage. You'd need to watch COMBAT_LOG_EVENT_UNFILTERED for all the damage sub-events: SWING_DAMAGE (melee auto attacks), RANGE_DAMAGE (ranged auto attacks), SPELL_DAMAGE (non-dot spells), SPELL_PERIODIC_DAMAGE (dots), and ENVIRONMENTAL_DAMAGE (falling, lava, etc) if that counts. In all of those cases, the target's GUID is arg8 (match it against the player's GUID to detect damage you took) and the amount of damage taken is arg15.

Not tested at all, and not related to WeakAuras, but may give you an idea of what kind of code is needed:

lua Code:
  1. local playerGUID
  2. local damageAmounts, damageTimestamps = {}, {}
  3. local damageInLast5Seconds = 0
  4.  
  5. local f = CreateFrame("Frame")
  6. f:RegisterEvent("PLAYER_LOGIN")
  7. f:SetScript("OnEvent", function(self, event)
  8.     playerGUID = UnitGUID("player")
  9.     self:RegisterEvent("COMBAT_LOG_EVENT_UNFILTERED")
  10.     self:SetScript("OnEvent", function(_, _, timestamp, event, _, _, _, _, _, destGUID, _, _, _, ...)
  11.         if destGUID ~= playerGUID then return end
  12.         local amount
  13.         if event == "SPELL_DAMAGE" or event == "SPELL_PERIODIC_DAMAGE" or event == "RANGE_DAMAGE" then
  14.             _, _, _, amount = ...
  15.         elseif event == "SWING_DAMAGE" then
  16.             amount = ...
  17.         elseif event == "ENVIRONMENTAL_DAMAGE" then
  18.             _, amount = ...
  19.         end
  20.         if amount then
  21.             -- Record new damage at the top of the log:
  22.             tinsert(damageAmounts, 1, amount)
  23.             tinsert(damageTimestamps, 1, timestamp)
  24.             -- Clear out old entries from the bottom, and add up the remaining ones:
  25.             local cutoff = timestamp - 5
  26.             damageInLast5Seconds = 0
  27.             for i = #damageTimestamps, 1, -1 do
  28.                 local timestamp = damageTimestamps[i]
  29.                 if timestamp < cutoff then
  30.                     damageTimestamps[i] = nil
  31.                     damageAmounts[i] = nil
  32.                 else
  33.                     damageInLast5Seconds = damageInLast5Seconds + damageAmounts[i]
  34.                 end
  35.             end
  36.         end
  37.     end)
  38. end)

Then at any given moment the amount of healing you'll get from Heart Strike can be calculated as:

lua Code:
  1. -- Calculate 20% of damage taken in the last 5 seconds:
  2. local healingFromDamage = damageInLast5Seconds * 0.2
  3. -- Calculate 10% of your maximum health:
  4. local minimumHealing = UnitHealthMax("player") * 0.1
  5. -- Take the larger of the two values:
  6. local actualHealing = math.max(healingFromDamage, minimumHealing)
  7. print("Heart Strike will heal you for " .. actualHealing)
__________________
Retired author of too many addons.
Message me if you're interested in taking over one of my addons.
Donít message me about addon bugs or programming questions.
  Reply With Quote
08-06-16, 06:04 PM   #6
ZikO
An Aku'mai Servant
Join Date: Jun 2008
Posts: 36
Thanks very much for the responses. I also appreciate the example code. It will definitely help me to kick off. Thanks


PS. I wasn't sure about Death Strike. I considered that it would be a moving 5 secs window but I was not sure about it. Thanks.
  Reply With Quote

WoWInterface » AddOns, Compilations, Macros » AddOn Help/Support » Average damage taken within time period

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off