#ifndef _GAMEMAIN_H
#define _GAMEMAIN_H

#include <vector>
#include <string>

#include "RuneDev.h"
#include "GameMainDef.h"

// **********************************************************************************************
// Globals
class	CGameMain;

extern	CGameMain							*g_pGameMain;

// **********************************************************************************************

using namespace std;

typedef union {
	int value;
	struct {
		unsigned char background;
		unsigned char foreground;
		unsigned char transient;
		unsigned char auxiliary;
	};
}PLAYER_ACTOR_STATE;

class CGameMain : public CRuneDev
{
public:
	CGameMain();
	virtual ~CGameMain();

	virtual void				Init();
	virtual void				Release();
	virtual void				Update();
	virtual void				SendCreateRoleSprite( CRoleSprite* pRoleSprite );
	virtual void				SendDeleteRoleSprite( CRoleSprite* pRoleSprite );	
	virtual LRESULT				WndProc( HWND hWnd, UINT iMsg, WPARAM wParam, LPARAM lParam );
	virtual	void				LoadINI( const char* fileName );
	virtual void				WriteINI( const char* fileName );

	virtual	void				SetIP(const char* ip)					{ m_ip = ip; }
	virtual	const char*			GetIP()									{ return m_ip.c_str(); }
	virtual	void				SetPort(int port)						{ m_port = port; }
	virtual	int					GetPort()								{ return m_port; }
	virtual	void				SetPlayerID(int playerID);
	virtual	int					GetPlayerID()							{ return m_playerID; }	
	virtual	int					GetDBID()								{ return m_DBID; }
	virtual	void				SetPlayerPos(CRuVector3& pos);
	virtual	void				SetZoneID(int zoneID);
	virtual	int					GetZoneID()								{ return m_zoneID; }
	virtual	void				SetMapID(int mapID);
	virtual	int					GetMapID()								{ return m_mapID; }
	virtual	void				SetTargetPlayer(CRoleSprite* player);
	virtual	CRoleSprite*		GetTargetPlayer()						{ return m_pTargetPlayer; }
	virtual	CRoleSprite*		GetPlayer()								{ return m_pPlayer; }
	virtual	CRoleSprite*		GetMouseInPlayer()						{ return m_pMouseInPlayer; }
	virtual	bool				IsEnterWorld()							{ return m_isEnterWorld; }
	virtual	const char*			GetPlayerName()							{ return m_playerName.c_str(); }
	virtual	void				EnterWorld(int DBID, const char* playerName);
	virtual	void				LeaveWorld();

	virtual	float				GetDistanceWithPlayer(CRoleSprite* sprite);
	virtual	void				LockFight();
	virtual	void				UnlockFight();
	virtual	bool				IsLockFight()							{ return m_isLockFight; }	
	virtual	void				CancelAttack();
	virtual	void				SetPlayerAction(int action);	
	virtual	void				Fight();
	virtual	void				Jump();

protected:	
	virtual	void				UpdateWorld();
	virtual	void				SendPlayerPos();
	virtual	void				SendPlayerActor();
	virtual	void				CheckTargetStatus();
	virtual	void				ChangeCursor();		
	virtual	void				ControlCamera();	
	virtual	void				EnterFightMode();
	virtual	void				LeaveFightMode();	
	virtual	void				SendDoAction(int action, int status);
	//virtual	void				MoveToScreenPoint( int xMouse, int yMouse );
	//virtual	void				MoveToPlayer( CRoleSprite* pPlayer );

protected:
	// net information
	string						m_ip;
	int							m_port;

	string						m_playerName;					// 玩家名稱
	int							m_playerID;						// 玩家角色編號
	int							m_DBID;							// SERVER角色唯一代碼
	int							m_zoneID;						// 區域名稱
	int							m_mapID;						// 地圖名稱
	bool						m_isEnterWorld;					// 是否進入遊戲世界	
	bool						m_isFirstViewpoint;				// 第一人稱視角	
	bool						m_isLockFight;	
	bool						m_isAttack;
	bool						m_isTouchQuest;	
	
	CRoleSprite*				m_pPlayer;
	CRoleSprite*				m_pTargetPlayer;
	CRoleSprite*				m_pMouseInPlayer;	

	CRuVector3					m_moveVector;
	CRuVector3					m_direction;
	CRuVector3					m_position;
	float						m_sendMoveTime;
	bool						m_jumpState;

	PLAYER_ACTOR_STATE			m_sendActorState;

	/*
	int						m_mouseState;					// 
	int						m_moveType;
	float					m_buttonPress[2];
	bool					m_isInitial;
	bool					m_isMouseEnter;
	bool					m_isFirstViewpoint;				// 第一人稱視角	
	bool					m_isLockFight;
	bool					m_isLockForward;
	float					m_elapsedTime;
	float					m_lastSendMoveTime;	

	bool					m_isAttack;
	bool					m_isTouchQuest;

	CRuVector3				m_lastSendMovePos;
	CRuVector3				m_lastSendDir;
	CRoleSprite*			m_pPlayer;
	CRoleSprite*			m_pMouseInPlayer;
	CRoleSprite*			m_pTargetPlayer;
	CRoleSprite*			m_pOldTargetPlayer;
	CEffectSprite*			m_pMoveTarget;
	*/
};

#endif //_GAMEMAIN_H