function onRunning(V)if isSeated then return end if V>0 then pose="\082\117\110\110\105\110\103"else pose="\083\116\097\110\100\105\110\103"end end function onDied()pose="\068\101\097\100"end function onJumping()isSeated=false pose="\074\117\109\112\105\110\103"end function onClimbing()pose="\067\108\105\109\098\105\110\103"end function onGettingUp()pose="\071\101\116\116\105\110\103\085\112"end function onFreeFall()pose="\070\114\101\101\070\097\108\108"end function onFallingDown()pose="\070\097\108\108\105\110\103\068\111\119\110"end function onSeated()isSeated=true pose="\083\101\097\116\101\100"print("\083\101\097\116\101\100")end function moveJump()RightShoulder.MaxVelocity=.5 LeftShoulder.MaxVelocity=.5 RightShoulder.DesiredAngle=3.14 LeftShoulder.DesiredAngle=-3.14 RightHip.DesiredAngle=0 LeftHip.DesiredAngle=0 end function moveFreeFall()RightShoulder.MaxVelocity=.5 LeftShoulder.MaxVelocity=.5 RightShoulder.DesiredAngle=1 LeftShoulder.DesiredAngle=-1 RightHip.DesiredAngle=0 LeftHip.DesiredAngle=0 end function moveClimb()RightShoulder.MaxVelocity=.5 LeftShoulder.MaxVelocity=.5 RightShoulder.DesiredAngle=.78 LeftShoulder.DesiredAngle=-0.78 RightHip.DesiredAngle=0 LeftHip.DesiredAngle=0 end function moveSit()print("\077\111\118\101 \083\105\116")RightShoulder.MaxVelocity=.15 LeftShoulder.MaxVelocity=.15 RightShoulder.DesiredAngle=1.57 LeftShoulder.DesiredAngle=-1.57 RightHip.DesiredAngle=1.57 LeftHip.DesiredAngle=-1.57 end function getTool()kidTable=Figure:children()if kidTable~=nil then numKids=#kidTable for V=1,numKids,1 do if kidTable[V].className=="\084\111\111\108"then return kidTable[V]end end end return nil end function getToolAnim(V)c=V:children()for V=1,#c,1 do if c[V].Name=="\116\111\111\108\097\110\105\109"and c[V].className=="\083\116\114\105\110\103\086\097\108\117\101"then return c[V]end end return nil end function animateTool()if toolAnim=="\078\111\110\101"then RightShoulder.DesiredAngle=1.57 return end if toolAnim=="\083\108\097\115\104"then RightShoulder.MaxVelocity=.5 RightShoulder.DesiredAngle=.78 return end if toolAnim=="\076\117\110\103\101"then RightShoulder.MaxVelocity=.5 LeftShoulder.MaxVelocity=.5 RightHip.MaxVelocity=.5 LeftHip.MaxVelocity=.5 RightShoulder.DesiredAngle=1.57 LeftShoulder.DesiredAngle=1.0 RightHip.DesiredAngle=1.57 LeftHip.DesiredAngle=1.0 return end end function move(V)local B local I if pose=="\074\117\109\112\105\110\103"then moveJump()return end if pose=="\070\114\101\101\070\097\108\108"then moveFreeFall()return end if pose=="\067\108\105\109\098\105\110\103"then moveClimb()return end if pose=="\083\101\097\116\101\100"then moveSit()return end RightShoulder.MaxVelocity=.15 LeftShoulder.MaxVelocity=.15 if pose=="\082\117\110\110\105\110\103"then B=.4 I=9 else B=.1 I=1 end desiredAngle=B*math.sin(V*I)RightShoulder.DesiredAngle=1.57 LeftShoulder.DesiredAngle=-1.57 RightHip.DesiredAngle=-desiredAngle LeftHip.DesiredAngle=-desiredAngle local b=getTool()if b~=nil then animStringValueObject=getToolAnim(b)if animStringValueObject~=nil then toolAnim=animStringValueObject.Value animStringValueObject.Parent=nil toolAnimTime=V+.3 end if V>toolAnimTime then toolAnimTime=0 toolAnim="\078\111\110\101"end animateTool()else toolAnim="\078\111\110\101"toolAnimTime=0 end end


function onRunning(speed)
	if isSeated then return end

	if speed>0 then
		pose = "Running"
	else
		pose = "Standing"
	end
end

function onDied()
	pose = "Dead"
