#include "CS_FallRock_Locator.h"
#include "CS_FallRock.h"
CS_FallRock_Locator::CS_FallRock_Locator()
{
	el.name = CS_FALLROCK_LOCATOR_CREATENAME;
}

void CS_FallRock_Locator::SetState(std::wstring stateName, int lr)
{
	if (stateName == L"fallrock")
	{
		//30%概率生成落石
		if (gameFunc)
			if (Random(0, 100) <= 30)
				sleep = Random(0, 60);
	}
}

void CS_FallRock_Locator::Step()
{
	if (sleep > 0)
	{
		sleep--;
		if (sleep == 0)
		{
			float dy = 0;
			if (el.arg2.length() > 0)
				swscanf_s(el.arg2.c_str(), L"%f", &dy);
			//产生落石
			auto e = std::make_shared<CS_FallRock>();
			e->x = x;
			e->y = y + dy * 16;
			e->lr = lr;
			e->el.arg = el.arg;
			e->SetState(0, 0);
			gameFunc->SetEntity(shared_from_this(), e);
		}
	}
}

std::shared_ptr<Entity> CreateCS_FallRock_Locator()
{
	return std::make_shared<CS_FallRock_Locator>();
}
