View Single Post
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