#include "stdafx.h"
#include "PartyManager.h"
#include "Protocol.h"
#include "UIMsgboxEvent.h"
#include "ChatManager.h"
#include "ObjectManager.h"
#include "Hero.h"
#include "GameUIManager.h"
#include "PartyWindow.h"
#include "PartyStateWindow.h"
#include "SmallMiniMapWindow.h"
#include "MiniMapWindow.h"
#include "SkillScript.h"
#include "Application.h"
#include "SkillObject.h"

#include "ItemManager.h"

cPartyManager* cPartyManager::mpSingleton = 0;

cPartyManager::cPartyManager()
: mCount(0)
, mPartyIndex(0)
, mPartyLevel(0)
, mLeaderIndex(0)
, mDivideType(PARTY_DIVIDE_NONE)
, mSelectDataIndex(-1)
, mLastAccumTime(0)
, mHPMPAccumTime(0)
, mBuffAccumTime(0)
{
	assert( mpSingleton == 0 && "bad singleton!" );
	mpSingleton = this;

	for( int i = 0; i < PARTY_NUM; ++i )
		mParty[i] = 0;
}

cPartyManager::~cPartyManager()
{

}

bool cPartyManager::Init()
{
	return true;
}

/// 맵체인지용 
void cPartyManager::Close()
{
	for( int i = 0; i < PARTY_NUM; ++i )
		mParty[i] = 0;

	mCount = 0;
	mPartyIndex = 0;
	mPartyLevel = 0;
	mLeaderIndex = 0;
	mDivideType = PARTY_DIVIDE_NONE;
	mSelectDataIndex = -1;

	/// 미니맵으로부터 삭제
	cSmallMiniMapWindow* minimap = GAMEUI->GetSmallMinimapWindow();
	cMiniMapWindow* pWide = GAMEUI->GetMinimapWindow();
	if( minimap && pWide )
	{
		minimap->ClearParty();
		pWide->ClearParty();
	}
}

void cPartyManager::Process( unsigned long accumTime )
{
	if( mCount == 0 )
		return;

	typedef tPointerHashMap<unsigned long, void*> cHashMap;

	/// 일정 갱신시간
	if( accumTime - mHPMPAccumTime > PARTY_HPMPUPDATE )
	{
		/// HP, MP 갱신
		for( int i = 0; i < mCount; ++i )
		{
			// 해당유저가 존재하면 갱신
			cPlayer* user = OBJECTMAN->GetPlayer( mParty[i].mIndex );
			if( user )
			{
				UpdatePartyHP( i, user->GetHP(), user->GetMaxHP() );
				UpdatePartyMP( i, user->GetMP(), user->GetMaxMP() );
			}
		}

		mHPMPAccumTime = accumTime;
	}

	if( accumTime - mBuffAccumTime > PARTY_BUFFUPDATE )
	{
		/// 버프 갱신
		for( int i = 0; i < mCount; ++i )
		{
			// 해당유저가 존재하면 갱신
			cPlayer* user = OBJECTMAN->GetPlayer( mParty[i].mIndex );
			if( user )
			{
				UpdateBuffList( i );
			}
		}

		mBuffAccumTime = accumTime;
	}
	
	if( accumTime - mLastAccumTime > PARTY_UPDATETIME )
	{
		UpdateMinimap();
		mLastAccumTime = accumTime;
	}
}

/// 파티 UI 열기
void cPartyManager::ShowPartyUI()
{
	/// 좌표 갱신
	UpdateStateUI();

	/// 보이기
	cUIWindow* partywin = GAMEUI->GetPartyWindow();
	if( partywin )
		partywin->ShowTop();

	cUIWindow* stateWindow = 0;
	for( int i = 0; i < PARTY_NUM; ++i )
	{
		if( mParty[i].mUIIndex == -1 )
			continue;

		stateWindow = GAMEUI->GetPartyStateWindow( mParty[i].mUIIndex );
		if( stateWindow )
		{
			if( i < mCount )
				stateWindow->ShowTop();
			else
				stateWindow->Hide( false );
		}
	}
}

/// 파티 UI 닫기
void cPartyManager::HidePartyUI()
{
	cUIWindow* partywin = GAMEUI->GetPartyWindow();
	if( partywin )
		partywin->Hide( false );

	cUIWindow* stateWindow = 0;
	for( int i = 0; i < PARTY_NUM; ++i )
	{
		stateWindow = GAMEUI->GetPartyStateWindow( i );
		if( stateWindow )
			stateWindow->Hide( false );
	}
}

/// 파티 생성
bool cPartyManager::CreateParty( MSG_SYN_PARTY_LIST* msgData )
{
	mPartyIndex = msgData->mIndex;
	mPartyLevel = msgData->mLevel;
	mDivideType = msgData->mDivideType;
	mLeaderIndex = msgData->mLeaderIndex;

	if( mPartyIndex <= 0 )
	{
		assert( 0 && "not create party" );
		return false;
	}

	cSmallMiniMapWindow* minimap = GAMEUI->GetSmallMinimapWindow();
	cMiniMapWindow* pWide = GAMEUI->GetMinimapWindow();

	/// 파티원 정보 세팅
	for( int i = 0; i < msgData->RowCount; ++i )
	{
		mParty[i].mIndex	= msgData->party[i].UserIndex;
		mParty[i].mName		= msgData->party[i].Name;
		mParty[i].mUIIndex  = i;

		mParty[i].mLevel	= msgData->party[i].Level;
		mParty[i].mJob		= msgData->party[i].Job;
		mParty[i].mMapNum	= msgData->party[i].MapNum;	
		mParty[i].mInitX	= msgData->party[i].InitX;
		mParty[i].mInitY	= msgData->party[i].InitY;
		mParty[i].mHP		= msgData->party[i].HP;
		mParty[i].mMaxHP	= msgData->party[i].MaxHP;
		mParty[i].mMP		= msgData->party[i].MP;
		mParty[i].mMaxMP	= msgData->party[i].MaxMP;
	
		if( minimap && pWide && HERO->GetObjectID() != mParty[i].mIndex )
		{
			minimap->AddPartyUser( &mParty[i] );
			pWide->AddPartyUser( &mParty[i] );
		}
	}

	mCount = msgData->RowCount;

	/// UI 세팅 
	CreatePartyUI();
	return true;
}

