#include "CS_JackJump.h"
#include "CS_Jack.h"
const int CS_JackSTATENAME_JUMP = ++entityStateID;
CS_JackJump::CS_JackJump()
{
	enable = true;
	SetPhysice(false);
	jump_disable = true;
	jumped = true;
	stateID = CS_JackSTATENAME_JUMP;
}

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

	auto mychar = std::static_pointer_cast<CS_Jack>(we);
	//重置状态
	if (we->cbRect.cbBottom)
		jumped = false;
	//锁键
	if (!we->input.GetJump())
		jump_disable = false;
	//通常跳跃
	bool 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 (a1)
		{
			we->vy = -jump;
		}
		jumped = true;
		jump_disable = true;
		we->gameFunc->PlaySound(L"CS_015_quote_jump");
		//是否在空中
		mychar->ChangeState(mychar->stateAir.GetStateID());
		mychar->action_timecounter = 0;
	}
}

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

void CS_JackJump::SetJump()
{
	auto we = e.lock();
	if (!we)
		return;

	auto mychar = std::static_pointer_cast<CS_Jack>(we);
	we->vy = -jump;
	jumped = true;
	jump_disable = true;
}
