#include "stdafx.h" #include "../eterPack/EterPackManager.h" #include "pythonnonplayer.h" #include "InstanceBase.h" #include "PythonCharacterManager.h" #ifdef ENABLE_WIKI #include "PythonWiki.h" #endif bool CPythonNonPlayer::LoadNonPlayerData(const char * c_szFileName) { static DWORD s_adwMobProtoKey[4] = { 4813894, 18955, 552631, 6822045 }; CMappedFile file; LPCVOID pvData; Tracef("CPythonNonPlayer::LoadNonPlayerData: %s, sizeof(TMobTable)=%u\n", c_szFileName, sizeof(TMobTable)); if (!CEterPackManager::Instance().Get(file, c_szFileName, &pvData)) return false; DWORD dwFourCC, dwElements, dwDataSize; file.Read(&dwFourCC, sizeof(DWORD)); if (dwFourCC != MAKEFOURCC('M', 'M', 'P', 'T')) { TraceError("CPythonNonPlayer::LoadNonPlayerData: invalid Mob proto type %s", c_szFileName); return false; } file.Read(&dwElements, sizeof(DWORD)); file.Read(&dwDataSize, sizeof(DWORD)); BYTE * pbData = new BYTE[dwDataSize]; file.Read(pbData, dwDataSize); ///// CLZObject zObj; if (!CLZO::Instance().Decompress(zObj, pbData, s_adwMobProtoKey)) { delete [] pbData; return false; } DWORD structSize = zObj.GetSize() / dwElements; DWORD structDiff = zObj.GetSize() % dwElements; #ifdef ENABLE_PROTOSTRUCT_AUTODETECT if (structDiff!=0 && !CPythonNonPlayer::TMobTableAll::IsValidStruct(structSize)) #else if ((zObj.GetSize() % sizeof(TMobTable)) != 0) #endif { TraceError("CPythonNonPlayer::LoadNonPlayerData: invalid size %u check data format. structSize %u, structDiff %u", zObj.GetSize(), structSize, structDiff); return false; } for (DWORD i = 0; i < dwElements; ++i) { #ifdef ENABLE_PROTOSTRUCT_AUTODETECT CPythonNonPlayer::TMobTable t = {0}; CPythonNonPlayer::TMobTableAll::Process(zObj.GetBuffer(), structSize, i, t); #else CPythonNonPlayer::TMobTable & t = *((CPythonNonPlayer::TMobTable *) zObj.GetBuffer() + i); #endif TMobTable * pTable = &t; TMobTable * pNonPlayerData = new TMobTable; memcpy(pNonPlayerData, pTable, sizeof(TMobTable)); #ifdef ENABLE_WIKI CPythonWiki::Instance().LoadMonster(pNonPlayerData); #endif //TraceError("%d : %s type[%d] color[%d]", pNonPlayerData->dwVnum, pNonPlayerData->szLocaleName, pNonPlayerData->bType, pNonPlayerData->dwMonsterColor); m_NonPlayerDataMap.insert(TNonPlayerDataMap::value_type(pNonPlayerData->dwVnum, pNonPlayerData)); } #ifdef ENABLE_WIKI CPythonWiki::Instance().ListReverse(); #endif delete [] pbData; return true; } bool CPythonNonPlayer::GetName(DWORD dwVnum, const char ** c_pszName) { const TMobTable * p = GetTable(dwVnum); if (!p) return false; *c_pszName = p->szLocaleName; return true; } bool CPythonNonPlayer::GetInstanceType(DWORD dwVnum, BYTE* pbType) { const TMobTable * p = GetTable(dwVnum); // dwVnum를 찾을 수 없으면 플레이어 캐릭터로 간주 한다. 문제성 코드 -_- [cronan] if (!p) return false; *pbType=p->bType; return true; } const CPythonNonPlayer::TMobTable * CPythonNonPlayer::GetTable(DWORD dwVnum) { TNonPlayerDataMap::iterator itor = m_NonPlayerDataMap.find(dwVnum); if (itor == m_NonPlayerDataMap.end()) return NULL; return itor->second; } BYTE CPythonNonPlayer::GetEventType(DWORD dwVnum) { const TMobTable * p = GetTable(dwVnum); if (!p) { //Tracef("CPythonNonPlayer::GetEventType - Failed to find virtual number\n"); return ON_CLICK_EVENT_NONE; } return p->bOnClickType; } #if defined(WJ_SHOW_MOB_INFO) && defined(ENABLE_SHOW_MOBLEVEL) && !defined(ENABLE_SEND_TARGET_INFO) DWORD CPythonNonPlayer::GetMonsterLevel(DWORD dwVnum) { const CPythonNonPlayer::TMobTable * c_pTable = GetTable(dwVnum); if (!c_pTable) return 0; return c_pTable->bLevel; } #endif #if defined(WJ_SHOW_MOB_INFO) && defined(ENABLE_SHOW_MOBAIFLAG) bool CPythonNonPlayer::IsAggressive(DWORD dwVnum) { const CPythonNonPlayer::TMobTable * c_pTable = GetTable(dwVnum); if (!c_pTable) return 0; return (IS_SET(c_pTable->dwAIFlag, AIFLAG_AGGRESSIVE)); } #endif BYTE CPythonNonPlayer::GetEventTypeByVID(DWORD dwVID) { CInstanceBase * pInstance = CPythonCharacterManager::Instance().GetInstancePtr(dwVID); if (NULL == pInstance) { //Tracef("CPythonNonPlayer::GetEventTypeByVID - There is no Virtual Number\n"); return ON_CLICK_EVENT_NONE; } WORD dwVnum = pInstance->GetVirtualNumber(); return GetEventType(dwVnum); } const char* CPythonNonPlayer::GetMonsterName(DWORD dwVnum) { const CPythonNonPlayer::TMobTable * c_pTable = GetTable(dwVnum); if (!c_pTable) { static const char* sc_szEmpty=""; return sc_szEmpty; } return c_pTable->szLocaleName; } DWORD CPythonNonPlayer::GetMonsterColor(DWORD dwVnum) { const CPythonNonPlayer::TMobTable * c_pTable = GetTable(dwVnum); if (!c_pTable) return 0; return c_pTable->dwMonsterColor; } #ifdef ENABLE_SEND_TARGET_INFO DWORD CPythonNonPlayer::GetMonsterMaxHP(DWORD dwVnum) { const CPythonNonPlayer::TMobTable * c_pTable = GetTable(dwVnum); if (!c_pTable) { DWORD dwMaxHP = 0; return dwMaxHP; } return c_pTable->dwMaxHP; } DWORD CPythonNonPlayer::GetMonsterRaceFlag(DWORD dwVnum) { const CPythonNonPlayer::TMobTable * c_pTable = GetTable(dwVnum); if (!c_pTable) { DWORD dwRaceFlag = 0; return dwRaceFlag; } return c_pTable->dwRaceFlag; } DWORD CPythonNonPlayer::GetMonsterLevel(DWORD dwVnum) { const CPythonNonPlayer::TMobTable * c_pTable = GetTable(dwVnum); if (!c_pTable) { DWORD level = 0; return level; } return c_pTable->bLevel; } DWORD CPythonNonPlayer::GetMonsterDamage1(DWORD dwVnum) { const CPythonNonPlayer::TMobTable * c_pTable = GetTable(dwVnum); if (!c_pTable) { DWORD range = 0; return range; } return c_pTable->dwDamageRange[0]; } DWORD CPythonNonPlayer::GetMonsterDamage2(DWORD dwVnum) { const CPythonNonPlayer::TMobTable * c_pTable = GetTable(dwVnum); if (!c_pTable) { DWORD range = 0; return range; } return c_pTable->dwDamageRange[1]; } DWORD CPythonNonPlayer::GetMonsterExp(DWORD dwVnum) { const CPythonNonPlayer::TMobTable * c_pTable = GetTable(dwVnum); if (!c_pTable) { DWORD dwExp = 0; return dwExp; } return c_pTable->dwExp; } float CPythonNonPlayer::GetMonsterDamageMultiply(DWORD dwVnum) { const CPythonNonPlayer::TMobTable * c_pTable = GetTable(dwVnum); if (!c_pTable) { DWORD fDamMultiply = 0; return fDamMultiply; } return c_pTable->fDamMultiply; } DWORD CPythonNonPlayer::GetMonsterST(DWORD dwVnum) { const CPythonNonPlayer::TMobTable * c_pTable = GetTable(dwVnum); if (!c_pTable) { DWORD bStr = 0; return bStr; } return c_pTable->bStr; } DWORD CPythonNonPlayer::GetMonsterDX(DWORD dwVnum) { const CPythonNonPlayer::TMobTable * c_pTable = GetTable(dwVnum); if (!c_pTable) { DWORD bDex = 0; return bDex; } return c_pTable->bDex; } bool CPythonNonPlayer::IsMonsterStone(DWORD dwVnum) { const CPythonNonPlayer::TMobTable * c_pTable = GetTable(dwVnum); if (!c_pTable) { return 0; } return c_pTable->bType == 2; } #endif BYTE CPythonNonPlayer::GetMobRegenCycle(DWORD dwVnum) { const CPythonNonPlayer::TMobTable* c_pTable = GetTable(dwVnum); if (!c_pTable) return 0; return c_pTable->bRegenCycle; } BYTE CPythonNonPlayer::GetMobRegenPercent(DWORD dwVnum) { const CPythonNonPlayer::TMobTable* c_pTable = GetTable(dwVnum); if (!c_pTable) return 0; return c_pTable->bRegenPercent; } DWORD CPythonNonPlayer::GetMobGoldMin(DWORD dwVnum) { const CPythonNonPlayer::TMobTable* c_pTable = GetTable(dwVnum); if (!c_pTable) return 0; return c_pTable->dwGoldMin; } DWORD CPythonNonPlayer::GetMobGoldMax(DWORD dwVnum) { const CPythonNonPlayer::TMobTable* c_pTable = GetTable(dwVnum); if (!c_pTable) return 0; return c_pTable->dwGoldMax; } DWORD CPythonNonPlayer::GetMobResist(DWORD dwVnum, BYTE bResistNum) { const CPythonNonPlayer::TMobTable* c_pTable = GetTable(dwVnum); if (!c_pTable) return 0; if (bResistNum >= MOB_RESISTS_MAX_NUM) return 0; return c_pTable->cResists[bResistNum]; } void CPythonNonPlayer::GetMatchableMobList(int iLevel, int iInterval, TMobTableList * pMobTableList) { /* pMobTableList->clear(); TNonPlayerDataMap::iterator itor = m_NonPlayerDataMap.begin(); for (; itor != m_NonPlayerDataMap.end(); ++itor) { TMobTable * pMobTable = itor->second; int iLowerLevelLimit = iLevel-iInterval; int iUpperLevelLimit = iLevel+iInterval; if ((pMobTable->abLevelRange[0] >= iLowerLevelLimit && pMobTable->abLevelRange[0] <= iUpperLevelLimit) || (pMobTable->abLevelRange[1] >= iLowerLevelLimit && pMobTable->abLevelRange[1] <= iUpperLevelLimit)) { pMobTableList->push_back(pMobTable); } } */ } void CPythonNonPlayer::Clear() { } #ifdef ENABLE_MOB_SCALE_SYSTEM bool CPythonNonPlayer::LoadMobScale(const char * c_szFileName) { const VOID* pvData; CMappedFile kFile; if (!CEterPackManager::Instance().Get(kFile, c_szFileName, &pvData)) return false; CMemoryTextFileLoader kTextFileLoader; kTextFileLoader.Bind(kFile.Size(), pvData); CTokenVector kTokenVector; for (DWORD i = 0; i < kTextFileLoader.GetLineCount(); ++i) { if (!kTextFileLoader.SplitLineByTab(i, &kTokenVector)) continue; if (kTokenVector.size() < 4) { TraceError("LoadMobScale: invalid line %d (%s).", i, c_szFileName); continue; } DWORD dwMobNum = atoi(kTokenVector[MOBSCALETABLE_MOB_NUM].c_str()); float fx = atof(kTokenVector[MOBSCALETABLE_X].c_str()); float fy = atof(kTokenVector[MOBSCALETABLE_Y].c_str()); float fz = atof(kTokenVector[MOBSCALETABLE_Z].c_str()); TMobScaleTable * pMobScale = new TMobScaleTable; pMobScale->dwMobNum = dwMobNum; pMobScale->fx = fx; pMobScale->fy = fy; pMobScale->fz = fz; m_NonMobScaleDataMap.insert(TNonMobScaleDataMap::value_type(dwMobNum, pMobScale)); } return true; } const CPythonNonPlayer::TMobScaleTable * CPythonNonPlayer::GetScaleTable(DWORD dwVnum) { TNonMobScaleDataMap::iterator itor = m_NonMobScaleDataMap.find(dwVnum); if (itor == m_NonMobScaleDataMap.end()) return NULL; return itor->second; } bool CPythonNonPlayer::GetScale(DWORD dwVnum, float & fx, float & fy, float & fz) { const CPythonNonPlayer::TMobScaleTable * c_pTable = GetScaleTable(dwVnum); if (!c_pTable) { fx = 1.0f; fy = 1.0f; fz = 1.0f; } else { fx = c_pTable->fx; fy = c_pTable->fy; fz = c_pTable->fz; } return true; } #endif void CPythonNonPlayer::Destroy() { for (TNonPlayerDataMap::iterator itor=m_NonPlayerDataMap.begin(); itor!=m_NonPlayerDataMap.end(); ++itor) { delete itor->second; } m_NonPlayerDataMap.clear(); } CPythonNonPlayer::CPythonNonPlayer() { Clear(); } CPythonNonPlayer::~CPythonNonPlayer(void) { Destroy(); } #ifdef ENABLE_WIKI DWORD CPythonNonPlayer::GetMonsterPrice1(DWORD dwVnum) { const CPythonNonPlayer::TMobTable* c_pTable = GetTable(dwVnum); if (!c_pTable) return 0; return c_pTable->dwGoldMin; } DWORD CPythonNonPlayer::GetMonsterPrice2(DWORD dwVnum) { const CPythonNonPlayer::TMobTable* c_pTable = GetTable(dwVnum); if (!c_pTable) return 0; return c_pTable->dwGoldMax; } char CPythonNonPlayer::GetMonsterResist(DWORD dwVnum, BYTE byResist) { if (byResist >= MOB_RESISTS_MAX_NUM) return 0; const CPythonNonPlayer::TMobTable* c_pTable = GetTable(dwVnum); if (!c_pTable) return 0; return c_pTable->cResists[byResist]; } #endif #ifdef ENABLE_NPC_WEAR_ITEM #include "PythonBackground.h" bool CPythonNonPlayer::LoadNPCWear(const char* szNPCWearFile) { m_mapnpcWear.clear(); CMappedFile File; LPCVOID pData; if (!CEterPackManager::Instance().Get(File, szNPCWearFile, &pData)) return false; CMemoryTextFileLoader textFileLoader; textFileLoader.Bind(File.Size(), pData); CTokenVector TokenVector; for (DWORD i = 0; i < textFileLoader.GetLineCount(); ++i) { if (!textFileLoader.SplitLine(i, &TokenVector, "\t")) continue; else if (TokenVector.size() != NPC_WEAR_MAX+2) continue; const DWORD npcVnum = atoi(TokenVector[0].c_str()); std::vector m_vec; m_vec.resize(NPC_WEAR_MAX); for (BYTE i = 0; i < NPC_WEAR_MAX; ++i) m_vec[i] = atoi(TokenVector[i+2].c_str()); if (m_vec[NPC_WEAR_RACE] > 7) continue; auto it = m_mapnpcWear.find(TokenVector[1].c_str()); if (it != m_mapnpcWear.end()) it->second.emplace(npcVnum, m_vec); else { std::map> m_map; m_map.emplace(npcVnum, m_vec); m_mapnpcWear.emplace(TokenVector[1].c_str(), m_map); } } return true; } int CPythonNonPlayer::GetNPCWear(const int raceIndex, const BYTE wearIndex) { if (wearIndex >= NPC_WEAR_MAX) return -1; CPythonBackground& rkBG = CPythonBackground::Instance(); const auto itSpecial = m_mapnpcWear.find(rkBG.GetWarpMapName()); if (itSpecial != m_mapnpcWear.end()) { auto itEx = itSpecial->second.find(raceIndex); if (itEx != itSpecial->second.end()) return itEx->second[wearIndex]; } const auto itAll = m_mapnpcWear.find("all"); if (itAll != m_mapnpcWear.end()) { auto itEx = itAll->second.find(raceIndex); if (itEx != itAll->second.end()) return itEx->second[wearIndex]; } return -1; } #endif