From 887e2a25f08a9572a7f2ef768ba3ebef39c29b73 Mon Sep 17 00:00:00 2001 From: David Markowitz Date: Fri, 21 Jul 2023 23:18:51 -0700 Subject: [PATCH] Fix race score bugs num wins serialized properly scores are saved and num wins and times played are incremented properly --- dGame/LeaderboardManager.cpp | 19 +++++++++++++++---- dGame/dComponents/RacingControlComponent.cpp | 2 +- 2 files changed, 16 insertions(+), 5 deletions(-) diff --git a/dGame/LeaderboardManager.cpp b/dGame/LeaderboardManager.cpp index 71efe141..a4c6ec1a 100644 --- a/dGame/LeaderboardManager.cpp +++ b/dGame/LeaderboardManager.cpp @@ -103,7 +103,7 @@ void Leaderboard::QueryToLdf(std::unique_ptr& rows) { // BestTime:3 entry.push_back(new LDFData(u"License", 1)); // License:1 - 1 if player has completed mission 637 and 0 otherwise - entry.push_back(new LDFData(u"NumWins", rows->getInt("tertiaryScore"))); + entry.push_back(new LDFData(u"NumWins", rows->getInt("numWins"))); // NumWins:1 break; case Type::UnusedLeaderboard4: @@ -342,6 +342,11 @@ void LeaderboardManager::SaveScore(const LWOOBJID& playerID, const GameID activi case Leaderboard::Type::Racing: { oldScore.SetPrimaryScore(myScoreResult->getInt("primaryScore")); oldScore.SetSecondaryScore(myScoreResult->getInt("secondaryScore")); + + // For wins we dont care about the score, just the time, so zero out the tertiary. + // Wins are updated later. + oldScore.SetTertiaryScore(0); + newScore.SetTertiaryScore(0); lowerScoreBetter = true; break; } @@ -368,17 +373,23 @@ void LeaderboardManager::SaveScore(const LWOOBJID& playerID, const GameID activi } if (newHighScore) { saveQuery = FormatInsert(leaderboardType, newScore, true); - } else if (leaderboardType == Leaderboard::Type::Racing && tertiaryScore) { - saveQuery = "UPDATE leaderboard SET numWins = numWins + 1, timesPlayed = timesPlayed + 1 WHERE character_id = ? AND game_id = ?;"; } } else { saveQuery = FormatInsert(leaderboardType, newScore, false); } - + Game::logger->Log("LeaderboardManager", "save query %s %i %i", saveQuery.c_str(), playerID, activityId); std::unique_ptr saveStatement(Database::CreatePreppedStmt(saveQuery)); saveStatement->setInt(1, playerID); saveStatement->setInt(2, activityId); saveStatement->execute(); + + // track wins separately + if (leaderboardType == Leaderboard::Type::Racing && tertiaryScore != 0.0f) { + std::unique_ptr winUpdate(Database::CreatePreppedStmt("UPDATE leaderboard SET numWins = numWins + 1 WHERE character_id = ? AND game_id = ?;")); + winUpdate->setInt(1, playerID); + winUpdate->setInt(2, activityId); + winUpdate->execute(); + } } void LeaderboardManager::SendLeaderboard(const GameID gameID, const Leaderboard::InfoType infoType, const bool weekly, const LWOOBJID playerID, const LWOOBJID targetID, const uint32_t resultStart, const uint32_t resultEnd) { diff --git a/dGame/dComponents/RacingControlComponent.cpp b/dGame/dComponents/RacingControlComponent.cpp index 1f3e144a..5de24445 100644 --- a/dGame/dComponents/RacingControlComponent.cpp +++ b/dGame/dComponents/RacingControlComponent.cpp @@ -838,7 +838,7 @@ void RacingControlComponent::Update(float deltaTime) { "Completed time %llu, %llu", raceTime, raceTime * 1000); - LeaderboardManager::SaveScore(playerEntity->GetObjectID(), m_ActivityID, static_cast(player.bestLapTime), static_cast(player.raceTime), static_cast(player.finished == 1)); + LeaderboardManager::SaveScore(playerEntity->GetObjectID(), m_ActivityID, static_cast(player.raceTime), static_cast(player.bestLapTime), static_cast(player.finished == 1)); // Entire race time missionComponent->Progress(eMissionTaskType::RACING, (raceTime) * 1000, (LWOOBJID)eRacingTaskParam::TOTAL_TRACK_TIME);