#include "CS_Torch_Trigger.h"
#include "CS_Torch_Mechanism.h"
void CS_Torch_Trigger::Step()
{
	if (bFindAllTorch)
	{
		bFindAllTorch = false;
		for (auto& we : entityLayer->Ls)
		{
			if (we->el.name == CS_TORCH_MECHANISM_CREATENAME)
			{
				auto wtorch = std::static_pointer_cast<CS_Torch_Mechanism>(we);
				torchList.push_back(wtorch);
			}
		}
	}
	if (torchList.empty())
		return;
	if (el.eventName.empty())
		return;
	//如果所有火炬全部点亮则触发事件
	if (bSetEvent && gameFunc->StartEvent)
	{
		bool bRunEvent = true;
		for (auto torch : torchList)
		{
			auto wtorch = torch.lock();
			if (wtorch)
			{
				if (wtorch->dispear_counter == 0)
				{
					bRunEvent = false;
					break;
				}
			}
		}
		if (bRunEvent)
		{
			bSetEvent = false;
			gameFunc->StartEvent(gameFunc->gameScript, el.eventName.c_str(), L"tBoot");
		}
	}
}

std::shared_ptr<Entity> CreateCS_Torch_Trigger()
{
	return std::make_shared<CS_Torch_Trigger>();
}


