Johnny C. Lam [05-21-13 - 05:11]
diff --git a/Ovale.toc b/Ovale.toc
index 08aa0bf..92cccbd 100644
--- a/Ovale.toc
+++ b/Ovale.toc
@@ -40,8 +40,7 @@ OvalePool.lua
OvaleRecount.lua
OvaleSkada.lua
OvaleStance.lua
-
-# First tier of modules with dependencies
+#
OvaleData.lua
OvaleScripts.lua
defaut\Chaman.lua
@@ -57,22 +56,21 @@ defaut\Moine.lua
defaut\Chevalier.lua
OvaleSpellDamage.lua
OvaleSwing.lua
-
-# Second tier of modules with dependencies
+#
OvaleAura.lua
OvaleComboPoints.lua
+#
OvaleFuture.lua
+#
+OvaleDamageTaken.lua
OvaleState.lua
-
-# Third tier of modules with dependencies
+#
OvaleCondition.lua
OvaleOptions.lua
-
-# Fourth tier of modules with dependencies
+#
OvaleBestAction.lua
OvaleCompile.lua
OvaleIcone.lua
OvaleIcone.xml
-# Fifth tier of modules with dependencies
OvaleFrame.lua
diff --git a/OvaleDamageTaken.lua b/OvaleDamageTaken.lua
new file mode 100644
index 0000000..b344318
--- /dev/null
+++ b/OvaleDamageTaken.lua
@@ -0,0 +1,118 @@
+--[[--------------------------------------------------------------------
+ Ovale Spell Priority
+ Copyright (C) 2013 Johnny C. Lam
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License in the LICENSE
+ file accompanying this program.
+----------------------------------------------------------------------]]
+
+-- This addon tracks the damage taken by the player from non-player sources.
+
+local _, Ovale = ...
+local OvaleDamageTaken = Ovale:NewModule("OvaleDamageTaken", "AceEvent-3.0")
+Ovale.OvaleDamageTaken = OvaleDamageTaken
+
+--<private-static-properties>
+local OvaleDeque = Ovale.OvaleDeque
+local OvaleGUID = Ovale.OvaleGUID
+local OvaleFuture = Ovale.OvaleFuture
+local OvalePool = Ovale.OvalePool
+
+local select = select
+
+-- Player's GUID.
+local self_player_guid = nil
+-- Damage event pool.
+local self_pool = OvalePool:NewPool("OvaleDamageTaken_pool")
+-- Damage event queue: new events are inserted at the front of the queue.
+local self_damageEvent = OvaleDeque:New("OvaleDamageTaken_damageEvent")
+-- Time window (past number of seconds) for which damage events are stored.
+local DAMAGE_TAKEN_WINDOW = 20
+
+local OVALE_DAMAGE_TAKEN_DEBUG = "damage_taken"
+--</private-static-properties>
+
+--<private-static-methods>
+local function AddDamageTaken(timestamp, damage)
+ local self = OvaleDamageTaken
+ local event = self_pool:Get()
+ event.timestamp = timestamp
+ event.damage = damage
+ self_damageEvent:InsertFront(event)
+ self:RemoveExpiredEvents()
+end
+--</private-static-methods>
+
+--<public-static-methods>
+function OvaleDamageTaken:OnEnable()
+ self_player_guid = OvaleGUID:GetGUID("player")
+ self:RegisterEvent("COMBAT_LOG_EVENT_UNFILTERED")
+ self:RegisterEvent("PLAYER_REGEN_ENABLED")
+end
+
+function OvaleDamageTaken:OnDisable()
+ self:UnregisterEvent("COMBAT_LOG_EVENT_UNFILTERED")
+ self:UnregisterEvent("PLAYER_REGEN_ENABLED")
+end
+
+function OvaleDamageTaken:COMBAT_LOG_EVENT_UNFILTERED(event, ...)
+ local timestamp, event, hideCaster, sourceGUID, sourceName, sourceFlags, sourceRaidFlags, destGUID, destName, destFlags, destRaidFlags = select(1, ...)
+ if destGUID == self_player_guid and event:find("_DAMAGE") then
+ if event:find("SWING_") == 1 then
+ local amount, overkill, school, resisted, blocked, absorbed, critical, glancing, crushing = select(12, ...)
+ Ovale:DebugPrintf(OVALE_DAMAGE_TAKEN_DEBUG, "%s caused %d damage.", event, amount)
+ AddDamageTaken(Ovale.now, amount)
+ elseif event:find("RANGE_") == 1 or event:find("SPELL_") == 1 then
+ local spellId, spellName, spellSchool = select(12, ...)
+ local amount, overkill, school, resisted, blocked, absorbed, critical, glancing, crushing = select(15, ...)
+ Ovale:DebugPrintf(OVALE_DAMAGE_TAKEN_DEBUG, "%s (%s) caused %d damage.", event, spellName, amount)
+ AddDamageTaken(Ovale.now, amount)
+ end
+ end
+end
+
+function OvaleDamageTaken:PLAYER_REGEN_ENABLED(event)
+ self_pool:Drain()
+end
+
+-- Return the total damage taken in the previous time interval (in seconds).
+function OvaleDamageTaken:GetRecentDamage(interval, lagCorrection)
+ local lowerBound = Ovale.now - interval
+ if lagCorrection then
+ lowerBound = lowerBound - OvaleFuture.latency
+ end
+ self:RemoveExpiredEvents()
+
+ local total = 0
+ for i, event in self_damageEvent:FrontToBackIterator() do
+ if event.timestamp < lowerBound then
+ break
+ end
+ total = total + event.damage
+ end
+ return total
+end
+
+function OvaleDamageTaken:RemoveExpiredEvents()
+ local now = Ovale.now
+ while true do
+ local event = self_damageEvent:Back()
+ if not event then break end
+ if event then
+ if now - event.timestamp < DAMAGE_TAKEN_WINDOW then
+ break
+ end
+ self_damageEvent:RemoveBack()
+ self_pool:Release(event)
+ end
+ end
+end
+
+function OvaleDamageTaken:Debug()
+ self_damageEvent:Debug()
+ for i, event in self_damageEvent:BackToFrontIterator() do
+ Ovale:FormatPrint("%d: %d damage", event.timestamp, event.damage)
+ end
+end
+--</public-static-methods>
diff --git a/OvaleOptions.lua b/OvaleOptions.lua
index b0c6179..dd71003 100644
--- a/OvaleOptions.lua
+++ b/OvaleOptions.lua
@@ -407,6 +407,12 @@ local self_options =
desc = L["Debug compile"],
type = "toggle",
},
+ damage_taken =
+ {
+ name = "Damage taken",
+ desc = L["Debug damage taken"],
+ type = "toggle",
+ },
enemy =
{
name = "Enemies",