#include "CS_ChaosDoor.h"

CS_ChaosDoor::CS_ChaosDoor()
{
	srand((UINT)time(NULL));
}

void CS_ChaosDoor::Step()
{
	//1.寻找arg和自身arg一致的实体
	std::vector<std::shared_ptr<Entity>> eList;
	for (auto& we : entityLayer->Ls)
	{
		if (we == shared_from_this())
			continue;
		if (we->el.arg == el.arg)
		{
			we->cbRect.top = 8;
			we->el.eventName = el.arg3;
			we->el.arg2 = L"fakeDoor";
			eList.push_back(we);
		}
	}
	//2.随机选择一个实体把事件设置为arg2
	int trueDoorIndex = Random(0, (int)eList.size() - 1);
	auto& trueDoor = eList[trueDoorIndex];
	trueDoor->el.eventName = el.arg2;
	trueDoor->el.arg2 = L"realDoor";
	Destroy();
}

std::shared_ptr<Entity> CreateCS_ChaosDoor()
{
	return std::make_shared<CS_ChaosDoor>();
}
