//------------------------------------------------------------------------------
// 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 "Enemy/Tanue/TanueAttackState.h"
#include "Game/Sound/SoundSystem.h"
#include "Enemy/System/Enemy.h"
#include "Stage/System/Stage.h"

#include "Enemy/Tanue/TanueRunState.h"

//------------------------------------------------------------------------------
// 生成、破棄
//------------------------------------------------------------------------------
// コンストラクタ
TanueAttackState::TanueAttackState(Tanue* tanue) : TanueState(tanue){
}
//------------------------------------------------------------------------------
// デストラクタ
TanueAttackState::~TanueAttackState(){
}
//------------------------------------------------------------------------------
// 実行
//------------------------------------------------------------------------------
// 初期化
void TanueAttackState::initialize(){
	// アニメーションシーケンス設定
	getAnimation()->setSequence(3);
	// 攻撃音を鳴らす
	getSoundSystem()->play("TanueAttack");
}
//------------------------------------------------------------------------------
// 後始末
void TanueAttackState::finalize(){
	// コリジョンを無効に戻す
	getAttackCollision()->setEnabled(false);
}
//------------------------------------------------------------------------------
// 実行
void TanueAttackState::run(){
	// 定数
	float animationScale = 1.f;
	float moveXZScale = 0.1f;

	// ステート変更
	if(!isDamaged()){
		if(getRunCounter() == 60){
			getEnemy()->setState(new TanueRunState(getTanue()));
		}
	}

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

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

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

	// 攻撃
	if(getRunCounter() == 20){ getAttackCollision()->setEnabled(true); }
	if(getRunCounter() == 45){ getAttackCollision()->setEnabled(false); }
	if(getAttackCollision()->isEnabled()){
		attackCollide(getAttackBone(), Vector3(0.f, 2.5f, 0.f), 7.5f, 60);
	}

}
//------------------------------------------------------------------------------
