------------------------------
--      Are you local?      --
------------------------------

local boss = BB["Akil'zon"]
local L = AceLibrary("AceLocale-2.2"):new("BigWigs"..boss)

local CheckInteractDistance = CheckInteractDistance
local db = nil

----------------------------
--      Localization      --
----------------------------

L:RegisterTranslations("enUS", function() return {
	cmd = "Akil'zon",

	engage_trigger = "I be da predator! You da prey...",

	elec = "Electrical Storm",
	elec_desc = "Warn who has Electrical Storm.",
	elec_bar = "~Storm Cooldown",
	elec_message = "Storm on %s!",
	elec_warning10 = "Storm in 10 seconds",
	elec_warning5 = "Storm in 5 seconds",
	elec_warning4 = "Storm in 4 seconds",
	elec_warning3 = "Storm in 3 seconds",
	elec_warning2 = "Storm in 2 seconds",
	elec_warning1 = "Storm in 1 second",

	elec_countdown = "Storm 3,2,1 Countdown",
	elec_countdown_desc = "Show additional countdown messages for Electrical Storm at 3, 2, and 1 seconds remaining.",
	elec_ten_audio = "Storm 10 Audio",
	elec_ten_audio_desc = "Play a local-only sound 10 seconds before Electrical Storm.",

	ping = "Ping",
	ping_desc = "Ping your current location if you are afflicted by Electrical Storm.",
	ping_message = "Storm - Pinging your location!",

	icon = "Raid Icon",
	icon_desc = "Place a Raid Target Icon on the player with Electrical Storm. (requires promoted or higher)",
} end )

L:RegisterTranslations("koKR", function() return {
	engage_trigger = "나는 사냥꾼이다! 너흰 먹잇감이고...",

	elec = "전하 폭풍",
	elec_desc = "전하 폭풍에 걸린 플레이어를 알립니다.",
	elec_bar = "~폭풍 대기 시간",
	elec_message = "%s 전하 폭풍!",
	elec_warning = "잠시후 전하 폭풍!",

	ping = "미니맵 표시",
	ping_desc = "자신이 전하 폭풍에 걸렸을 때 현재 위치를 미니맵에 표시합니다.",
	ping_message = "폭풍 - 현재 위치 미니맵에 표시 중!",

	icon = "전술 표시",
	icon_desc = "전하 폭풍 대상이된 플레이어에게 전술 표시를 지정합니다. (승급자 이상 권한 필요)",
} end )

L:RegisterTranslations("frFR", function() return {
	engage_trigger = "Moi, chuis le prédateur ! Vous, z'êtes la proie…",

	elec = "Orage électrique",
	elec_desc = "Prévient quand un joueur subit les effets de l'Orage électrique.",
	elec_bar = "~Recharge Orage",
	elec_message = "Orage sur %s !",
	elec_warning = "Orage imminent !",

	ping = "Ping",
	ping_desc = "Indique votre position actuelle sur la minicarte si vous subissez les effets de l'Orage électrique.",
	ping_message = "Orage - Position signalée sur la minicarte !",

	icon = "Icône",
	icon_desc = "Place une icône de raid sur le dernier joueur affecté par l'Orage électrique (nécessite d'être promu ou mieux).",
} end )

L:RegisterTranslations("deDE", function() return {
	engage_trigger = "Ich bin der Jäger! Ihr seid die Beute...",

	elec = "Elektrischer Sturm",
	elec_desc = "Gib Warnung mit dem Spielernamen des Ziels von Elektrischer Sturm aus.",
	elec_bar = "~Sturm Cooldown",
	elec_message = "Sturm auf %s!",
	elec_warning = "Sturm bald!",

	ping = "Ping",
	ping_desc = "Pinge deinen Standort, wenn du von Elektrischer Sturm betroffen bist.",
	ping_message = "Sturm - Pinge deinen Standort!",

	icon = "Schlachtzugsymbol",
	icon_desc = "Platziere ein Schlachtzugsymbol auf dem Spieler, der von Elektrischer Sturm betroffen ist (benötigt Assistent oder höher).",
} end )

L:RegisterTranslations("zhCN", function() return {
	engage_trigger = "我是猎鹰，而你们，就是猎物！",

	elec = "电能风暴",
	elec_desc = "当玩家受到电能风暴时发出警报。",
	elec_bar = "<电能风暴 冷却>",
	elec_message = "电能风暴：>%s<！",
	elec_warning = "即将 电能风暴！",

	ping = "点击",
	ping_desc = "若你受到电能风暴再你当前区域点击小地图发出警报。",
	ping_message = "风暴！本区域发动了，快在小地图上点你位置！",

	icon = "团队标记",
	icon_desc = "给中了电能风暴的玩家打上标记。（需要权限）",
} end )

