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

#include "PVP_Common.h"

enum ePVPDM_PROCESS
{
	ePVPDM_PROCESS_WAIT,					/// 유저 입장 대기
	ePVPDM_PROCESS_READY,					/// 전투전 1분 카운트 시작
	ePVPDM_PROCESS_READY_OUT,				/// 카운트 시작 조건 비만족 - 전투불가
	ePVPDM_PROCESS_FIGHT_MINIMUM,			/// 시작후 5분간 인원 체크 안함
	ePVPDM_PROCESS_FIGHT,					/// 모든 조건을 체크하는 전투 상태
	ePVPDM_PROCESS_FIGHTEND,				/// 전투 끝 결과 처리
	ePVPDM_PROCESS_END,						/// 객체 제거
};

class cDeathMatchObject
{
public:
	cDeathMatchObject();
	virtual ~cDeathMatchObject();

	/// Duelmanager의 메모리풀에서 객체 공간을 할당받음
	void* operator new( size_t n ); 
	/// 메모리풀에서 할당 받은 객체를 제거해줌
	void operator delete( void* ptr, size_t n );

	bool				Init( unsigned char DMIdx, sDMInfo* pDMInfo );
	void				Process( unsigned long elapsedTime, unsigned long accumTime );
	void				LeaderProcess( unsigned long elapsedTime, unsigned long accumTime );

	/// 데스매치 맴버 추가
	unsigned char		JoinTeam( unsigned long playerIdx, ePVPDM_TEAM_TYPE teamType, sDMInfo* pDMInfo );
	void				SendTeamList( cPlayer* pPlayer );
	void				OutMember( unsigned long playerIdx, ePVPDM_TEAM_TYPE teamType );

	bool				IsFight();
	unsigned char		TeamCnt( ePVPDM_TEAM_TYPE teamType )	{ return mTeamInfo[teamType].mMemberCnt; }
	sPvPDMMemberInfo*	TeamMember( ePVPDM_TEAM_TYPE teamType );


	/// 카운트 시작
	void				Ready();

	/// pvp 시작 메세지 발송
	void				SendFight();

	/// 점수 변경
	void				ScoreUpdate( unsigned long killIdx, ePVPDM_TEAM_TYPE killerTeam, unsigned long deadIdx, ePVPDM_TEAM_TYPE deadTeam );

	/// 결과 처리
	void				Result();
	void				SendResult( ePVPDM_TEAM_TYPE winTeam, ePVPDM_END_TYPE endType );
	void				SendTeamResult( sPvPDMTeamInfo* pTeam, sPvPDMMemberInfo* pMember, ePVPDM_END_TYPE endType, char protocol );

	/// pvp 전투 맴버 추방
	void				SendOut();
	void				SendOut( unsigned long playerIdx, unsigned long teamType );

	/// msg발송
	void				DMQuickSend( char* msg, unsigned long length );
	void				TeamQuickSend( ePVPDM_TEAM_TYPE teamType, char* msg, unsigned long length );

private:

	unsigned char		mDMIdx;					/// 고유 번호
	ePVPDM_PROCESS		mProcess;

	unsigned long		mProcessEndTime;		/// 현재 프로세스 종료 시간

	ePVPDM_TEAM_TYPE	mFirstJoinTeam;			/// 가장 먼저 접속한 팀

	sDMInfo*			mpDMInfo;				/// dm스크립트정보

	/// 팀 정보
	sPvPDMTeamInfo		mTeamInfo[ePVPDM_TEAMTYPE_MAX];	

	bool				mScoreEnd;

	/// 프로세스 부하 방지
	unsigned long		mLeaderTimePass;

	/// 맴버 정보
	sPvPDMMemberInfo	mAMemberInfo[PVP_DM_TEAM_CNT];
	sPvPDMMemberInfo	mBMemberInfo[PVP_DM_TEAM_CNT];

};
