#include "CS_QuoteGravity.h"
#include "EntityStateGravity.h"
const int& CS_QuoteSTATENAME_GRAVITY = ES_STATENAME_GRAVITY;
CS_QuoteGravity::CS_QuoteGravity()
{
	SetPhysice(false);
	gravity = gravity_default;
	enable = true;
	stateID = CS_QuoteSTATENAME_GRAVITY;
}

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

	//玩家上升时，按住跳跃键可能改变重力
	if (we->vy > 0)//恢复重力
		gravity = gravity_default * gravity_scale;
	if (we->vy + gravity < max_fall_speed)
	{
		we->vy += gravity * gravity_scale;
		if (we->vy > max_fall_speed * gravity_scale)
			we->vy = max_fall_speed * gravity_scale;
	}
}

void CS_QuoteGravity::SetPhysice(bool bInWater)
{
	if (bInWater)
	{
		gravity_default = inwater_gravity_default;
		max_fall_speed = inwater_max_fall_speed;
	}
	else
	{
		gravity_default = ground_gravity_default;
		max_fall_speed = ground_max_fall_speed;
	}
}

void CS_QuoteGravity::SetGravityScale(float scale)
{
	gravity_scale = scale;
}