#include "EntityStateResist.h"
const int ES_STATENAME_RESIST = GetNextEntityStateID();
EntityStateResist::EntityStateResist()
{
	enable = true;
	stateID = ES_STATENAME_RESIST;
	resist = resist_default = ground_resist_default;
}

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

	if (apply_resistH)
	{
		resist = resist_default;
		if (we->cbRect.cbBottom && !PxaIsIce(we->cbRect.pxaBottom))
		{
			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;
		}
		else
		{
			we->vx /= 1.1f;
		}
	}
}

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