#include "gamesrv.h" #include "StdAfx.h" #include "levelscript.h" #include "./util/Tokenizer.h" cLevelScript* cLevelScript::mpLevelScript = NULL; cLevelScript::cLevelScript(void) { /// ½Ì±ÛÅæ if( mpLevelScript ) { #ifndef _CLIENT Verbose->WriteLog( "LevelScript new error"); #endif } else { mpLevelScript = this; } mMaxLevel = 0; mMaxSkill = 0; } cLevelScript::~cLevelScript(void) { } bool cLevelScript::Init() { mpExpTableMap = new cHashMap( 100 ); mpSxpTableMap = new cHashMap( 100 ); bool check = true; /// °æÇèÄ¡ Å×ÀÌºí ·Îµå if( !LoadExpTable() ) { #ifndef _CLIENT Verbose->WriteLog("ASSERT-070515-LoadExpTable ERROR"); #endif assert(NULL); MessageBox(NULL,_T("LoadExpTable ERROR"),_T("ERROR"),MB_OK); check = false; } /// ½ºÅ³°æÇèÄ¡ Å×ÀÌºí ·Îµå if( !LoadSxpTable() ) { #ifndef _CLIENT Verbose->WriteLog("ASSERT-070515-LoadSxpTable ERROR"); #endif assert(NULL); MessageBox(NULL,_T("LoadSxpTable ERROR"),_T("ERROR"),MB_OK); check = false; } return check; } void cLevelScript::Release() { if( mpExpTableMap ) { sExpTable* pInfo = NULL; cHashMap::cIterator i = mpExpTableMap->Begin(); cHashMap::cIterator end = mpExpTableMap->End(); for( ; i != end; ++i ) { pInfo = (sExpTable*)((*i).mSecond); if( pInfo ) { delete pInfo; } } mpExpTableMap->Clear(); SAFE_DELETE( mpExpTableMap ); } if( mpSxpTableMap ) { sSxpTable* pInfo = NULL; cHashMap::cIterator i = mpSxpTableMap->Begin(); cHashMap::cIterator end = mpSxpTableMap->End(); for( ; i != end; ++i ) { pInfo = (sSxpTable*)((*i).mSecond); if( pInfo ) { delete pInfo; } } mpSxpTableMap->Clear(); SAFE_DELETE( mpSxpTableMap ); } } bool cLevelScript::LoadExpTable() { cFileLoader loader; cString pathName = "./Script/Resource/ExpTable.txt"; if( loader.Open( pathName, true ) == false ) { assert( 0 && "failed to load ExpTable.txt" ); cString msg; msg.Format("[%s]", pathName.Cstr() ); MessageBoxA( NULL, msg.Cstr(), "fail to open file", MB_OK | MB_ICONERROR ); return false; } cTokenizer tokenizer( loader.GetBufferPtr(), loader.GetSize(), " \t\r\n", pathName.Cstr() ); cString str; sExpTable* pList = NULL, *pExp2 = NULL; while( tokenizer.IsEnd() == false ) { pList = new sExpTable; /// ·¹º§ if( tokenizer.GetNext( &str ) == false ) { goto ERR; } pList->mLevel = (unsigned char)str.ToInt(); /// ÃÖ´ë ·¹º§ ±â·Ï if( mMaxLevel < pList->mLevel ) mMaxLevel = pList->mLevel; /// °æÇèÄ¡ if( tokenizer.GetNext( &str ) == false ) { goto ERR; } pList->mExp = str.ToInt(); /// ´©Àû °æÇèÄ¡ if( pList->mLevel - 1 == 0 ) { pList->mAccumulationExp = pList->mExp; } else { pExp2 = GetExpTable( pList->mLevel - 1 ); pList->mAccumulationExp = pList->mExp + pExp2->mExp; } /// º¸°ü¼Ò ÀúÀå if( mpExpTableMap->Insert( pList->mLevel, pList ) == false ) { assert(0); goto ERR; } } return true; ERR: delete pList; cString msg; msg.Format("[%s] [Line:%d]", pathName.Cstr(), tokenizer.mLine ); MessageBoxA( NULL, msg.Cstr(), "fail to parse", MB_OK | MB_ICONERROR ); return false; } sExpTable* cLevelScript::GetExpTable( unsigned char level ) { sExpTable* pExpTable; pExpTable = (sExpTable*)mpExpTableMap->GetAt( level ); if( !pExpTable ) return NULL; return pExpTable; } bool cLevelScript::LoadSxpTable() { cFileLoader loader; cString pathName = "./Script/Resource/SxpTable.txt"; if( loader.Open( pathName, true ) == false ) { assert( 0 && "failed to load SxpTable.txt" ); cString msg; msg.Format("[%s]", pathName.Cstr() ); MessageBoxA( NULL, msg.Cstr(), "fail to open file", MB_OK | MB_ICONERROR ); return false; } cTokenizer tokenizer( loader.GetBufferPtr(), loader.GetSize(), " \t\r\n", pathName.Cstr() ); cString str; sSxpTable* pList = NULL, *pSxp2 = NULL; while( tokenizer.IsEnd() == false ) { pList = new sSxpTable; /// ·¹º§ if( tokenizer.GetNext( &str ) == false ) { goto ERR; } pList->mLevel = (unsigned char)str.ToInt(); /// ÃÖ´ë ·¹º§ ±â·Ï if( mMaxSkill < pList->mLevel ) mMaxSkill = pList->mLevel; /// ½ºÅ³ if( tokenizer.GetNext( &str ) == false ) { goto ERR; } pList->mSxp = str.ToInt(); /// ´©Àû °æÇèÄ¡ if( pList->mLevel - 1 == 0 ) { pList->mAccumulationSxp = pList->mSxp; } else { pSxp2 = GetSxpTable( pList->mLevel - 1 ); pList->mAccumulationSxp = pList->mSxp + pSxp2->mSxp; } /// º¸°ü¼Ò ÀúÀå if( mpSxpTableMap->Insert( pList->mLevel, pList ) == false ) { assert(0); goto ERR; } } return true; ERR: delete pList; cString msg; msg.Format("[%s] [Line:%d]", pathName.Cstr(), tokenizer.mLine ); MessageBoxA( NULL, msg.Cstr(), "fail to parse", MB_OK | MB_ICONERROR ); return false; } sSxpTable* cLevelScript::GetSxpTable( unsigned char level ) { sSxpTable* pSxpTable; pSxpTable = (sSxpTable*)mpSxpTableMap->GetAt( level ); if( !pSxpTable ) return NULL; return pSxpTable; }