📄 summonmanager.cpp
字号:
#include "StdAfx.h"
#include "SummonManager.h"
#include "SummonedNPCs.h"
#include "SkillInfoParser.h"
#include "Summoned.h"
SummonManager::SummonManager()
{
m_pSummonNPCsPool = new CMemoryPoolFactory<SummonedNPCs>;
m_pSummonNPCsList = new util::SolarHashTable<SummonedNPCs *, DWORD>;
}
SummonManager::~SummonManager()
{
SAFE_DELETE( m_pSummonNPCsPool );
SAFE_DELETE( m_pSummonNPCsList );
}
VOID SummonManager::Release()
{
if( m_pSummonNPCsPool )
{
m_pSummonNPCsPool->Release();
}
}
VOID SummonManager::Init( DWORD dwMaxPoolSize )
{
m_pSummonNPCsPool->Initialize( dwMaxPoolSize, dwMaxPoolSize/2+1 );
m_pSummonNPCsList->Initialize( dwMaxPoolSize );
}
SummonedNPCs* SummonManager::AllocSummonNPCs( Character *pSummoner, BOOL bPlayerSkill )
{
SummonedNPCs *pSummonedNPCs = FindSummonNPCs( pSummoner->GetObjectKey() );
if( pSummonedNPCs )
{
// 敲饭捞绢 家券狼 版快
if( bPlayerSkill )
{
// 捞固 家券阑 沁栏搁 捞傈 家券眉甫 昏力茄促.
FreeSummonNPCs( pSummonedNPCs );
}
else
{
// NPC狼 版快 捞傈 家券沥焊甫 弊措肺 捞侩茄促.
return pSummonedNPCs;
}
}
// 秦寸窍绰 弊缝捞 绝栏搁 货肺积己
pSummonedNPCs = (SummonedNPCs*)m_pSummonNPCsPool->Alloc();
if( !pSummonedNPCs )
{
SUNLOG( eCRITICAL_LOG, "[SummonManager::AllocSummonNPCs] Can't Allocate SummonedNPCs " );
return NULL;
}
// SummonedNPCs 檬扁拳
if( (pSummoner->GetObjectType() & PLAYER_OBJECT) == PLAYER_OBJECT )
{
pSummonedNPCs->Init( pSummoner, eSUMMON_COMMAND_DELEGATE_ATTACK );
}
else
{
pSummonedNPCs->Init( pSummoner, eSUMMON_COMMAND_DELEGATE_ATTACK );
}
// SummonManager俊 殿废
if( m_pSummonNPCsList->Add( pSummonedNPCs, pSummoner->GetObjectKey() ) )
{
return pSummonedNPCs;
}
else
{
SUNLOG( eCRITICAL_LOG, "[SummonManager::AllocSummonNPCs] AddSummon Fail! " );
m_pSummonNPCsPool->Free( pSummonedNPCs );
return NULL;
}
}
BOOL SummonManager::FreeSummonNPCs( SummonedNPCs *pSummonNPCs )
{
if( NULL == FindSummonNPCs( pSummonNPCs->GetSummonerKey() ) )
{
SUNLOG( eCRITICAL_LOG, "[SummonManager::FreeSummonNPCs] Can't Remove SummonNPCs " );
return FALSE;
}
m_pSummonNPCsList->Remove( pSummonNPCs->GetSummonerKey() );
m_pSummonNPCsPool->Free( pSummonNPCs );
pSummonNPCs->Release();
return TRUE;
}
VOID SummonManager::AddSummonedSkill( DWORD dwSummonKey, SLOTCODE SkillCode )
{
SummonedNPCs *pSummonedNPCs = FindSummonNPCs( dwSummonKey );
if( !pSummonedNPCs ) return;
SkillScriptInfo *pBaseCurSkillInfo = SkillInfoParser::Instance()->GetSkillInfo( SkillCode );
if( pBaseCurSkillInfo->m_bySkillUserType != eSKILL_USER_SUMMONED ) return;
NPC *pNPC;
for( SUMMONED_ITERATOR it = pSummonedNPCs->Begin(); it != pSummonedNPCs->End(); ++it )
{
pNPC = *it;
if( ( pNPC->GetObjectType() & SUMMON_OBJECT ) != SUMMON_OBJECT ) continue;
Summoned *pSummoned = (Summoned*)pNPC;
pSummoned->AddSkill( SkillCode );
}
}
VOID SummonManager::DelSummonedSkill( DWORD dwSummonKey, SLOTCODE SkillCode )
{
SummonedNPCs *pSummonedNPCs = FindSummonNPCs( dwSummonKey );
if( !pSummonedNPCs ) return;
SkillScriptInfo *pBaseCurSkillInfo = SkillInfoParser::Instance()->GetSkillInfo( SkillCode );
if( pBaseCurSkillInfo->m_bySkillUserType != eSKILL_USER_SUMMONED ) return;
NPC *pNPC;
for( SUMMONED_ITERATOR it = pSummonedNPCs->Begin(); it != pSummonedNPCs->End(); ++it )
{
pNPC = *it;
if( ( pNPC->GetObjectType() & SUMMON_OBJECT ) != SUMMON_OBJECT ) continue;
Summoned *pSummoned = (Summoned*)pNPC;
pSummoned->DelSkill( SkillCode );
}
}
RC::eSUMMON_RESULT SummonManager::SetCommandState( DWORD dwSummonKey, eSUMMON_COMMAND eCommand, DWORD dwObjectKey, DWORD dwTargetKey )
{
SummonedNPCs *pSummonedNPCs = FindSummonNPCs( dwSummonKey );
if( !pSummonedNPCs ) return RC::RC_SUMMON_SUMMONED_NPC_NOTEXIST;
if( eCommand == eSUMMON_COMMAND_DESTROY )
{
// 泅犁绰 家券眉啊 1付府扼辑 坷宏璃飘虐肺 备盒捞 鞘夸绝瘤父
// 唱吝阑 困秦 努扼肺何磐 疙飞阑 郴副 家券眉 坷宏璃飘虐甫 罐酒具 茄促!
pSummonedNPCs->Destroy( dwObjectKey );
}
else
{
// 惑怕甫 官操绢霖促.
return pSummonedNPCs->SetCommandState( eCommand, dwObjectKey, dwTargetKey );
}
return RC::RC_SUMMON_SUCCESS;
}
VOID SummonManager::LeaveSummonNPCs( Character *pLeaveChar )
{
SummonedNPCs *pSummonedNPCs = FindSummonNPCs( pLeaveChar->GetSummonerKey() );
if( !pSummonedNPCs ) return;
DWORD dwObjectKey = pLeaveChar->GetObjectKey();
// 敲饭捞绢啊 栋朝版快 家券沥焊甫 公炼扒 秦力茄促.
if( (pLeaveChar->GetObjectType() & PLAYER_OBJECT) == PLAYER_OBJECT )
{
FreeSummonNPCs( pSummonedNPCs );
}
else
{
NPC *pLeaveNPC = (NPC*)pLeaveChar;
// 家券阑 寸茄 NPC牢 版快 家券沥焊俊辑 力芭茄促.
if( !pSummonedNPCs->IsSummoner( dwObjectKey ) )
{
pSummonedNPCs->DecreaseSummoned( pLeaveNPC->GetBaseInfo()->m_MonsterCode, dwObjectKey );
}
// 家券阑 矫挪 林眉牢 版快 家券NPC甸狼 傍蜡家券虐(m_dwSummonerKey)甫 NULL肺 檬扁拳茄促.
// FreeSummonNPCs甫 龋免窍瘤臼绰 巴篮 NPC啊 家券茄 何窍(家券眉)甸篮 昏力登瘤 臼扁 锭巩捞促.
if( pSummonedNPCs->IsSummoner( dwObjectKey ) )
{
NPC *pNPC = NULL;
for( SUMMONED_ITERATOR it = pSummonedNPCs->Begin(); it != pSummonedNPCs->End(); ++it )
{
pNPC = *it;
pNPC->SetSummonerKey(0);
}
pSummonedNPCs->SetSummoner( NULL );
}
// 家券府胶飘狼 糕滚荐啊 0捞搁 钱俊 馆券茄促.
if( !pSummonedNPCs->GetNumberOfNPCs() )
{
FreeSummonNPCs( pSummonedNPCs );
}
pLeaveNPC->SetSummonerKey(0);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -