#include "gamesrv.h" #include "StdAfx.h" #include "PvPScript.h" #include "./util/Tokenizer.h" cPvPScript* cPvPScript::mpPvPScript = NULL; bool PvPTimeSort( const void *arg1, const void *arg2 ) { sPvPStartTime* left = (sPvPStartTime*)arg1; sPvPStartTime* right = (sPvPStartTime*)arg2; return left->mHour * 100 + left->mMinute < right->mHour * 100 + right->mMinute; } cPvPScript::cPvPScript() { /// ½Ì±ÛÅæ if( !mpPvPScript ) { mpPvPScript = this; } } cPvPScript::~cPvPScript() { Release(); } bool cPvPScript::Init() { Release(); if( LoadDMInfo() == false ) return false; if( LoadMemberGive() == false ) return false; #ifndef _CLIENT switch( NETWORK2->GetServerType() ) { case _E_ST_ID_PVP_: { if( LoadTime( NETWORK2->GetInDunMapNum() ) == false ) return false; } break; } #endif return true; } void cPvPScript::Release() { /// cHashMap::cIterator i = mDMInfoMap.Begin(); cHashMap::cIterator iend = mDMInfoMap.End(); for( ; i!=iend; i++ ) { delete (sDMInfo*)(*i).mSecond; } mDMInfoMap.Clear(); } bool cPvPScript::LoadDMInfo() { cFileLoader loader; cString pathName = "./script/resource/pvp_map.txt"; if( loader.Open( pathName, true ) == false ) { assert( 0 && "failed to load pvp_map.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; sDMInfo* pDMInfo = 0; while( tokenizer.IsEnd() == false ) { pDMInfo = new sDMInfo; // ÀüÀå Á¾·ù if( tokenizer.GetNext( &str ) == false ) { goto ERR; } pDMInfo->mType = static_cast(str.ToInt()); /// ÀÔÀåÁÖ±â if( tokenizer.GetNext( &str ) == false ) { goto ERR; } pDMInfo->mTotalDMTime = static_cast(str.ToInt()); /// Áø¿µÃÖ¼ÒÀοø if( tokenizer.GetNext( &str ) == false ) { goto ERR; } pDMInfo->mTeamPlayerMin = static_cast(str.ToInt()); /// Áø¿µÃÖ´ëÀοø if( tokenizer.GetNext( &str ) == false ) { goto ERR; } pDMInfo->mTeamPlayerMax = static_cast(str.ToInt()); /// ·¹º§ ±¸°£º° ¸®½ºÆ® pDMInfo->mLevelBlockInfo.Clear(); tokenizer.GetNext( &str ); if( str != "{" ) goto ERR; while( tokenizer.IsEnd() == false ) { tokenizer.GetNext( &str ); if( str == "}" ) break; sDMBlockInfo* pBlockInfo = new sDMBlockInfo; /// ÃÖ¼Ò·¹º§ //if( tokenizer.GetNext( &str ) == false ) { goto ERR; } pBlockInfo->mLevelMin = static_cast(str.ToInt()); /// ÃÖ´ë·¹º§ if( tokenizer.GetNext( &str ) == false ) { goto ERR; } pBlockInfo->mLevelMax = static_cast(str.ToInt()); /// ¸ñÇ¥ Æ÷ÀÎÆ® if( tokenizer.GetNext( &str ) == false ) { goto ERR; } pBlockInfo->mGoalPoint = static_cast(str.ToInt()); /// ÆÐ¹è½Ã ÀüÀåÆ÷ÀÎÆ® º¸»ó±âÁØ if( tokenizer.GetNext( &str ) == false ) { goto ERR; } pBlockInfo->mLoseDMBasePoint = static_cast(str.ToInt()); /// ÆÐ¹è½Ã Ä£¹Ðµµ º¸»ó±âÁØ if( tokenizer.GetNext( &str ) == false ) { goto ERR; } pBlockInfo->mLoseFriendlyBasePoint = static_cast(str.ToInt()); pDMInfo->mLevelBlockInfo.PushBack( pBlockInfo ); } if( mDMInfoMap.Insert( pDMInfo->mType, pDMInfo ) == false ) { assert(0); goto ERR; } } return true; ERR: SAFE_DELETE(pDMInfo); cString msg; msg.Format("[%s] [Line:%d]", pathName.Cstr(), tokenizer.mLine ); MessageBoxA( NULL, msg.Cstr(), "fail to parse", MB_OK | MB_ICONERROR ); return false; } bool cPvPScript::LoadMemberGive() { cFileLoader loader; cString pathName = "./Script/resource/pvp_character.txt"; if( loader.Open( pathName, true ) == false ) { assert( 0 && "failed to load pvp_character.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; sDMGiveInfo* giveInfo = 0; while( tokenizer.IsEnd() == false ) { giveInfo = new sDMGiveInfo; // ÀüÀå Type if( tokenizer.GetNext( &str ) == false ) { goto ERR; } unsigned char type = static_cast(str.ToInt()); // ij¸¯ÅÍ ·¹º§ if( tokenizer.GetNext( &str ) == false ) { goto ERR; } giveInfo->mLevel = static_cast(str.ToInt()); // µ· º¸»ó-½Â¸® if( tokenizer.GetNext( &str ) == false ) { goto ERR; } giveInfo->mWinMoney = str.ToInt(); // µ· º¸»ó-ÆÐ¹è if( tokenizer.GetNext( &str ) == false ) { goto ERR; } giveInfo->mLoseMoney = str.ToInt(); // EXP º¸»ó-½Â¸®(%) if( tokenizer.GetNext( &str ) == false ) { goto ERR; } giveInfo->mWinExpPer = str.ToFloat(); if( giveInfo->mWinExpPer < 0.0f ) { goto ERR; } // EXP º¸»ó-ÆÐ¹è(%) if( tokenizer.GetNext( &str ) == false ) { goto ERR; } giveInfo->mLoseExpPer = str.ToFloat(); if( giveInfo->mLoseExpPer < 0.0f ) { goto ERR; } // SXP º¸»ó-½Â¸®(%) if( tokenizer.GetNext( &str ) == false ) { goto ERR; } giveInfo->mWinSxpPer = str.ToFloat(); if( giveInfo->mWinSxpPer < 0.0f ) { goto ERR; } // SXP º¸»ó-ÆÐ¹è(%) if( tokenizer.GetNext( &str ) == false ) { goto ERR; } giveInfo->mLoseSxpPer = str.ToFloat(); if( giveInfo->mLoseSxpPer < 0.0f ) { goto ERR; } // kill-ÀÏ¹Ý if( tokenizer.GetNext( &str ) == false ) { goto ERR; } giveInfo->mKillPoint = str.ToInt(); // kill-¼öÀå if( tokenizer.GetNext( &str ) == false ) { goto ERR; } giveInfo->mLeaderKillPoint = str.ToInt(); // Àڱ⼼·ÂÆ÷ÀÎÆ®-½Â¸® if( tokenizer.GetNext( &str ) == false ) { goto ERR; } giveInfo->mWinMyForcePoint = str.ToInt(); // Àڱ⼼·ÂÄ£¹Ðµµ-½Â¸® if( tokenizer.GetNext( &str ) == false ) { goto ERR; } giveInfo->mWinMyForceFriendly = str.ToInt(); // Àڱ⼼·ÂÆ÷ÀÎÆ®-ÆÐ¹è if( tokenizer.GetNext( &str ) == false ) { goto ERR; } giveInfo->mLoseMyForcePoint = str.ToInt(); // Àڱ⼼·ÂÄ£¹Ðµµ-ÆÐ¹è if( tokenizer.GetNext( &str ) == false ) { goto ERR; } giveInfo->mLoseMyForceFriendly = str.ToInt(); // µ¿¸Í¼¼·ÂÆ÷ÀÎÆ®-½Â¸® if( tokenizer.GetNext( &str ) == false ) { goto ERR; } giveInfo->mWinFamilyForcePoint = str.ToInt(); // µ¿¸Í¼¼·ÂÄ£¹Ðµµ-½Â¸® if( tokenizer.GetNext( &str ) == false ) { goto ERR; } giveInfo->mWinFamilyForceFriendly = str.ToInt(); /// ¸ñ·Ï¿¡ ´ã´Â´Ù. sDMInfo* pDMInfo = GetDmInfo( type ); if( pDMInfo ) { if( pDMInfo->mGiveInfo.Insert( giveInfo->mLevel, giveInfo ) == false ) { assert(0); goto ERR; } } else { assert(0); goto ERR; } } return true; ERR: SAFE_DELETE( giveInfo ); cString msg; msg.Format("[%s] [Line:%d]", pathName.Cstr(), tokenizer.mLine ); MessageBoxA( NULL, msg.Cstr(), "fail to parse", MB_OK | MB_ICONERROR ); return false; } sDMInfo* cPvPScript::GetDmInfo( unsigned int type ) { return (sDMInfo*)mDMInfoMap.GetAt( type ); } bool cPvPScript::LoadTime( unsigned short pvpType ) { cFileLoader loader; cString pathName = "./Script/resource/pvp_time.txt"; if( loader.Open( pathName, true ) == false ) { assert( 0 && "failed to load pvp_time.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; sPvPStartTime* pStartTime = NULL; while( tokenizer.IsEnd() == false ) { // ÀüÀå Type if( tokenizer.GetNext( &str ) == false ) { goto ERR; } unsigned short type = (unsigned short)str.ToInt(); if( pvpType != type ) { tokenizer.GetNext( &str ); tokenizer.GetNext( &str ); continue; } pStartTime = new sPvPStartTime; /// ½ÃÀÛ ½Ã if( tokenizer.GetNext( &str ) == false ) { goto ERR; } pStartTime->mHour = (unsigned char)str.ToInt(); /// ½ÃÀÛ ºÐ if( tokenizer.GetNext( &str ) == false ) { goto ERR; } pStartTime->mMinute = (unsigned char)str.ToInt(); mPvPStarttimeAry.PushBack( pStartTime ); } std::sort( mPvPStarttimeAry.Begin(), mPvPStarttimeAry.End(), PvPTimeSort ); return true; ERR: SAFE_DELETE( pStartTime ); cString msg; msg.Format("[%s] [Line:%d]", pathName.Cstr(), tokenizer.mLine ); MessageBoxA( NULL, msg.Cstr(), "fail to parse", MB_OK | MB_ICONERROR ); return false; }