local CMD = {}

function CMD:ANP(event,anim,dir)
	if not self return false end
	console.debug("Animating "..event..": "..anim)
	for k,v in pairs(self.stage.ents)
		if v.event == event
			event = v
			v.anim = anim
			v.flags = v.flags & (~NPCF.FLIP)
			if dir
				v.flags = v.flags | NPCF.FLIP
			end
			break
		end
	end
	net.ent_anim(self.id,event)
end

function CMD:CAT()
	if not self return false end
	self.tsc.tur = "cat"
end

function CMD:CLO()
	if not self return false end
	self.tsc.msg = false
	net.tsc_clr(self.id)
end

function CMD:CLR()
	if not self return false end
	net.tsc_clr(self.id)
end

function CMD:EVE(event)
	if not self return true end
	-- <EVE tries to jump to same-script if possible.
	tsc.start(self,event,self.tsc.script,true)
	return true
end

function CMD:END()
	if not self return true end
	console.debug("Script end")
	self.tsc = nil
	net.tsc_end(self.id)
	return true
end

function CMD:FAI(fade)
	if not self return false end
	--console.debug("Fading in")
	net.tsc_fai(self.id,fade)
	self.tsc.wait = (320+256)/16
end

function CMD:FAO(fade)
	if not self return false end
	--console.debug("Fading out")
	net.tsc_fao(self.id,fade)
	self.tsc.wait = (320+256)/16
end

function CMD:KEY()
	if not self return false end
	--console.debug("Key lock")
	self.tsc.keylock = 1
	net.tsc_keylock(self.id)
end

function CMD:MSG()
	if not self return false end
	self.tsc.msg = 1
	if self.tsc.tur == "tur"
		self.tsc.tur = nil
	end
	net.tsc_msg(self.id)
end

function CMD:MS2()
	if not self return false end
	self.tsc.msg = 2
	if self.tsc.tur == "tur"
		self.tsc.tur = nil
	end
	net.tsc_msg(self.id)
end

function CMD:MS3()
	if not self return false end
	self.tsc.msg = 3
	if self.tsc.tur == "tur"
		self.tsc.tur = nil
	end
	net.tsc_msg(self.id)
end

function CMD:NOD()
	if not self return false end
	self.tsc.wait = "nod"
	net.tsc_nod(self.id)
end

function CMD:PRI()
	if not self return false end
	--console.debug("Time lock")
	self.tsc.keylock = 2
	net.tsc_keylock(self.id)
end

function CMD:SAT()
	if not self return false end
	self.tsc.tur = "sat"
end

function CMD:TUR()
	if not self return false end
	self.tsc.tur = "tur"
end

function CMD:TRA(map,event,x,y)
	if not self return true end
	net.send_map(self.id,stage.load(map))
	tsc.start(self,event,true) -- After map change, map script changes, so...
	return true
end

function CMD:WAI(wait)
	if not self return (wait == 9999) end
	--console.debug("Wait "..wait)
	self.tsc.wait = wait
end

------------------------------------
-- FILLER COMMANDS FROM HERE DOWN --
------------------------------------

--[[
function CMD:CMU(musicslot)
	if not self return false end
	-- TODO: Change music
end

function CMD:FLJ(flag,event)
	if not self return false end
end

CMD["FL+"] = function(self,flag)
	if not self return false end
end

function CMD:MNA()
	if not self return false end
	console.debug("Map name")
	-- Show map name for 2 seconds
end

function CMD:SKJ(flag,event)
	if not self return false end
end
]]

return CMD
