/* ==========================================================================
* 파    일 : PVPManager.h
* 목    적 : 
* 작 성 자 : 박경희
* 작 성 일 : 2008-09-04
* 주의사항 :
*===========================================================================*/
#pragma once
#include "DeathMatchObject.h"

enum ePVP_PROCESS
{
	ePVPPROCESS_WAIT,				/// pvp 대기상태
	ePVPPROCESS_NOTICE,				/// 공지 발송상태
	ePVPPROCESS_OBJECTRUN_OPEN,		/// dm 개별 오브젝트 프로세싱 상태
	ePVPPROCESS_OBJECTRUN_CLOSE,

};

class cPVPManager
{
public:

	static cPVPManager* mpPVPManager;

public:

	cPVPManager();
	~cPVPManager();

	bool				Init();
	void				Release();
	void				Process( unsigned long elapsedTime, unsigned long accumTime );
	void				ObjectProcess( unsigned long elapsedTime, unsigned long accumTime );

	/// pool 처리
	cDeathMatchObject*	AllocDMObject() { return mDMObjectPool.Alloc(); }
	void				FreeDMObject(cDeathMatchObject* ptr) { mDMObjectPool.Free(ptr); }

	cDeathMatchObject*	GetPvPDMObject( unsigned long dmIdx )	{ return (cDeathMatchObject*)mDMMap.GetAt(dmIdx); }

	unsigned char		JoinDeathMatch( unsigned long playerIdx, ePVPDM_TEAM_TYPE teamType, sDMInfo* pDMInfo );

	void				Ready();

	/// 삭제 배열에 추가
	void				DelAryInsertPVP( unsigned long pvpDMIdx );

	void				MemberOut( unsigned long pvpIdx, unsigned long playerIdx, ePVPDM_TEAM_TYPE teamType );

	bool				IsAttack( unsigned long playerIdx, unsigned long targetIdx );

private:

	typedef tPool<cDeathMatchObject> cDMObjectPool;
	cDMObjectPool		mDMObjectPool;


	typedef tPointerHashMap<unsigned long, void*> cPHashMap;
	typedef tHashSet<unsigned long> cHashSet;
	typedef tArray<unsigned long> cAry;

	ePVP_PROCESS		mProcess;			/// 프로세스 상태
	unsigned long		mStartTime;			/// pvp 시작 시간
	unsigned long		mNextEventTime;		/// 다음 이벤트 시작 시간

	///  객체를 담을 맵
	//typedef tPointerHashMap<unsigned long, cDeathMatchObject*> cDMMap;
	cPHashMap			mDMMap;

	///  객체 삭제 배열
	cAry				mDelDMAry;

	unsigned char		mNoticeCount;
	unsigned long		mNoticeSendTime;


	/// sync메세지를 보낼 대상들
	cHashSet			mMsgSendSet;

	unsigned char		mDMObjectIdx;

	cRangeCheck			mRangeCheck;

};

#define PVPMANAGER	cPVPManager::mpPVPManager

