[LDoN] Update methods for removing wins/losses

This commit is contained in:
fryguy 2021-06-02 08:51:24 -04:00
parent d2f8eead1f
commit b7eeb3b2f9
3 changed files with 26 additions and 16 deletions

View File

@ -2019,7 +2019,7 @@ void Database::ClearRaidLeader(uint32 gid, uint32 rid)
QueryDatabase(query);
}
void Database::UpdateAdventureStatsEntry(uint32 char_id, uint8 theme, bool win)
void Database::UpdateAdventureStatsEntry(uint32 char_id, uint8 theme, bool win, bool remove)
{
std::string field;
@ -2057,16 +2057,26 @@ void Database::UpdateAdventureStatsEntry(uint32 char_id, uint8 theme, bool win)
}
}
if (win)
if (win) {
field += "wins";
else
} else {
field += "losses";
}
std::string query = StringFormat("UPDATE `adventure_stats` SET %s=%s+1 WHERE player_id=%u",field.c_str(), field.c_str(), char_id);
std::string modification;
if (remove){
modification = "-1";
} else {
modification = "+1";
}
std::string query = StringFormat("UPDATE `adventure_stats` SET %s=%s%s WHERE player_id=%u",field.c_str(), field.c_str(), modification.c_str(), char_id);
auto results = QueryDatabase(query);
if (results.RowsAffected() != 0)
if (results.RowsAffected() != 0) {
return;
}
query = StringFormat("INSERT INTO `adventure_stats` SET %s=1, player_id=%u", field.c_str(), char_id);
QueryDatabase(query);

View File

@ -174,7 +174,7 @@ public:
/* Adventure related. */
void UpdateAdventureStatsEntry(uint32 char_id, uint8 theme, bool win);
void UpdateAdventureStatsEntry(uint32 char_id, uint8 theme, bool win, bool remove = false);
bool GetAdventureStats(uint32 char_id, AdventureStats_Struct *as);
/* Account Related */

View File

@ -5581,23 +5581,23 @@ void Client::RemoveLDoNLoss(uint32 theme_id)
{
case 1:
m_pp.ldon_losses_guk -= 1;
database.UpdateAdventureStatsEntry(CharacterID(), theme_id, false);
database.UpdateAdventureStatsEntry(CharacterID(), theme_id, false, true);
break;
case 2:
m_pp.ldon_losses_mir -= 1;
database.UpdateAdventureStatsEntry(CharacterID(), theme_id, false);
database.UpdateAdventureStatsEntry(CharacterID(), theme_id, false, true);
break;
case 3:
m_pp.ldon_losses_mmc -= 1;
database.UpdateAdventureStatsEntry(CharacterID(), theme_id, false);
database.UpdateAdventureStatsEntry(CharacterID(), theme_id, false, true);
break;
case 4:
m_pp.ldon_losses_ruj -= 1;
database.UpdateAdventureStatsEntry(CharacterID(), theme_id, false);
database.UpdateAdventureStatsEntry(CharacterID(), theme_id, false, true);
break;
case 5:
m_pp.ldon_losses_tak -= 1;
database.UpdateAdventureStatsEntry(CharacterID(), theme_id, false);
database.UpdateAdventureStatsEntry(CharacterID(), theme_id, false, true);
break;
default:
return;
@ -5639,23 +5639,23 @@ void Client::RemoveLDoNWin(uint32 theme_id)
{
case 1:
m_pp.ldon_wins_guk -= 1;
database.UpdateAdventureStatsEntry(CharacterID(), theme_id, true);
database.UpdateAdventureStatsEntry(CharacterID(), theme_id, true, true);
break;
case 2:
m_pp.ldon_wins_mir -= 1;
database.UpdateAdventureStatsEntry(CharacterID(), theme_id, true);
database.UpdateAdventureStatsEntry(CharacterID(), theme_id, true, true);
break;
case 3:
m_pp.ldon_wins_mmc -= 1;
database.UpdateAdventureStatsEntry(CharacterID(), theme_id, true);
database.UpdateAdventureStatsEntry(CharacterID(), theme_id, true, true);
break;
case 4:
m_pp.ldon_wins_ruj -= 1;
database.UpdateAdventureStatsEntry(CharacterID(), theme_id, true);
database.UpdateAdventureStatsEntry(CharacterID(), theme_id, true, true);
break;
case 5:
m_pp.ldon_wins_tak -= 1;
database.UpdateAdventureStatsEntry(CharacterID(), theme_id, true);
database.UpdateAdventureStatsEntry(CharacterID(), theme_id, true, true);
break;
default:
return;