#include "CS_KanpaResist2.h"
#include "EntityStateResist.h"
#include "CS_Kanpa.h"
#include "CS_KanpaControl2.h"
const int& CS_KanpaSTATENAME_RESIST2 = ++entityStateID;
CS_KanpaResist2::CS_KanpaResist2()
{
	SetPhysice(false);
	resist = resist_default;
	enable = true;
	stateID = CS_KanpaSTATENAME_RESIST2;
}

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

	auto mychar = std::static_pointer_cast<CS_Kanpa>(we);
	auto& controlState = mychar->stateControl2;
	resist = resist_default;
	//空中阻力
	if (apply_resistH && !we->cbRect.cbBottom)
	{
		if (!mychar->InAction())
			we->vx /= 1.1f;
		else
			we->vx /= 1.05f;
	}
	//步行阻力 让玩家在地面低速滑行停下
	if (!apply_resistH && we->cbRect.cbBottom && !PxaIsIce(we->cbRect.pxaBottom) && abs(we->vx) < controlState.max_move / 2.05f)
		we->vx /= 2.0f;
	//地面阻力
	if (apply_resistH && we->cbRect.cbBottom && !PxaIsIce(we->cbRect.pxaBottom) && !(we->cbRect.cbLeft || we->cbRect.cbRight))
	{
		if (we->vx < 0)
			if (we->vx > -resist)
				we->vx = 0;
			else
				we->vx += resist;
		if (we->vx > 0)
			if (we->vx < resist)
				we->vx = 0;
			else
				we->vx -= resist;
	}
}

void CS_KanpaResist2::SetPhysice(bool bInWater)
{
	if (bInWater)
		resist_default = inwater_resist_default;
	else
		resist_default = ground_resist_default;
}
