#include "CS_Boss_TapPress.h"
#include "CS_PeSmoke.h"
#include "CS_Exp.h"

CS_Boss_TapPress::CS_Boss_TapPress(std::shared_ptr<Entity> parent)
{
	type = 2;
	attackParent = parent;
	lr = parent->lr;
	//启用碰撞
	cbRect.enableCbRect = true;
	cbRect.enableSoild = true;
	cbRect.enableSelfSoild = true;
	cbRect.enableMovePlatform = true;
	cbRect.ignoreMovePlatform = true;
	cbRect.left = cbRect.right = 72;
	cbRect.bottom = 8;
	cbRect.top = 88;
	hp_max = hp = 16 * 15;
	dropExp = 99;
	//设置动画
	ani.png = L"CS_CaveStoryMod";
	ani.sprite_index = L"am_tappress";
	//特殊属性
	speedDir = true;
	bFall = true;
}

void CS_Boss_TapPress::Init(std::weak_ptr<Entity> self)
{
	if (gameFunc->pGameOption_difficulty)
		if (*gameFunc->pGameOption_difficulty == 0)
			bNormalMode = true;
	Entity::Init(self);
}

void CS_Boss_TapPress::Step()
{
	if (bFall)
	{
		vy = 0x800 / ts;
		if(bNormalMode)
			vy = 0x400 / ts;
	}
	if (cbRect.cbBottom && bFall)
	{
		gameFunc->PlaySound(L"CS_035_explosion1");
		bFall = false;
	}
	//清除最后一次碰撞结果
	Entity::ClearCollisionResult();
	//执行运动
	Entity::Step();
	//执行碰撞
	Entity::Collision();
}

bool CS_Boss_TapPress::Hurt(std::weak_ptr<Entity> src, int getDamage, float angle, bool bTakedown, int elemType, float shockForce, float heavy, int* outRealDamage)
{
	if (getDamage < 5)
	{
		*outRealDamage = 0;
		return true;
	}
	hp -= getDamage;
	if (hp > 0)
	{
		gameFunc->PlaySound(L"CS_054_enemy_hurt_cool");
	}
	else
	{
		gameFunc->PlaySound(L"CS_071_little_crash");
		//创建云团
		SetCS_PeSmokeLarge(shared_from_this(), x, y);
		hp = 0;
		cbRect.enableMovePlatform = false;
		cbRect.enableSelfSoild = false;
		//掉落物品
		SetExp();
		Destroy();
		return true;
	}
	*outRealDamage = getDamage;
	if (bFall)
		y -= 0x4000 / ts;
	return true;
}

void CS_Boss_TapPress::SetExp()
{
	float offy = y - (cbRect.bottom + cbRect.top) / 2;
	for (int i = 0; i < dropExp; i++)
	{
		auto e = std::make_shared<CS_Exp>();
		e->x = x;
		e->y = offy;
		e->SetSize(0);
		e->SetState(1, 0);//跳过速度初始化
		e->SetState(L"unlimit_speed", 0);
		float radian = Random(180, 360) * deg2rad;
		float force = Random(0x100, 0x1000) / ts;
		e->vx = force * cosf(radian);
		e->vy = force * sinf(radian);
		gameFunc->SetEntity(shared_from_this(), e);
	}
}
