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
		end
	end
	if unitAuraUpdateInfo.updatedAuraInstanceIDs ~= nil then
		for _, auraInstanceID in ipairs(unitAuraUpdateInfo.updatedAuraInstanceIDs) do
			local updateAura = C_UnitAuras.GetAuraDataByAuraInstanceID("player", auraInstanceID);
			if not updateAura or not updateAura.spellId or not updateAura.applications then return end
			if updateAura.applications < 3 then return end
			if updateAura.spellId == 240443 then	--测试384035
				PlaySoundFile("Interface\\AddOns\\AddUI\\Func\\call\\number\\"..updateAura.applications..".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 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,"摆放了一桌") and string.match(msg,"供大家享用") then
		PlaySoundFile("Interface\\AddOns\\AddUI\\Func\\call\\【露露】吃大餐咯~.ogg","Master")
	end
end)

ns.ADDUIEVENT("UNIT_SPELLCAST_SUCCEEDED", function(unit,guid,spellid)
	if unit == "player" and spellid == 385969 then 
		if IsInRaid() then
			SendChatMessage("已放置"..(select(2,GetItemInfo(198277))), "RAID")
		elseif IsInGroup() then
			SendChatMessage("已放置"..(select(2,GetItemInfo(198277))), "PARTY")
		end
	end
end)