bool CShopManager::Initialize(TShopTable * table, int size) { if (!m_map_pkShop.empty()) return false; int i; for (i = 0; i < size; ++i, ++table) { LPSHOP shop = M2_NEW CShop; if (!shop->Create(table->dwVnum, table->dwNPCVnum, table->items)) { M2_DELETE(shop); continue; } m_map_pkShop.insert(TShopMap::value_type(table->dwVnum, shop)); m_map_pkShopByNPCVnum.insert(TShopMap::value_type(table->dwNPCVnum, shop)); } char szShopTableExFileName[256]; snprintf(szShopTableExFileName, sizeof(szShopTableExFileName), "%s/shop_table_ex.txt", LocaleService_GetBasePath().c_str()); return ReadShopTableEx(szShopTableExFileName); }
// // C functions // const char* GetSungziMapPath() { static char s_szMapPath[128]; snprintf(s_szMapPath, sizeof(s_szMapPath), "%s/map/%s/", LocaleService_GetBasePath().c_str(), CThreeWayWar::instance().GetEventSungZiMapInfo().m_stMapName.c_str()); return s_szMapPath; }
const char* GetPassMapPath( BYTE bEmpire ) { if (bEmpire > 0 && bEmpire < EMPIRE_MAX_NUM) { static char s_szMapPath[128]; snprintf(s_szMapPath, sizeof(s_szMapPath), "%s/map/%s/", LocaleService_GetBasePath().c_str(), CThreeWayWar::instance().GetEventPassMapInfo().m_stMapName[bEmpire-1].c_str()); return s_szMapPath; } return NULL; }
bool CThreeWayWar::LoadSetting(const char* szFileName) { char szPath[1024]; snprintf( szPath, sizeof(szPath), "%s/%s", LocaleService_GetBasePath().c_str(), szFileName); FILE* pf = fopen( szPath, "r" ); if (NULL == pf) { sys_err("[INIT_FORKED] Do not open file (%s)", szPath ); return false; } char szLine[256]; char szSungziName[128]; char szPassName[3][128]; while( NULL != fgets(szLine, 256, pf) ) { if (0 == strncmp(szLine, "sungzi:", 7)) { struct ForkedSungziMapInfo sungziinfo; sscanf( szLine+7, "%d %d %d %d %d %d %d %s %d", &sungziinfo.m_iForkedSung, &sungziinfo.m_iForkedSungziStartPosition[0][0], &sungziinfo.m_iForkedSungziStartPosition[0][1], &sungziinfo.m_iForkedSungziStartPosition[1][0], &sungziinfo.m_iForkedSungziStartPosition[1][1], &sungziinfo.m_iForkedSungziStartPosition[2][0], &sungziinfo.m_iForkedSungziStartPosition[2][1], szSungziName, &sungziinfo.m_iBossMobVnum); sungziinfo.m_stMapName = static_cast<std::string>(szSungziName); SungZiInfoMap_.push_back( sungziinfo ); MapIndexSet_.insert( sungziinfo.m_iForkedSung ); } else if (0 == strncmp(szLine, "pass:"******"%d %d %d %s %d %d %d %s %d %d %d %s", &passinfo.m_iForkedPass[0], &passinfo.m_iForkedPassStartPosition[0][0], &passinfo.m_iForkedPassStartPosition[0][1], szPassName[0], &passinfo.m_iForkedPass[1], &passinfo.m_iForkedPassStartPosition[1][0], &passinfo.m_iForkedPassStartPosition[1][1], szPassName[1], &passinfo.m_iForkedPass[2], &passinfo.m_iForkedPassStartPosition[2][0], &passinfo.m_iForkedPassStartPosition[2][1], szPassName[2] ); passinfo.m_stMapName[0] = static_cast<std::string>(szPassName[0]); passinfo.m_stMapName[1] = static_cast<std::string>(szPassName[1]); passinfo.m_stMapName[2] = static_cast<std::string>(szPassName[2]); PassInfoMap_.push_back( passinfo ); MapIndexSet_.insert( passinfo.m_iForkedPass[0] ); MapIndexSet_.insert( passinfo.m_iForkedPass[1] ); MapIndexSet_.insert( passinfo.m_iForkedPass[2] ); } } fclose(pf); return true; }
bool ITEM_MANAGER::ConvSpecialDropItemFile() { char szSpecialItemGroupFileName[256]; snprintf(szSpecialItemGroupFileName, sizeof(szSpecialItemGroupFileName), "%s/special_item_group.txt", LocaleService_GetBasePath().c_str()); FILE *fp = fopen("special_item_group_vnum.txt", "w"); if (!fp) { sys_err("could not open file (%s)", "special_item_group_vnum.txt"); return false; } CTextFileLoader loader; if (!loader.Load(szSpecialItemGroupFileName)) { fclose(fp); return false; } std::string stName; for (DWORD i = 0; i < loader.GetChildNodeCount(); ++i) { loader.SetChildNode(i); loader.GetCurrentNodeName(&stName); int iVnum; if (!loader.GetTokenInteger("vnum", &iVnum)) { sys_err("ConvSpecialDropItemFile : Syntax error %s : no vnum, node %s", szSpecialItemGroupFileName, stName.c_str()); loader.SetParentNode(); fclose(fp); return false; } std::string str; int type = 0; if (loader.GetTokenString("type", &str)) { stl_lowers(str); if (str == "pct") { type = 1; } } TTokenVector * pTok; fprintf(fp, "Group %s\n", stName.c_str()); fprintf(fp, "{\n"); fprintf(fp, " Vnum %i\n", iVnum); if (type) fprintf(fp, " Type Pct"); for (int k = 1; k < 256; ++k) { char buf[4]; snprintf(buf, sizeof(buf), "%d", k); if (loader.GetTokenVector(buf, &pTok)) { const std::string& name = pTok->at(0); DWORD dwVnum = 0; if (!GetVnumByOriginalName(name.c_str(), dwVnum)) { if ( name == "경험치" || name == "mob" || name == "slow" || name == "drain_hp" || name == "poison" || name == "group") { dwVnum = 0; } else { str_to_number(dwVnum, name.c_str()); if (!ITEM_MANAGER::instance().GetTable(dwVnum)) { sys_err("ReadSpecialDropItemFile : there is no item %s : node %s", name.c_str(), stName.c_str()); fclose(fp); return false; } } } int iCount = 0; str_to_number(iCount, pTok->at(1).c_str()); int iProb = 0; str_to_number(iProb, pTok->at(2).c_str()); int iRarePct = 0; if (pTok->size() > 3) { str_to_number(iRarePct, pTok->at(3).c_str()); } // 1 "기술 수련서" 1 100 if (0 == dwVnum) fprintf(fp, " %d %s %d %d\n", k, name.c_str(), iCount, iProb); else fprintf(fp, " %d %u %d %d\n", k, dwVnum, iCount, iProb); continue; } break; } fprintf(fp, "}\n"); fprintf(fp, "\n"); loader.SetParentNode(); } fclose(fp); return true; }
/** * @version 05/06/08 Bang2ni - __get_guildid_byname 스크립트 함수 등록 */ bool CQuestManager::InitializeLua() { #if LUA_V == 503 L = lua_open(); luaopen_base(L); luaopen_table(L); luaopen_string(L); luaopen_math(L); //TEMP luaopen_io(L); luaopen_debug(L); #elif LUA_V == 523 L = luaL_newstate(); luaL_openlibs(L); //luaopen_debug(L); #else #error "lua version not found" #endif RegisterAffectFunctionTable(); RegisterBuildingFunctionTable(); RegisterDungeonFunctionTable(); RegisterGameFunctionTable(); RegisterGuildFunctionTable(); RegisterHorseFunctionTable(); #ifdef __PET_SYSTEM__ RegisterPetFunctionTable(); #endif RegisterITEMFunctionTable(); RegisterMarriageFunctionTable(); RegisterNPCFunctionTable(); RegisterPartyFunctionTable(); RegisterPCFunctionTable(); RegisterQuestFunctionTable(); RegisterTargetFunctionTable(); RegisterArenaFunctionTable(); RegisterForkedFunctionTable(); RegisterMonarchFunctionTable(); RegisterOXEventFunctionTable(); RegisterMgmtFunctionTable(); RegisterBattleArenaFunctionTable(); RegisterDanceEventFunctionTable(); RegisterDragonLairFunctionTable(); RegisterSpeedServerFunctionTable(); RegisterDragonSoulFunctionTable(); { luaL_reg member_functions[] = { { "chat", member_chat }, { "set_ready", member_set_ready }, { "clear_ready", member_clear_ready }, { NULL, NULL } }; AddLuaFunctionTable("member", member_functions); } { luaL_reg highscore_functions[] = { { "register", highscore_register }, { "show", highscore_show }, { NULL, NULL } }; AddLuaFunctionTable("highscore", highscore_functions); } { luaL_reg mob_functions[] = { { "spawn", mob_spawn }, { "spawn_group", mob_spawn_group }, { NULL, NULL } }; AddLuaFunctionTable("mob", mob_functions); } // // global namespace functions // RegisterGlobalFunctionTable(L); // LUA_INIT_ERROR_MESSAGE { char settingsFileName[256]; snprintf(settingsFileName, sizeof(settingsFileName), "%s/settings.lua", LocaleService_GetBasePath().c_str()); int settingsLoadingResult = lua_dofile(L, settingsFileName); sys_log(0, "LoadSettings(%s), returns %d", settingsFileName, settingsLoadingResult); if (settingsLoadingResult != 0) { sys_err("LOAD_SETTINS_FAILURE(%s)", settingsFileName); return false; } } { char questlibFileName[256]; snprintf(questlibFileName, sizeof(questlibFileName), "%s/questlib.lua", LocaleService_GetQuestPath().c_str()); int questlibLoadingResult = lua_dofile(L, questlibFileName); sys_log(0, "LoadQuestlib(%s), returns %d", questlibFileName, questlibLoadingResult); if (questlibLoadingResult != 0) { sys_err("LOAD_QUESTLIB_FAILURE(%s)", questlibFileName); return false; } } if (LC_IsEurope()) { char translateFileName[256]; snprintf(translateFileName, sizeof(translateFileName), "%s/translate.lua", LocaleService_GetBasePath().c_str()); int translateLoadingResult = lua_dofile(L, translateFileName); sys_log(0, "LoadTranslate(%s), returns %d", translateFileName, translateLoadingResult); if (translateLoadingResult != 0) { sys_err("LOAD_TRANSLATE_ERROR(%s)", translateFileName); return false; } } { char questLocaleFileName[256]; if (LC_IsEurope()) { snprintf(questLocaleFileName, sizeof(questLocaleFileName), "%s/locale.lua", g_stQuestDir.c_str()); } else { snprintf(questLocaleFileName, sizeof(questLocaleFileName), "%s/locale_%s.lua", g_stQuestDir.c_str(), g_stLocale.c_str()); } int questLocaleLoadingResult = lua_dofile(L, questLocaleFileName); sys_log(0, "LoadQuestLocale(%s), returns %d", questLocaleFileName, questLocaleLoadingResult); if (questLocaleLoadingResult != 0) { sys_err("LoadQuestLocale(%s) FAILURE", questLocaleFileName); return false; } } // END_OF_LUA_INIT_ERROR_MESSAGE for (itertype(g_setQuestObjectDir) it = g_setQuestObjectDir.begin(); it != g_setQuestObjectDir.end(); ++it) { const string& stQuestObjectDir = *it; char buf[PATH_MAX]; snprintf(buf, sizeof(buf), "%s/state/", stQuestObjectDir.c_str()); DIR * pdir = opendir(buf); int iQuestIdx = 0; if (pdir) { dirent * pde; while ((pde = readdir(pdir))) { if (pde->d_name[0] == '.') continue; snprintf(buf + 11, sizeof(buf) - 11, "%s", pde->d_name); RegisterQuest(pde->d_name, ++iQuestIdx); int ret = lua_dofile(L, (stQuestObjectDir + "/state/" + pde->d_name).c_str()); sys_log(0, "QUEST: loading %s, returns %d", (stQuestObjectDir + "/state/" + pde->d_name).c_str(), ret); BuildStateIndexToName(pde->d_name); } closedir(pdir); } } #if LUA_V == 503 lua_setgcthreshold(L, 0); #endif lua_newtable(L); lua_setglobal(L, "__codecache"); return true; }