/// 파티 정보 UI 에 세팅
void cPartyManager::CreatePartyUI()
{
	/// 파티원 정보 세팅
	cPartyStateWindow* stateWindow = 0;
	for( int i = 0; i < mCount; ++i )
	{
		if( mParty[i].mIndex > 0 && mParty[i].mUIIndex > -1 )
		{
			/// UI 에 정보 세팅
			stateWindow = GAMEUI->GetPartyStateWindow( i );
			if( stateWindow )
			{
				stateWindow->SetUserIndex( mParty[i].mIndex );
				stateWindow->SetLevel( mParty[i].mLevel );
				stateWindow->SetJob( mParty[i].mJob );
				stateWindow->SetMaxHP( mParty[i].mMaxHP );
				stateWindow->SetHPGauge( mParty[i].mHP );
				stateWindow->SetMaxMP( mParty[i].mMaxMP );
				stateWindow->SetMPGauge( mParty[i].mMP );
				stateWindow->SetMapNum( mParty[i].mMapNum );
				stateWindow->LinkPartyIndex( i );

				eText_Color color = eCOLOR_WHITE;
				int mapnum = HERO->GetMapNum();
				if( mapnum == mParty[i].mMapNum )
				{
					/// 동일 맵인경우
					color = eCOLOR_WHITE;
					stateWindow->ShowData( true );

					/// 버프 정보 세팅
					UpdateBuffList( i );
				}
				else
				{
					/// 아닌경우
					color = eCOLOR_DARKGRAY;
					stateWindow->ShowData( false );
				}

				stateWindow->SetName( (LPCTSTR)mParty[i].mName.Cstr(), color );
		
				/// NPC랑 대화중이면 파티윈도우를 보이지 않는다
				if( UIMAN->IsShowNpcBack() == false && GAMEUI->IsDuelMode() == false )
					stateWindow->ShowTop();
			}
		}
		else
		{
			assert(0);
		}
	}

	/// 파티장 세팅
	cPartyWindow* pPartyWindow = GAMEUI->GetPartyWindow();
	if( pPartyWindow )
	{
		/// 자기자신이 리더
		if( mLeaderIndex == HERO->GetObjectID() )
		{
			pPartyWindow->SetLeader( true );
		}
		/// 다른 유저가 리더
		else
		{
			pPartyWindow->SetLeader( false );

			int i = FindUser( mLeaderIndex );
			if( i > -1 && mParty[i].mUIIndex > -1 )
			{
				cPartyStateWindow* state = GAMEUI->GetPartyStateWindow( mParty[i].mUIIndex );
				if( state )
					state->SetLeader( true );
			}
			else
			{
				assert(0);
			}
		}

		pPartyWindow->SetDivideType( mDivideType );

		if( UIMAN->IsShowNpcBack() == false && GAMEUI->IsDuelMode() == false )
			pPartyWindow->ShowTop();
	}

	/// 파티내용을 전체 받으면 선택 리셋
	unsigned long userIdx =	( mParty[0].mIndex != HERO->GetObjectID() ) ? mParty[0].mIndex : mParty[1].mIndex;
	ChangeTarget( userIdx );
}

/// 파티원 추가
void cPartyManager::AddUser( MSG_SYN_PARTY_ADDONE* msgData )
{
	/// 새 유저가 추가되면서, 파티 최고레벨 재세팅
	mPartyLevel = msgData->mPartyLevel;

	/// 유저 추가
	if( mCount < PARTY_NUM )
	{
		int i = FindEmptyUI();
		if( i == -1 )
		{
			assert(0);
			return;
		}

		mParty[mCount].mIndex	= msgData->UserIndex;
		mParty[mCount].mName	= msgData->Name;
		mParty[mCount].mLevel	= msgData->Level;
		mParty[mCount].mJob		= msgData->Job;
		mParty[mCount].mHP		= msgData->HP;
		mParty[mCount].mMaxHP	= msgData->MaxHP;
		mParty[mCount].mMP		= msgData->MP;
		mParty[mCount].mMaxMP	= msgData->MaxMP;
		mParty[mCount].mMapNum	= msgData->MapNum;
		mParty[mCount].mInitX	= msgData->InitX;
		mParty[mCount].mInitY	= msgData->InitY;
		mParty[mCount].mUIIndex = i;

		cSmallMiniMapWindow* minimap = GAMEUI->GetSmallMinimapWindow();
		cMiniMapWindow* pWide = GAMEUI->GetMinimapWindow();
		if( minimap && pWide )
		{
			if( HERO->GetObjectID() != mParty[mCount].mIndex )
			{
				minimap->AddPartyUser( &mParty[mCount] );
				pWide->AddPartyUser( &mParty[mCount] );

				cPlayer* p = OBJECTMAN->GetPlayer( mParty[mCount].mIndex );
				if( p )
					p->PartyIn_Init();
			}
		}

		/// 추가된 UI 세팅
		cPartyStateWindow* stateWindow = GAMEUI->GetPartyStateWindow( mParty[mCount].mUIIndex );
		if( stateWindow )
		{
			stateWindow->SetUserIndex( mParty[mCount].mIndex );
			stateWindow->SetLevel( mParty[mCount].mLevel );
			stateWindow->SetJob( mParty[mCount].mJob );
			stateWindow->SetMaxHP( mParty[mCount].mMaxHP );
			stateWindow->SetHPGauge( mParty[mCount].mHP );
			stateWindow->SetMaxMP( mParty[mCount].mMaxMP );
			stateWindow->SetMPGauge( mParty[mCount].mMP );
			stateWindow->SetMapNum( mParty[mCount].mMapNum );
			stateWindow->LinkPartyIndex( mCount );

			eText_Color color = eCOLOR_WHITE;
			if( HERO->GetMapNum() == mParty[mCount].mMapNum )
			{
				/// 동일 맵인경우
				color = eCOLOR_WHITE;
				stateWindow->ShowData( true );

				/// 버프 정보 세팅
				UpdateBuffList( mCount );
			}
			else
			{
				/// 아닌경우
				color = eCOLOR_DARKGRAY;
				stateWindow->ShowData( false );
			}

			stateWindow->SetName( (LPCTSTR)mParty[mCount].mName.Cstr(), color );

			/// NPC 창이 열려있지 않으면 SHOW 하지 않음
			if( UIMAN->IsShowNpcBack() == false && GAMEUI->IsDuelMode() == false )
				stateWindow->ShowTop();
		}
		else
		{
			assert(0);
		}

		mCount++;
	}
}

/// 근접 유저인 경우 버프리스트 받아서 세팅
void cPartyManager::UpdateBuffList( unsigned long index )
{
	if( mParty[index].mUIIndex > -1 )
	{
		cPartyStateWindow* state = GAMEUI->GetPartyStateWindow( mParty[index].mUIIndex );

		typedef tPointerHashMap<unsigned long, void*>	cInfluenceMap;
		cPlayer* player = OBJECTMAN->GetPlayer( mParty[index].mIndex );
		if( player && state )
		{
			state->ClearBuff();

			cInfluenceMap* buffMap = player->GetBufMap();
			cInfluenceMap* debuffMap = player->GetDeBufMap();
			if( buffMap )
			{
				/// 버프 정보 세팅
				cInfluenceMap::cIterator i = buffMap->Begin();
				cInfluenceMap::cIterator end = buffMap->End();
				for( ; i != end; ++i )
				{
					unsigned long uniqueIndex = (unsigned long)(i->mFirst);
					cInfluenceObject* p = (cInfluenceObject*)(i->mSecond);
					if( p )
						state->AddBuff( uniqueIndex, p->GetInfluenceIdx() );
				}
			}

			if( debuffMap )
			{
				/// 디버프 정보 세팅
				cInfluenceMap::cIterator i = debuffMap->Begin();
				cInfluenceMap::cIterator end = debuffMap->End();
				for( ; i != end; ++i )
				{
					unsigned long uniqueIndex = (unsigned long)(i->mFirst);
					cInfluenceObject* p = (cInfluenceObject*)(i->mSecond);
					if( p )
						state->AddBuff( uniqueIndex, p->GetInfluenceIdx() );
				}
			}	
		}
	}
}

