#include "CS_PuuBubble_Empty.h"
#include "CS_PeSmoke.h"
CS_PuuBubble_Empty::CS_PuuBubble_Empty()
{
	type = 2;
	el.name = CS_PUUBUBBLE_EMPTY_CREATENAME;
	//启用碰撞
	cbRect.enableCbRect = true;
	hp_max = hp = 1;
	//设置动画
	ani.png = L"CS_CaveStoryMod";
	ani.sprite_index = L"ls_puububble_empty";
	speedDir = true;
}

void CS_PuuBubble_Empty::Step()
{
	vy += 10 / ts;
	if (cbRect.cbLeft)
		vx = abs(vx);
	if (cbRect.cbRight)
		vx = -abs(vx);
	if (cbRect.cbTop)
		vy = abs(vy);
	if (cbRect.cbBottom)
		vy = -abs(vy);
	lr = vx < 0 ? 0 : 1;
	if (existTime > 0)
	{
		existTime--;
		if (existTime == 0)
		{
			int out;
			Hurt(shared_from_this(), 1, 0, false, 0, 0, 0, &out);
		}
	}
	//清除最后一次碰撞结果
	Entity::ClearCollisionResult();
	//执行运动
	Entity::Step();
	//执行碰撞
	Entity::Collision();
}

void CS_PuuBubble_Empty::Attack(std::weak_ptr<Entity> dst, int* outDamage, float* outAngle, bool* outTakedown, int* outElemType, float* outShockForce, float* outHeavy)
{
	*outDamage = 1;
	auto wdst = dst.lock();
	if (wdst)
	{
		if (wdst->lr == 0)
		{
			*outAngle = 315;
		}
		else
		{
			*outAngle = 225;
		}
	}
	*outTakedown = true;
	*outElemType = 0;
	*outShockForce = 0x200 / ts;
	*outHeavy = 2;
}

bool CS_PuuBubble_Empty::Hurt(std::weak_ptr<Entity> src, int getDamage, float angle, bool bTakedown, int elemType, float shockForce, float heavy, int* outRealDamage)
{
	if (getDamage == 0)
		return false;
	*outRealDamage = getDamage;
	hp -= getDamage;
	if (hp <= 0)
	{
		gameFunc->PlaySound(L"CS_021_bubble");
		//创建云团
		SetCS_PeSmokeWater(shared_from_this(), x, y, 2);
		hp = 0;
		Destroy();
	}
	return true;
}

std::shared_ptr<Entity> CreateCS_PuuBubble_Empty()
{
	return std::make_shared<CS_PuuBubble_Empty>();
}

std::weak_ptr<Entity> SetCS_PuuBubble_Empty(std::shared_ptr<Entity> parent, float x, float y, float vx, float vy)
{
	auto am = std::make_shared<CS_PuuBubble_Empty>();
	am->x = x;
	am->y = y;
	am->vx = vx;
	am->vy = vy;
	parent->gameFunc->SetEntity(parent, am);
	return am;
}
