#include "StdAfx.h" #include ".\dropmanager.h" CDropManager::CDropManager(void) { m_nScriptType = 0; m_dwCntKillMonster = 0; } CDropManager::~CDropManager(void) { ItemInfoParser::Instance()->Release(); ItemInfoParser::Instance()->DestroyInstance(); FormulaRatioParser::Instance()->Release(); FormulaRatioParser::Instance()->DestroyInstance(); NPCInfoParser::Instance()->Release(); NPCInfoParser::Instance()->DestroyInstance(); m_DropCore.Unload(); } vector CDropManager::GetProcessTitle() { vector vecTitle; CString strTemp; strTemp = "Á¾·ù"; vecTitle.push_back(strTemp); strTemp = "ÄÚµå"; vecTitle.push_back(strTemp); strTemp = "À̸§ ¶Ç´Â µ·¾×¼ö"; vecTitle.push_back(strTemp); strTemp = "µå¶ø·¹º§"; vecTitle.push_back(strTemp); strTemp = "ÀÎþƮ±Þ¼ö"; vecTitle.push_back(strTemp); strTemp = "·©Å©±Þ¼ö"; vecTitle.push_back(strTemp); strTemp = "µð¹ÙÀο©ºÎ"; vecTitle.push_back(strTemp); return vecTitle; } vector CDropManager::GetResultTitle() { vector vecTitle; CString strTemp; strTemp = "Á¾·ù"; vecTitle.push_back(strTemp); strTemp = "ÄÚµå"; vecTitle.push_back(strTemp); strTemp = "À̸§ ¶Ç´Â µ·¾×¼ö"; vecTitle.push_back(strTemp); strTemp = "µå¶ø·¹º§"; vecTitle.push_back(strTemp); //strTemp = "ÀÎþƮ±Þ¼ö"; //vecTitle.push_back(strTemp); //strTemp = "·©Å©±Þ¼ö"; //vecTitle.push_back(strTemp); //strTemp = "µð¹ÙÀο©ºÎ"; //vecTitle.push_back(strTemp); strTemp = "°³¼ö"; vecTitle.push_back(strTemp); strTemp = "µå¶øÈ®·ü"; vecTitle.push_back(strTemp); return vecTitle; } vector CDropManager::GetNameScriptType() { vector vecTitle; CString strTemp; strTemp = "ÇåÆÃ"; vecTitle.push_back(strTemp); strTemp = "¹Ì¼Ç"; vecTitle.push_back(strTemp); return vecTitle; } vector CDropManager::GetNameMonsterType() { vector vecTitle; CString strTemp; strTemp = "ÀϹÝ"; vecTitle.push_back(strTemp); strTemp = "Á¤¿¹"; vecTitle.push_back(strTemp); strTemp = "´ëÀå"; vecTitle.push_back(strTemp); strTemp = "Áߺ¸½º"; vecTitle.push_back(strTemp); strTemp = "º¸½º"; vecTitle.push_back(strTemp); return vecTitle; } //³ªÁß¿¡ ÀÌ ºÎºÐÀ» ÃʱâÈ­ ºÎºÐ¿¡¼­ ½ÇÇàÇϵµ·Ï Çϰí, //µû·Î ¼±Åÿɼǿ¡ µû¶ó µ¥ÀÌŸ¸¦ ó¸®Çϵµ·Ï ÄÚµùÇÒ°Í... BOOL CDropManager::Initialize() { BOOL bRet = FALSE; ItemInfoParser::Instance()->Init(100); bRet = ItemInfoParser::Instance()->Load( "data\\AccessoryItemInfo.txt" ); if(bRet == FALSE) { AfxMessageBox( "AccessroyItemInfo.txt Load Error" ); return FALSE; } bRet = ItemInfoParser::Instance()->Load( "data\\ArmorItemInfo.txt" ); if(bRet == FALSE) { AfxMessageBox( "ArmorItemInfo.txt Load Error" ); return FALSE; } bRet = ItemInfoParser::Instance()->Load( "data\\WeaponItemInfo.txt" ); if(bRet == FALSE) { AfxMessageBox( "WeaponItemInfo.txt Load Error" ); return FALSE; } bRet = ItemInfoParser::Instance()->Load( "data\\WasteItemInfo.txt" ); if(bRet == FALSE) { AfxMessageBox( "WasteItemInfo.txt Load Error" ); return FALSE; } NPCInfoParser::Instance()->Init( 300); NPCInfoParser::Instance()->Load( "data\\NPCInfo.txt" ); if(bRet == FALSE) { AfxMessageBox( "NPCInfo.txt Load Error" ); return FALSE; } FormulaRatioParser::Instance()->Init(10); bRet = FormulaRatioParser::Instance()->Load( "data\\FormulaRatio.txt" ); if(bRet == FALSE) { AfxMessageBox( "FormulaRatio.txt Load Error" ); return FALSE; } m_DropCore.Load( "data\\DropRatioInfo.txt", "data\\ItemTypeDropRatio.txt", "data\\ItemTypeList.txt" ); return TRUE; } BOOL CDropManager::DropItem( WORD wLowerLevel, WORD wUpperLevel, BYTE byGrade, DWORD dwNpcCount, BYTE byFieldType ) { MONSTER_LIST listMonster; GetMonster( wLowerLevel, wUpperLevel, byGrade, listMonster ); int nMonsterCnt = (int)listMonster.size(); if( nMonsterCnt <= 0 ) { AfxMessageBox("ÇØ´ç Á¶°ÇÀÇ ¸ó½ºÅͰ¡ ¾ø½À´Ï´Ù."); return FALSE; } //ÇѸó½ºÅÍ´ç Á×ÀÏ È½¼ö( Àüü Á×ÀÏ ¸ó½ºÅÍÀÇ ¼ö¿¡ ÇöÀç Á¶°ÇÀÇ ¸ó½ºÅͼö·Î ³ª´«´Ù.) DWORD dwKillCntPerMonster = dwNpcCount / nMonsterCnt; DWORD dwKillCntLast = dwNpcCount - ( dwKillCntPerMonster * nMonsterCnt ); FLOAT PlusBonusPercent = 1.0f; // (ÇåÆÃ:¹Ì¼Ç) ±¸ºÐ if( byFieldType == eZONETYPE_HUNTING ) PlusBonusPercent = 1.1f; MONEY DroppedMoney = 0; SCItemSlot DroppedItemSlot; eDROP_TYPE_ DroppedType; DWORD dwDecidedSeed = 0; //Initialize m_mapDropItem.clear(); m_vecItemCode.clear(); // ±âº» ¸ó½ºÅ͸¦ Á×ÀδÙ. for( DWORD dwMonster = 0; dwMonster < dwKillCntPerMonster; dwMonster++ ) { for( MONSTER_ITER iter = listMonster.begin() ; iter != listMonster.end(); iter++ ) { BASE_NPCINFO* pNPCInfo = *iter; if( !pNPCInfo ) continue; for( int i = 0 ; i < BASE_NPCINFO::MAX_DROPRATIO_INDEX_NUM ; ++i ) { DWORD dwDropIndex = pNPCInfo->m_dwDropIndex[i]; if( 0 == dwDropIndex ) continue; if( !m_DropCore.Drop( byFieldType, dwDropIndex, (eNPC_GRADE)pNPCInfo->m_byGrade, PlusBonusPercent, DroppedType, DroppedMoney, DroppedItemSlot, dwDecidedSeed ) ) continue; CDropItem item; DWORD dwCode = 0; if( DroppedType == DROP_TYPE_ITEM ) { dwCode = (DWORD)DroppedItemSlot.GetCode(); item.SetCode( dwCode ); item.SetName( DroppedItemSlot.GetItemInfo()->m_pszName ); item.SetDropLevel( (BYTE)DroppedItemSlot.GetDropLevel() ); item.SetRank( DroppedItemSlot.GetRank() ); item.SetEnchantLevel( (BYTE)DroppedItemSlot.GetEnchant() ); item.SetDivine( DroppedItemSlot.IsDivine() ); } else { MONEY money; DropMoney( DroppedMoney, money ); item.SetCode( dwCode ); item.SetName( "" ); item.SetDropLevel( 0 ); item.SetMoney( (DWORD)money ); item.SetRank( 0 ); item.SetEnchantLevel( 0 ); item.SetDivine( FALSE ); } item.SetDropType_( DroppedType ); m_mapDropItem.insert( make_pair( dwCode, item ) ); vector::iterator iterCode = find( m_vecItemCode.begin(), m_vecItemCode.end(), dwCode ); if( iterCode == m_vecItemCode.end() ) m_vecItemCode.push_back( dwCode ); } } } // ³ª¸ÓÁö ¸ó½ºÅ͸¦ Á×ÀδÙ.. ¹«Á¶°Ç 1¹ø ¸ó½ºÅÍ·Î ÇÑ´Ù. for( DWORD dwMonster = 0; dwMonster < dwKillCntLast; dwMonster++ ) { BASE_NPCINFO* pNPCInfo = *listMonster.begin(); if( !pNPCInfo ) continue; for( int i = 0 ; i < BASE_NPCINFO::MAX_DROPRATIO_INDEX_NUM ; ++i ) { DWORD dwDropIndex = pNPCInfo->m_dwDropIndex[i]; if( 0 == dwDropIndex ) continue; if( !m_DropCore.Drop( byFieldType, dwDropIndex, (eNPC_GRADE)pNPCInfo->m_byGrade, PlusBonusPercent, DroppedType, DroppedMoney, DroppedItemSlot, dwDecidedSeed ) ) continue; CDropItem item; DWORD dwCode = 0; if( DroppedType == DROP_TYPE_ITEM ) { dwCode = (DWORD)DroppedItemSlot.GetCode(); item.SetCode( dwCode ); item.SetName( DroppedItemSlot.GetItemInfo()->m_pszName ); item.SetDropLevel( (BYTE)DroppedItemSlot.GetDropLevel() ); item.SetRank( DroppedItemSlot.GetRank() ); item.SetEnchantLevel( (BYTE)DroppedItemSlot.GetEnchant() ); item.SetDivine( DroppedItemSlot.IsDivine() ); } else { MONEY money; DropMoney( DroppedMoney, money ); item.SetCode( dwCode ); item.SetName( "" ); item.SetDropLevel( 0 ); item.SetMoney( (DWORD)money ); item.SetRank( 0 ); item.SetEnchantLevel( 0 ); item.SetDivine( FALSE ); } item.SetDropType_( DroppedType ); m_mapDropItem.insert( make_pair( dwCode, item ) ); vector::iterator iterCode = find( m_vecItemCode.begin(), m_vecItemCode.end(), dwCode ); if( iterCode == m_vecItemCode.end() ) m_vecItemCode.push_back( dwCode ); } } return TRUE; } BOOL CDropManager::DropItemEx( DWORD dwNpcCode, DWORD dwNpcCount, BYTE byFieldType ) { BASE_NPCINFO* pNpcInfo = NPCInfoParser::Instance()->GetMonsterInfo( dwNpcCode ); if( !pNpcInfo ) return FALSE; FLOAT PlusBonusPercent = 1.0f; // (ÇåÆÃ:¹Ì¼Ç) ±¸ºÐ if( byFieldType == eZONETYPE_HUNTING ) PlusBonusPercent = 1.1f; MONEY DroppedMoney = 0; SCItemSlot DroppedItemSlot; eDROP_TYPE_ DroppedType; DWORD dwDecidedSeed = 0; //Initialize m_mapDropItem.clear(); m_vecItemCode.clear(); // ±âº» ¾ÆÀÌÅÛ µå¶ø for( DWORD dwMonster = 0; dwMonster < dwNpcCount; dwMonster++ ) { for( int i = 0 ; i < BASE_NPCINFO::MAX_DROPRATIO_INDEX_NUM ; ++i ) { DWORD dwDropIndex = pNpcInfo->m_dwDropIndex[i]; if( 0 == dwDropIndex ) continue; if( !m_DropCore.Drop( dwDropIndex, (eNPC_GRADE)pNpcInfo->m_byGrade, PlusBonusPercent, DroppedType, DroppedMoney, DroppedItemSlot, dwDecidedSeed ) ) continue; CDropItem item; DWORD dwCode = 0; if( DroppedType == DROP_TYPE_ITEM ) { dwCode = (DWORD)DroppedItemSlot.GetCode(); item.SetCode( dwCode ); item.SetName( DroppedItemSlot.GetItemInfo()->m_pszName ); item.SetDropLevel( (BYTE)DroppedItemSlot.GetDropLevel() ); item.SetRank( DroppedItemSlot.GetRank() ); item.SetEnchantLevel( (BYTE)DroppedItemSlot.GetEnchant() ); item.SetDivine( DroppedItemSlot.IsDivine() ); } else { MONEY money; DropMoney( DroppedMoney, money ); item.SetCode( dwCode ); item.SetName( "" ); item.SetDropLevel( 0 ); item.SetMoney( (DWORD)money ); item.SetRank( 0 ); item.SetEnchantLevel( 0 ); item.SetDivine( FALSE ); } item.SetDropType_( DroppedType ); m_mapDropItem.insert( make_pair( dwCode, item ) ); vector::iterator iterCode = find( m_vecItemCode.begin(), m_vecItemCode.end(), dwCode ); if( iterCode == m_vecItemCode.end() ) m_vecItemCode.push_back( dwCode ); } } return TRUE; } void CDropManager::SetScriptType(int nType) { m_nScriptType = nType; } int CDropManager::GetScriptType() { return m_nScriptType; } //¾ÆÀÌÅÛ µå·Ó °á°ú void CDropManager::CalcItemDropResult() { m_mapDropResult.clear(); //1. DropµÈ ¸ðµç Äڵ带 »Ì¾Æ³½´Ù. for( int i = 0; i < (int)m_vecItemCode.size(); i++ ) { DWORD dwCode = m_vecItemCode[i]; DWORD dwItemCnt = 0; DWORD dwSumMoney = 0; CDropItem item; DROPITEM_ITER iterPos; for( iterPos = m_mapDropItem.lower_bound( dwCode ) ; iterPos != m_mapDropItem.upper_bound( dwCode ) ; ++iterPos ) { item = iterPos->second; dwItemCnt++; dwSumMoney += item.GetMoney(); } if( dwItemCnt > 0 ) { CDropResult resultInfo; resultInfo.SetItem( item ); resultInfo.SetSumMoney( dwSumMoney ); resultInfo.SetItemCount( dwItemCnt ); if( m_dwCntKillMonster == 0 ) resultInfo.SetDropRate( 0.0f ); else resultInfo.SetDropRate( (float)( ((float)resultInfo.GetItemCount() / (float)m_dwCntKillMonster)*100 ) ); m_mapDropResult.insert( make_pair( dwCode, resultInfo ) ); } } } CString CDropManager::GetSaveDropInfo(int nViewOption) { int nSize = 0; CString strSave, str; if( nViewOption == 0 ) // °á°ú { for( DROPRESULT_ITER iter = m_mapDropResult.begin(); iter != m_mapDropResult.end() ; iter++ ) { CDropResult info = iter->second; // ¾ÆÀÌÅÛ Á¾·ù str = GetItemType( info.GetItem().GetDropType() ); strSave += str; strSave += "\t"; // ¾ÆÀÌÅÛ ÄÚµå str.Format("%d", (WORD)info.GetItem().GetCode() ); strSave += str; strSave += "\t"; // À̸§ if( info.GetItem().GetDropType() == DROP_MONEY_1 || info.GetItem().GetDropType() == DROP_MONEY_40 || info.GetItem().GetDropType() == DROP_MONEY_400 ) str.Format("%d", info.GetItem().GetMoney() ); else str.Format("%s", info.GetItem().GetName() ); strSave += str; strSave += "\t"; // µå¶ø·¹º§ str.Format("%d", (WORD)info.GetItem().GetDropLevel() ); strSave += str; strSave += "\t"; //ÀÎþƮ ±Þ¼ö str = GetEnchantLevel( (eENCHANTLEVEL)info.GetItem().GetEnchantLevel() ); strSave += str; strSave += "\t"; //·©Å© ±Þ¼ö str = GetRank( (eRANK)info.GetItem().GetRank() ); strSave += str; strSave += "\t"; //µð¹ÙÀÎ ¿©ºÎ if( info.GetItem().GetDivine() ) str = "Y"; else str = "N"; strSave += str; strSave += "\t"; //°³¼ö str.Format("%d", info.GetItemCount() ); strSave += str; strSave += "\t"; //È®·ü str.Format("%0.3f%%", info.GetDropRate() ); strSave += str; strSave += "\r\n"; } } else if( nViewOption == 1 ) // °úÁ¤ { for( DROPITEM_ITER iter = m_mapDropItem.begin(); iter != m_mapDropItem.end(); iter++ ) { CDropItem item = iter->second; // ¾ÆÀÌÅÛ Á¾·ù str = GetItemType( item.GetDropType() ); strSave += str; strSave += "\t"; // ¾ÆÀÌÅÛ ÄÚµå str.Format("%d", (WORD)item.GetCode() ); strSave += str; strSave += "\t"; // À̸§ if(item.GetDropType() == DROP_MONEY_1 || item.GetDropType() == DROP_MONEY_40 || item.GetDropType() == DROP_MONEY_400 ) str.Format("%d", item.GetMoney() ); else str.Format("%s", item.GetName().c_str() ); strSave += str; strSave += "\t"; // µå¶ø·¹º§ str.Format("%d", (WORD)item.GetDropLevel() ); strSave += str; strSave += "\t"; //ÀÎþƮ ±Þ¼ö str = GetEnchantLevel( (eENCHANTLEVEL)item.GetEnchantLevel() ); strSave += str; strSave += "\t"; //·©Å© ±Þ¼ö str = GetRank( (eRANK)item.GetRank() ); strSave += str; strSave += "\t"; //µð¹ÙÀÎ ¿©ºÎ if( item.GetDivine()) str = "Y"; else str = "N"; strSave += str; strSave += "\r\n"; } } return strSave; } CString CDropManager::GetItemType(eDROP_TYPE type) { CString str; if( type == DROP_MONEY_1 || type == DROP_MONEY_40 || type == DROP_MONEY_400 ) return "µ·"; else if( type == DROP_ITEM_0 || type == DROP_ITEM_1 || type == DROP_ITEM_2 || type == DROP_ITEM_3 || type == DROP_ITEM_4 || type == DROP_ITEM_5 || type == DROP_ITEM_6 || type == DROP_ITEM_7 || type == DROP_ITEM_8 || type == DROP_ITEM_9 || type == DROP_ITEM_10 ) { return "¾ÆÀÌÅÛ"; } else if( type == DROP_RARE_ITEM ) return "·¹¾î¾ÆÀÌÅÛ"; return "NONE"; } CString CDropManager::GetItemType(eDROP_TYPE_ type) { CString str; if( type == DROP_TYPE_MONEY ) return "µ·"; else if( type == DROP_TYPE_ITEM ) return "¾ÆÀÌÅÛ"; return "NONE"; } CString CDropManager::GetEnchantLevel(eENCHANTLEVEL level) { CString str = "¾øÀ½"; if( level == ENCHANT_LOW ) str = "ÇϱÞ"; else if( level == ENCHANT_MIDDLE ) str = "Áß±Þ"; else if( level == ENCHANT_HIGH ) str = "°í±Þ"; return str; } CString CDropManager::GetRank( eRANK rank ) { CString str = "NONE"; if( rank == RANK_F ) //·¹¾î¾ÆÀÌÅÛ½Ã.. str = "F"; else if( rank == RANK_E ) str = "E"; else if( rank == RANK_D ) str = "D"; else if( rank == RANK_C ) str = "C"; else if( rank == RANK_B ) str = "B"; else if( rank == RANK_MA ) str = "MA"; else if( rank == RANK_A ) str = "A"; else if( rank == RANK_PA ) str = "PA"; else if( rank == RANK_MS ) str = "MS"; else if( rank == RANK_S ) str = "S"; else if( rank == RANK_PS ) str = "PS"; return str; } VOID CDropManager::DropMoney( MONEY DroppedMoney, MONEY & TotalMoney ) { TotalMoney = 0; if( DroppedMoney >= 10000 ) //< 1¸¸ ÀÌ»óÀÇ ±Ý¾×ÀÏ ¶§ ÀèÆÌ { MONEY RemainMoney = DroppedMoney; MONEY CurMoney = 0; MONEY LastMoney = (MONEY)(DroppedMoney*0.06f); // µô·¹ÀÌ Á༭ ¶³¾î ¶ß¸² INT i = 0; while(1) { if( RemainMoney <= LastMoney) break; CurMoney = (MONEY)(DroppedMoney*random(3,5)/100); if( RemainMoney < CurMoney ) break; RemainMoney -= CurMoney; if( CurMoney != 0 ) TotalMoney += CurMoney; ++i; } if( RemainMoney != 0 ) TotalMoney += RemainMoney; } else TotalMoney = DroppedMoney; } void CDropManager::GetMonster( WORD wLowerLevel, WORD wUperLevel, BYTE byGrade, MONSTER_LIST& listMonster ) { NPCINFO_ITERATOR iterBegin = NPCInfoParser::Instance()->Begin(); NPCINFO_ITERATOR iterEnd = NPCInfoParser::Instance()->End(); NPCINFO_ITERATOR iter; for( iter = iterBegin; iter != iterEnd; ++iter ) { BASE_NPCINFO* pInfo = *iter; if( !pInfo || pInfo->m_byGrade >= eNPC_MERCHANT_NPC ) //µ¥ÀÌÅͰ¡ ¾ø°Å³ª, »óÀÎ ÀÌ»óÀ̸é.. ¹«½Ã. continue; if( pInfo->m_DisplayLevel >= wLowerLevel && pInfo->m_DisplayLevel <= wUperLevel && pInfo->m_byGrade == byGrade ) listMonster.push_back( pInfo ); } }