//------------------------------------------------------------------------------
// Lamp : Open source game middleware
// Copyright (C) 2004  Junpei Ohtani ( Email : junpee@users.sourceforge.jp )
//
// This library is free software; you can redistribute it and/or
// modify it under the terms of the GNU Lesser General Public
// License as published by the Free Software Foundation; either
// version 2.1 of the License, or (at your option) any later version.
//
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
// Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public
// License along with this library; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
//------------------------------------------------------------------------------

/** @file
 * アンズジャンプ攻撃状態実装
 * @author Junpee
 */

#include "Core/Utility/stdafx.h"
#include "Player/Anzu/AnzuJumpAttackState.h"
#include "Game/Sound/SoundSystem.h"
#include "Player/System/Player.h"
#include "Stage/System/Stage.h"

#include "Player/Anzu/AnzuStandState.h"
#include "Player/Anzu/AnzuRunState.h"

//------------------------------------------------------------------------------
// 生成、破棄
//------------------------------------------------------------------------------
// コンストラクタ
AnzuJumpAttackState::AnzuJumpAttackState(Anzu* anzu, bool doubleJump) :
	AnzuState(anzu), isDoubleJump_(doubleJump){
}
//------------------------------------------------------------------------------
// デストラクタ
AnzuJumpAttackState::~AnzuJumpAttackState(){
}
//------------------------------------------------------------------------------
// 実行
//------------------------------------------------------------------------------
// 初期化
void AnzuJumpAttackState::initialize(){
	// アニメーションシーケンス設定
	getAnimation()->setSequence(7);
	// ジャンプ攻撃音を鳴らす
	getSoundSystem()->play("AnzuJumpAttack");
	// 実行カウンタクリア
	runCounter_ = 0;
}
//------------------------------------------------------------------------------
// 後始末
void AnzuJumpAttackState::finalize(){
	// コリジョンを無効に戻す
	getAttackCollision()->setEnabled(false);
}
//------------------------------------------------------------------------------
// 実行
void AnzuJumpAttackState::run(){
	// 定数
	float animationScale = 2.f;
	float moveXZScale = 0.5f;

	// ステート変更
	Point2f moveStick = getMoveStick();
	if(!isDamaged()){
		if(!isAerial()){
			if(moveStick == Point2f::zero){
				getPlayer()->setState(new AnzuStandState(getAnzu()));
			}else{
				getPlayer()->setState(new AnzuRunState(getAnzu()));
			}
		}
	}

	// 移動ベクトル算出
	Vector3 moveVelocity(moveStick.x, 0.f, moveStick.y);
	moveVelocity *= moveXZScale;

	// 位置と速度の計算
	calcVelocityAndPosition(moveVelocity);
	// 向きの設定
	setDirection(moveVelocity);

	// 地形コリジョン
	landCollide();

	// 描画セットアップ
	drawSetup(animationScale);

	// 攻撃
	if(runCounter_ == 10){ getAttackCollision()->setEnabled(true); }
	if(runCounter_ == 22){ getAttackCollision()->setEnabled(false); }
	float range = 9.f;
	if(getAttackCollision()->isEnabled()){
		if(isDoubleJump_){
			attackCollide(getRightHandBone(),
				Vector3(0.f, range, range), range, 400);
		}else{
			attackCollide(getRightHandBone(),
				Vector3(0.f, range, range), range, 200);
		}
	}

	// 実行カウンタインクリメント
	runCounter_++;
}
//------------------------------------------------------------------------------
