--Add raid frame glow for target of spellcast
--COMBAT_LOG_EVENT_UNFILTERED REMOVE_GUID NAME_PLATE_UNIT_ADDED NAME_PLATE_UNIT_REMOVED
function(allstates, e, ...)
	if e == "COMBAT_LOG_EVENT_UNFILTERED" then
		local se = select(2, ...)
		if se == "SPELL_CAST_START" or se == "SPELL_CAST_SUCCESS" then
			local spell = select(13, ...)
			if aura_env.spells[spell] then
				local ID = select(7, GetSpellInfo(aura_env.spells[spell].ID))
				if ID == aura_env.spells[spell].ID then
					local castTime = select(4, GetSpellInfo(aura_env.spells[spell].ID))
					local GUID = select(4, ...)
					if GUID then allstates[GUID] = {} end
					if allstates[GUID].timer then allstates[GUID].timer:Cancel() end
					if castTime > 1000 and se == "SPELL_CAST_START" then
						if allstates[GUID].timer then allstates[GUID].timer:Cancel() end
						allstates[GUID].changed = true
						allstates[GUID].show = true
						allstates[GUID].showTime = GetTime()
						allstates[GUID].ID = aura_env.spells[spell].ID
						allstates[GUID].ins = aura_env.spells[spell].ins
						allstates[GUID].GUID = GUID
						allstates[GUID].progressType = "timed"
						allstates[GUID].expirationTime  = GetTime() + castTime / 1000
						allstates[GUID].duration  = castTime / 1000
						allstates[GUID].timer = C_Timer.NewTimer(castTime / 1000, function() WeakAuras.ScanEvents("REMOVE_GUID", GUID); end)
						allstates[GUID].text = aura_env.spells[spell].ins
						return true
					elseif castTime == 0 and se == "SPELL_CAST_SUCCESS" then
						if allstates[GUID].timer then allstates[GUID].timer:Cancel() end
						allstates[GUID].changed = true
						allstates[GUID].show = true
						allstates[GUID].showTime = GetTime()
						allstates[GUID].ID = aura_env.spells[spell].ID
						allstates[GUID].ins = aura_env.spells[spell].ins
						allstates[GUID].GUID = GUID
						allstates[GUID].expirationTime  = GetTime() + 2
						allstates[GUID].timer = C_Timer.NewTimer(2, function() WeakAuras.ScanEvents("REMOVE_GUID", GUID); end)
						allstates[GUID].text = aura_env.spells[spell].ins
						return true
					end
				end
			end
		elseif se == "SPELL_CAST_FAILED" then
			local spell = select(13, ...)
			if aura_env.spells[spell] then
				local ID = select(7, GetSpellInfo(aura_env.spells[spell].ID))
				if ID == aura_env.spells[spell].ID then
					local GUID = select(4, ...)
					if allstates[GUID].timer then allstates[GUID].timer:Cancel() end
					--WeakAuras.ScanEvents("REMOVE_GUID", GUID)
					local rem = aura_env.round(allstates[GUID].expirationTime - GetTime(), 1)
					local maxrem = allstates[GUID].expirationTime - allstates[GUID].showTime
					allstates[GUID].changed = true
					allstates[GUID].show = true
					allstates[GUID].progressType = "static"
					allstates[GUID].value = rem
					allstates[GUID].total = maxrem
					allstates[GUID].interrupted = true
					allstates[GUID].timer = C_Timer.NewTimer(1, function() WeakAuras.ScanEvents("REMOVE_GUID", GUID) end)
					return true
				end
			end
		elseif se == "UNIT_DIED" then
			local GUID = select(8, ...)
			if allstates[GUID] and allstates[GUID].expirationTime and not allstates[GUID].interrupted then
				local rem = allstates[GUID].expirationTime - GetTime()
				local maxrem = allstates[GUID].expirationTime - allstates[GUID].showTime
				allstates[GUID].changed = true
				allstates[GUID].show = true
				allstates[GUID].progressType = "static"
				allstates[GUID].value = rem
				allstates[GUID].total = maxrem
				allstates[GUID].interrupted = true
				allstates[GUID].timer = C_Timer.NewTimer(1, function() WeakAuras.ScanEvents("REMOVE_GUID", GUID) end)
				return true
			end
		end
	elseif e == "REMOVE_GUID" then
		local GUID = select(1, ...)
		if allstates[GUID] then
			allstates[GUID].show = false
			allstates[GUID].changed = true
			return true
		end
	end
