#include "CS_KingSwordV1.h"
#include "CS_King.h"
#include "CS_KingSwordV1Blade.h"
const int CS_KingSTATENAME_SWORDV1 = GetNextEntityStateID();
CS_KingSwordV1::CS_KingSwordV1()
{
	stateID = CS_KingSTATENAME_SWORDV1;
	cd_counter = 0;
	cd_counter_max = 1;
	iconIndex = 0;
}

const wchar_t* CS_KingSwordV1::GetSaveName()
{
	return L"SwordV1";
}

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

	auto mychar = std::static_pointer_cast<CS_King>(we);
	bool a1 = !lock && !mychar->InAction();
	bool b1 = (mychar->input.key & keyMask);
	bool c1 = cd_counter == 0 && mychar->mp >= mp_cost;

	bool a = a1;
	bool b = b1;
	bool c = c1;
	if (a && b && c)
	{
		mychar->lastSkill = this;
		mychar->ChangeState(GetStateID());
	}
	//不需要更新UI
}

void CS_KingSwordV1::ChangeStateMsg(int stateID)
{
	//初始化技能
	auto we = e.lock();
	if (!we)
		return;
	auto mychar = std::static_pointer_cast<CS_King>(we);
	if (stateID == GetStateID() && mychar->amList.size() < 1)
	{
		enable = false;
		//开火
		auto& bClimb = mychar->stateControl.bClimb;
		auto lrSrc = mychar->lr;
		if (bClimb)
			mychar->lr = mychar->lr == 0 ? 1 : 0;
		auto am = std::make_shared<CS_KingSwordV1Blade>(we);
		mychar->lr = lrSrc;
		we->gameFunc->SetEntity(we, am);
		mychar->amList.push_back(am);
		//锁住按键
		mychar->inputLock.key |= keyMask;
	}
	else
		enable = false;
}