/// 파티 삭제
void cPartyManager::DeleteParty()
{
	/// 파티메뉴 UI 초기화
	cPartyWindow* partyWin = GAMEUI->GetPartyWindow();
	if( partyWin )
	{
		partyWin->Hide();
		partyWin->Clear();
	}

	/// 파티 데이터 초기화 및 파티원 UI 초기화 
	cPartyStateWindow* stateWindow = 0;
	for( int i = 0; i < PARTY_NUM; ++i )
	{
		cPlayer* p = 0;

		/// 정보 초기화
		if( mParty[i].mIndex > 0 )
			p = OBJECTMAN->GetPlayer( mParty[i].mIndex );
		
		/// UI 초기화
		stateWindow = GAMEUI->GetPartyStateWindow( i );
		if( stateWindow )
		{
			stateWindow->Hide();
			stateWindow->Clear();
		}

		mParty[i] = 0;

		if( p )
			p->PartyOut_Init();
	}

	mPartyIndex = 0;
	mCount = 0;
	mPartyLevel = 0;
	mLeaderIndex = 0;
	mDivideType = PARTY_DIVIDE_NONE;

	/// 미니맵으로부터 삭제
	cSmallMiniMapWindow* minimap = GAMEUI->GetSmallMinimapWindow();
	cMiniMapWindow* pWide = GAMEUI->GetMinimapWindow();
	if( minimap && pWide )
	{
		minimap->ClearParty();
		pWide->ClearParty();
	}
}

void cPartyManager::DeleteUser( int arrIdx )
{
	if( arrIdx < PARTY_NUM )
	{
		/// 미니맵으로부터 삭제
		cSmallMiniMapWindow* minimap = GAMEUI->GetSmallMinimapWindow();
		cMiniMapWindow* pWide = GAMEUI->GetMinimapWindow();
		if( minimap && pWide )
		{
			minimap->RemovePartyUser( mParty[arrIdx].mIndex );
			pWide->RemovePartyUser( mParty[arrIdx].mIndex );
		}

		cPlayer* p = OBJECTMAN->GetPlayer( mParty[arrIdx].mIndex );

		/// UI 초기화 및 닫기
		cPartyStateWindow* state = GAMEUI->GetPartyStateWindow( mParty[arrIdx].mUIIndex );
		if( state )
		{
			state->Hide();
			state->Clear();
		}

		/// 정보 땡기기
		mCount--;
		for( int i = arrIdx; i < mCount; ++i )
			mParty[i] = mParty[i+1];

		mParty[mCount] = 0;

		if( p )
			p->PartyOut_Init();
		
		/// UI 위치 갱신
		UpdateStateUI();
	}
	else
	{
		assert(0);
	}
}

/// 파티원 윈도우 위치 갱신
void cPartyManager::UpdateStateUI()
{
	for( int i = 0; i < mCount; i++ )
	{
		if( mParty[i].mIndex == 0 )
			break;

		/// 연결된 파티정보 갱신 및 위치 갱신
		cPartyStateWindow* state = GAMEUI->GetPartyStateWindow( mParty[i].mUIIndex );
		if( state )
			state->LinkPartyIndex( i );
	}
}

/// 파티장 변경
void cPartyManager::ChangeLeader()
{
	/// 우선 리더세팅 초기화
	cPartyStateWindow* state = 0;
	for( int i = 0; i < PARTY_NUM; i++ )
	{
		state = GAMEUI->GetPartyStateWindow( i );
		if( state )
			state->SetLeader( false );
	}

	cPartyWindow* pPartyWindow = GAMEUI->GetPartyWindow();
	if( pPartyWindow )
	{
		/// 자기자신이 리더
		if( mLeaderIndex == HERO->GetObjectID() )
		{
			pPartyWindow->SetLeader( true );
		}
		else
		{
			pPartyWindow->SetLeader( false );

			/// 다른 유저 리더세팅
			int i = FindUser( mLeaderIndex );
			if( i > -1 && mParty[i].mUIIndex > -1 )
			{
				cPartyStateWindow* state = GAMEUI->GetPartyStateWindow( mParty[i].mUIIndex );
				if( state )
					state->SetLeader( true );
			}
			else
			{
				assert(0);
			}
		}
	}
}

/// 타겟 변경 - 파티윈도우도 세팅 
void cPartyManager::ChangeTarget( unsigned long userIdx )
{
	/// 파티가 없으면 리턴
	if( mCount <= 0 )
		return;

	if( userIdx == 0 || userIdx == HERO->GetObjectID() )
		return;

	int i = FindUser( userIdx );
	if( i > -1 )
		UpdateTarget( i );
}

void cPartyManager::ChangeTabTarget( unsigned long userIdx )
{
	if( mCount <= 0 )
		return;

	int i = FindUser( userIdx );

	/// (Not party user)?
	if( i < 0 )
	{
		HERO->SetTargetObject( eOBJECTTYPE_PLAYER, mParty[0].mIndex);
	}
	else
	{
		/// (last party user)?
		if( i+1 >= mCount )
		{
			HERO->SetTargetObject( eOBJECTTYPE_PLAYER, mParty[0].mIndex);
		}

		/// next party user
		HERO->SetTargetObject( eOBJECTTYPE_PLAYER, mParty[i+1].mIndex);
	}
}

/// 파티윈도우 선택 갱신 ( 파티데이터 인덱스 )
void cPartyManager::UpdateTarget( int index )
{
	GAMEUI->ShowGameUI();

	/// 없는 데이터면 리턴
	if( index >= mCount )
		return;

	if( mParty[index].mUIIndex == -1 )
	{
		assert(0);
		return;
	}

	/// 기존 타겟 릴리즈
	cPartyStateWindow* pState = 0;
	unsigned long color = eCOLOR_WHITE;
	for( int i = 0; i < PARTY_NUM; ++i )
	{
		pState = GAMEUI->GetPartyStateWindow( i );
		if( pState )
		{
			color = ( mParty[index].mMapNum == HERO->GetObjectID() ) ? eCOLOR_WHITE : eCOLOR_DARKGRAY;
			pState->ReleaseTarget( color );
		}
	}

	/// 타겟된 윈도우로 세팅
	cPartyWindow* pPartyWindow = GAMEUI->GetPartyWindow();
	cPartyStateWindow* pTargetState = GAMEUI->GetPartyStateWindow( mParty[index].mUIIndex );
	if( pPartyWindow && pTargetState )
	{
		pPartyWindow->ChangeTarget( pTargetState );
		pTargetState->SetTarget();
	}		

	/// 선택갱신
	mSelectDataIndex = index;
}

