//////////////////////////////////////////////////////////////////////////////
//
// AVP_ServerEntity_InteractPredatorLock.h
//
// Created by AJK 21/10/2008
//
// Copyright (c) 2008 Rebellion. All rights reserved.
//
//////////////////////////////////////////////////////////////////////////////


#ifdef ASURA_USE_PRAGMA_ONCE
#pragma once
#endif

#ifndef AVP_SERVERENTITY_INTERACTPREDATORLOCK
#define AVP_SERVERENTITY_INTERACTPREDATORLOCK

// AVP
#include "Entity/PhysicalObject/Interact/AVP_ServerEntity_InteractObject.h"

class AVP_ServerEntity_InteractPredatorLock : public AVP_ServerEntity_InteractObject
{
public:
	static AVP_ServerEntity_InteractPredatorLock* Create(Asura_Guid uGuid)					{ return new AVP_ServerEntity_InteractPredatorLock(uGuid); }
	static AVP_ServerEntity_InteractPredatorLock* FindEntity(Asura_Guid uGuid)				{ return s_xList.FindEntity(uGuid); }
	static const Asura_Hashed_List<AVP_ServerEntity_InteractPredatorLock>* GetList()		{ return &s_xList; }    

	bool			IsEnabled() const { return m_bEnabled; }
	u_char          GetLockCurrentPosition() const { return m_cLockCurrentPosition;}

	virtual bool	HandleMessage(const Asura_Message* pxMessage);
	virtual void	ReadFromChunkStream(Asura_Chunk_Stream& xStream);
	virtual void	WriteToChunkStream(Asura_Chunk_Stream& xStream) const;
	virtual void	PostLoadInitialise();
	virtual bool	GetHasCreateMessage() const { return true; }
	virtual void	MakeCreateMessage( Asura_Guid uRequestingClient, bool bSendGuaranteed /*= false*/ );

#ifdef ASURA_TOOLS
	virtual bool			CanBeIncludedInTemplate() const;
	virtual void			ApplyChangesForTemplateInstance( Tools_EntityTemplateInstance* pxInstance );
	virtual bool			SupportsCustomEvents() const { return true; }
	virtual int				GetNumCustomEvents() const { return NUM_MESSAGE_BLOCKS; }
	virtual unsigned short* GetCustomEvent(int iIndex);
	virtual void			GetCustomEventName(int iEventIndex, Asura_String& xEventName);
	static void				CreateFromTools(Asura_Guid uGuid);
#endif

protected:
	
	AVP_ServerEntity_InteractPredatorLock( Asura_Guid uGuid = ASURA_GUID_UNREGISTERED );
	virtual ~AVP_ServerEntity_InteractPredatorLock();

	void		OnReachPosition1();
	void		OnReachPosition2();
	void		OnReachPosition3();
	void		OnReachPosition4();

	void		OnLeavePosition1();
	void		OnLeavePosition2();
	void		OnLeavePosition3();
	void		OnLeavePosition4();

	enum
	{
		MESSAGE_BLOCK_REACH_POS1,
		MESSAGE_BLOCK_REACH_POS2,
		MESSAGE_BLOCK_REACH_POS3,
		MESSAGE_BLOCK_REACH_POS4,

		MESSAGE_BLOCK_LEAVE_POS1,
		MESSAGE_BLOCK_LEAVE_POS2,
		MESSAGE_BLOCK_LEAVE_POS3,
		MESSAGE_BLOCK_LEAVE_POS4,

		NUM_MESSAGE_BLOCKS,
	};

	unsigned short			m_usReachPosition1MessageBlock;
	unsigned short			m_usReachPosition2MessageBlock;
	unsigned short			m_usReachPosition3MessageBlock;
	unsigned short			m_usReachPosition4MessageBlock;

	unsigned short			m_usLeavePosition1MessageBlock;
	unsigned short			m_usLeavePosition2MessageBlock;
	unsigned short			m_usLeavePosition3MessageBlock;
	unsigned short			m_usLeavePosition4MessageBlock;

	u_char					m_cLockCurrentPosition;              // From 1 to 4

private:

	enum
	{
		CURRENT_CHUNK_VERSION = 1,
	};

	void SendLeavePositionMessage();
	void SendReachPositionMessage();

	typedef AVP_ServerEntity_InteractObject PARENT;

#ifdef ASURA_TOOLS
	friend class ToolsAVP_Entity_InteractPredatorLock;
#endif

	static Asura_Hashed_List<AVP_ServerEntity_InteractPredatorLock> s_xList;
};

#endif // #ifndef AVP_SERVERENTITY_INTERACTPREDATORLOCK
