local _,ns = ...
ns.ADDUIEVENT("UNIT_AURA", function(unit,unitAuraUpdateInfo)
	if unit ~= "player" then return end
	if unitAuraUpdateInfo.addedAuras ~= nil then
		if not AddUIDB.buffcall then return end
		for _, aura in ipairs(unitAuraUpdateInfo.addedAuras) do
			if aura.spellId == 342246 then
				PlaySoundFile("Interface\\AddOns\\AddUI\\Func\\call\\操控时间音效.mp3","Master")
			end
		end
	end
end)
ns.ADDUIEVENT("COMBAT_LOG_EVENT_UNFILTERED", function()
	if not AddUIDB.buffcall then return end
    local _, subevent, _, _, sourceName, sourceFlag, RaidFlags, _, destName, _, _, SpellID, SpellName = CombatLogGetCurrentEventInfo()
	if (subevent ~= 'SPELL_CAST_SUCCESS') then return end
	if not sourceName then return end
	if not UnitInParty(sourceName) and not UnitInRaid(sourceName) then return end
	--检测队友的技能
	if SpellID == 8143 then
		PlaySoundFile("Interface\\AddOns\\AddUI\\Func\\call\\spell\\战栗.mp3","Master")
	end
	if SpellID == 383013 then
		PlaySoundFile("Interface\\AddOns\\AddUI\\Func\\call\\spell\\清毒.mp3","Master")
	end
	if SpellID == 115310 then
		PlaySoundFile("Interface\\AddOns\\AddUI\\Func\\call\\spell\\还魂.mp3","Master")
	end
	if SpellID == 374227 then
		PlaySoundFile("Interface\\AddOns\\AddUI\\Func\\call\\spell\\微风.mp3","Master")
	end
	if SpellID == 414660 then
		PlaySoundFile("Interface\\AddOns\\AddUI\\Func\\call\\spell\\群盾.mp3","Master")
	end
	if SpellID == 31821 then
		PlaySoundFile("Interface\\AddOns\\AddUI\\Func\\call\\spell\\光环.mp3","Master")
	end
	if SpellID == 64901 then
		PlaySoundFile("Interface\\AddOns\\AddUI\\Func\\call\\spell\\蓝歌.mp3","Master")
	end
	if SpellID == 97462 then
		PlaySoundFile("Interface\\AddOns\\AddUI\\Func\\call\\spell\\集结呐喊.mp3","Master")
	end
	if SpellID == 374968 then
		PlaySoundFile("Interface\\AddOns\\AddUI\\Func\\call\\spell\\螺旋.mp3","Master")
	end
	if SpellID == 372048 then
		PlaySoundFile("Interface\\AddOns\\AddUI\\Func\\call\\spell\\压迫.mp3","Master")
	end
	if SpellID == 37375 then
		PlaySoundFile("Interface\\AddOns\\AddUI\\Func\\call\\spell\\群驱.mp3","Master")
	end

	--仅检测对自己释放的法术
	if not destName then return end
	if not UnitIsUnit("player",destName) then return end
	if SpellID == 10060 then
		PlaySoundFile("Interface\\AddOns\\AddUI\\Func\\call\\spell\\能量灌注.mp3","Master")
	end
	if SpellID == 388007 then
		PlaySoundFile("Interface\\AddOns\\AddUI\\Func\\call\\spell\\仲夏祝福.mp3","Master")
	end
	if SpellID == 388010 then
		PlaySoundFile("Interface\\AddOns\\AddUI\\Func\\call\\spell\\暮秋祝福.mp3","Master")
	end
	if SpellID == 374251 then
		PlaySoundFile("Interface\\AddOns\\AddUI\\Func\\call\\spell\\红驱.mp3","Master")
	end
	if SpellID == 6940 then
		PlaySoundFile("Interface\\AddOns\\AddUI\\Func\\call\\spell\\牺牲.mp3","Master")
	end
	if SpellID == 1044 then
		PlaySoundFile("Interface\\AddOns\\AddUI\\Func\\call\\spell\\自由.mp3","Master")
	end
	if SpellID == 1022 then
		PlaySoundFile("Interface\\AddOns\\AddUI\\Func\\call\\spell\\保护.mp3","Master")
	end
	if SpellID == 204018 then
		PlaySoundFile("Interface\\AddOns\\AddUI\\Func\\call\\spell\\破咒.mp3","Master")
	end
	if SpellID == 33206 then
		PlaySoundFile("Interface\\AddOns\\AddUI\\Func\\call\\spell\\压制.mp3","Master")
	end
	if SpellID == 102342 then
		PlaySoundFile("Interface\\AddOns\\AddUI\\Func\\call\\spell\\树皮.mp3","Master")
	end
	if SpellID == 357170 then
		PlaySoundFile("Interface\\AddOns\\AddUI\\Func\\call\\spell\\膨胀.mp3","Master")
	end
	if SpellID == 306732 then
		PlaySoundFile("Interface\\AddOns\\AddUI\\Func\\call\\spell\\悖论.mp3","Master")
	end
end)