/// 파티에 연결되지 않은 ui 찾기
int cPartyManager::FindEmptyUI()
{
	cPartyStateWindow* state = 0;
	for( int i = 0; i < PARTY_NUM; ++i )
	{
		state = GAMEUI->GetPartyStateWindow(i);
		if( state && state->GetLinkPartyIndex() == -1 )
			return i;
	}
	return -1;
}

LPCTSTR cPartyManager::GetUserName( unsigned long userIdx )
{
	int i = FindUser( userIdx );
	return ( i == -1 ) ? 0 : (LPCTSTR)mParty[i].mName.Cstr();
}

LPCTSTR cPartyManager::GetSelectName()
{
	if( mSelectDataIndex == -1 )
	{
		assert(0);
		return 0;
	}

	return (LPCTSTR)mParty[mSelectDataIndex].mName.Cstr();
}

///
void cPartyManager::RequestPartyAdd( LPCTSTR targetName )
{
	/// 파티 가입중일때는 자신이 파티장이어야 함
	if( HERO->GetPartyIndex() > 0 )
	{
		if( mLeaderIndex != HERO->GetObjectID() )
		{
			CHATMANAGER->AddSystemMsg( eSYSTEM_NORMAL, GAMERESOURCEMAN->GetGameText( 110 ) );
			return;
		}
	}

	/// 자기자신 초대불가
	if( ::_tcscmp( targetName, HERO->GetName() ) == 0 )
	{
		CHATMANAGER->AddSystemMsg( eSYSTEM_NORMAL, GAMERESOURCEMAN->GetGameText( 142 ) );
		return;
	}

	mTempTargetName = targetName;

	///
	MSG_REQ_PARTY_ADD msg;
	::memset( &msg, 0, sizeof(msg) );
	msg.Category = NM_PARTY;
	msg.Protocol = NM_PARTY_ADD_REQ;
	Sstrncpy( msg.Name, MAX_NAME_BUFFER_SIZE, targetName, MAX_NAME_SIZE );
	NETWORK->SendNetworkMsg( (char*)&msg, sizeof(msg) );

	/// 파티 관련 UI 모두 락
	GAMEUI->NetLockParty( eLOCK_PARTYADD );
}

void cPartyManager::RequestPartyOut()
{
	/// 파티가 아니면 탍퇴 불가
	if( HERO->GetPartyIndex() == 0 )
		return;

	MSG_REQ_PARTY_OUT msg;
	::memset( &msg, 0, sizeof( msg ) );

	msg.Category = NM_PARTY;
	msg.Protocol = NM_PARTY_OUT_REQ;
	NETWORK->SendNetworkMsg( (char*)&msg, sizeof(msg) );

	/// 파티 관련 UI 모두 락
	GAMEUI->NetLockParty( eLOCK_PARTYOUT );
}

void cPartyManager::RequestChangeDivide( PARTY_DIVIDE_TYPE type )
{
	/// 파티검사
	if( HERO->GetPartyIndex() == 0 )
		return;

	/// 파티장 검사
	if( mLeaderIndex != HERO->GetObjectID() )
	{
		CHATMANAGER->AddSystemMsg( eSYSTEM_NORMAL, GAMERESOURCEMAN->GetGameText( 122 ) );
		return;
	}

	if( type == mDivideType )
		return;

	if( type == PARTY_DIVIDE_NONE )
	{
		assert(0);
		return;
	}

	MSG_REQ_PARTY_CHANGEDIVIDE msg;
	::memset( &msg, 0, sizeof( msg ) );

	msg.Category = NM_PARTY;
	msg.Protocol = NM_PARTY_CHANGEDIVIDE_REQ;
	msg.type = type;
	NETWORK->SendNetworkMsg( (char*)&msg, sizeof(msg) );

	/// 파티 관련 UI 모두 락
	GAMEUI->NetLockParty( eLOCK_PARTYCHANGEDIVIDE );
}

///
void cPartyManager::RequestChangeLeader()
{
	/// 파티검사
	if( HERO->GetPartyIndex() == 0 )
		return;

	/// 파티장 검사
	if( mLeaderIndex != HERO->GetObjectID() )
	{
		CHATMANAGER->AddSystemMsg( eSYSTEM_NORMAL, GAMERESOURCEMAN->GetGameText( 122 ) );
		return;
	}

	if( mSelectDataIndex == -1 )
	{
		assert(0);
		return;
	}

	if( mParty[mSelectDataIndex].mIndex == 0 )
	{
		assert(0);
		return;
	}

	///
	if( mParty[mSelectDataIndex].mIndex == HERO->GetObjectID() )
		return;

	if( mParty[mSelectDataIndex].mIndex != 0 )
	{
		MSG_REQ_PARTY_CHANGELEADER msg;
		::memset( &msg, 0, sizeof( msg ) );

		msg.Category = NM_PARTY;
		msg.Protocol = NM_PARTY_CHANGELEADER_REQ;
		msg.UserIndex = mParty[mSelectDataIndex].mIndex;
		NETWORK->SendNetworkMsg( (char*)&msg, sizeof(msg) );

		/// 파티 관련 UI 모두 락
		GAMEUI->NetLockParty( eLOCK_PARTYCHANGELEADER );
	}
	else
	{
		/// 타겟이 없으면 타겟 세팅 요청
		CHATMANAGER->AddSystemMsg( eSYSTEM_NORMAL, GAMERESOURCEMAN->GetGameText( 121 ) );
	}
}

void cPartyManager::RequestChangeLeader( unsigned long playerIdx )
{
	/// 파티검사
	if( HERO->GetPartyIndex() == 0 )
		return;

	/// 파티장 검사
	if( mLeaderIndex != HERO->GetObjectID() )
	{
		CHATMANAGER->AddSystemMsg( eSYSTEM_NORMAL, GAMERESOURCEMAN->GetGameText( 122 ) );
		return;
	}

	for( int i = 0; i < mCount; ++i )
	{
		if( mParty[i].mIndex == HERO->GetObjectID() )
			continue;

		if( mParty[i].mIndex == playerIdx )
		{
			MSG_REQ_PARTY_CHANGELEADER msg;
			::memset( &msg, 0, sizeof( msg ) );

			msg.Category = NM_PARTY;
			msg.Protocol = NM_PARTY_CHANGELEADER_REQ;
			msg.UserIndex = mParty[i].mIndex;
			NETWORK->SendNetworkMsg( (char*)&msg, sizeof(msg) );

			/// 파티 관련 UI 모두 락
			GAMEUI->NetLockParty( eLOCK_PARTYCHANGELEADER );
			break;
		}
	}
}


