//----------------------------------//----------------------------------//----------------------------------//----------------------------------
//
// File   : AVP_Human_MovesGamescene.cpp
// Author : Gareth Thomas
// Date   : 01 / 07 / 2008
//
// Copyright (C) 2007 Rebellion, All Rights Reserved.
//
//----------------------------------//----------------------------------//----------------------------------//----------------------------------

//----------------------------------//----------------------------------//----------------------------------//----------------------------------
// Include files...
//----------------------------------//----------------------------------//----------------------------------//----------------------------------
// Core
#include "Core/Asura.h"

// This Files Header
#include "Moves/Vertebrates/Human/AVP_Human_Moves_MoveToFloor.h"

// Asura
#include "Blueprint/Asura_Blueprint_System.h"

// AVP
#include "Actor/Vertebrates/AVP_Vertebrate_AnimationHandler.h"
#include "Blueprint/AVP_Blueprint_HashIDs.h"
#include "Entity/PhysicalObject/Actor/Vertebrates/Human/AVP_ClientActor_Human.h"
#include "Moves/AVP_Moves.h"
#include "Moves/AVP_MoveData_Animation.h"

//----------------------------------//----------------------------------//----------------------------------//----------------------------------
bool AVP_Move_Human_MoveToFloor::Start(const Asura_Msg_Move* pxStartMsg)
{
// 	if ( pxStartMsg == NULL )
// 	{
// 		Asura_Assert( false, "Human Into Peek Emerge move can only be triggered by message." );
// 		return(false);
// 	}
// 
// 	const AVP_Message_Human_MoveToFloor* pxMessage = static_cast< const AVP_Message_Human_MoveToFloor* >( pxStartMsg );
// 
// 	if ( pxMessage )
// 	{
// 		Asura_Hash_ID uThirdPersonAnim = pxMessage->m_uAnimHash;
// 
// 		SetAnimHashes( ASURA_HASH_ID_UNSET, uThirdPersonAnim );
// 
// 		if ( m_pxAVPAnimationData )
// 		{
// 			m_pxAVPAnimationData->SetAnimHash( m_uThirdPersonAnimHash );
// 		}
// 	}
// 
// 	// Finally, call the base-function...
// 	return( PARENT::Start( pxStartMsg ) );

	//------------------------------------------------//
	if ( !pxStartMsg ) { return false; }

	AVP_ClientEntity_Actor* pxHuman = AVP_ClientEntity_Actor::FindEntity( GetParentSystem().GetOwner().GetGuid() );
	const AVP_Message_Human_MoveToFloor* pxMsg = static_cast<const AVP_Message_Human_MoveToFloor*>(pxStartMsg);

	SetAnimHashes( ASURA_HASH_ID_UNSET, pxMsg->m_uAnimHash );

	if ( !m_pxAVPAnimationData ) { return false; }

	m_pxAVPAnimationData->SetTweenData(0.1f, 0.2, true);

	u_int uPriority = AVP_AAPC_FLINCH_ANIM_TP;
	m_pxAVPAnimationData->SetAnimPriority(uPriority);
	m_pxAVPAnimationData->SetLeaveAnimAtEnd(true);

	Asura_Matrix_3x3 xTargetOrientation;

	// Base it on our own orientation.
	Asura_Euler_3 xEuler;
	Asura_Matrix_3x3 xMat;
	xEuler.FromMatrix(pxHuman->GetCurrentOrientation());
	xEuler.x = xEuler.z = 0.0f;
	xEuler.ToMatrix(xMat);

	m_xOrientationInterpolationData.SetMovementOffsetOperation(Asura_MoveData_OrientationInterpolation::ADD_MOVEMENT_OFFSET);
	m_xOrientationInterpolationData.SetDuration(0.3f);
	m_xOrientationInterpolationData.SetFinal(xMat);
	m_xOrientationInterpolationData.SetSingularityHintAxis(Asura_AVector3(0.0f,0.0f,-1.0f));
	InitialiseOrientationInterpolation(m_xOrientationInterpolationData);

	SetAimDirectionUsage(AVP_ClientEntity_Actor::AIM_DIRECTION_RESET);
	SetLookAtPositionUsage(AVP_ClientEntity_Actor::LOOK_AT_POSITION_RESET);

	SetPositionUsage(POSITION_SET_FROM_VELOCITY);

	return PARENT::Start(pxStartMsg);
}


