137 lines
4.3 KiB
C++
137 lines
4.3 KiB
C++
#include "stdafx.h"
|
|
#include "SMonsterSpeciesDB.h"
|
|
|
|
#include <kfile/KFileManager.h>
|
|
|
|
#include "SLog.h"
|
|
|
|
#include "SkillBaseFile.h"
|
|
#include <kfile/KStream.h>
|
|
#include "KTypes.h"
|
|
|
|
//-----------------------------------------------------------------------------------------------------------------
|
|
// 몬스터 종 정보 DB 인스턴스 얻기
|
|
//-----------------------------------------------------------------------------------------------------------------
|
|
SMonsterSpeciesDB & GetMonsterSpeciesDB()
|
|
{
|
|
static SMonsterSpeciesDB MonsterSpeciesDB;
|
|
return MonsterSpeciesDB;
|
|
}
|
|
|
|
|
|
//-----------------------------------------------------------------------------------------------------------------
|
|
// 생성자
|
|
//-----------------------------------------------------------------------------------------------------------------
|
|
SMonsterSpeciesDB::SMonsterSpeciesDB()
|
|
{
|
|
if( false == Load() )
|
|
{
|
|
SDEBUGLOG( "[SMonsterSpeciesDB] Load Failed " );
|
|
assert( NULL );
|
|
}
|
|
}
|
|
|
|
|
|
//-----------------------------------------------------------------------------------------------------------------
|
|
// 파괴자
|
|
//-----------------------------------------------------------------------------------------------------------------
|
|
SMonsterSpeciesDB::~SMonsterSpeciesDB()
|
|
{
|
|
Destroy();
|
|
}
|
|
|
|
|
|
//-----------------------------------------------------------------------------------------------------------------
|
|
// RDB 파일 불러오기
|
|
//-----------------------------------------------------------------------------------------------------------------
|
|
bool SMonsterSpeciesDB::Load()
|
|
{
|
|
KStream* pRes( KFileManager::Instance().CreateStreamFromResource( "db_MonsterSpeciesResource.rdb" ) );
|
|
if( NULL == pRes )
|
|
{
|
|
SLOG( "[SMonsterSpeciesDB] Create Stream Failed - [db_MonsterSpeciesResoruce.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++ )
|
|
{
|
|
MonsterSpeciesBase stMonsterSpeciesBase;
|
|
size_t ReadSize( pRes->Read( &stMonsterSpeciesBase, sizeof(stMonsterSpeciesBase) ) );
|
|
if( NULL == ReadSize )
|
|
{
|
|
SDEBUGLOG( "[SMonsterSpeciesDB] Read Failed" );
|
|
assert( ReadSize );
|
|
return false;
|
|
}
|
|
|
|
PMONSTER_SPECIES_INFO pMonsterSpeciesInfo( new MONSTER_SPECIES_INFO() );
|
|
if( NULL == pMonsterSpeciesInfo )
|
|
{
|
|
SDEBUGLOG( "[SMonsterSpeciesDB] Memory Alloc Failed" );
|
|
assert( pMonsterSpeciesInfo );
|
|
continue;
|
|
}
|
|
|
|
pMonsterSpeciesInfo->m_nUniqueID = stMonsterSpeciesBase.uid;
|
|
pMonsterSpeciesInfo->m_nSpeciesID = stMonsterSpeciesBase.species_id;
|
|
pMonsterSpeciesInfo->m_nStringID = stMonsterSpeciesBase.string_id;
|
|
|
|
if( false == m_mapMonsterSpeciesInfo.insert( pair<UINT, PMONSTER_SPECIES_INFO>( stMonsterSpeciesBase.uid, pMonsterSpeciesInfo ) ).second )
|
|
{
|
|
SAFE_DELETE( pMonsterSpeciesInfo );
|
|
SLOG( "[SMonsterSpeciesDB] ID 중복이거나 컨테이너 삽입에 실패하였습니다." );
|
|
assert( pMonsterSpeciesInfo );
|
|
continue;
|
|
}
|
|
}
|
|
|
|
KFileManager::Instance().DeleteStream( pRes );
|
|
|
|
return true;
|
|
}
|
|
|
|
|
|
//-----------------------------------------------------------------------------------------------------------------
|
|
// 파괴
|
|
//-----------------------------------------------------------------------------------------------------------------
|
|
void SMonsterSpeciesDB::Destroy()
|
|
{
|
|
for( MONSTER_SPECIES_INFO_ITER Iter = m_mapMonsterSpeciesInfo.begin(); Iter != m_mapMonsterSpeciesInfo.end(); ++Iter )
|
|
{
|
|
PMONSTER_SPECIES_INFO pMonsterSpecies( Iter->second );
|
|
SAFE_DELETE( pMonsterSpecies );
|
|
}
|
|
|
|
m_mapMonsterSpeciesInfo.clear();
|
|
}
|
|
|
|
|
|
//-----------------------------------------------------------------------------------------------------------------
|
|
// 몬스터 종 정보 얻기
|
|
//-----------------------------------------------------------------------------------------------------------------
|
|
MONSTER_SPECIES_INFO* const SMonsterSpeciesDB::GetMonsterSpeciesInfo( const int nSpeciesID )
|
|
{
|
|
if( m_mapMonsterSpeciesInfo.empty() )
|
|
return NULL;
|
|
|
|
for( MONSTER_SPECIES_INFO_ITER Iter = m_mapMonsterSpeciesInfo.begin(); Iter != m_mapMonsterSpeciesInfo.end(); ++Iter )
|
|
{
|
|
PMONSTER_SPECIES_INFO pMonsterSpecies( Iter->second );
|
|
if( NULL == pMonsterSpecies )
|
|
continue;
|
|
|
|
if( nSpeciesID == pMonsterSpecies->m_nSpeciesID )
|
|
return pMonsterSpecies;
|
|
}
|
|
|
|
SDEBUGLOG( "[SMonsterSpeciesDB] 종 정보를 찾을 수 없습니다. Species ID - [%u]", nSpeciesID );
|
|
assert( NULL );
|
|
|
|
return NULL;
|
|
} |