void cPartyManager::RequestThrow()
{
	/// 파티검사
	if( HERO->GetPartyIndex() == 0 )
		return;

	/// 파티장 검사
	if( mLeaderIndex != HERO->GetObjectID() )
	{
		CHATMANAGER->AddSystemMsg( eSYSTEM_NORMAL, GAMERESOURCEMAN->GetGameText( 122 ) );
		return;
	}

	if( mSelectDataIndex == -1 )
	{
		assert(0);
		return;
	}

	if( mParty[mSelectDataIndex].mIndex == 0 )
	{
		assert(0);
		return;
	}

	/// 자기자신은 추방할수 없음
	if( mParty[mSelectDataIndex].mIndex == HERO->GetObjectID() )
		return;

	MSG_REQ_PARTY_THROW msg;
	::memset( &msg, 0, sizeof( msg ) );
	msg.Category = NM_PARTY;
	msg.Protocol = NM_PARTY_THROW_REQ;
	msg.UserIndex = mParty[mSelectDataIndex].mIndex;
	NETWORK->SendNetworkMsg( (char*)&msg, sizeof(msg) );

	/// 파티 관련 UI 모두 락
	GAMEUI->NetLockParty( eLOCK_PARTYTHROW );
}

void cPartyManager::RequestThrow( unsigned long playerIdx )
{
	/// 파티검사
	if( HERO->GetPartyIndex() == 0 )
		return;

	/// 파티장 검사
	if( mLeaderIndex != HERO->GetObjectID() )
	{
		CHATMANAGER->AddSystemMsg( eSYSTEM_NORMAL, GAMERESOURCEMAN->GetGameText( 122 ) );
		return;
	}

	for( int i = 0; i < mCount; ++i )
	{
		if( mParty[i].mIndex == HERO->GetObjectID() )
			continue;

		if( mParty[i].mIndex == playerIdx )
		{
			MSG_REQ_PARTY_THROW msg;
			::memset( &msg, 0, sizeof( msg ) );
			msg.Category = NM_PARTY;
			msg.Protocol = NM_PARTY_THROW_REQ;
			msg.UserIndex = mParty[i].mIndex;
			NETWORK->SendNetworkMsg( (char*)&msg, sizeof(msg) );

			/// 파티 관련 UI 모두 락
			GAMEUI->NetLockParty( eLOCK_PARTYTHROW );
			break;
		}
	}
}


/// 근접 유저 정보 세팅
void cPartyManager::UpdateMinimap()
{
	cSmallMiniMapWindow* minimap = GAMEUI->GetSmallMinimapWindow();
	cMiniMapWindow* pWide = GAMEUI->GetMinimapWindow();
	if( minimap && pWide )
	{
		for( int i = 0; i < mCount; ++i )
		{
			/// 근접한 그리드에 있는 유저만 세팅
			cPlayer* player = OBJECTMANAGER->GetPlayer( mParty[i].mIndex );
			if( player )
			{
				minimap->SetPosParty( mParty[i].mIndex, player->GetXPos(), player->GetYPos() );
				pWide->SetPosParty( mParty[i].mIndex, player->GetXPos(), player->GetYPos() );
			}
		}
	}
}

/// 근접 유저 정보 세팅
void cPartyManager::UpdatePartyHP( unsigned int i, unsigned long hp, unsigned long maxhp )
{
	/// 해당 유저 정보 세팅
	mParty[i].mMaxHP = maxhp;
	mParty[i].mHP	 = hp;

	cPartyStateWindow* state = GAMEUI->GetPartyStateWindow( mParty[i].mUIIndex );
	if( state )
	{
		state->SetMaxHP( maxhp );
		state->SetHPGauge( hp );
	}
}

/// 근접 유저 정보 세팅
void cPartyManager::UpdatePartyMP( unsigned int i, unsigned long mp, unsigned long maxmp )
{
	/// 해당 유저 정보 세팅
	mParty[i].mMaxMP = maxmp;
	mParty[i].mMP	 = mp;

	cPartyStateWindow* state = GAMEUI->GetPartyStateWindow( mParty[i].mUIIndex );
	if( state )
	{
		state->SetMaxMP( maxmp );
		state->SetMPGauge( mp );
	}
}

/// 근접 유저 정보 세팅
void cPartyManager::UpdateLevelUp( unsigned long userIndex, unsigned char level )
{
	int i = FindUser( userIndex );
	if( !(i > -1 && mParty[i].mUIIndex > -1) )
	{
		assert( 0 && "not exist user" );
		return;
	}

	/// 해당 유저 정보 세팅
	mParty[i].mLevel = level;

	cPartyStateWindow* state = GAMEUI->GetPartyStateWindow( mParty[i].mUIIndex );
	if( state )
		state->SetLevel( level );
}

bool cPartyManager::IsHeroLeader()
{
	return (mLeaderIndex == HERO->GetObjectID());
}

