
--
--
--	AEmotes Classic, Tiped by Holyfrey and repaired for classic og retail by Michael Boyle (a.k.a. Codermik)
--	Original author credit goes to DrArkaneX <cfaulkner70@gmail.com - www.mainsteam.net>
--
--	Look me up on Classic Mirage Raceway playing Mik (Warrior), Castanova (Mage) and many
--	other characters... too many to mention here lol.
--
--	You can also find me on Twitch @ www.twitch.tv/codermik
--
--	Thanks to Holyfrey that updating this addon with help from Codermik on Mirage Raceway Alliance.
--
--



local AEmotes = CreateFrame("Frame")
AEmotes:RegisterEvent("VARIABLES_LOADED")
AEmotes:RegisterEvent("CHAT_MSG_SAY")
AEmotes:RegisterEvent("PLAYER_LOGIN")
AEmotes:SetScript("OnEvent", function(self, event, a1) self:OnEvent(event, a1) end)

AEMOTES							= {}
AEMOTES.artists					= {};
AEMOTES.TimeTilNext 			= time()


---
--- global event processor
---
function AEmotes:OnEvent(event, a1, ...)

	if event == "PLAYER_LOGIN" then
		DEFAULT_CHAT_FRAME:AddMessage("|cff00e0ffAEmotes Classic loaded! |cffffffff - Developed by Holyfrey with help from coder Michael Boyle (a.k.a Codermik).")
	end

	if (a1 and event=="CHAT_MSG_SAY" and time() >= AEMOTES.TimeTilNext) then
	local artist
	local found
	for _,artist in pairs(AEMOTES.artists) do
		if (AEMOTES[artist] and AEMOTES[artist].parms) then
			for _,parm in pairs(AEMOTES[artist].parms) do
				if (parm.msgs) then
					for _,msg in pairs(parm.msgs) do
						if (a1=="* "..msg.." *") then
							PlaySoundFile(AEMOTES[artist].AddonPath..parm.track..".ogg", "Master")
							if (parm.emote ~= nil) then
								DoEmote(parm.emote)
							end
							AEMOTES.TimeTilNext = time() + parm.len;
							found = 1
							break;
						end
					end
				end
				if (found) then
				  break
				end
			end
		end
		if (found) then
		  break
		end
	end
  end
end


---
--- global slash command processor
---
function ProcessCommandline(msg)
	if msg then
		local s,ss					= string.find(msg, " ");
		if (s) then
			local artist 			= string.sub(msg,1,s-1);
			local track				= string.sub(msg,s+1);
			if (AEMOTES[artist] and AEMOTES[artist].parms) then
				local parm;
				for _,parm in pairs(AEMOTES[artist].parms) do
					if (parm.track==track) then
						SendChatMessage("* "..parm.msgs.common.." *", "SAY");
						break;
					end
				end
			end
		else
			DEFAULT_CHAT_FRAME:AddMessage("AEmote usage: /ae {artist} {track}");
		end
	end

end


SLASH_AEMOTES1					= "/ae"
SlashCmdList["AEMOTES"] 		= ProcessCommandline


