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

using namespace GEnum;

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

	int nFaceDirection = lpObject->getFaceDirection();

	if( this->m_State.isAttackState() ) {

		if( this->m_State.getState() == StateType::ATTACK ) {
			// 近接
			if( this->m_lpSequence->getFrameIndex() == 1 &&
				this->m_lpSequence->getStepCounter() == 0 )
			{
				// 剣で攻撃

				// 攻撃発生
				HPLVector vecShotCenter = lpObject->getCenter();
				vecShotCenter.add( ( lpObject->getFaceDirection() > 0 ? 1: -1 ) * 20, 0 );
				GShot* lpShot = getStaticData()->m_ObjectManager.m_ShotManager.create(
					ShotType::ONLY_SLASH, vecShotCenter, lpObject->getID(), nFaceDirection );
				lpShot->setVelocityAngle( 0, 0 );
			}
		}
		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) 
			{
				// 近距離
				getStaticData()->m_CommonWork.changeState( lpObject, StateType::ATTACK );
				
			} else if( vecCurrentKeyState[ GEnum::KeyMap::B ] &&
				vecPreviousKeyState[ GEnum::KeyMap::B] == false )
			{
				// 中距離
				getStaticData()->m_CommonWork.changeState( lpObject, StateType::ATTACK_2 );

				// パイナップル
				HPLVector vecShotCenter = lpObject->getCenter();
				vecShotCenter.add( 0, 0 );
				GShot* lpShot = getStaticData()->m_ObjectManager.m_ShotManager.create(
					ShotType::PINE_APPLE_0, vecShotCenter, lpObject->getID(), nFaceDirection );

			} else if( vecCurrentKeyState[ GEnum::KeyMap::C ] &&
				vecPreviousKeyState[ GEnum::KeyMap::C] == false )
			{
				// 長距離
				getStaticData()->m_CommonWork.changeState( lpObject, StateType::ATTACK_GUN );

				// FIRE_BALL発射
				HPLVector vecShotCenter = lpObject->getCenter();
				vecShotCenter.add(
					(lpObject->getFaceDirection() > 0 ? 1 : -1) * 30,
					10 );
				GShot* lpShot = getStaticData()->m_ObjectManager.m_ShotManager.create(
					ShotType::FIRE_BALL, vecShotCenter, lpObject->getID(), nFaceDirection );
			}
		}
	}
}
