156 lines
3.7 KiB
C++
156 lines
3.7 KiB
C++
#include "stdafx.h"
|
|
#include "SCreatureDB.h"
|
|
|
|
#include <Windows.h>
|
|
#include <kfile/KStream.h>
|
|
#include "KTypes.h"
|
|
#include <kfile/KFileManager.h>
|
|
#include <toolkit/XStringUtil.h>
|
|
#include "SkillBaseFile.h"
|
|
|
|
#include "SDebug_Util.h"
|
|
|
|
extern HWND g_hWnd;
|
|
|
|
SCreatureDB::SCreatureDB()
|
|
{
|
|
Init();
|
|
}
|
|
|
|
SCreatureDB::~SCreatureDB()
|
|
{
|
|
Destroy();
|
|
}
|
|
|
|
void SCreatureDB::Init()
|
|
{
|
|
Load();
|
|
}
|
|
|
|
void SCreatureDB::Destroy()
|
|
{
|
|
auto pos = m_mapCreatureList.cbegin();
|
|
auto end = m_mapCreatureList.cend();
|
|
|
|
for( ; pos != end; ++pos )
|
|
{
|
|
delete pos->second;
|
|
}
|
|
|
|
m_mapCreatureList.clear();
|
|
}
|
|
|
|
void SCreatureDB::GetEvolveID( const int nCreatureID, std::vector<int> & vIDList )
|
|
{
|
|
_SUMMON_INFO_FILE_CLIENT* pCreature = GetCreatureClientData( nCreatureID );
|
|
while( pCreature != NULL )
|
|
{
|
|
vIDList.insert( vIDList.begin(), pCreature->uid );
|
|
pCreature = GetCreatureClientData( pCreature->nPrev_Evolve_target );
|
|
}
|
|
}
|
|
|
|
void SCreatureDB::Load()
|
|
{
|
|
KStream * pRes = KFileManager::Instance().CreateStreamFromResource( "db_creature.rdb" );
|
|
if( !pRes ) return;
|
|
|
|
GAME_DB db_hdr;
|
|
|
|
pRes->Read( &db_hdr, sizeof(db_hdr) );
|
|
|
|
#ifdef _DEV_RDB_
|
|
// RDB 와 Header의 사이즈 비교.
|
|
int fileSize = pRes->Size() - ( STR_DATE_BUFFER + sizeof( int ) );
|
|
int headerSize = sizeof(_SUMMON_INFO_FILE) * db_hdr.nCount;
|
|
if( fileSize != headerSize )
|
|
{
|
|
char str[512] = { NULL, };
|
|
sprintf( str, "*** RDB Error !!! ***\n\n생성날짜%s\n파일:%s\n파일사이즈:%d\n헤더사이즈:%d\n ",
|
|
db_hdr.szDate,
|
|
__FILE__,
|
|
fileSize,
|
|
headerSize
|
|
);
|
|
|
|
::MessageBox( g_hWnd, str, "Error", MB_OK );
|
|
|
|
if( ::MessageBox( g_hWnd, "RDB와 클라이언트가 맞지않습니다. 강제종료하시겠습니까?", "Error", MB_YESNO ) == IDYES )
|
|
{
|
|
exit( 1 );
|
|
}
|
|
}
|
|
#endif
|
|
|
|
for( int i(0); db_hdr.nCount>i; i++ )
|
|
{
|
|
_SUMMON_INFO_FILE_CLIENT * pSummon = new _SUMMON_INFO_FILE_CLIENT;
|
|
memset( pSummon, 0, sizeof(_SUMMON_INFO_FILE_CLIENT) );
|
|
pRes->Read( pSummon, sizeof(_SUMMON_INFO_FILE) );
|
|
|
|
// { sonador 0.2.1 몬스터 DB 로컬 플레그 적용
|
|
if( !( pSummon->local_flag & GameRule::GetCurrentLocalBitSet() ) )
|
|
{
|
|
// 크리쳐 일러파일 확장자 변경 tga->jpg
|
|
// 2009-09-19 : hunee
|
|
//strcat( pSummon->illust_file_name, ".tga" );
|
|
strcat( pSummon->illust_file_name, ".jpg" );
|
|
|
|
pSummon->real_uid = pSummon->uid;
|
|
pSummon->nPrev_Evolve_target = 0;
|
|
//pSummon->uid = XFastRandom();
|
|
|
|
m_mapCreatureList.insert( std::make_pair( pSummon->real_uid, pSummon ) );
|
|
}
|
|
else
|
|
{
|
|
delete pSummon;
|
|
}
|
|
// }
|
|
}
|
|
|
|
KFileManager::Instance().DeleteStream( pRes );
|
|
|
|
//진화 단계 링크 설정
|
|
auto pos = m_mapCreatureList.begin();
|
|
auto end = m_mapCreatureList.end();
|
|
|
|
for( ; pos != end; ++pos )
|
|
{
|
|
_SUMMON_INFO_FILE_CLIENT* pSummon = pos->second;
|
|
if( pSummon->nEvolve_target > 0 )
|
|
{
|
|
_SUMMON_INFO_FILE_CLIENT * pEvolve = GetCreatureClientData( pSummon->nEvolve_target );
|
|
if( pEvolve != NULL )
|
|
{
|
|
#ifdef _DEV
|
|
if( pEvolve->nPrev_Evolve_target != 0 )
|
|
{
|
|
char szErrorMsg[512] = "";
|
|
s_sprintf( szErrorMsg, _countof( szErrorMsg ), "The previous evolution stage is already set. (my: %d <- %d) (Target: %d <- %d)",
|
|
pSummon->uid, pSummon->nEvolve_target, pEvolve->uid, pEvolve->nPrev_Evolve_target );
|
|
|
|
::MessageBox( g_hWnd, szErrorMsg, "Error", MB_OK );
|
|
}
|
|
#endif
|
|
pEvolve->nPrev_Evolve_target = pSummon->uid;
|
|
}
|
|
}
|
|
}
|
|
|
|
// std::vector<int> vIDList;
|
|
// GetEvolveID( 2001, vIDList );
|
|
// GetEvolveID( 2002, vIDList );
|
|
// GetEvolveID( 1001, vIDList );
|
|
}
|
|
|
|
SCreatureDB* SCreatureDB::m_pThis = NULL;
|
|
SCreatureDB & GetCreatureDB()
|
|
{
|
|
if( NULL == SCreatureDB::m_pThis )
|
|
SCreatureDB::m_pThis = new SCreatureDB;
|
|
|
|
return *SCreatureDB::m_pThis;
|
|
// static SCreatureDB creaturedb;
|
|
// return creaturedb;
|
|
} |