#include "AiRecord.h"
#include "AiStation.h"
AiRecord::AiRecord()
{
	ani.png = L"sys_obj";
}

void AiRecord::Step()
{
	if (decodeRecord)
	{
		decodeRecord = false;
		//游戏编辑器里不解码
		if (gameFunc->GetMyChar_Player1 && el.arg3.length())
		{
			//进行解码
			const BYTE* data = nullptr;
			size_t dataLen = 0;
			gameFunc->DecodeRecord(el.arg3.data(), (const void**)&data, &dataLen);
			record.resize(dataLen / sizeof(GameInput));
			memcpy_s(record.data(), dataLen, data, dataLen);
		}
		//寻找自己的上级实体
		if (!stationID.empty())
		{
			EntityLayer* layer = (EntityLayer*)entityLayer;
			for (auto& p : layer->Ls)
			{
				if (p->el.name == AISTATION_CREATENAME)
				{
					
					auto e = std::static_pointer_cast<AiStation>(p);
					if (e->stationID == stationID)
					{
						parentStation = e;
						break;
					}
				}
			}
		}
	}
	//往上连线
	auto wparentStation = parentStation.lock();
	if (wparentStation)
	{
		DWORD c = RGBA(0xff, 0xdc, 0x5f, 0xff);
		AddLine(lineList, 0, 0, 0, c, wparentStation->x - x, wparentStation->y - y, c);
	}
}

void AiRecord::SetState(int stateID, int lr)
{
	if (el.arg.length() && ParseInts(el.arg.c_str(), argbuff))
	{
		if (argbuff.size() == 4)
		{
			cbRect.left = (float)argbuff[0];
			cbRect.right = (float)argbuff[1];
			cbRect.top = (float)argbuff[2];
			cbRect.bottom = (float)argbuff[3];
		}
	}
	if (el.arg2.length())
	{
		ParseInts(el.arg2.c_str(), stationID);
	}
}
