From 67fd26a719563ebaca95d2d05e5c05ba9a8d5f17 Mon Sep 17 00:00:00 2001 From: "Johnny C. Lam" Date: Wed, 27 Nov 2013 14:04:36 +0000 Subject: [PATCH] Fix BuffStealable script condition. Implement GetStealable(unitId) as a state machine mix-in method. git-svn-id: svn://svn.curseforge.net/wow/ovale/mainline/trunk@1225 d5049fe3-3747-40f7-a4b5-f36d6801af5f --- OvaleAura.lua | 41 +++++++++++++++++++++++++++++++++++++++++ conditions/BuffStealable.lua | 10 +++++++--- 2 files changed, 48 insertions(+), 3 deletions(-) diff --git a/OvaleAura.lua b/OvaleAura.lua index 0563359..a01608f 100644 --- a/OvaleAura.lua +++ b/OvaleAura.lua @@ -832,6 +832,47 @@ statePrototype.AddAuraToGUID = function(state, guid, auraId, casterGUID, filter, return aura end +statePrototype.GetStealable = function(state, unitId) + local count = 0 + local start, ending = math.huge, 0 + local guid = OvaleGUID:GetGUID(unitId) + local now = state.currentTime + + -- Loop through auras not kept in the simulator that match the criteria. + if self_aura[guid] then + for auraId, whoseTable in pairs(self_aura[guid]) do + for casterGUID in pairs(whoseTable) do + local aura = GetStateAura(state, guid, auraId, self_guid) + if state:IsActiveAura(aura, now) and not aura.state then + if aura.stealable and aura.filter == "HELPFUL" then + count = count + 1 + start = (aura.start < start) and aura.start or start + ending = (aura.ending > ending) and aura.ending or ending + end + end + end + end + end + -- Loop through auras in the simulator that match the criteria. + if state.aura[guid] then + for auraId, whoseTable in pairs(state.aura[guid]) do + for casterGUID, aura in pairs(whoseTable) do + if state:IsActiveAura(aura, now) then + if aura.stealable and aura.filter == "HELPFUL" then + count = count + 1 + start = (aura.start < start) and aura.start or start + ending = (aura.ending > ending) and aura.ending or ending + end + end + end + end + end + if count > 0 then + return count, start, ending + end + return nil +end + do -- The total count of the matched aura. local count diff --git a/conditions/BuffStealable.lua b/conditions/BuffStealable.lua index 57c5b0f..3821589 100644 --- a/conditions/BuffStealable.lua +++ b/conditions/BuffStealable.lua @@ -11,9 +11,10 @@ local _, Ovale = ... do local OvaleCondition = Ovale.OvaleCondition - local OvaleAura = Ovale.OvaleAura + local OvaleState = Ovale.OvaleState local ParseCondition = OvaleCondition.ParseCondition + local state = OvaleState.state --- Test if there is a stealable buff on the target. -- @name BuffStealable @@ -27,9 +28,12 @@ do -- Spell(spellsteal) local function BuffStealable(condition) - -- TODO: This should really be checked only against OvaleState. local target = ParseCondition(condition) - return OvaleAura:GetStealable(target) + local count, start, ending = state:GetStealable(target) + if count > 0 then + return start, ending + end + return nil end OvaleCondition:RegisterCondition("buffstealable", false, BuffStealable) -- 1.7.9.5