end

--ANIMATION
function()
	if aura_env.statee and aura_env.statee.interrupted then return 0, 1, 0, 1 end
end

--ON SHOW
PlaySoundFile("Interface\\AddOns\\WeakAuras\\Media\\Sounds\\RobotBlip.ogg", "Master")

--INIT
aura_env.spells = {
	["Hateful Charge"] = {
		["ID"] = 224188,
		["ins"] = "Hateful Charge - Intercept",
	},
	["Growing Paranoia"] = {
		["ID"] = 200289,
		["ins"] = "Growing Paranoia - Avoid",
	},
	["Waking Nightmare"] = {
		["ID"] = 200243,
		["ins"] = "Waking Nightmare - Stack",
	},
	["Static Nova"] = {
		["ID"] = 193597,
		["ins"] = "Static Nova - Run to island",
	},
	["Focused Lightning"] = {
		["ID"] = 193611,
		["ins"] = "Focused Lightning - Run from island",
	},
	["Scent Of Blood"] = {
		["ID"] = 196838,
		["ins"] = "Scent Of Blood - Prepare for Claw Frenzy",
	},
	["Celerity Zone"] = {
		["ID"] = 211037,
		["ins"] = "Celerity Zone - Get 50% haste",
	},
	["Sap Soul"] = {
		["ID"] = 200905,
		["ins"] = "Sap Soul - Manage",
	},
	["Meteor"] = {
		["ID"] = 196249,
		["ins"] = "Meteor - Stack",
	},
	["Fissure"] = {
		["ID"] = 192522,
		["ins"] = "Fissure - Yoink lava",
	},
	["Lava Wreath"] = {
		["ID"] = 192631,
		["ins"] = "Lava Wreath - Yoink lava",
	},
	["Knockdown Kick"] = {
		["ID"] = 214989,
		["ins"] = "Knockdown Kick - Beware",
	},
	["Knife Dance"] = {
		["ID"] = 200291,
		["ins"] = "Knife Dance - Beware",
	},
	["Mana Fang"] = {
		["ID"] = 209516,
		["ins"] = "Mana Fang - Beware",
	},
	["Frantic Rip"] = {
		["ID"] = 200620,
		["ins"] = "Frantic Rip - Beware",
	},
	["Grievous Tear"] = {
		["ID"] = 196376,
		["ins"] = "Grievous Tear - Beware",
	},
	["Nightmare Bolt"] = {
		["ID"] = 212834,
		["ins"] = "Nightmare Bolt - Beware",
	},
	["Rising Fury"] = {
		["ID"] = 195944,
		["ins"] = "Rising Fury - Beware",
	},
	["Ravenous Leap"] = {
		["ID"] = 197556,
		["ins"] = "Ravenous Leap - Beware",
	},
	["Lantern Of Darkness"] = {
		["ID"] = 192019,
		["ins"] = "Lantern Of Darkness - Beware",
	},
	["Shatter"] = {
		["ID"] = 188114,
		["ins"] = "Shatter - Beware",
	},
	["Prophecies Of Doom"] = {
		["ID"] = 211771,
		["ins"] = "Prophecies Of Doom - Beware",
	},
	["Quarantine"] = {
		["ID"] = 195791,
		["ins"] = "Quarantine - Beware",
	},
	["Deepening Shadows"] = {
		["ID"] = 213583,
		["ins"] = "Deepening Shadows - Beware",
	},
	["Maddening Roar"] = {
		["ID"] = 200580,
		["ins"] = "Maddening Roar - CC",
	},
	["Spray Sand"] = {
		["ID"] = 196129,
		["ins"] = "Spray Sand - CC",
	},
	["Drain"] = {
		["ID"] = 202658,
		["ins"] = "Drain - CC",
	},
	["Dark Mending"] = {
		["ID"] = 225573,
		["ins"] = "Dark Mending - Interrupt",
	},
	["Hinder"] = {
		["ID"] = 215204,
		["ins"] = "Hinder - Interrupt",
	},
	["Drain Magic"] = {
		["ID"] = 209485,
		["ins"] = "Drain Magic - Interrupt",
	},
	["Charging Station"] = {
		["ID"] = 225100,
		["ins"] = "Charging Station - Interrupt",
	},
	["Unnerving Screech"] = {
		["ID"] = 200631,
		["ins"] = "Unnerving Screech - Interrupt",
	},
	["Tormenting Eye"] = {
		["ID"] = 204243,
		["ins"] = "Tormenting Eye - Interrupt",
	},
	["Blood Metamorphosis"] = {
		["ID"] = 225562,
		["ins"] = "Blood Metamorphosis - Interrupt",
	},
	["Restoration"] = {
		["ID"] = 197502,
		["ins"] = "Restoration - Interrupt",
	},
	["Arcane Rebound"] = {
		["ID"] = 196028,
		["ins"] = "Arcane Rebound - Interrupt",
	},
	["Polymorph:Fish"] = {
		["ID"] = 197105,
		["ins"] = "Polymorph:Fish - Interrupt",
	},
	["Aqua Spout"] = {
		["ID"] = 196027,
		["ins"] = "Aqua Spout - Interrupt",
	},
	["Shattered Rune"] = {
		["ID"] = 198962,
		["ins"] = "Shattered Rune - Interrupt",
	},
	["Etch"] = {
		["ID"] = 198959,
		["ins"] = "Etch - Interrupt",
	},
	["Unruly Yell"] = {
		["ID"] = 199726,
		["ins"] = "Unruly Yell - Interrupt",
	},
	["Surge"] = {
		["ID"] = 198750,
		["ins"] = "Surge - Interrupt",
	},
	["Void Snap"] = {
		["ID"] = 194266,
		["ins"] = "Void Snap - Interrupt",
	},
	["Bound"] = {
		["ID"] = 193585,
		["ins"] = "Bound - Interrupt",
	},
	["Demonic Ascension"] = {
		["ID"] = 226285,
		["ins"] = "Demonic Ascension - Interrupt",
	},
	["Nightmares"] = {
		["ID"] = 193069,
		["ins"] = "Nightmares - Interrupt",
	},
	["Bonebreaking Strike"] = {
		["ID"] = 200261,
		["ins"] = "Bonebreaking Strike - Avoid",
	},
	["Ravens Dive"] = {
		["ID"] = 214001,
		["ins"] = "Ravens Dive - Avoid",
	},
	["Quelling Strike"] = {
		["ID"] = 209027,
		["ins"] = "Quelling Strike - Avoid",
	},
	["Wild Detonation"] = {
		["ID"] = 209477,
		["ins"] = "Wild Detonation - Avoid",
	},
	["Charged Blast"] = {
		["ID"] = 212031,
		["ins"] = "Charged Blast - Avoid",
	},
	["Charged Smash"] = {
		["ID"] = 209495,
		["ins"] = "Charged Smash - Avoid",
	},
	["Fel Detonation"] = {
		["ID"] = 211464,
		["ins"] = "Fel Detonation - Avoid",
	},
	["Star Shower"] = {
		["ID"] = 200658,
		["ins"] = "Star Shower - Avoid",
	},
	["Nightfall"] = {
		["ID"] = 198408,
		["ins"] = "Nightfall - Avoid",
	},
	["Dread Inferno"] = {
		["ID"] = 201400,
		["ins"] = "Dread Inferno - Avoid",
	},
	["Thunderstrike"] = {
		["ID"] = 198605,
		["ins"] = "Thunderstrike - Avoid",
	},
	["Felblaze Rush"] = {
		["ID"] = 193659,
		["ins"] = "Felblaze Rush - Avoid",
	},
	["Deceptive Strike"] = {
		["ID"] = 199250,
		["ins"] = "Deceptive Strike - Avoid",
	},
	["Cosmic Scythe"] = {
		["ID"] = 194216,
		["ins"] = "Cosmic Scythe - Avoid",
	},
	["Strike Of The Mountain"] = {
		["ID"] = 198475,
		["ins"] = "Strike Of The Mountain - Avoid",
	},
	["Spiked Tongue"] = {
		["ID"] = 199176,
		["ins"] = "Spiked Tongue - Avoid",
	},
	["Magma Wave"] = {
		["ID"] = 200404,
		["ins"] = "Magma Wave - Avoid",
	},
	["Shadow Slash"] = {
		["ID"] = 212030,
		["ins"] = "Shadow Slash - Avoid",
	},
	["Blink Strikes"] = {
		["ID"] = 199811,
		["ins"] = "Blink Strikes - Avoid",
	},
	["Nether Venom"] = {
		["ID"] = 200040,
		["ins"] = "Nether Venom - Avoid",
	},
	["Unstable Mana"] = {
		["ID"] = 220871,
		["ins"] = "Unstable Mana - Avoid",
	},
	["Lingering Gaze"] = {
		["ID"] = 194945,
		["ins"] = "Lingering Gaze - Avoid",
	},
	["Soul Blade"] = {
		["ID"] = 200084,
		["ins"] = "Soul Blade - Use Mitigation",
	},
	["Strike Down"] = {
		["ID"] = 225732,
		["ins"] = "Strike Down - Use Mitigation",
	},
	["Vengeful Shear"] = {
		["ID"] = 197418,
		["ins"] = "Vengeful Shear - Use Mitigation",
	},
	["Brutal Assault"] = {
		["ID"] = 201139,
		["ins"] = "Brutal Assault - Use Mitigation",
	},
	["Indigestion"] = {
		["ID"] = 200913,
		["ins"] = "Indigestion - Use Mitigation",
	},
	["Brutal Haymaker"] = {
		["ID"] = 198245,
		["ins"] = "Brutal Haymaker - Use Mitigation",
	},
	["Coup De Grace"] = {
		["ID"] = 214003,
		["ins"] = "Coup De Grace - Use Mitigation",
	},
	["Primal Rampage"] = {
		["ID"] = 198376,
		["ins"] = "Primal Rampage - Use Mitigation",
	},
	["Breath Of Corruption"] = {
		["ID"] = 191326,
		["ins"] = "Breath Of Corruption - Use Mitigation",
	},
	["Feed On The Weak"] = {
		["ID"] = 200238,
		["ins"] = "Feed On The Weak - Use Mitigation",
	},
	["Crashing Wave"] = {
		["ID"] = 191900,
		["ins"] = "Crashing Wave - Use Mitigation",
	},
	["Lightning Breath"] = {
		["ID"] = 198888,
		["ins"] = "Lightning Breath - Use Mitigation",
	},
	["Penetrating Shot"] = {
		["ID"] = 199210,
		["ins"] = "Penetrating Shot - Use Mitigation",
	},
	["Shield Of Light"] = {
		["ID"] = 192018,
		["ins"] = "Shield Of Light - Use Mitigation",
	},
	["Fire Blast"] = {
		["ID"] = 202365,
		["ins"] = "Fire Blast - Use Mitigation",
	},
	["Flare"] = {
		["ID"] = 202408,
		["ins"] = "Flare - Use Mitigation",
	},
	["Dark Slash"] = {
		["ID"] = 193211,
		["ins"] = "Dark Slash - Use Mitigation",
	},
	["Bile Breath"] = {
		["ID"] = 194099,
		["ins"] = "Bile Breath - Use Mitigation",
	},
	["Piercing Shards"] = {
		["ID"] = 226296,
		["ins"] = "Piercing Shards - Use Mitigation",
	},
	["Razor Shards"] = {
		["ID"] = 188169,
		["ins"] = "Razor Shards - Use Mitigation",
	},
	["Sunder"] = {
		["ID"] = 198496,
		["ins"] = "Sunder - Use Mitigation",
	},
	["Molten Crash"] = {
		["ID"] = 200732,
		["ins"] = "Molten Crash - Use Mitigation",
	},
	["Flame Breath"] = {
		["ID"] = 226420,
		["ins"] = "Flame Breath - Use Mitigation",
	},
	["Hatred"] = {
		["ID"] = 190836,
		["ins"] = "Hatred - Use Mitigation",
	},
	["a Mothers Love"] = {
		["ID"] = 194064,
		["ins"] = "a Mothers Love - Use Mitigation",
	},
}
aura_env.classColor = function(class)
if class == "Death Knight" then return "|cFFC41F3B" elseif
class == "Demon Hunter" then return "|cFFA330C9" elseif
class == "Druid" then return "|cFFFF7D0A" elseif
class == "Hunter" then return "|cFFABD473" elseif
class == "Mage" then return "|cFF40C7EB" elseif
class == "Monk" then return "|cFF00FF96" elseif
class == "Paladin" then return "|cFFF58CBA" elseif
class == "Priest" then return "|cFFFFFFFF"  elseif
class == "Rogue" then return "|cFFFFF569"  elseif
class == "Shaman" then return "|cFF0070DE" elseif
class == "Warlock" then return "|cFF8787ED" elseif
class == "Warrior" then return "|cFFC79C6E" else
return "|cFFFFFFFF" end
end
aura_env.round = function(var, n)
	if (n) then
		var = math.floor((var * 10 ^ n) + 0.5) / (10 ^ n)
	else
		var = math.floor(var + 0.5)
	end
	return var
end