L:RegisterTranslations("zhTW", function() return {
	engage_trigger = "我是掠食者!而你們，就是獵物!",

	elec = "電荷風暴",
	elec_desc = "警告誰受到電荷風暴",
	elec_bar = "<電荷風暴冷卻>",
	elec_message = "電荷風暴: [%s]",
	elec_warning = "電荷風暴即將來臨!",

	ping = "點擊",
	ping_desc = "若你中了電荷風暴，在小地圖點擊你的位置",
	ping_message = "電荷風暴 - 在小地圖點擊你的位置!",

	icon = "標記圖示",
	icon_desc = "為被電荷風暴的玩家設置團隊標記（需要權限）",
} end )

L:RegisterTranslations("esES", function() return {
	engage_trigger = "¡Yo soy el depredador! Vosotros la presa...",

	elec = "Tormenta eléctrica (Electrical Storm)",
	elec_desc = "Avisa quién tiene Tormenta eléctrica.",
	elec_bar = "~Tormenta eléctrica",
	elec_message = "¡Tormenta en %s!",
	elec_warning = "Tormenta en breve",

	ping = "Señalar posición",
	ping_desc = "Señala tu posición actual si sufres Tormenta eléctrica.",
	ping_message = "¡Tormenta - Señalando tu posición!",

	icon = "Icono de banda",
	icon_desc = "Pone un icono de banda en el jugador con Tormenta eléctrica. (Requiere derechos de banda)",
} end )

----------------------------------
--      Module Declaration      --
----------------------------------

local mod = BigWigs:NewModule(boss)
mod.zonename = BZ["Zul'Aman"]
mod.enabletrigger = boss
mod.guid = 23574
mod.toggleoptions = {"elec", "ping", "icon", "enrage", "proximity", "bosskill", "elec_countdown", "elec_ten_audio"}
mod.revision = tonumber(("$Revision: 76590 $"):sub(12, -3))
mod.defaultDB = {
	elec_ten_audio = false,
}
mod.proximityCheck = function( unit ) return CheckInteractDistance( unit, 3 ) end
mod.proximitySilent = true

------------------------------
--      Initialization      --
------------------------------

function mod:OnEnable()
	self:AddCombatListener("SPELL_AURA_APPLIED", "Storm", 43648)
	self:AddCombatListener("SPELL_AURA_REMOVED", "RemoveIcon", 43648)
	self:AddCombatListener("UNIT_DIED", "BossDeath")

	self:RegisterEvent("CHAT_MSG_MONSTER_YELL")
	self:RegisterEvent("PLAYER_REGEN_ENABLED", "CheckForWipe")

	db = self.db.profile
end

------------------------------
--      Event Handlers      --
------------------------------

function mod:Storm(player, spellID)
	if not db.elec then return end

	local show = L["elec_message"]:format(player)
	self:IfMessage(L["elec_message"]:format(self:ColorName(player)), "Attention", spellID)
	self:Bar(show, 8, spellID)
	self:Bar(L["elec_bar"], 66, spellID)
	self:DelayedMessage(56, L["elec_warning10"], "Attention")
	if db.elec_ten_audio then
		self:ScheduleEvent("BWAkilzonStormTenSound", "BigWigs_Sound", 56, "BigWigs: Akil'zon Storm 10")
	end
	self:DelayedMessage(61, L["elec_warning5"], "Urgent")
	if db.elec_countdown then
		self:DelayedMessage(62, L["elec_warning4"], "Important")
		self:DelayedMessage(63, L["elec_warning3"], "Important")
		self:DelayedMessage(64, L["elec_warning2"], "Important")
		self:DelayedMessage(65, L["elec_warning1"], "Important")
	end
	if UnitIsUnit(player, "player") and db.ping then
		Minimap:PingLocation()
		BigWigs:Print(L["ping_message"])
	end
	self:Icon(player, "icon")
end

function mod:RemoveIcon()
	self:TriggerEvent("BigWigs_RemoveRaidIcon")
end

function mod:CHAT_MSG_MONSTER_YELL(msg)
	if msg == L["engage_trigger"] then
		if db.enrage then
			self:Enrage(480, true, true)
		end
		if db.elec then
			self:Bar(L["elec_bar"], 50, 43648)
			self:DelayedMessage(40, L["elec_warning10"], "Attention")
			if db.elec_ten_audio then
				self:ScheduleEvent("BWAkilzonStormTenSound", "BigWigs_Sound", 40, "BigWigs: Akil'zon Storm 10")
			end
			self:DelayedMessage(45, L["elec_warning5"], "Urgent")
			if db.elec_countdown then
				self:DelayedMessage(46, L["elec_warning4"], "Important")
				self:DelayedMessage(47, L["elec_warning3"], "Important")
				self:DelayedMessage(48, L["elec_warning2"], "Important")
				self:DelayedMessage(49, L["elec_warning1"], "Important")
			end
		end
		self:TriggerEvent("BigWigs_ShowProximity", self)
	end
end

