#pragma once
#include "global.h"
//前置声明
class Entity;
struct GameInput;
class GameMap;
class EntityRes;
class GameFade;
class MyCamera;
class GameMsgbox;
class MyGame;

struct EventInfo
{
	std::wstring eventName;
	std::wstring triggerType;
};
//游戏脚本
class GameScript
{
public:
	void Init(MyGame* pGame);
	void EachNOD(bool bEachNOD, int targetNOD_playerIndex);//该NOD只能被目标玩家响应
	//脚本是否正在运行
	bool IsRunning();
	void StartEvent(const wchar_t* eventName,const wchar_t* triggerType);//设置启动事件
	void EndEvent();
	void TRA(const wchar_t* mapName, const wchar_t* eventName);
	//运行脚本
	void Step();
	void SetWait(int wait);
	bool GetNOD();
	void SetNOD(bool nod);
	bool GetPRI();
	void SetPRI(bool pri);
	bool GetKEY();
	void SetKEY(bool key);
	void Reset();
	void SetWAS(bool was = true);
	void SetYNJ();
	bool GetYES();
	void SetW99(bool w99);
	bool GetW99();
	void SetNODBlock();
	const wchar_t* GetTriggerType();
	void SetCheckEntity(std::weak_ptr<Entity> e);
	std::weak_ptr<Entity> GetCheckEntity();
	void SetCheckItemIndex(int itemIndex);
	int GetCheckItemIndex();
private:
	std::list<std::shared_ptr<Entity>>* globalEntity = nullptr;
	GameMap* pGameMap = nullptr;
	EntityRes* pEntityRes = nullptr;
	GameFade* pGameFade = nullptr;
	MyCamera* pMyCamera = nullptr;
	GameMsgbox* pGameMsgbox = nullptr;
	MyGame* pGame = nullptr;
	lua_State** scriptL_ptr = nullptr;
	bool cmd_PRI = false;//游戏是否锁住
	bool cmd_KEY = false;//屏蔽键盘操作
	bool cmd_WAS = false;//暂停脚本直到玩家落在地上
	bool cmd_NOD = false;//等待玩家按z键继续
	bool cmd_YNJ = false;//等待玩家选择
	int cmd_WAI = 0;//脚本时间等待
	bool cmd_W99 = false;//等待物品栏操作
	bool bTRA = false;
	bool bYes = false;//YNJ最后一次的选择结果
	bool NOD_block = false;//防止跳过NOD
	bool bEachNOD = false;//玩家1的NOD和玩家2的区分开
	int targetNOD_playerIndex = 0;//NOD指定响应的目标玩家
	std::weak_ptr<Entity> checkEntity;//最后一次调查的实体对象
	int checkItemIndex = -1;//正在调查的物品下标
	std::wstring mapTRA;//目标传送地图
	std::wstring triggerType;//触发器类型
	std::vector<char> utf8;
	std::vector<wchar_t> wbuff;
	std::vector<EventInfo> eventStack;
	void PreventJumpNOD();
	bool YesNoControl();
	bool NODStep();
	bool bYield = false;
};

