local mod	= DBM:NewMod(2369, "DBM-Nyalotha", nil, 1180)
local L		= mod:GetLocalizedStrings()

mod:SetRevision("20191111030008")
mod:SetCreatureID(157620)
mod:SetEncounterID(2334)
mod:SetZone()
mod:SetBossHPInfoToHighest()--Must set boss HP to highest, since boss health will get screwed up during images phase
mod.noBossDeathKill = true--Killing an image in image phase fires unit Died for boss creature ID, so must filter this
mod:SetHotfixNoticeRev(20191109000000)--2019, 11, 09
mod:SetMinSyncRevision(20190918000000)--2019, 9, 18
--mod.respawnTime = 29

mod:RegisterCombat("combat")

mod:RegisterEventsInCombat(
	"SPELL_CAST_START 309687 307937 307725",
	"SPELL_CAST_SUCCESS 313239 307937 313276",
	"SPELL_AURA_APPLIED 307784 307785 313208 308065 307950",
	"SPELL_AURA_APPLIED_DOSE 308059",
	"SPELL_AURA_REMOVED 313208 308065 307950",--307784 307785
--	"SPELL_PERIODIC_DAMAGE",
--	"SPELL_PERIODIC_MISSED",
--	"UNIT_DIED",
	"UNIT_SPELLCAST_SUCCEEDED boss1"
)

--TODO, if tanks each get a diff mind debuff, mark them, and they can be designated callers
--TODO, update timerImagesofAbsolutionCD after Projection phases
local warnShadowShock						= mod:NewStackAnnounce(308059, 2, nil, "Tank")
local warnImagesofAbsolution				= mod:NewCountAnnounce(313239, 3)--Spawn, not when killable
local warnShredPsyche						= mod:NewTargetNoFilterAnnounce(307937, 2)
local warnPsychicOutburst					= mod:NewCastAnnounce(309687, 4)
local warnProjections						= mod:NewSpellAnnounce(307725, 2)
local warnProjectionsOver					= mod:NewEndAnnounce(307725, 2)

local specWarnCloudedMind					= mod:NewSpecialWarningYou(307784, nil, nil, nil, 1, 2)--voice not yet decided
local specWarnTwistedMind					= mod:NewSpecialWarningYou(307785, nil, nil, nil, 1, 2)--voice not yet decided
local yellMark								= mod:NewPosYell(307784, DBM_CORE_AUTO_YELL_CUSTOM_POSITION, false)
local specWarnImagesofAbsolutionSwitch		= mod:NewSpecialWarningSwitch(313239, "dps", nil, nil, 1, 2)--30 seconds after spawn, when killable
local specWarnShadowShock					= mod:NewSpecialWarningStack(308059, nil, 7, nil, nil, 1, 6)
local specWarnShadowShockTaunt				= mod:NewSpecialWarningTaunt(308059, nil, nil, nil, 1, 2)
local specWarnShredPsyche					= mod:NewSpecialWarningMoveAway(307937, nil, nil, nil, 1, 2)
local yellShredPsyche						= mod:NewPosYell(307937)
local yellShredPsycheFades					= mod:NewIconFadesYell(307937)
--local specWarnGTFO						= mod:NewSpecialWarningGTFO(270290, nil, nil, nil, 1, 8)

local timerImagesofAbsolutionCD				= mod:NewCDTimer(84.9, 313239, nil, nil, nil, 1, nil, DBM_CORE_HEROIC_ICON)
local timerShredPsycheCD					= mod:NewCDTimer(32.5, 307937, nil, nil, nil, 3, nil, DBM_CORE_DAMAGE_ICON, nil, 1, 4)--32.5-34

--local berserkTimer						= mod:NewBerserkTimer(600)

--mod:AddRangeFrameOption(6, 264382)
--mod:AddInfoFrameOption(275270, true)
mod:AddSetIconOption("SetIconOnAdds", 307937, true, false, {1, 2})
mod:AddNamePlateOption("NPAuraOnIntangibleIllusion", 313208)

mod.vb.ImagesOfAbsolutionCast = 0
mod.vb.shredIcon = 1

function mod:OnCombatStart(delay)
	self.vb.ImagesOfAbsolutionCast = 0
	self.vb.shredIcon = 1
	timerShredPsycheCD:Start(12.8-delay)--SUCCESS
	if self:IsHard() then
		timerImagesofAbsolutionCD:Start(30.5-delay)
	end
	if self.Options.NPAuraOnIntangibleIllusion then
		DBM:FireEvent("BossMod_EnableHostileNameplates")
	end
end

function mod:OnCombatEnd()
	self:UnregisterShortTermEvents()
--	if self.Options.InfoFrame then
--		DBM.InfoFrame:Hide()
--	end
--	if self.Options.RangeFrame then
--		DBM.RangeCheck:Hide()
--	end
	if self.Options.NPAuraOnIntangibleIllusion then
		DBM.Nameplate:Hide(true, nil, nil, nil, true, true)
	end
end

--function mod:OnTimerRecovery()

--end

