📄 partymanager.cpp
字号:
#include "StdAfx.h"
#include "Party.h"
#include "PartyManager.h"
#include "Player.h"
PartyManager::PartyManager()
{
m_pPartyPool = new CMemoryPoolFactory<Party>;
m_pPartyHashTable = new util::SolarHashTable<Party*>;
m_PartyKeyGenerater.Create( 1, 10000 );
}
PartyManager::~PartyManager()
{
SAFE_DELETE( m_pPartyPool );
SAFE_DELETE( m_pPartyHashTable );
}
VOID PartyManager::Release()
{
if( m_pPartyPool )
{
m_pPartyPool->Release();
}
}
VOID PartyManager::Init( DWORD dwMaxPoolSize )
{
m_pPartyPool->Initialize( dwMaxPoolSize, dwMaxPoolSize/2+1 );
m_pPartyHashTable->Initialize( dwMaxPoolSize );
}
Party* PartyManager::AllocParty()
{
WORD wPartyKey = (WORD)m_PartyKeyGenerater.GetKey();
// 货肺积己
Party *pParty = (Party*)m_pPartyPool->Alloc();
if( !pParty )
{
SUNLOG( eCRITICAL_LOG, "[PartyManager::AllocParty] Can't Allocate Party " );
m_PartyKeyGenerater.RestoreKey( wPartyKey );
return NULL;
}
pParty->SetPartyKey( wPartyKey );
// Party Manager俊 殿废
if( m_pPartyHashTable->Add( pParty, wPartyKey ) )
{
return pParty;
}
else
{
SUNLOG( eCRITICAL_LOG, "[PartyManager::AllocParty] AddParty Fail! " );
m_pPartyPool->Free( pParty );
m_PartyKeyGenerater.RestoreKey( wPartyKey );
return NULL;
}
}
BOOL PartyManager::RemoveParty( WORD wPartyKey, BOOL bSendPacket )
{
Party *pParty = FindParty( wPartyKey );
if( !pParty ) return FALSE;
// 颇萍秦眉 荤角阑 颇萍盔甸俊霸 舅妨霖促.
if( bSendPacket )
{
MSG_CG_PARTY_DESTROY_PARTY_BRD PartyDestroyMsg;
PartyDestroyMsg.m_byCategory = CG_PARTY;
PartyDestroyMsg.m_byProtocol = CG_PARTY_DESTROY_PARTY_BRD;
pParty->SendPacketAll( &PartyDestroyMsg, sizeof(PartyDestroyMsg) );
}
m_pPartyHashTable->Remove( wPartyKey );
m_pPartyPool->Free( pParty );
pParty->Init( INITIAL_KEY_VALUE );
m_PartyKeyGenerater.RestoreKey( wPartyKey );
return TRUE;
}
RC::ePARTY_RESULT PartyManager::ChangeMaster( WORD wPartyKey, DWORD dwNextMasterObjKey )
{
// 秦寸窍绰 颇萍啊 粮犁窍绰瘤 八荤
Party *pParty = m_pPartyHashTable->GetData( wPartyKey );
if( !pParty )
return RC::RC_PARTY_PARTY_NOTEXIST;
// 颇萍厘栏肺 烙疙窍妨绰 某腐磐啊 颇萍盔捞 酒聪促.
Player *pNextMaster = pParty->GetMemberInfo( dwNextMasterObjKey );
if( !pNextMaster )
{
return RC::RC_PARTY_ISNOT_MEMBEROFPARTY;
}
if( pParty->GetMasterUserKey() == pNextMaster->GetUserKey() )
return RC::RC_PARTY_CANNOT_CHANGE_MASTER;
// 颇萍盔甸狼 沥焊甸阑 货肺款 颇萍厘栏肺 函版茄促.
pParty->ChangeMaster( pNextMaster->GetUserKey() );
// 颇萍厘 函版 荤角阑 颇萍盔甸俊霸 舅妨霖促.
MSG_CG_PARTY_CHANGE_MASTER_BRD BrdMsg;
BrdMsg.m_byCategory = CG_PARTY;
BrdMsg.m_byProtocol = CG_PARTY_CHANGE_MASTER_BRD;
BrdMsg.m_dwObjKey = pNextMaster->GetObjectKey();
pParty->SendPacketAll( &BrdMsg, sizeof(BrdMsg) );
return RC::RC_PARTY_SUCCESS;
}
RC::ePARTY_RESULT PartyManager::AppointMaster( WORD wPartyKey, DWORD dwNextMasterUserKey )
{
Player *pPlayer = PlayerManager::Instance()->FindPlayer( dwNextMasterUserKey );
if( !pPlayer )
{
return RC::RC_PARTY_PLAYER_NOTEXIST;
}
// 烙疙窍妨绰 敲饭捞绢啊 捞固 颇萍盔吝狼 茄疙捞扼搁 ChangeMaster甫 烹秦 颇萍厘阑 函版茄促.
if( pPlayer->GetPartyState().GetPartyKey() == wPartyKey )
{
return ChangeMaster( wPartyKey, pPlayer->GetObjectKey() );
}
// 秦寸窍绰 颇萍啊 粮犁窍绰瘤 八荤
Party *pParty = m_pPartyHashTable->GetData( wPartyKey );
if( !pParty )
return RC::RC_PARTY_PARTY_NOTEXIST;
if( pParty->GetMasterUserKey() == dwNextMasterUserKey )
return RC::RC_PARTY_CANNOT_CHANGE_MASTER;
// 颇萍盔甸狼 沥焊甸阑 货肺款 颇萍厘栏肺 函版茄促.
pParty->ChangeMaster( dwNextMasterUserKey );
return RC::RC_PARTY_SUCCESS;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -