void NamesObjectTable::reload() { #ifdef DataConnect_DEBUG std::cout << "NamesObjectTable: reload" << std::endl; #endif try { Database::SelectQuery query; query.addColumn("itemname", "itn_itemid"); query.addColumn("itemname", "itn_german"); query.addColumn("itemname", "itn_english"); query.addServerTable("itemname"); Database::Result results = query.execute(); if (!results.empty()) { clearOldTable(); NamesStruct temprecord; for (Database::ResultConstIterator itr = results.begin(); itr != results.end(); ++itr) { temprecord.German = (TYPE_OF_GERMAN)((*itr)["itn_german"].as<std::string>()); temprecord.English = (TYPE_OF_ENGLISH)((*itr)["itn_english"].as<std::string>()); m_table[(TYPE_OF_ITEM_ID)((*itr)["itn_itemid"].as<int32_t>())] = temprecord; } m_dataOK = true; } else { m_dataOK = false; } #ifdef DataConnect_DEBUG std::cout << "loaded " << rows << " rows into NamesObjectTable" << std::endl; #endif } catch (...) { m_dataOK = false; } }
void ContainerObjectTable::reload() { #ifdef DataConnect_DEBUG std::cout << "ContainerObjectTable: reload" << std::endl; #endif try { Database::SelectQuery query; query.addColumn("container", "con_itemid"); query.addColumn("container", "con_volume"); query.addServerTable("container"); Database::Result results = query.execute(); if (!results.empty()) { clearOldTable(); ContainerStruct temprecord; for (Database::ResultConstIterator itr = results.begin(); itr != results.end(); ++itr) { temprecord.ContainerVolume = (TYPE_OF_VOLUME)((*itr)["con_volume"].as<int32_t>()); m_table[(TYPE_OF_ITEM_ID)((*itr)["con_itemid"].as<TYPE_OF_ITEM_ID>())] = temprecord; } m_dataOK = true; } else { m_dataOK = false; } #ifdef DataConnect_DEBUG std::cout << "loaded " << rows << " rows into ContainerObjectTable" << std::endl; #endif } catch (...) { m_dataOK = false; } }
void ScheduledScriptsTable::reload() { #ifdef DataConnect_DEBUG std::cout << "ScheduledScriptsTable: reload" << std::endl; #endif try { Database::SelectQuery query; query.addColumn("scheduledscripts", "sc_scriptname"); query.addColumn("scheduledscripts", "sc_mincycletime"); query.addColumn("scheduledscripts", "sc_maxcycletime"); query.addColumn("scheduledscripts", "sc_functionname"); query.addServerTable("scheduledscripts"); Database::Result results = query.execute(); if (!results.empty()) { clearOldTable(); ScriptData tmpRecord; for (Database::ResultConstIterator itr = results.begin(); itr != results.end(); ++itr) { tmpRecord.minCycleTime = (uint32_t)((*itr)["sc_mincycletime"].as<uint32_t>()); tmpRecord.maxCycleTime = (uint32_t)((*itr)["sc_maxcycletime"].as<uint32_t>()); tmpRecord.nextCycleTime = 0; if (!((*itr)["sc_scriptname"].is_null()) && !((*itr)["sc_functionname"].is_null())) { tmpRecord.functionName = ((*itr)["sc_functionname"].as<std::string>()); tmpRecord.scriptName = ((*itr)["sc_scriptname"].as<std::string>()); try { boost::shared_ptr<LuaScheduledScript> tmpScript(new LuaScheduledScript(tmpRecord.scriptName)); tmpRecord.scriptptr = tmpScript; addData(tmpRecord); } catch (ScriptException &e) { Logger::writeError("scripts", "Error while loading scheduled script: " + tmpRecord.scriptName + ":\n" + e.what() + "\n"); } } } } m_dataOk = true; } catch (std::exception &e) { std::cerr << "exception: " << e.what() << std::endl; m_dataOk = false; } }
void ScheduledScriptsTable::reload() { try { Database::SelectQuery query; query.addColumn("scheduledscripts", "sc_scriptname"); query.addColumn("scheduledscripts", "sc_mincycletime"); query.addColumn("scheduledscripts", "sc_maxcycletime"); query.addColumn("scheduledscripts", "sc_functionname"); query.addServerTable("scheduledscripts"); Database::Result results = query.execute(); if (!results.empty()) { clearOldTable(); ScriptData tmpRecord; for (const auto &row : results) { tmpRecord.minCycleTime = row["sc_mincycletime"].as<uint32_t>(); tmpRecord.maxCycleTime = row["sc_maxcycletime"].as<uint32_t>(); tmpRecord.nextCycleTime = 0; if (!row["sc_scriptname"].is_null() && !row["sc_functionname"].is_null()) { tmpRecord.functionName = row["sc_functionname"].as<std::string>(); tmpRecord.scriptName = row["sc_scriptname"].as<std::string>(); try { std::shared_ptr<LuaScheduledScript> tmpScript = std::make_shared<LuaScheduledScript>(tmpRecord.scriptName); tmpRecord.scriptptr = tmpScript; addData(tmpRecord); } catch (const ScriptException &e) { Logger::error(LogFacility::Script) << "Error while loading scheduled script: " << tmpRecord.scriptName << ": " << e.what() << Log::end; } } } } m_dataOk = true; } catch (std::exception &e) { Logger::error(LogFacility::Other) << "Exception in ScheduledScriptsTable::reload: " << e.what() << Log::end; m_dataOk = false; } }
void WeaponObjectTable::reload() { #ifdef DataConnect_DEBUG std::cout << "WeaponObjectTable: reload" << std::endl; #endif try { Database::SelectQuery query; query.addColumn("weapon", "wp_itemid"); query.addColumn("weapon", "wp_attack"); query.addColumn("weapon", "wp_defence"); query.addColumn("weapon", "wp_accuracy"); query.addColumn("weapon", "wp_range"); query.addColumn("weapon", "wp_weapontype"); query.addColumn("weapon", "wp_ammunitiontype"); query.addColumn("weapon", "wp_actionpoints"); query.addColumn("weapon", "wp_magicdisturbance"); query.addColumn("weapon", "wp_poison"); query.addColumn("weapon", "wp_fightingscript"); query.addServerTable("weapon"); Database::Result results = query.execute(); if (!results.empty()) { clearOldTable(); WeaponStruct temprecord; std::string scriptname; TYPE_OF_ITEM_ID weaponId; for (Database::ResultConstIterator itr = results.begin(); itr != results.end(); ++itr) { weaponId = (*itr)["wp_itemid"].as<TYPE_OF_ITEM_ID>(); temprecord.Attack = (TYPE_OF_ATTACK)((*itr)["wp_attack"].as<uint16_t>()); temprecord.Defence = (TYPE_OF_DEFENCE)((*itr)["wp_defence"].as<uint16_t>()); temprecord.Accuracy = (TYPE_OF_ACCURACY)((*itr)["wp_accuracy"].as<uint16_t>()); temprecord.Range = (TYPE_OF_RANGE)((*itr)["wp_range"].as<uint16_t>()); temprecord.WeaponType = (TYPE_OF_WEAPONTYPE)((*itr)["wp_weapontype"].as<uint16_t>()); temprecord.AmmunitionType = (TYPE_OF_AMMUNITIONTYPE)((*itr)["wp_ammunitiontype"].as<uint16_t>()); temprecord.ActionPoints = (TYPE_OF_ACTIONPOINTS)((*itr)["wp_actionpoints"].as<uint16_t>()); temprecord.MagicDisturbance = (TYPE_OF_MAGICDISTURBANCE)((*itr)["wp_magicdisturbance"].as<uint16_t>()); temprecord.PoisonStrength = (TYPE_OF_POISONSTRENGTH)((*itr)["wp_poison"].as<uint16_t>()); if (!(*itr)["wp_fightingscript"].is_null()) { scriptname = (*itr)["wp_fightingscript"].as<std::string>(); if (!scriptname.empty()) { try { boost::shared_ptr<LuaWeaponScript> tmpScript(new LuaWeaponScript(scriptname)); temprecord.script = tmpScript; } catch (ScriptException &e) { Logger::writeError("scripts", "Error while loading weapon script: " + scriptname + ":\n" + e.what() + "\n"); } } } m_table[weaponId] = temprecord; } m_dataOK = true; } else { m_dataOK = false; } #ifdef DataConnect_DEBUG std::cout << "loaded " << rows << " rows into WeaponObjectTable" << std::endl; #endif } catch (...) { m_dataOK = false; } }
void NPCTable::reload() { try { Database::SelectQuery query; query.addColumn("npc", "npc_id"); query.addColumn("npc", "npc_type"); query.addColumn("npc", "npc_posx"); query.addColumn("npc", "npc_posy"); query.addColumn("npc", "npc_posz"); query.addColumn("npc", "npc_name"); query.addColumn("npc", "npc_faceto"); query.addColumn("npc", "npc_is_healer"); query.addColumn("npc", "npc_script"); query.addColumn("npc", "npc_sex"); query.addColumn("npc", "npc_hair"); query.addColumn("npc", "npc_beard"); query.addColumn("npc", "npc_hairred"); query.addColumn("npc", "npc_hairgreen"); query.addColumn("npc", "npc_hairblue"); query.addColumn("npc", "npc_skinred"); query.addColumn("npc", "npc_skingreen"); query.addColumn("npc", "npc_skinblue"); query.addServerTable("npc"); query.addOrderBy("npc", "npc_id", Database::SelectQuery::ASC); Database::Result results = query.execute(); if (!results.empty()) { auto questNodes = QuestNodeTable::getInstance().getNpcNodes(); auto questItr = questNodes.first; auto questEnd = questNodes.second; for (const auto &row : results) { NPC *newNPC = nullptr; TYPE_OF_CHARACTER_ID npcID = 0; std::string npcName; try { npcID = row["npc_id"].as<TYPE_OF_CHARACTER_ID>(); const position pos( row["npc_posx"].as<int16_t>(), row["npc_posy"].as<int16_t>(), row["npc_posz"].as<int16_t>() ); npcName = row["npc_name"].as<std::string>(); Character::appearance appearance; appearance.hairtype = uint8_t(row["npc_hair"].as<int16_t>()); appearance.beardtype = uint8_t(row["npc_hair"].as<int16_t>()); appearance.hair = { uint8_t(row["npc_hairred"].as<int16_t>()), uint8_t(row["npc_hairgreen"].as<int16_t>()), uint8_t(row["npc_hairblue"].as<int16_t>()) }; appearance.skin = { (uint8_t)(row["npc_skinred"].as<int16_t>()), (uint8_t)(row["npc_skingreen"].as<int16_t>()), (uint8_t)(row["npc_skinblue"].as<int16_t>()) }; newNPC = new NPC( npcID, npcName, row["npc_type"].as<TYPE_OF_RACE_ID>(), pos, Character::face_to(row["npc_faceto"].as<uint32_t>()), row["npc_is_healer"].as<bool>(), Character::sex_type(row["npc_sex"].as<uint32_t>()), appearance); // add npc to npc list _world->Npc.insert(newNPC); // set field to occupied Field *tempf; if (_world->GetPToCFieldAt(tempf, pos)) { tempf->setChar(); } if (!row["npc_script"].is_null()) { const std::string scriptname = row["npc_script"].as<std::string>(); try { std::shared_ptr<LuaNPCScript> script(new LuaNPCScript(scriptname, newNPC)); while (questItr != questEnd && questItr->first == npcID) { script->addQuestScript(questItr->second.entrypoint, questItr->second.script); ++questItr; } newNPC->setScript(script); } catch (ScriptException &e) { Logger::error(LogFacility::Script) << "Error while loading npc script: " << scriptname << ": " << e.what() << Log::end; } } newNPC = nullptr; } catch (NoSpace &s) { Logger::error(LogFacility::Other) << "No space available for NPC " << npcName << "(" << npcID << "): " << s.what() << Log::end; } delete newNPC; } } m_dataOK = true; } catch (...) { Logger::error(LogFacility::Other) << "Error while loading NPCs" << Log::end; m_dataOK = false; } }