function mod:SPELL_CAST_START(args)
	local spellId = args.spellId
	if spellId == 309687 and self:AntiSpam(5, 3) then
		warnPsychicOutburst:Show()
	elseif spellId == 307937 then
		self.vb.shredIcon = 1
	elseif spellId == 307725 then
		warnProjections:Show()
		timerShredPsycheCD:Stop()
		timerImagesofAbsolutionCD:Stop()
		self:RegisterShortTermEvents(
			"UNIT_TARGETABLE_CHANGED"
		)
	end
end

function mod:SPELL_CAST_SUCCESS(args)
	local spellId = args.spellId
	if spellId == 313239 then
		self.vb.ImagesOfAbsolutionCast = self.vb.ImagesOfAbsolutionCast + 1
		warnImagesofAbsolution:Show(self.vb.ImagesOfAbsolutionCast)
		timerImagesofAbsolutionCD:Start()
	elseif spellId == 307937 or spellId == 313276 then--Non Mythic/Mythic
		timerShredPsycheCD:Start()
	end
end

function mod:SPELL_AURA_APPLIED(args)
	local spellId = args.spellId
	if spellId == 307784 then--Clouded Mind
		if args:IsPlayer() then
			specWarnCloudedMind:Show()
			specWarnCloudedMind:Play("targetyou")
			yellMark:Yell(2, "")--Circle
		end
	elseif spellId == 307785 then--Twisted Mind
		if args:IsPlayer() then
			specWarnTwistedMind:Show()
			specWarnTwistedMind:Play("targetyou")
			yellMark:Yell(3, "")--Diamond
		end
	elseif spellId == 308059 then
		local uId = DBM:GetRaidUnitId(args.destName)
		if self:IsTanking(uId) then
			local amount = args.amount or 1
			if (amount >= 3) and amount % 2 == 1 then
				if amount >= 7 then
					if args:IsPlayer() then
						specWarnShadowShock:Show(amount)
						specWarnShadowShock:Play("stackhigh")
					else
						--Don't show taunt warning if you're 3 tanking and aren't near the boss (this means you are the add tank)
						--Show taunt warning if you ARE near boss, or if number of alive tanks is less than 3
						--Can't taunt less you've dropped yours off, period
						if (self:CheckNearby(8, args.destName) or self:GetNumAliveTanks() < 3) and not DBM:UnitDebuff("player", spellId) and not UnitIsDeadOrGhost("player") then
							specWarnShadowShockTaunt:Show(args.destName)
							specWarnShadowShockTaunt:Play("tauntboss")
						else
							warnShadowShock:Show(args.destName, amount)
						end
					end
				end
			end
		end
	elseif spellId == 313208 then
		if self.Options.NPAuraOnIntangibleIllusion then
			DBM.Nameplate:Show(true, args.destGUID, spellId, nil, 30)
		end
	elseif spellId == 308065 or spellId == 307950 then
		local icon = self.vb.shredIcon
		warnShredPsyche:CombinedShow(0.3, args.destName)
		if args:IsPlayer() then
			specWarnShredPsyche:Show()
			specWarnShredPsyche:Play("runout")
			yellShredPsyche:Yell(icon, icon, icon)
			yellShredPsycheFades:Countdown(spellId, nil, icon)
		end
		if self.Options.SetIconOnAdds then
			self:SetIcon(args.destName, icon)
		end
		self.vb.shredIcon = self.vb.shredIcon + 1
	end
end
mod.SPELL_AURA_APPLIED_DOSE = mod.SPELL_AURA_APPLIED

function mod:SPELL_AURA_REMOVED(args)
	local spellId = args.spellId
	if spellId == 313208 then
		if self.Options.NPAuraOnIntangibleIllusion then
			DBM.Nameplate:Hide(true, args.destGUID, spellId)
		end
		if self:AntiSpam(10, 2) then
			specWarnImagesofAbsolutionSwitch:Show()
			specWarnImagesofAbsolutionSwitch:Play("killmob")
		end
	elseif spellId == 308065 or spellId == 307950 then
		if args:IsPlayer() then
			yellShredPsycheFades:Cancel()
		end
	end
end

function mod:UNIT_TARGETABLE_CHANGED()
	if UnitCanAttack("player", "boss1") then--Returning from Illusions
		warnProjectionsOver:Show()
		self:UnregisterShortTermEvents()
		timerShredPsycheCD:Start(16)
		--if self:IsHard() then
		--	timerImagesofAbsolutionCD:Start(30.5-delay)
		--end
	end
end

--[[
function mod:SPELL_PERIODIC_DAMAGE(_, _, _, _, destGUID, _, _, _, spellId, spellName)
	if spellId == 270290 and destGUID == UnitGUID("player") and self:AntiSpam(2, 2) then
		specWarnGTFO:Show(spellName)
		specWarnGTFO:Play("watchfeet")
	end
end
mod.SPELL_PERIODIC_MISSED = mod.SPELL_PERIODIC_DAMAGE

function mod:UNIT_DIED(args)
	local cid = self:GetCIDFromGUID(args.destGUID)
	if cid == 152311 then

	end
end

function mod:UNIT_SPELLCAST_SUCCEEDED(uId, _, spellId)
	if spellId == 307445 and self:AntiSpam(8, 1) then--Illusionary Projection (or 313349 or 307861)

	end
end
--]]