local willPlay,indexHandle
local targetindex = GetRaidTargetIndex("player") or 0
ns.ADDUIEVENT("RAID_TARGET_UPDATE", function(unit,index)
	if not AddUIDB.iconcall then return end
	if targetindex ~= GetRaidTargetIndex("player") then
		targetindex = GetRaidTargetIndex("player") or 0
		if indexHandle then StopSound(indexHandle,0) end
		if targetindex == 1 then
			willPlay,indexHandle = PlaySoundFile("Interface\\AddOns\\AddUI\\Func\\call\\你是星星.mp3","Master")
		elseif targetindex == 2 then
			willPlay,indexHandle = PlaySoundFile("Interface\\AddOns\\AddUI\\Func\\call\\你是大饼.mp3","Master")
		elseif targetindex == 3 then
			willPlay,indexHandle = PlaySoundFile("Interface\\AddOns\\AddUI\\Func\\call\\你是紫菱.mp3","Master")
		elseif targetindex == 4 then
			willPlay,indexHandle = PlaySoundFile("Interface\\AddOns\\AddUI\\Func\\call\\你是三角.mp3","Master")
		elseif targetindex == 5 then
			willPlay,indexHandle = PlaySoundFile("Interface\\AddOns\\AddUI\\Func\\call\\你是月亮.mp3","Master")
		elseif targetindex == 6 then
			willPlay,indexHandle = PlaySoundFile("Interface\\AddOns\\AddUI\\Func\\call\\你是方块.mp3","Master")
		elseif targetindex == 7 then
			willPlay,indexHandle = PlaySoundFile("Interface\\AddOns\\AddUI\\Func\\call\\你是红叉.mp3","Master")
		elseif targetindex == 8 then
			willPlay,indexHandle = PlaySoundFile("Interface\\AddOns\\AddUI\\Func\\call\\你是骷髅.mp3","Master")
		end
	end
end)

--说/喊 通报标记和时间
local PlayerGUID = UnitGUID("player")
local MSGICON = CreateFrame("frame")
MSGICON:RegisterEvent('CHAT_MSG_SAY')
MSGICON:RegisterEvent('CHAT_MSG_YELL')
MSGICON:SetScript("OnEvent",function(self, event,text,...)
	if not AddUIDB.msgcall then return end
	if PlayerGUID ~= select(11, ...) then return end

	local msgicon = string.match(text, "{rt(%d+)}")

	if not msgicon then return end
	PlaySoundFile("Interface\\AddOns\\AddUI\\Func\\call\\numbericon\\"..msgicon..".mp3","Master")
	
	local msgtime = string.match(text, "{rt%d+}(.*)")
	
	if not msgtime then return end
	msgtime = string.gsub(msgtime, "{rt%d+}", "")
	
	if not msgtime then return end
	msgtime = string.match(msgtime, "%d+")
	
	if tonumber(msgtime) and tonumber(msgtime) > 20 then
		msgtime = string.match(msgtime, "(%d)$")
	end
	
	if not msgtime then return end
	C_Timer.After(0.5,function()
		PlaySoundFile("Interface\\AddOns\\AddUI\\Func\\call\\number\\"..msgtime..".mp3","Master")
	end)
end)

--吃鱼
local T=CreateFrame("frame")
T:RegisterEvent('CHAT_MSG_MONSTER_EMOTE')
T:SetScript("OnEvent",function(_,_,msg,unit)
	if not AddUIDB.buffcall then return end
	if not UnitInParty(unit) and not UnitInRaid(unit) then return end
	if string.match(msg,"供大家享用") then
		PlaySoundFile("Interface\\AddOns\\AddUI\\Func\\call\\【露露】吃大餐咯~.ogg","Master")
	end
end)