added mantikora spear alert via map ping

René Welbers [01-28-16 - 13:15]
added mantikora spear alert via map ping
Filename
RaidNotifier.lua
RaidNotifier.txt
lang/de.lua
lang/en.lua
diff --git a/RaidNotifier.lua b/RaidNotifier.lua
index dce595f..8b30889 100644
--- a/RaidNotifier.lua
+++ b/RaidNotifier.lua
@@ -5,7 +5,7 @@ RaidNotifier = RaidNotifier or {}

 RaidNotifier.name		   = 'RaidNotifier'
 RaidNotifier.slash		   = '/rn'
-RaidNotifier.version	   = '1.3.4'
+RaidNotifier.version	   = '1.3.6'
 RaidNotifier.versionDB	   = 1
 RaidNotifier.loaded	       = false
 RaidNotifier.author        = 'silentgecko'
@@ -27,6 +27,11 @@ RaidNotifier.variables = {
     },
     debug = false
 }
+
+RaidNotifier.pingEventCodes = {
+    mantikora_spear = 51816
+}
+
 RaidNotifier.tempVars = {
     last_notify = {
         sanctum_ophidia = {
@@ -42,6 +47,7 @@ RaidNotifier.tempVars = {
             stage9_synergy = 0,
         }
     },
+    last_ping = 0,
 }

 local function CreateSettingsMenu()
@@ -162,7 +168,7 @@ end


 ---------Passing saved variables to the labels at initialize-------
-function RaidNotifier.Initialize(event, addonName)
+function RaidNotifier.Initialize(_, addonName)
     local self = RaidNotifier

     if addonName ~= self.name then return end
@@ -192,6 +198,7 @@ function RaidNotifier.addEventListeners()
     -- add general
     if raidId > 0 then
         EVENT_MANAGER:RegisterForEvent(self.name .. "_BUFFFOOD", EVENT_EFFECT_CHANGED, self.generalBuffFoodReminder)
+        EVENT_MANAGER:RegisterForEvent(self.name .. "_PINGS",    EVENT_MAP_PING,       self.receivePing)
     end

     -- add sanctum
@@ -209,9 +216,10 @@ end
 function RaidNotifier.removeEventListeners()
     local self   = RaidNotifier

-    EVENT_MANAGER:UnregisterForEvent(self.name .. "_BUFFFOOD", EVENT_EFFECT_CHANGED)
-    EVENT_MANAGER:UnregisterForEvent(self.name .. "_SANCTUM", EVENT_EFFECT_CHANGED)
+    EVENT_MANAGER:UnregisterForEvent(self.name .. "_BUFFFOOD",  EVENT_EFFECT_CHANGED)
+    EVENT_MANAGER:UnregisterForEvent(self.name .. "_SANCTUM",   EVENT_EFFECT_CHANGED)
     EVENT_MANAGER:UnregisterForEvent(self.name .. "_MAELSTROM", EVENT_EFFECT_CHANGED)
+    EVENT_MANAGER:UnregisterForEvent(self.name .. "_PINGS",     EVENT_MAP_PING)
 end


@@ -267,17 +275,16 @@ function RaidNotifier.sanctumDebuffs(_, change, _, name, unit, _, _, _, _, _, _,
         end

         -- Sanctum Mantikora Spear Throw Alert
+        -- @todo send map ping and listen to it
         if self.savedVariables.sanctum_ophidia.mantikora_spear then
             -- only notify when the last one is at least 5 seconds ago and it is the spear
             local currentTime = GetTimeStamp()
             local lastNotify  = self.tempVars.last_notify.sanctum_ophidia.mantikora_spear
             local timeDiff = GetDiffBetweenTimeStamps(currentTime, lastNotify)
-            if (buffsDebuffs.spear[abilityId]) and timeDiff > 5 then
-                if self.savedVariables.debug then
-                    RaidNotifier.debug('manti spear ability id', abilityId)
-                end
+            if (buffsDebuffs.spear == abilityId) and timeDiff > 5 then
                 self.tempVars.last_notify.sanctum_ophidia.mantikora_spear = currentTime
                 CENTER_SCREEN_ANNOUNCE:AddMessage(2, CSA_EVENT_SMALL_TEXT, SOUNDS.CHAMPION_POINTS_COMMITTED, GetString(RAIDNOTIFIER_ALERTS_SANCTUM_MANTIKORA_SPEAR))
+                self.sendPing('manti_spear')
             end
         end
     end
@@ -327,7 +334,7 @@ function RaidNotifier.maelstromDebuffs(_, change, _, name, unit, _, _, _, _, _,
 end

 -- General Events
-function RaidNotifier.generalBuffFoodReminder(_, _, _, _, unit, _, _, _, _, _, _, _, _, _, _, abilityId)
+function RaidNotifier.generalBuffFoodReminder(_, _, _, _, unit)
     -- only take care of player
     if (unit ~= 'player') then return end

@@ -362,21 +369,6 @@ function RaidNotifier.generalBuffFoodReminder(_, _, _, _, unit, _, _, _, _, _, _
                 local lastNotifyDiff     = GetDiffBetweenTimeStamps(currentTime, lastNotify)
                 local formatedTime       = ZO_FormatTime(bufffood_remaining, TIME_FORMAT_STYLE_COLONS, TIME_FORMAT_PRECISION_SECONDS)

-                -- old fixed interval
---                if bufffood_remaining <= 60 and (lastNotifyDiff > 49) then
---                    -- alert 1 min
---                    self.tempVars.last_notify.general.buffFood_reminder = currentTime
---                    CENTER_SCREEN_ANNOUNCE:AddMessage(3, CSA_EVENT_SMALL_TEXT, SOUNDS.CHAMPION_POINTS_COMMITTED, zo_strformat(GetString(RAIDNOTIFIER_ALERTS_GENERAL_BUFFFOOD_MINUTES), name, formatedTime))
---                elseif bufffood_remaining <= 120 and (lastNotifyDiff > 170) then
---                    -- alert 2 min
---                    self.tempVars.last_notify.general.buffFood_reminder = currentTime
---                    CENTER_SCREEN_ANNOUNCE:AddMessage(7, CSA_EVENT_SMALL_TEXT, SOUNDS.CHAMPION_POINTS_COMMITTED, zo_strformat(GetString(RAIDNOTIFIER_ALERTS_GENERAL_BUFFFOOD_MINUTES), name, formatedTime))
---                elseif bufffood_remaining <= 300 and (lastNotifyDiff > 3600) then
---                    -- alert 5 min
---                    self.tempVars.last_notify.general.buffFood_reminder = currentTime
---                    CENTER_SCREEN_ANNOUNCE:AddMessage(10, CSA_EVENT_SMALL_TEXT, SOUNDS.CHAMPION_POINTS_COMMITTED, zo_strformat(GetString(RAIDNOTIFIER_ALERTS_GENERAL_BUFFFOOD_MINUTES), name, formatedTime))
---                end
-
                 -- new set interval
                 if bufffood_remaining <= 600 and (lastNotifyDiff > reminderInterval) then
                     -- every set interval
@@ -405,10 +397,72 @@ function RaidNotifier.generalBuffFoodReminder(_, _, _, _, unit, _, _, _, _, _, _
     end
 end

+-- send pings
+function RaidNotifier.sendPing(event)
+    local self           = RaidNotifier
+    local realEventCodes = self.pingEventCodes
+
+    if event == 'manti_spear' then
+        local lastPing     = self.tempVars.last_ping
+        local currentTime  = GetTimeStamp()
+        local lastPingDiff = GetDiffBetweenTimeStamps(currentTime, lastPing)
+        local eventCode    = realEventCodes.mantikora_spear
+
+        -- only ping every 5 seks
+        if lastPingDiff > 5 then
+            local eventCoordX = eventCode/100000
+            local eventCoordY = eventCode/1000000
+
+            --send the ping
+            PingMap(MAP_PIN_TYPE_PING, MAP_TYPE_LOCATION_CENTERED, eventCoordX , eventCoordY)
+            self.tempVars.last_ping = currentTime
+        end
+    end
+end
+
+-- receive pings
+function RaidNotifier.receivePing(_, pingEventType, _, pingTag, offsetX, offsetY, isOwner)
+    -- ignore
+    if (offsetX == 0 and offsetY == 0) then return end
+    if (pingEventType == PING_EVENT_REMOVED) then return end
+    if (isOwner == true) then return end
+
+    local self           = RaidNotifier
+    local realEventCodes = self.pingEventCodes
+
+    --ping data
+    local unitName        = GetUnitName(pingTag)
+    local eventCodeA      = math.abs(offsetX * 100000)
+    local eventCodeB      = math.abs(offsetY * 1000000)
+    local currentTime     = GetTimeStamp()
+    local realEventCode   = realEventCodes.mantikora_spear -- atm we only have this one, @todo iterate over them and then switch for the different alerts
+    local zosEventCodeMin = realEventCode - 100
+    local zosEventCodeMax = realEventCode + 100
+
+    -- make sure we have a correct eventCode
+    -- the pingmap make some rounding errors, so we have to define a range and check if the ping is inside this range
+    if (eventCodeA >= zosEventCodeMin and eventCodeA <= zosEventCodeMax) and (eventCodeB >= zosEventCodeMin and eventCodeB <= zosEventCodeMax) then
+        local eventCode = realEventCode
+        self.debug('eventCode matched', eventCode)
+        self.debug('eventCode for manti spear')
+        -- set last ping to now to prevent spamming
+        self.tempVars.last_ping = currentTime
+
+        CENTER_SCREEN_ANNOUNCE:AddMessage(10, CSA_EVENT_SMALL_TEXT, SOUNDS.CHAMPION_POINTS_COMMITTED, zo_strformat(GetString(RAIDNOTIFIER_ALERTS_SANCTUM_MANTIKORA_SPEAR_PLAYER), unitName))
+    end
+end
+
 -- debug func
 function RaidNotifier.debug(message, data)
-    d('RaidNotifier Debug:')
-    d(message, data)
+    local self = RaidNotifier
+    if self.savedVariables.debug then
+        d('RaidNotifier Debug:')
+        if data ~= nil then
+            d(message, data)
+        else
+            d(message)
+        end
+    end
 end

 ---------Events-------
diff --git a/RaidNotifier.txt b/RaidNotifier.txt
index 2abfb19..914b5e3 100644
--- a/RaidNotifier.txt
+++ b/RaidNotifier.txt
@@ -1,7 +1,7 @@
 ## Title: |cEFEBBERaidNotifier|r
 ## Description: Displays on-screen notifications on different events during trials.
 ## Author: |c009ad6silentgecko|r
-## Version: 1.3.4
+## Version: 1.3.6
 ## APIVersion: 100013
 ## SavedVariables: RNVars
 ## OptionalDependsOn: LibAddonMenu-2.0
diff --git a/lang/de.lua b/lang/de.lua
index 3e66f7e..6e751c3 100644
--- a/lang/de.lua
+++ b/lang/de.lua
@@ -31,9 +31,10 @@ L.Settings_Debug_TT                      = 'Zeigt an bestimmten Stellen Debug In
 -- ---------------------------------------------------
 -- Alerts --------------------------------------------
 -- ---------------------------------------------------
-L.Alerts_Sanctum_Poison             = '|c39942eGift|r! Zusammen stehen!'
-L.Alerts_Sanctum_Magicka_Detonation = '|c234afaMagicka Detonation|r! Verbrenn dein gesamtes Magicka!'
-L.Alerts_Sanctum_Mantikora_Spear    = 'Mantikor |ccde846Speer|r auf dir! Raus da!'
+L.Alerts_Sanctum_Poison                 = '|c39942eGift|r! Zusammen stehen!'
+L.Alerts_Sanctum_Magicka_Detonation     = '|c234afaMagicka Detonation|r! Verbrenn dein gesamtes Magicka!'
+L.Alerts_Sanctum_Mantikora_Spear        = 'Mantikor |ccde846Speer|r auf dir! Raus da!'
+L.Alerts_Sanctum_Mantikora_Spear_Player = 'Mantikor |ccde846Speer|r auf <<!aC:1>>! Raus da!'

 L.Alerts_Maelstrom_Stage7_Poison    = '|c39942eVergiftet|r! Nutze eine der beiden Flächen am Rand um dich zu reinigen!'
 L.Alerts_Maelstrom_Stage9_Synergy   = '|c23afe7Spektrale Explosion|r bereit! Synergie nutzen!'
diff --git a/lang/en.lua b/lang/en.lua
index 7992247..e4c8590 100644
--- a/lang/en.lua
+++ b/lang/en.lua
@@ -31,9 +31,10 @@ L.Settings_Debug_TT                      = 'Turns on debugging output in chatwin
 -- ---------------------------------------------------
 -- Alerts --------------------------------------------
 -- ---------------------------------------------------
-L.Alerts_Sanctum_Poison             = '|c39942ePoison|r! Stack together!'
-L.Alerts_Sanctum_Magicka_Detonation = '|c234afaMagicka Detonation|r! Burn all your Magicka!'
-L.Alerts_Sanctum_Mantikora_Spear    = 'Mantikora |ccde846Spear|r on you! Move out!'
+L.Alerts_Sanctum_Poison                 = '|c39942ePoison|r! Stack together!'
+L.Alerts_Sanctum_Magicka_Detonation     = '|c234afaMagicka Detonation|r! Burn all your Magicka!'
+L.Alerts_Sanctum_Mantikora_Spear        = 'Mantikora |ccde846Spear|r on you! Move out!'
+L.Alerts_Sanctum_Mantikora_Spear_Player = 'Mantikora |ccde846Spear|r on <<!aC:1>>! Move out!'

 L.Alerts_Maelstrom_Stage7_Poison    = '|c39942ePoisoned|r! Use one of the two areas to purge!'
 L.Alerts_Maelstrom_Stage9_Synergy   = '|c23afe7Spectral Explosion|r ready! Use the synergy!'