end

function onJumping()
	isSeated = false
	pose = "Jumping"
end

function onClimbing()
	pose = "Climbing"
end

function onGettingUp()
	pose = "GettingUp"
end

function onFreeFall()
	pose = "FreeFall"
end

function onFallingDown()
	pose = "FallingDown"
end

function onSeated()
	isSeated = true
	pose = "Seated"
	print("Seated")
end



function moveJump()
	RightShoulder.MaxVelocity = 0.5
	LeftShoulder.MaxVelocity = 0.5
	RightShoulder.DesiredAngle = 3.14
	LeftShoulder.DesiredAngle = -3.14
	RightHip.DesiredAngle = 0
	LeftHip.DesiredAngle = 0
end

function moveFreeFall()
	RightShoulder.MaxVelocity = 0.5
	LeftShoulder.MaxVelocity = 0.5
	RightShoulder.DesiredAngle = 1
	LeftShoulder.DesiredAngle = -1
	RightHip.DesiredAngle = 0
	LeftHip.DesiredAngle = 0
end


function moveClimb()
	RightShoulder.MaxVelocity = 0.5
	LeftShoulder.MaxVelocity = 0.5
	RightShoulder.DesiredAngle = 0.78
	LeftShoulder.DesiredAngle = -0.78
	RightHip.DesiredAngle = 0
	LeftHip.DesiredAngle = 0
end

function moveSit()
	print("Move Sit")
	RightShoulder.MaxVelocity = 0.15
	LeftShoulder.MaxVelocity = 0.15
	RightShoulder.DesiredAngle = 3.14 /2
	LeftShoulder.DesiredAngle = -3.14 /2
	RightHip.DesiredAngle = 3.14 /2
	LeftHip.DesiredAngle = -3.14 /2
end

function getTool()
	
	kidTable = Figure:children()
	if (kidTable ~= nil) then
		numKids = #kidTable
		for i=1,numKids do
			if (kidTable[i].className == "Tool") then return kidTable[i] end
		end
	end
	
	return nil
end

function getToolAnim(tool)

	c = tool:children()
	for i=1,#c do
		if (c[i].Name == "toolanim" and c[i].className == "StringValue") then
			return c[i]
		end
	end
	return nil
end

function animateTool()
	
	if (toolAnim == "None") then
		RightShoulder.DesiredAngle = 1.57
		return
	end

	if (toolAnim == "Slash") then
		RightShoulder.MaxVelocity = 0.5
		RightShoulder.DesiredAngle = 0.78
		return
	end

	if (toolAnim == "Lunge") then
		RightShoulder.MaxVelocity = 0.5
		LeftShoulder.MaxVelocity = 0.5
		RightHip.MaxVelocity = 0.5
		LeftHip.MaxVelocity = 0.5
		RightShoulder.DesiredAngle = 1.57
		LeftShoulder.DesiredAngle = 1.0
		RightHip.DesiredAngle = 1.57
		LeftHip.DesiredAngle = 1.0
		return
	end
end

function move(time)
	local amplitude
	local frequency

	if (pose == "Jumping") then
		moveJump()
		return
	end

	if (pose == "FreeFall") then
		moveFreeFall()
		return
	end

	if (pose == "Climbing") then
		moveClimb()
		return
	end

	if (pose == "Seated") then
		moveSit()
		return
	end


	RightShoulder.MaxVelocity = 0.15
	LeftShoulder.MaxVelocity = 0.15
	if (pose == "Running") then
		amplitude = 0.4
		frequency = 9
	else
		amplitude = 0.1
		frequency = 1
	end

	desiredAngle = amplitude * math.sin(time*frequency)

	RightShoulder.DesiredAngle = 1.57
	LeftShoulder.DesiredAngle = -1.57
	RightHip.DesiredAngle = -desiredAngle
	LeftHip.DesiredAngle = -desiredAngle


	local tool = getTool()

	if tool ~= nil then
	
		animStringValueObject = getToolAnim(tool)

		if animStringValueObject ~= nil then
			toolAnim = animStringValueObject.Value
			-- message recieved, delete StringValue
			animStringValueObject.Parent = nil
			toolAnimTime = time + .3
		end

		if time > toolAnimTime then
			toolAnimTime = 0
			toolAnim = "None"
		end

		animateTool()

		
	else
		toolAnim = "None"
		toolAnimTime = 0
	end
end

