#include "GPMPeseruAttack.h"

#ifdef _DXLIB
#include "GStaticDataDX.h"
#else
#include "GStaticData.h"
#endif

using namespace GEnum;

GPMPeseruAttack::GPMPeseruAttack(){
}
GPMPeseruAttack::~GPMPeseruAttack(){
}

void GPMPeseruAttack::setup( HPLShootingObject* lpObject ) {
	this->m_State = *lpObject->getState();
	this->m_nWeaponType = lpObject->getUsingWeaponTypeIndex();

	this->m_bIsHeavyWeapon = false;

	this->m_lpSequence = getStaticData()->m_CommonWork.getSequenceFromObject( lpObject );

	this->m_SequenceState = this->m_lpSequence->getState();

}


void GPMPeseruAttack::attack( HPLShootingObject* lpObject, HPLShootingObject* lpTarget,
	HPLVector* lpCenter, HPLVector* lpVelocityAngle, 
	std::vector<bool>& vecCurrentKeyState, std::vector<bool>& vecPreviousKeyState )
{
	// セットアップ
	this->setup( lpObject );

	// 
	if( this->m_State.isAttackGunState() ) {

		if( this->m_SequenceState.isFinishAnimation ) {
			
			// ステート巻き戻し
			getStaticData()->m_CommonWork.rollBack( lpObject );
		}
	} else if( this->m_State.isAttackState() ) {

		// 進行方向へ移動する
		if( this->m_State.getState() == StateType::ATTACK ) {
			// 斬る
			lpVelocityAngle->setX( lpObject->getFaceDirection() * GEnum::PESERU_SLASH_MOVE_X );
		}

		if( this->m_SequenceState.isFinishAnimation ) {
			// ステート巻き戻し
			getStaticData()->m_CommonWork.rollBack( lpObject );
		}
	} else {
		// 通常状態

		if( lpObject->getState()->isReadyToAttackState() ) {
			// 攻撃可能な状態

			if( vecCurrentKeyState[ GEnum::KeyMap::A ] && vecPreviousKeyState[ GEnum::KeyMap::A ] == false ) {
				// 攻撃状態へ TODO
				getStaticData()->m_CommonWork.changeState( lpObject, StateType::ATTACK );
				// 攻撃発生
				HPLVector vecShotCenter = lpObject->getCenter();
				vecShotCenter.add( 0, PESERU_SLASH_Y );
				GShot* lpShot = getStaticData()->m_ObjectManager.m_ShotManager.create(
					ShotType::SLASH, vecShotCenter, lpObject->getID(), lpObject->getFaceDirection() );
				lpShot->setVelocityAngle( ( lpObject->getFaceDirection() > 0 ? 1: -1 ) * PESERU_SLASH_MOVE_X, 0 );

			} else if( vecCurrentKeyState[ GEnum::KeyMap::B ] && vecPreviousKeyState[ GEnum::KeyMap::B ] == false ) {
				// X→スライディング
				getStaticData()->m_CommonWork.changeState( lpObject, StateType::ATTACK_2 );
				lpVelocityAngle->set( 
					( lpObject->getFaceDirection() > 0 ? 1: -1 ) * PESERU_SLIDING_SPEED_X,
					0 );
			} else if( vecCurrentKeyState[ GEnum::KeyMap::C ] && vecPreviousKeyState[ GEnum::KeyMap::C ] == false ) {

				((GPlayer*)lpObject)->m_bIsNaked = !((GPlayer*)lpObject)->m_bIsNaked;
			}
		}
	}
}
