#include "CS_SantaJump.h"
#include "CS_Santa.h"
const int CS_SantaSTATENAME_JUMP = GetNextEntityStateID();
CS_SantaJump::CS_SantaJump()
{
	enable = true;
	SetPhysice(false);
	jump_disable = true;
	jumped = true;
	stateID = CS_SantaSTATENAME_JUMP;
}

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

	auto mychar = std::static_pointer_cast<CS_Santa>(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_SantaJump::SetPhysice(bool bInWater)
{
	if (bInWater)
		jump = inwater_jump;
	else
		jump = ground_jump;
}

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

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