From 87de4687ae6464bc58f1b71554ec3efdb7729eb8 Mon Sep 17 00:00:00 2001 From: Taracque Date: Tue, 28 Aug 2012 17:23:35 +0200 Subject: [PATCH] Added FoF detection Friend or Foe detection added. --- DKCrutch.lua | 89 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 89 insertions(+) diff --git a/DKCrutch.lua b/DKCrutch.lua index d3c2e35..05c82e7 100755 --- a/DKCrutch.lua +++ b/DKCrutch.lua @@ -57,6 +57,14 @@ DKCrutch.lastProc = "" DKCrutch.lastGlow = false DKCrutch.lastD1 = "" DKCrutch.lastD2 = "" +-- FoF detection +DKCrutch.person = { + ["lastPurged"] = 0.0, + ["foeCount"] = 0, + ["friendCount"] = 0, + ["foe"] = {}, + ["friend"] = {} +} -- Our sneaky frame to watch for events ... checks DKCrutch.events[] for the function. Passes all args. DKCrutch.eventFrame = CreateFrame("Frame") @@ -111,6 +119,10 @@ end function DKCrutch.events.COMBAT_LOG_EVENT_UNFILTERED(timestamp, event, hideCaster, srcGUID, srcName, srcFlags, srcRaidFlags, dstGUID, dstName, dstFlags, dstRaidFlags, spellId, spellName, spellSchool, damage, ...) if(DKCrutchDB.enabled) and (srcName == DKCrutch.playerName) then DKCrutch:Update() + if (UnitAffectingCombat("player")) then + -- enemy count for AoE advise and multiple player in combat (for aggro warning) + DKCrutch:CountPerson(timestamp, event, srcGUID, srcName, srcFlags, dstGUID, dstName, dstFlags) + end end end @@ -120,6 +132,15 @@ function DKCrutch.events.PLAYER_TARGET_CHANGED(...) end end +function DKCrutch.events.PLAYER_REGEN_ENABLED(...) + -- left combat + DKCrutch.person["friend"] = {} + DKCrutch.person["friendCount"] = 0 + DKCrutch.person["foe"] = {} + DKCrutch.person["foeCount"] = 0 + DKCrutch:PurgePersonTable() +end + function DKCrutch:OnLoad() local _,playerClass = UnitClass("player") if playerClass ~= "DEATHKNIGHT" then @@ -151,6 +172,7 @@ function DKCrutch:OnLoad() DKCrutch.eventFrame:RegisterEvent("RUNE_POWER_UPDATE") DKCrutch.eventFrame:RegisterEvent("RUNE_TYPE_UPDATE") DKCrutch.eventFrame:RegisterEvent("PLAYER_TARGET_CHANGED") + DKCrutch.eventFrame:RegisterEvent("PLAYER_REGEN_ENABLED") DKCrutch:CreateGUI() DKCrutch:ApplySettings() @@ -216,6 +238,73 @@ function DKCrutch:detectTalent() end end +function DKCrutch:RemoveFromTables(guid) + if (DKCrutch.person["friend"][guid]) and (DKCrutch.person["friend"][guid] ~= 0) then + DKCrutch.person["friend"][guid] = 0 + DKCrutch.person["friendCount"] = DKCrutch.person["friendCount"] - 1 + end + if (DKCrutch.person["foe"][guid]) and (DKCrutch.person["foe"][guid] ~= 0) then + DKCrutch.person["foe"][guid] = 0 + DKCrutch.person["foeCount"] = DKCrutch.person["foeCount"] - 1 + end +end + +function DKCrutch:PurgePersonTable() + for i,v in pairs(DKCrutch.person["foe"]) do + if ( ( GetTime() - DKCrutch.person["foe"][i] ) > 3) then + -- no activity from that unit in last 2 seconds, remove it + if ( DKCrutch.person["foe"][i] ~= 0) then + DKCrutch.person["foe"][i] = 0 -- mark as inactive + DKCrutch.person["foeCount"] = DKCrutch.person["foeCount"] - 1 + end + end + end + for i,v in pairs(DKCrutch.person["friend"]) do + if ( ( GetTime() - DKCrutch.person["friend"][i] ) > 3) then + -- no activity from that unit in last 2 seconds, remove it + if ( DKCrutch.person["friend"][i] ~= 0 ) then + DKCrutch.person["friend"][i] = 0 -- mark as inactive + DKCrutch.person["friendCount"] = DKCrutch.person["friendCount"] - 1 + DKCrutch:Debug('Friend removed:', DKCrutch.person["friendCount"]) + end + end + end + DKCrutch.person["lastPurged"] = GetTime() +end + +function DKCrutch:CountPerson(time, event, sguid, sname, sflags, dguid, dname, dflags) + local suffix = event:match(".+(_.-)$") + local stype = (tonumber(sguid:sub(5,5), 16)) % 8 + local dtype = (tonumber(dguid:sub(5,5), 16)) % 8 + if DKCrutch.HostileFilter[suffix] then + if (bit.band(dflags, COMBATLOG_OBJECT_REACTION_HOSTILE) == COMBATLOG_OBJECT_REACTION_HOSTILE) and (bit.band(dflags, COMBATLOG_OBJECT_AFFILIATION_OUTSIDER) == COMBATLOG_OBJECT_AFFILIATION_OUTSIDER) and ((dtype==0) or (dtype==3)) then + if ((not DKCrutch.person["foe"][dguid]) or (DKCrutch.person["foe"][dguid]==0)) then + DKCrutch.person["foeCount"] = DKCrutch.person["foeCount"] + 1 + end + DKCrutch.person["foe"][dguid] = GetTime() + elseif (bit.band(sflags, COMBATLOG_OBJECT_REACTION_HOSTILE) == COMBATLOG_OBJECT_REACTION_HOSTILE) and (bit.band(sflags, COMBATLOG_OBJECT_AFFILIATION_OUTSIDER) == COMBATLOG_OBJECT_AFFILIATION_OUTSIDER) and ((stype==0) or (stype==3)) then + if ((not DKCrutch.person["foe"][sguid]) or (DKCrutch.person["foe"][sguid]==0)) then + DKCrutch.person["foeCount"] = DKCrutch.person["foeCount"] + 1 + end + DKCrutch.person["foe"][sguid] = GetTime() + end + if (bit.band(dflags, COMBATLOG_OBJECT_REACTION_FRIENDLY) == COMBATLOG_OBJECT_REACTION_FRIENDLY) and ((dtype==0) or (dtype==3)) then + if ((not DKCrutch.person["friend"][dguid]) or (DKCrutch.person["friend"][dguid]==0)) then + DKCrutch.person["friendCount"] = DKCrutch.person["friendCount"] + 1 + end + DKCrutch.person["friend"][dguid] = GetTime() + elseif (bit.band(sflags, COMBATLOG_OBJECT_REACTION_FRIENDLY) == COMBATLOG_OBJECT_REACTION_FRIENDLY) and ((stype==0) or (stype==3)) then + if ((not DKCrutch.person["friend"][sguid]) or (DKCrutch.person["friend"][sguid]==0)) then + DKCrutch.person["friendCount"] = DKCrutch.person["friendCount"] + 1 + end + DKCrutch.person["friend"][sguid] = GetTime() + end + end + if (DKCrutch.person["lastPurged"] < (GetTime() - 3)) and (DKCrutch.person["foeCount"]>0) then + DKCrutch:PurgePersonTable() + end +end + function DKCrutch:InitSettings() if not DKCrutchDB then DKCrutchDB = {} -- fresh start -- 1.7.9.5