#include "CS_KingSwordV3.h"
#include "CS_King.h"
#include "CS_KingSwordV3Blade.h"
const int CS_KingSTATENAME_SWORDV3 = ++entityStateID;
CS_KingSwordV3::CS_KingSwordV3()
{
	stateID = CS_KingSTATENAME_SWORDV3;
	cd_counter = 0;
	cd_counter_max = 1;
	iconIndex = 1;
}

const wchar_t* CS_KingSwordV3::GetSaveName()
{
	return L"SwordV3";
}

const wchar_t* CS_KingSwordV3::GetFuncName()
{
	return L"KingSkill_SwordV3";
}

const wchar_t* CS_KingSwordV3::GetCheckFuncName()
{
	return L"KingSkill_SwordV3_Check";
}

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

	auto mychar = std::static_pointer_cast<CS_King>(we);
	bUIShowDisableSkill = !((
		!mychar->InAction() &&
		mychar->amList.size() < 1
		) &&
		!lock
		);

	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
	EntitySkillState::SubStep();
}

void CS_KingSwordV3::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_KingSwordV3Blade>(we);
		mychar->lr = lrSrc;
		we->gameFunc->SetEntity(we, am);
		mychar->amList.push_back(am);
		//锁住按键
		mychar->inputLock.key |= keyMask;
	}
	else
		enable = false;
}