///
void cPartyManager::NetworkMsgParser( char* msg )
{
	MSGROOT* tempMsg = (MSGROOT*)msg;
	cStringT Message;

	switch( tempMsg->Protocol )
	{
	case NM_PARTY_ADD_RES:
		{
			/// 파티 신청 결과
			MSG_RES_PARTY_ADD* pmsg = (MSG_RES_PARTY_ADD*)msg;
			switch( pmsg->ErrorCode )
			{
			case ERROR_PARTY_ADD_SUCCESS:
				{
					/// 초대한 유저 이름 보여주기
					cStringT str;
					str.Format( GAMERESOURCEMAN->GetGameText( 100 ), (LPCTSTR)mTempTargetName.Cstr() );
					CHATMANAGER->AddSystemMsg( eSYSTEM_NORMAL, (LPCTSTR)str.Cstr() );
				}
				break;
			case ERROR_PARTY_ADD_CREATE_SUCCESS:	/// 파티생성됨
				CHATMANAGER->AddSystemMsg( eSYSTEM_NORMAL, GAMERESOURCEMAN->GetGameText( 103 ) );
				break;
			case ERROR_PARTY_ADD_STATUS:			/// 파티 신청 불가 상태
				CHATMANAGER->AddSystemMsg( eSYSTEM_NORMAL, GAMERESOURCEMAN->GetGameText( 135 ) );
				break;
			case ERROR_PARTY_ADD_USEROUT:			/// 초대한 유저가 게임을 종료함 
				CHATMANAGER->AddSystemMsg( eSYSTEM_NORMAL, GAMERESOURCEMAN->GetGameText( 106 ) );
				UIMAN->CreateModal(	eStage_Game,
					eMBEVENT_NONE, 
					GAMERESOURCEMAN->GetGameText( 106 ),	// 파티 초대 불가
					GAMERESOURCEMAN->GetGameText( 301 ),	// 알림
					eSKIN_OK
					);
				break;
			case ERROR_PARTY_ADD_COMPLETE:			/// 해당유저가 파티 가입중
				CHATMANAGER->AddSystemMsg( eSYSTEM_NORMAL, GAMERESOURCEMAN->GetGameText( 107 ) );
				break;
			case ERROR_PARTY_ADD_CONTINUE:			/// 여러명 초대 불가
				UIMAN->CreateModal(	eStage_Game,
					eMBEVENT_NONE, 
					GAMERESOURCEMAN->GetGameText( 138 ),	// 여러명 초대 불가
					GAMERESOURCEMAN->GetGameText( 301 ),	// 알림
					eSKIN_OK
					);
				break;
			case ERROR_PARTY_ADD_USER:				/// 초대한캐릭터 없음.
				CHATMANAGER->AddSystemMsg( eSYSTEM_NORMAL, GAMERESOURCEMAN->GetGameText( 101 ) );
				break;
			case ERROR_PARTY_ADD_COUNT:			/// 파티인원 풀
				CHATMANAGER->AddSystemMsg( eSYSTEM_NORMAL, GAMERESOURCEMAN->GetGameText( 109 ) );
				UIMAN->CreateModal(	eStage_Game,
					eMBEVENT_NONE, 
					GAMERESOURCEMAN->GetGameText( 109 ),	// 파티 인원 풀
					GAMERESOURCEMAN->GetGameText( 301 ),	// 알림
					eSKIN_OK
					);
				break;
			case ERROR_PARTY_ADD_REFUSE:		/// 파티 거절
				CHATMANAGER->AddSystemMsg( eSYSTEM_NORMAL, GAMERESOURCEMAN->GetGameText( 104 ) );
				UIMAN->CreateModal(	eStage_Game,
					eMBEVENT_NONE, 
					GAMERESOURCEMAN->GetGameText( 104 ),	// 파티 거절안내
					GAMERESOURCEMAN->GetGameText( 301 ),	// 알림
					eSKIN_OK
					);
				break;
			case ERROR_PARTY_ADD_NOTLEADER:		/// 권한없음
				CHATMANAGER->AddSystemMsg( eSYSTEM_NORMAL, GAMERESOURCEMAN->GetGameText( 110 ) );
				break;
			case ERROR_PARTY_ADD_MAP:			/// 맵이동이라 초대할수 없음
				CHATMANAGER->AddSystemMsg( eSYSTEM_NORMAL, GAMERESOURCEMAN->GetGameText( 106 ) );
				break;
			case ERROR_PARTY_ADD_CREATEFAIL:	/// 파티 생성 실패
				CHATMANAGER->AddSystemMsg( eSYSTEM_NORMAL, GAMERESOURCEMAN->GetGameText( 111 ) );
				break;
			case ERROR_PARTY_ADD_OPTIONREFUSE:	/// 파티 거부 상태
				CHATMANAGER->AddSystemMsg( eSYSTEM_NORMAL, GAMERESOURCEMAN->GetGameText( 2701 ) );
				break;		
			case ERROR_PARTY_ADD_FAIL:			/// 파티 신청 실패
				CHATMANAGER->AddSystemMsg( eSYSTEM_NORMAL, GAMERESOURCEMAN->GetGameText( 2701 ) );
				break;
			}

			mTempTargetName.Clear();

			/// 파티관련 UI 락 풀기
			GAMEUI->NetUnLockParty( eLOCK_PARTYADD );
		}
		break;
	case NM_PARTY_ADD_SYN:
		{
			/// 파티로부터 가입 신청 옴
			MSG_SYN_PARTY_ADD* pmsg = (MSG_SYN_PARTY_ADD*)msg;

			/// 신청
			Message.Format( GAMERESOURCEMAN->GetGameText( 131 ), pmsg->Name );
			CHATMANAGER->AddSystemMsg( eSYSTEM_NORMAL, (LPCTSTR)Message.Cstr() );

			Message.Format( GAMERESOURCEMAN->GetGameText( 132 ), pmsg->Name );
			UIMAN->CreateModal(	eStage_Game,
								eMBEVENT_PARTY_ADD_REQ, 
								(LPCTSTR)Message.Cstr(),			// 파티요청 메시지
								GAMERESOURCEMAN->GetGameText( 99 ), // 파티 요청
								eSKIN_YESNO
								, 0, PARTY_WAIT_TIME, false, false );
		}
		break;
	case NM_PARTY_REP_RES:
		{
			/// 파티 신청 수락에 대한 결과
			UIMAN->SendEventToMsgbox( false, eMBEVENT_PARTY_ADD_REQ );

			MSG_RES_PARTY_REP* pmsg = (MSG_RES_PARTY_REP*)msg;

			switch( pmsg->ErrorCode )
			{
			case ERROR_PARTY_REP_REFUSE:
				{
					/// 파티거절
					CHATMANAGER->AddSystemMsg( eSYSTEM_NORMAL, GAMERESOURCEMAN->GetGameText( 133 ) );
				}
				break;
			case ERROR_PARTY_REP_FULL:
				{
					/// 파티인원 초과
					UIMAN->CreateModal(	eStage_Game,
						eMBEVENT_NONE, 
						GAMERESOURCEMAN->GetGameText( 112 ),	// 파티 정원초과
						GAMERESOURCEMAN->GetGameText( 301 ),	// 알림
						eSKIN_OK
						);
				}
				break;
			case ERROR_PARTY_REP_FAIL:
				{
					/// 초대한 파티 존재 하지 않음
					UIMAN->CreateModal(	eStage_Game,
						eMBEVENT_NONE, 
						GAMERESOURCEMAN->GetGameText( 114 ),	// 파티 없음
						GAMERESOURCEMAN->GetGameText( 301 ),	// 알림
						eSKIN_OK
						);
				}
				break;
			}
		}
		break;
	case NM_PARTY_LIST_SYN:	/// 파티가 생성되었을떄만 받는다!!!!!!!
		{
			/// 파티 전체 리스트
			MSG_SYN_PARTY_LIST* pmsg = (MSG_SYN_PARTY_LIST*)msg;

			/// 파티 생성
			CreateParty( pmsg );

			/// 파티 인덱스 세팅
			HERO->SetPartyIndex( pmsg->mIndex );
		}
		break;
	case NM_PARTY_ADDONE_SYN:
		{
			/// 파티원 한명 추가
			MSG_SYN_PARTY_ADDONE* pmsg = (MSG_SYN_PARTY_ADDONE*)msg;
			AddUser( pmsg );

			Message.Format( GAMERESOURCEMAN->GetGameText( 105 ), pmsg->Name );
			CHATMANAGER->AddSystemMsg( eSYSTEM_NORMAL, (LPCTSTR)Message.Cstr() );
		}
		break;
	case NM_PARTY_OUT_RES:
		{
			/// 파티탈퇴요청 결과
			CHATMANAGER->AddSystemMsg( eSYSTEM_NORMAL, GAMERESOURCEMAN->GetGameText( 116 ) );

			/// 파티 UI 닫기
			DeleteParty();

			/// 파티 탈퇴
			HERO->SetPartyIndex( 0 );

			/// 파티 관련 UI 락 풀기
			GAMEUI->NetUnLockParty( eLOCK_PARTYOUT );
		}
		break;
	case NM_PARTY_OUT_SYN:
		{
			/// 파티 탈퇴 알림.
			MSG_SYN_PARTY_OUT* pmsg = (MSG_SYN_PARTY_OUT*)msg;

			int i = FindUser( pmsg->UserIndex );
			if( i > -1 )
			{
				Message.Format( GAMERESOURCEMAN->GetGameText( 115 ), (LPCTSTR)mParty[i].mName.Cstr() );
				CHATMANAGER->AddSystemMsg( eSYSTEM_NORMAL, (LPCTSTR)Message.Cstr() );

				DeleteUser(i);
			}
			else
			{
				assert(0);
			}
		}
		break;
	case NM_PARTY_DELETE_SYN:
		{
			DeleteParty();

			/// 파티 탈퇴
			HERO->SetPartyIndex( 0 );

			/// 파티 해산됨
			Message.Format( GAMERESOURCEMAN->GetGameText( 141 ) );
			CHATMANAGER->AddSystemMsg( eSYSTEM_NORMAL, (LPCTSTR)Message.Cstr() );

			UIMAN->CreateModal(	eStage_Game,
								eMBEVENT_NONE, 
								GAMERESOURCEMAN->GetGameText( 117 ),	// 파티 해산
								GAMERESOURCEMAN->GetGameText( 301 ),	// 알림
								eSKIN_OK
								);
		}
		break;
	case NM_PARTY_CHANGELEADER_RES:
		{
			MSG_RES_PARTY_CHANGELEADER* pmsg = (MSG_RES_PARTY_CHANGELEADER*)msg;

			switch( pmsg->ErrorCode )
			{
			case ERROR_PARTY_CHANGELEADER_SUCESS:
				break;
			case ERROR_PARTY_CHANGELEADER_LEADER:
				CHATMANAGER->AddSystemMsg( eSYSTEM_NORMAL, GAMERESOURCEMAN->GetGameText( 119 ) );
				break;
			case ERROR_PARTY_CHANGELEADER_FAIL:
				CHATMANAGER->AddSystemMsg( eSYSTEM_NORMAL, GAMERESOURCEMAN->GetGameText( 120 ) );
				break;
			}

			/// 파티 관련 UI 락 풀기
			GAMEUI->NetUnLockParty( eLOCK_PARTYCHANGELEADER );
		}
		break;
	case NM_PARTY_CHANGELEADER_SYN:
		{
			/// 파티장 변경됨
			MSG_SYN_PARTY_CHANGELEADER* pmsg = (MSG_SYN_PARTY_CHANGELEADER*)msg;

			if( HERO->GetObjectID() == pmsg->UserIndex )
			{
				mLeaderIndex = pmsg->UserIndex;
				Message.Format( GAMERESOURCEMAN->GetGameText( 118 ), HERO->GetName() );
				CHATMANAGER->AddSystemMsg( eSYSTEM_NORMAL, (LPCTSTR)Message.Cstr() );
			}
			else
			{
				for( int i = 0; i < mCount; ++i )
				{
					if( mParty[i].mIndex == pmsg->UserIndex )
					{
						mLeaderIndex = pmsg->UserIndex;
						Message.Format( GAMERESOURCEMAN->GetGameText( 118 ), (LPCTSTR)mParty[i].mName.Cstr() );
						CHATMANAGER->AddSystemMsg( eSYSTEM_NORMAL, (LPCTSTR)Message.Cstr() );
						break;
					}
				}

			}

			ChangeLeader();
		}
		break;
	case NM_PARTY_CHANGEDIVIDE_RES:
		{
			/// 파티분배방식 변경 요청 결과
			MSG_RES_PARTY_CHAGNEDIVIDE* pmsg = (MSG_RES_PARTY_CHAGNEDIVIDE*)msg;

			switch( pmsg->ErrorCode )
			{
			case ERROR_PARTY_CHANGEDIVIDE_SUCESS:
				break;
			case ERROR_PARTY_CHANGEDIVIDE_LEADER:
				CHATMANAGER->AddSystemMsg( eSYSTEM_NORMAL, GAMERESOURCEMAN->GetGameText( 122 ) );
				break;
			case ERROR_PARTY_CHANGEDIVIDE_FAIL:
				CHATMANAGER->AddSystemMsg( eSYSTEM_NORMAL, GAMERESOURCEMAN->GetGameText( 123 ) );
				break;
			}

			/// 파티 관련 UI 
			GAMEUI->NetUnLockParty( eLOCK_PARTYCHANGEDIVIDE );
		}
		break;
	case NM_PARTY_CHANGEDIVIDE_SYN:
		{
			/// 파티분배방식 변경 알림
			MSG_SYN_PARTY_CHANGEDIVDE* pmsg = (MSG_SYN_PARTY_CHANGEDIVDE*)msg;
			mDivideType = pmsg->type;

			unsigned int textId = 0;
			switch( mDivideType )
			{
			case PARTY_DIVIDE_TURN:		textId = 265;	break;
			case PARTY_DIVIDE_RANDOM:	textId = 266; 	break;
			case PARTY_DIVIDE_DAMAGE:	textId = 267; 	break;
			case PARTY_DIVIDE_FREE:		textId = 268; 	break;
			default:					assert(0);		return;
			}

			if( textId > 0 )
			{
				Message.Format( GAMERESOURCEMAN->GetGameText( 124 ), UIMAN->GetUIText( textId ) );
				CHATMANAGER->AddSystemMsg( eSYSTEM_NORMAL, (LPCTSTR)Message.Cstr() );
			}

			/// UI 세팅
			cPartyWindow* pPartyWindow = GAMEUI->GetPartyWindow();
			if( pPartyWindow )
			{
				pPartyWindow->SetDivideType( mDivideType );
			}
			else
			{
				assert(0);
			}
		}
		break;
	case NM_PARTY_THROW_RES:
		{
			/// 파티원 추방 결과
			MSG_RES_PARTY_THROW* pmsg = (MSG_RES_PARTY_THROW*)msg;

			switch( pmsg->ErrorCode )
			{
			case ERROR_PARTY_THROW_SUCESS:
				break;
			case ERROR_PARTY_THROW_LEADER:
				/// 권한 없음
				CHATMANAGER->AddSystemMsg( eSYSTEM_NORMAL, GAMERESOURCEMAN->GetGameText( 122 ) );
				break;
			case ERROR_PARTY_THROW_FAIL:
				/// 추방 실패
				CHATMANAGER->AddSystemMsg( eSYSTEM_NORMAL, GAMERESOURCEMAN->GetGameText( 125 ) );
				break;
			}

			/// 파티 관련 UI 
			GAMEUI->NetUnLockParty( eLOCK_PARTYTHROW );
		}
		break;
	case NM_PARTY_THROW_SYN:
		{
			/// 파티원 추방 알림
			MSG_SYN_PARTY_THROW* pmsg = (MSG_SYN_PARTY_THROW*)msg;
			int i = FindUser( pmsg->UserIndex );
			if( i > -1 )
			{
				Message.Format( GAMERESOURCEMAN->GetGameText( 126 ), (LPCTSTR)mParty[i].mName.Cstr() );
				CHATMANAGER->AddSystemMsg( eSYSTEM_NORMAL, (LPCTSTR)Message.Cstr() );

				DeleteUser(i);
			}
			else
			{
				assert(0);
			}
		}
		break;
	case NM_PARTY_CUT_SYN:
		{
			/// 파티로부터 추방당함
			DeleteParty();

			/// 파티 탈퇴
			HERO->SetPartyIndex( 0 );

			CHATMANAGER->AddSystemMsg( eSYSTEM_NORMAL, GAMERESOURCEMAN->GetGameText( 127 ) );
			UIMAN->CreateModal(	eStage_Game,
								eMBEVENT_NONE, 
								GAMERESOURCEMAN->GetGameText( 127 ),	// 파티 추방
								GAMERESOURCEMAN->GetGameText( 301 ),	// 알림
								eSKIN_OK
								);
		}
		break;
	case NM_PARTY_MAPCHANGE_SYN:
		{
			MSG_SYN_PARTY_MAPCHANGE* pmsg = (MSG_SYN_PARTY_MAPCHANGE*)msg;
			int i = FindUser( pmsg->UserIndex );
			if( i > -1 && mParty[i].mUIIndex > -1 )
			{
				/// 파티원이 맵 체인지 함
				mParty[i].mMapNum = pmsg->MapNum;

				cPartyStateWindow* state = GAMEUI->GetPartyStateWindow( mParty[i].mUIIndex );
				if( state )
				{
					if( HERO->GetMapNum() == mParty[i].mMapNum )
					{
						/// 동일 맵인경우
						state->SetNameColor( eCOLOR_WHITE );
						state->ShowData( true );
					}
					else
					{
						/// 아닌경우
						state->SetNameColor( eCOLOR_DARKGRAY );
						state->ShowData( false );
					}
					
					state->SetMapNum( mParty[i].mMapNum );
				}

				/// 미니맵 세팅
				cSmallMiniMapWindow* minimap = GAMEUI->GetSmallMinimapWindow();
				cMiniMapWindow* pWide = GAMEUI->GetMinimapWindow();
				if( minimap && pWide )
				{
					minimap->SetMapNumParty( mParty[i].mMapNum, pmsg->UserIndex );
					pWide->SetMapNumParty( mParty[i].mMapNum, pmsg->UserIndex );
				}

				Message.Format( GAMERESOURCEMAN->GetGameText( 136 ),  (LPCTSTR)mParty[i].mName.Cstr(), GAMERESOURCEMAN->GetMapName( pmsg->MapNum ) );
				CHATMANAGER->AddSystemMsg( eSYSTEM_NORMAL, (LPCTSTR)Message.Cstr() );	
			}
			else
			{
				assert(0);
			}
		}
		break;
	case NM_PARTY_ITEMGET_SYN:
		{
			/// 파티원들의 아이템 획득
			MSG_SYN_PARTY_ITEMGET* pmsg = (MSG_SYN_PARTY_ITEMGET*)msg;
			int i = FindUser( pmsg->UserIndex );
			if( i > -1 )
			{
				for( long idx = 0; idx < pmsg->RowCount; ++idx )
				{
					Message.Format( GAMERESOURCEMAN->GetGameText( 139 ), (LPCTSTR)mParty[i].mName.Cstr() );
					CHATMANAGER->AddItemMsg( pmsg->ItemIndex[idx], UINT_MAX, (LPCTSTR)Message.Cstr(), GAMERESOURCEMAN->GetGameText( 140 ) );
				}
			}
			else
			{
				assert(0);
			}
		}
		break;
	case NM_PARTY_DATA_SYN:
		{
			/// 일정시간마다 갱신되는 데이터
			MSG_SYN_PARTY_DATA* pmsg = (MSG_SYN_PARTY_DATA*)msg;
		
			/// 해당 파티원 정보 갱신
			int i = FindUser( pmsg->userIndex );
			if( i > -1 && mParty[i].mUIIndex > -1 )
			{
				mParty[i].mMaxHP = pmsg->maxHP;
				mParty[i].mHP	 = pmsg->hp;
				mParty[i].mMaxMP = pmsg->maxMP;
				mParty[i].mMP	 = pmsg->mp;
				mParty[i].mLevel = pmsg->level;

				/// UI 갱신
				cPartyStateWindow* state = GAMEUI->GetPartyStateWindow( mParty[i].mUIIndex );
				if( state )
				{
					state->SetMaxHP( pmsg->maxHP );
					state->SetHPGauge( pmsg->hp );
					state->SetMaxMP( pmsg->maxMP );
					state->SetMPGauge( pmsg->mp );
					state->SetLevel( pmsg->level );

					/// 버프 재 세팅
					state->ClearBuff();
					for( int count = 0; count < pmsg->RowCount; ++count )
						state->AddBuff( pmsg->mTable[count].mUniqueIdx, pmsg->mTable[count].mInfluenceClassIdx );

					bool show = ( HERO->GetMapNum() == mParty[i].mMapNum ) ? true : false;
                    state->ShowData( show );
				}

				/// 이동 좌표 - 미니맵 세팅
				cSmallMiniMapWindow* minimap = GAMEUI->GetSmallMinimapWindow();
				cMiniMapWindow* pWide = GAMEUI->GetMinimapWindow();
				if( minimap && pWide )
				{
					minimap->SetPosParty( pmsg->userIndex, pmsg->posX, pmsg->posY );
					pWide->SetPosParty( pmsg->userIndex, pmsg->posX, pmsg->posY );
				}
			}
		}
		break;
	case NM_PARTY_JOBCHANGE_SYN:
		{
			/// 전직 정보
			MSG_SYN_PARTY_CHANGEJOB* pmsg = (MSG_SYN_PARTY_CHANGEJOB*)msg;
			int i = FindUser( pmsg->userIndex );
			if( i > -1 && mParty[i].mUIIndex > -1 )
			{
				mParty[i].mJob = pmsg->job;
				
				/// UI 갱신
				cPartyStateWindow* state = GAMEUI->GetPartyStateWindow( mParty[i].mUIIndex );
				if( state )
					state->SetJob( pmsg->job );
			}
		}
		break;
	case NM_PARTY_BREAK_SYN:
		{
			/// 파티 강제 해체
			DeleteParty();

			/// 파티 탈퇴
			HERO->SetPartyIndex( 0 );
			Message.Format( GAMERESOURCEMAN->GetGameText( 143 ) );
			CHATMANAGER->AddSystemMsg( eSYSTEM_NORMAL, (LPCTSTR)Message.Cstr() );

			UIMAN->CreateModal(	eStage_Game,
				eMBEVENT_NONE, 
				GAMERESOURCEMAN->GetGameText( 143 ),	// 강제 해체
				GAMERESOURCEMAN->GetGameText( 301 ),	// 알림
				eSKIN_OK
				);
		}
		break;
	default:
		assert(0);
		break;
	}
}
