137 lines
4.6 KiB
C++
137 lines
4.6 KiB
C++
#include "stdafx.h"
|
|
#include "SMonsterAffiliationDB.h"
|
|
|
|
#include <kfile/KFileManager.h>
|
|
|
|
#include "SLog.h"
|
|
|
|
#include "SkillBaseFile.h"
|
|
#include <kfile/KStream.h>
|
|
#include "KTypes.h"
|
|
|
|
//-----------------------------------------------------------------------------------------------------------------
|
|
// 몬스터 계열 정보 DB 인스턴스 얻기
|
|
//-----------------------------------------------------------------------------------------------------------------
|
|
SMonsterAffiliationDB & GetMonsterAffiliationDB()
|
|
{
|
|
static SMonsterAffiliationDB MonsterAffiliationDB;
|
|
return MonsterAffiliationDB;
|
|
}
|
|
|
|
|
|
//-----------------------------------------------------------------------------------------------------------------
|
|
// 생성자
|
|
//-----------------------------------------------------------------------------------------------------------------
|
|
SMonsterAffiliationDB::SMonsterAffiliationDB()
|
|
{
|
|
if( false == Load() )
|
|
{
|
|
SDEBUGLOG( "[SMonsterAffiliationDB] Load Failed " );
|
|
assert( NULL );
|
|
}
|
|
}
|
|
|
|
|
|
//-----------------------------------------------------------------------------------------------------------------
|
|
// 파괴자
|
|
//-----------------------------------------------------------------------------------------------------------------
|
|
SMonsterAffiliationDB::~SMonsterAffiliationDB()
|
|
{
|
|
Destroy();
|
|
}
|
|
|
|
|
|
//-----------------------------------------------------------------------------------------------------------------
|
|
// RDB 파일 불러오기
|
|
//-----------------------------------------------------------------------------------------------------------------
|
|
bool SMonsterAffiliationDB::Load()
|
|
{
|
|
KStream* pRes( KFileManager::Instance().CreateStreamFromResource( "db_MonsterAffiliationResource.rdb" ) );
|
|
if( NULL == pRes )
|
|
{
|
|
SLOG( "[SMonsterAffiliationDB] Create Stream Failed - [db_MonsterAffiliationResoruce.rdb]" );
|
|
assert( NULL );
|
|
return false;
|
|
}
|
|
|
|
GAME_DB db_hdr;
|
|
std::string idKey;
|
|
|
|
pRes->Read( &db_hdr, sizeof(db_hdr) );
|
|
|
|
for( int nCount = 0; nCount < db_hdr.nCount; nCount++ )
|
|
{
|
|
MonsterAffiliationBase stMonsterAffiliationBase;
|
|
size_t ReadSize( pRes->Read( &stMonsterAffiliationBase, sizeof(stMonsterAffiliationBase) ) );
|
|
if( NULL == ReadSize )
|
|
{
|
|
SDEBUGLOG( "[SMonsterAffiliationDB] Read Failed" );
|
|
assert( ReadSize );
|
|
return false;
|
|
}
|
|
|
|
PMONSTER_AFFILIATION_INFO pMonsterAffiliationInfo( new MONSTER_AFFILIATION_INFO() );
|
|
if( NULL == pMonsterAffiliationInfo )
|
|
{
|
|
SDEBUGLOG( "[SMonsterAffiliationDB] Memory Alloc Failed" );
|
|
assert( pMonsterAffiliationInfo );
|
|
continue;
|
|
}
|
|
|
|
pMonsterAffiliationInfo->m_nUniqueID = stMonsterAffiliationBase.uid;
|
|
pMonsterAffiliationInfo->m_nAffiliationID = stMonsterAffiliationBase.affiliation_id;
|
|
pMonsterAffiliationInfo->m_nStringID = stMonsterAffiliationBase.string_id;
|
|
|
|
if( false == m_mapMonsterAffiliationInfo.insert( pair<UINT, PMONSTER_AFFILIATION_INFO>( stMonsterAffiliationBase.uid, pMonsterAffiliationInfo ) ).second )
|
|
{
|
|
SAFE_DELETE( pMonsterAffiliationInfo );
|
|
SLOG( "[SMonsterAffiliationDB] ID 중복이거나 컨테이너 삽입에 실패하였습니다." );
|
|
assert( pMonsterAffiliationInfo );
|
|
continue;
|
|
}
|
|
}
|
|
|
|
KFileManager::Instance().DeleteStream( pRes );
|
|
|
|
return true;
|
|
}
|
|
|
|
|
|
//-----------------------------------------------------------------------------------------------------------------
|
|
// 파괴
|
|
//-----------------------------------------------------------------------------------------------------------------
|
|
void SMonsterAffiliationDB::Destroy()
|
|
{
|
|
for( MONSTER_AFFILIATION_INFO_ITER Iter = m_mapMonsterAffiliationInfo.begin(); Iter != m_mapMonsterAffiliationInfo.end(); ++Iter )
|
|
{
|
|
PMONSTER_AFFILIATION_INFO pMonsterAffiliationInfo( Iter->second );
|
|
SAFE_DELETE( pMonsterAffiliationInfo );
|
|
}
|
|
|
|
m_mapMonsterAffiliationInfo.clear();
|
|
}
|
|
|
|
|
|
//-----------------------------------------------------------------------------------------------------------------
|
|
// 몬스터 종 정보 얻기
|
|
//-----------------------------------------------------------------------------------------------------------------
|
|
MONSTER_AFFILIATION_INFO* const SMonsterAffiliationDB::GetMonsterAffiliationInfo( const int nAffiliationID )
|
|
{
|
|
if( m_mapMonsterAffiliationInfo.empty() )
|
|
return NULL;
|
|
|
|
for( MONSTER_AFFILIATION_INFO_ITER Iter = m_mapMonsterAffiliationInfo.begin(); Iter != m_mapMonsterAffiliationInfo.end(); ++Iter )
|
|
{
|
|
PMONSTER_AFFILIATION_INFO pMonsterAffiliationInfo( Iter->second );
|
|
if( NULL == pMonsterAffiliationInfo )
|
|
continue;
|
|
|
|
if( nAffiliationID == pMonsterAffiliationInfo->m_nAffiliationID )
|
|
return pMonsterAffiliationInfo;
|
|
}
|
|
|
|
SDEBUGLOG( "[SMonsterAffiliationDB] 종 정보를 찾을 수 없습니다. Affiliation ID - [%u]", nAffiliationID );
|
|
assert( NULL );
|
|
|
|
return NULL;
|
|
} |