Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
Luan Luciano committed Apr 3, 2024
1 parent cb3df6d commit 14287bc
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 20 deletions.
2 changes: 1 addition & 1 deletion src/creatures/players/player.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2693,7 +2693,7 @@ class Player final : public Creature, public Cylinder, public Bankable {

std::vector<uint16_t> quickLootListItemIds;

std::map<uint16_t, uint8_t> outfitsMap;
std::unordered_set<uint16_t, uint8_t> outfitsMap;
std::unordered_set<uint16_t> mountsMap;
std::vector<FamiliarEntry> familiars;

Expand Down
4 changes: 2 additions & 2 deletions src/io/functions/iologindata_load_player.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -273,15 +273,15 @@ void IOLoginDataLoad::loadPlayerDefaultOutfit(std::shared_ptr<Player> player, DB
player->currentOutfit = player->defaultOutfit;

// load outfits & addons
auto result2 = g_database().storeQuery(fmt::format("SELECT `outfit_id`, `addons` FROM `player_outfits` WHERE `player_id` = {}", player->getGUID()));
auto result2 = g_database().storeQuery(fmt::format("SELECT `outfit_id`, `addons` FROM `player_outfits` WHERE `player_id` = {:d}", player->getGUID()));
if (result2) {
do {
player->outfitsMap.emplace(result2->getNumber<uint16_t>("outfit_id"), result2->getNumber<uint8_t>("addons"));
} while (result2->next());
}

// load mounts
auto result3 = g_database().storeQuery(fmt::format("SELECT `mount_id` FROM `player_mounts` WHERE `player_id` = {}", player->getGUID()));
auto result3 = g_database().storeQuery(fmt::format("SELECT `mount_id` FROM `player_mounts` WHERE `player_id` = {:d}", player->getGUID()));
if (result3) {
do {
player->mountsMap.emplace(result3->getNumber<uint16_t>("mount_id"));
Expand Down
22 changes: 5 additions & 17 deletions src/io/functions/iologindata_save_player.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -802,20 +802,14 @@ bool IOLoginDataSave::savePlayerOutfits(std::shared_ptr<Player> player) {
return false;
}

Database &db = Database::getInstance();
std::ostringstream query;
query << "DELETE FROM `player_outfits` WHERE `player_id` = " << player->getGUID();
if (!db.executeQuery(query.str())) {
if (!g_database().executeQuery(fmt::format("DELETE FROM `player_outfits` WHERE `player_id` = {:d}", player->getGUID()))) {
return false;
}

query.str("");

DBInsert outfitQuery("INSERT INTO `player_outfits` (`player_id`, `outfit_id`, `addons`) VALUES ");

for (const auto &it : player->outfitsMap) {
query << player->getGUID() << ',' << it.first << ',' << it.second;
if (!outfitQuery.addRow(query)) {
for (const auto &outfit : player->outfitsMap) {
if (!outfitQuery.addRow(fmt::format("{:d}, {:d}, {:d}", player->getGUID(), outfit.first, outfit.second))) {
return false;
}
}
Expand All @@ -832,20 +826,14 @@ bool IOLoginDataSave::savePlayerMounts(std::shared_ptr<Player> player) {
return false;
}

Database &db = Database::getInstance();
std::ostringstream query;
query << "DELETE FROM `player_mounts` WHERE `player_id` = " << player->getGUID();
if (!db.executeQuery(query.str())) {
if (!g_database().executeQuery(fmt::format("DELETE FROM `player_mounts` WHERE `player_id` = {:d}", player->getGUID()))) {
return false;
}

query.str("");

DBInsert mountQuery("INSERT INTO `player_mounts` (`player_id`, `mount_id`) VALUES ");

for (const auto &mountId : player->mountsMap) {
query << player->getGUID() << ',' << mountId;
if (!mountQuery.addRow(query)) {
if (!mountQuery.addRow(fmt::format("{:d}, {:d}", player->getGUID(), mountId))) {
return false;
}
}
Expand Down

0 comments on commit 14287bc

Please sign in to comment.