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 == 10060 then
				PlaySoundFile("Interface\\AddOns\\AddUI\\Func\\call\\能量灌注.mp3","Master")
			end
			if aura.spellId == 388007 then
				PlaySoundFile("Interface\\AddOns\\AddUI\\Func\\call\\仲夏祝福.mp3","Master")
			end
			if aura.spellId == 388010 then
				PlaySoundFile("Interface\\AddOns\\AddUI\\Func\\call\\暮秋祝福.mp3","Master")
			end
			if aura.spellId == 342246 then
				PlaySoundFile("Interface\\AddOns\\AddUI\\Func\\call\\操控时间音效.mp3","Master")
			end
		end
	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)