#include "CS_QuoteJump.h"
#include "CS_Quote.h"
const int CS_QuoteSTATENAME_JUMP = ++entityStateID;
CS_QuoteJump::CS_QuoteJump()
{
	enable = true;
	SetPhysice(false);
	jump_disable = true;
	jumped = true;
	stateID = CS_QuoteSTATENAME_JUMP;
}

void CS_QuoteJump::State()
{
	auto we = e.lock();
	if (!we)
		return;

	auto mychar = std::static_pointer_cast<CS_Quote>(we);
	//重置状态
	if (mychar->fishState)
	{
		if (jump_reset_counter > 0)
		{
			if (we->ani.image_counter_speed == 0)
				we->ani.image_index = 1;
			jump_reset_counter--;
		}
		if (jump_reset_counter == 0)
			jumped = false;
	}
	else
	{
		if (we->cbRect.cbBottom)
			jumped = false;
	}
	//锁键
	if (!we->input.GetJump())
		jump_disable = false;
	//通常跳跃
	bool a1 = false;
	if (mychar->fishState)
	{
		a1 = (we->cbRect.cbBottom || we->cbRect.inWater) &&
			!mychar->InAction() &&
			!jumped;
	}
	else
	{
		a1 = we->cbRect.cbBottom &&
			!mychar->InAction() &&
			!jumped;
	}
	bool b1 = we->input.GetJump() &&
		!we->blockJump &&
		!jump_disable;

	bool a = a1;
	bool b = b1;
	if (a && b)
	{
		if (mychar->stateBooster.inBoost)//着陆
			mychar->stateBooster.QuitBoost();
		else if (a1)
		{
			if (mychar->fishState)
				we->vy = -inwater_jump;
			else
				we->vy = -jump;
		}
		jumped = true;
		jump_reset_counter = jump_reset_counter_max;
		jump_disable = true;
		if (mychar->fishState)
			we->gameFunc->PlaySound(L"CS_fishjump");
		else
			we->gameFunc->PlaySound(L"CS_015_quote_jump");
		//是否在空中
		mychar->ChangeState(mychar->stateAir.GetStateID());
		mychar->action_timecounter = 0;
	}
}

void CS_QuoteJump::SetPhysice(bool bInWater)
{
	if (bInWater)
		jump = inwater_jump;
	else
		jump = ground_jump;
}
