//------------------------------------------------------------------------------
// 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/Gelaim/GelaimState.h"
#include "Enemy/Gelaim/Gelaim.h"

#include "Stage/System/Stage.h"
#include "Enemy/Gelaim/GelaimBigDamageState.h"
#include "Enemy/Gelaim/GelaimSmallDamageState.h"

#include "Player/System/PlayerSystem.h"
#include "Player/System/Player.h"

//------------------------------------------------------------------------------
// 生成、破棄
//------------------------------------------------------------------------------
// コンストラクタ
GelaimState::GelaimState(Gelaim* gelaim) :
	EnemyState(gelaim), gelaim_(gelaim){
}
//------------------------------------------------------------------------------
// デストラクタ
GelaimState::~GelaimState(){
}
//------------------------------------------------------------------------------
// ダメージを受けたか
bool GelaimState::isDamaged(){
	// 無敵カウンタ処理
	int matchlessCounter = getMatchlessCounter();
	if(matchlessCounter > 0){
		matchlessCounter--;
		setMatchlessCounter(matchlessCounter);
		clearDamage();
		return false;
	}
	// ダメージ
	int damageValue = getDamageValue();
	// 無敵カウンタの設定はダメージステートにて行う
	if(damageValue == 0){ return false; }

	// ダメージ処理
	setHealth(getHealth() - damageValue);

	// 死亡か空中か大きいダメージなら吹っ飛び
	if(isDeath() || isAerial() || (damageValue > 100)){
		getEnemy()->setState(new GelaimBigDamageState(getGelaim()));
	}else{
		getEnemy()->setState(new GelaimSmallDamageState(getGelaim()));
	}
	return true;
}
//------------------------------------------------------------------------------
