#include "CS_SantaFishJump.h"
#include "CS_SantaFish.h"
const int CS_SantaFishSTATENAME_JUMP = ++entityStateID;
CS_SantaFishJump::CS_SantaFishJump()
{
	enable = true;
	SetPhysice(false);
	jump_disable = true;
	jumped = true;
	stateID = CS_SantaFishSTATENAME_JUMP;
}

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

	auto mychar = std::static_pointer_cast<CS_SantaFish>(we);
	//重置状态
	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;
	//锁键
	if (!we->input.GetJump())
		jump_disable = false;
	//通常跳跃
	bool a1 = (we->cbRect.cbBottom || we->cbRect.inWater) &&
		!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_reset_counter = jump_reset_counter_max;
		jump_disable = true;
		we->gameFunc->PlaySound(L"CS_fishjump");
		//游泳动画
		mychar->ChangeState(mychar->stateSwim.GetStateID());
		mychar->action_timecounter = 0;
	}
}

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

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

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