#include "stdafx.h" #include "SExpDB.h" #include #include #include "KTypes.h" #include #include #include "SkillBaseFile.h" #include "MonsterBase.h" #include "SDebug_Util.h" extern HWND g_hWnd; SExpDB::SExpDB() { Init(); } SExpDB::~SExpDB() { Destroy(); } __int64 SExpDB::GetNeedExp( int nLevel ) { if( m_vExpList.empty() ) return 0; int nRef = nLevel - 1; if( 0 < nLevel && nLevel <= (int)m_vExpList.size() ) { return m_vExpList[nRef]->exp; } return 0; } __int64 SExpDB::GetNeedJp( int nLevel,int nCha ) { if( m_vExpList.empty() ) return 0; int nRef = nLevel - 1; if( 0 < nLevel && (int)m_vExpList.size() > nLevel ) { if( nCha >= 0 && nCha < 4 ) return m_vExpList[nRef]->jp[nCha]; } return 0; } void SExpDB::Init() { Load(); } void SExpDB::Destroy() { SAFE_DELETE_VECTOR( m_vExpList ); } void SExpDB::Load() { KStream * pRes = KFileManager::Instance().CreateStreamFromResource( "db_Exp.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(_EXP_TABLE) * 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++ ) { _EXP_TABLE * pExp = new _EXP_TABLE; memset( pExp, 0, sizeof(_EXP_TABLE) ); pRes->Read( pExp, sizeof(_EXP_TABLE) ); m_vExpList.push_back( pExp ); } KFileManager::Instance().DeleteStream( pRes ); } SExpDB* SExpDB::m_pThis = NULL; SExpDB & GetExpDB() { if( NULL == SExpDB::m_pThis ) SExpDB::m_pThis = new SExpDB; return *SExpDB::m_pThis; // static SExpDB Expdb; // return Expdb; } SSummonExpDB::SSummonExpDB() { Init(); } SSummonExpDB::~SSummonExpDB() { Destroy(); } __int64 SSummonExpDB::GetNeedExp( int nLevel, int nGrow_Type ) { if( m_vExpList.empty() ) return 0; int nRef = nLevel - 1; if( 0 < nLevel && nLevel <= (int)m_vExpList.size() ) { return m_vExpList[nRef]->exp_normal; // 2011.03.22 servantes } return 0; } __int64 SSummonExpDB::GetLevelByExp( __int64 nExp ) // 2011.03.10 servantes { if(nExp <= 0) return 0; if( m_vExpList.empty() ) return 0; // 2011.03.22 - servantres __int64 exp1 = 0; __int64 exp2 = 0; for(int x=0; x<(int)m_vExpList.size()-1; x++) { exp1 = m_vExpList[ x ]->exp_normal; exp2 = m_vExpList[ x+1 ]->exp_normal; if(exp1 <= nExp && exp2 > nExp) { return x; } } return -1; } void SSummonExpDB::Init() { Load(); } void SSummonExpDB::Destroy() { SAFE_DELETE_VECTOR( m_vExpList ); } void SSummonExpDB::Load() { KStream * pRes = KFileManager::Instance().CreateStreamFromResource( "db_SummonExp.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_EXP_TABLE) * 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_EXP_TABLE * pExp = new _SUMMON_EXP_TABLE; memset( pExp, 0, sizeof(_SUMMON_EXP_TABLE) ); pRes->Read( pExp, sizeof(_SUMMON_EXP_TABLE) ); m_vExpList.push_back( pExp ); } KFileManager::Instance().DeleteStream( pRes ); } SSummonExpDB & GetSummonExpDB() { static SSummonExpDB Expdb; return Expdb; }