#include "CS_CurlyNemesis.h"
#include "CS_Curly.h"
const int CS_CurlySTATENAME_NEMESIS = ++entityStateID;
CS_CurlyNemesis::CS_CurlyNemesis()
{
	stateID = CS_CurlySTATENAME_NEMESIS;
	cd_counter = 0;
	cd_counter_max = 7;
	iconIndex = 1;
}

const wchar_t* CS_CurlyNemesis::GetSaveName()
{
	return L"Nemesis";
}

const wchar_t* CS_CurlyNemesis::GetFuncName()
{
	return L"CurlySkill_Nemesis";
}

const wchar_t* CS_CurlyNemesis::GetCheckFuncName()
{
	return L"CurlySkill_Nemesis_Check";
}

void CS_CurlyNemesis::SubStep()
{
	auto we = e.lock();
	if (!we)
		return;

	auto mychar = std::static_pointer_cast<CS_Curly>(we);
	bUIShowDisableSkill = !(
		mychar->lastGun != this &&
		!lock
		);
	bool a1 = mychar->lastGun != this &&
		!lock;
	bool b1 = (mychar->input.key & keyMask);
	bool c1 = mychar->mp >= mp_cost;

	bool a = a1;
	bool b = b1;
	bool c = c1;
	if (a && b && c)
	{
		mychar->lastSkill = this;
		mychar->ChangeState(GetStateID());
	}
	//无技能冷却时间
	EntitySkillState::SubStep();
	if (cd_counter > 0)
		cd_counter--;
}

void CS_CurlyNemesis::ChangeStateMsg(int stateID)
{
	auto we = e.lock();
	if (!we)
		return;
	auto mychar = std::static_pointer_cast<CS_Curly>(we);

	if (stateID == GetStateID())
	{
		//初始化技能
		enable = true;
		//切换到这把枪
		mychar->lastGun = this;
		we->gameFunc->PlaySound(L"CS_004_switchweapon");
	}
	else if (stateID == CS_CurlySTATENAME_FIRE && amList.size() < 2 &&
		mychar->lastGun == this)
	{
		bool bShot = false;
		if (mychar->enableAI)
		{
			if(cd_counter == 0)
				bShot = true;
		}
		else
		{
			bShot = true;
		}
		if (bShot)
		{
			//初始化技能
			enable = false;
			//开火
			auto am = std::make_shared<CS_CurlyNemesisBlade>(we);
			we->gameFunc->SetEntity(we, am);
			amList.push_back(am);
			cd_counter = cd_counter_max;
			//锁住按键
			mychar->inputLock.SetAtk(true);
		}
	}
	else
		enable = false;
}
