From 238fc98ea541af108ee07a82b2e377c07b99aa14 Mon Sep 17 00:00:00 2001 From: David Markowitz Date: Wed, 21 Jun 2023 21:46:11 -0700 Subject: [PATCH] Fix shooting gallery leaderboard bugs - add weekly functionality for top scores - Fix shooting gallery score saving - remove extra leaderboard fetch --- dGame/LeaderboardManager.cpp | 16 +++++++------- .../ai/MINIGAME/SG_GF/SERVER/SGCannon.cpp | 21 +++++-------------- .../dlu/9_Update_Leaderboard_Storage.sql | 6 ++++-- 3 files changed, 17 insertions(+), 26 deletions(-) diff --git a/dGame/LeaderboardManager.cpp b/dGame/LeaderboardManager.cpp index 2fd48dc..f9e44b2 100644 --- a/dGame/LeaderboardManager.cpp +++ b/dGame/LeaderboardManager.cpp @@ -89,12 +89,12 @@ void Leaderboard::QueryToLdf(std::unique_ptr& rows) { entry.push_back(new LDFData(u"RowNumber", rows->getInt("ranking"))); switch (leaderboardType) { case Type::ShootingGallery: - entry.push_back(new LDFData(u"HitPercentage", (rows->getInt("primaryScore") / 100.0f))); - // HitPercentage:3 between 0 and 1 - entry.push_back(new LDFData(u"Score", rows->getInt("secondaryScore"))); + entry.push_back(new LDFData(u"Score", rows->getInt("primaryScore"))); // Score:1 - entry.push_back(new LDFData(u"Streak", rows->getInt("tertiaryScore"))); + entry.push_back(new LDFData(u"Streak", rows->getInt("secondaryScore"))); // Streak:1 + entry.push_back(new LDFData(u"HitPercentage", (rows->getInt("tertiaryScore") / 100.0f))); + // HitPercentage:3 between 0 and 1 break; case Type::Racing: entry.push_back(new LDFData(u"BestTime", rows->getDouble("primaryScore"))); @@ -229,14 +229,14 @@ void Leaderboard::SetupLeaderboard(bool weekly, uint32_t resultStart, uint32_t r // For top query, we want to just rank all scores, but for all others we need the scores around a specific player std::string baseLookup; if (this->infoType == InfoType::Top) { - baseLookup = "SELECT id FROM leaderboard WHERE game_id = ? ORDER BY "; + baseLookup = "SELECT id, last_played FROM leaderboard WHERE game_id = ? " + (this->weekly ? weeklyFilter : std::string("")) + " ORDER BY "; baseLookup += orderBase.data(); } else { - baseLookup = "SELECT id FROM leaderboard WHERE game_id = ? AND character_id = "; + baseLookup = "SELECT id, last_played FROM leaderboard WHERE game_id = ? " + (this->weekly ? weeklyFilter : std::string("")) + " AND character_id = "; baseLookup += std::to_string(static_cast(this->relatedPlayer)); } baseLookup += " LIMIT 1"; - + Game::logger->LogDebug("LeaderboardManager", "query is %s", baseLookup.c_str()); std::unique_ptr baseQuery(Database::CreatePreppedStmt(baseLookup)); baseQuery->setInt(1, this->gameID); std::unique_ptr baseResult(baseQuery->executeQuery()); @@ -251,7 +251,7 @@ void Leaderboard::SetupLeaderboard(bool weekly, uint32_t resultStart, uint32_t r int32_t res = snprintf(lookupBuffer.get(), STRING_LENGTH, queryBase.c_str(), orderBase.data(), filter.c_str(), resultStart, resultEnd); DluAssert(res != -1); std::unique_ptr query(Database::CreatePreppedStmt(lookupBuffer.get())); - + Game::logger->LogDebug("LeaderboardManager", "Query is %s vars are %i %i %i", lookupBuffer.get(), this->gameID, this->relatedPlayer, relatedPlayerLeaderboardId); query->setInt(1, this->gameID); if (this->infoType == InfoType::Friends) { query->setInt(2, this->relatedPlayer); diff --git a/dScripts/ai/MINIGAME/SG_GF/SERVER/SGCannon.cpp b/dScripts/ai/MINIGAME/SG_GF/SERVER/SGCannon.cpp index 558c24c..5b0dfc3 100644 --- a/dScripts/ai/MINIGAME/SG_GF/SERVER/SGCannon.cpp +++ b/dScripts/ai/MINIGAME/SG_GF/SERVER/SGCannon.cpp @@ -546,13 +546,13 @@ void SGCannon::StopGame(Entity* self, bool cancel) { // The player won, store all the score and send rewards if (!cancel) { - int32_t percentage = 50; + int32_t percentage = 0.0f; auto misses = self->GetVar(MissesVariable); auto fired = self->GetVar(ShotsFiredVariable); - // if (fired > 0) { - // percentage = misses / fired; - // } + if (fired > 0) { + percentage = misses / fired; + } auto* missionComponent = player->GetComponent(); @@ -566,7 +566,7 @@ void SGCannon::StopGame(Entity* self, bool cancel) { StopActivity(self, player->GetObjectID(), self->GetVar(TotalScoreVariable), self->GetVar(MaxStreakVariable), percentage); SaveScore(self, player->GetObjectID(), - static_cast(self->GetVar(TotalScoreVariable)), percentage, static_cast(self->GetVar(MaxStreakVariable))); + static_cast(self->GetVar(TotalScoreVariable)), static_cast(self->GetVar(MaxStreakVariable)), percentage); self->SetNetworkVar(AudioFinalWaveDoneVariable, true); // Give the player the model rewards they earned @@ -580,17 +580,6 @@ void SGCannon::StopGame(Entity* self, bool cancel) { self->SetNetworkVar(u"UI_Rewards", GeneralUtils::to_u16string(self->GetVar(TotalScoreVariable)) + u"_0_0_0_0_0_0" ); - - GameMessages::SendRequestActivitySummaryLeaderboardData( - player->GetObjectID(), - self->GetObjectID(), - player->GetSystemAddress(), - GetGameID(self), - 1, - 10, - 0, - false - ); } GameMessages::SendActivityStop(self->GetObjectID(), false, cancel, player->GetSystemAddress()); diff --git a/migrations/dlu/9_Update_Leaderboard_Storage.sql b/migrations/dlu/9_Update_Leaderboard_Storage.sql index a68cc2d..c87e350 100644 --- a/migrations/dlu/9_Update_Leaderboard_Storage.sql +++ b/migrations/dlu/9_Update_Leaderboard_Storage.sql @@ -5,8 +5,6 @@ ALTER TABLE leaderboard MODIFY time INT NOT NULL DEFAULT 0; /* Can only ALTER one column at a time... */ -ALTER TABLE leaderboard - CHANGE last_played last_played TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP() ON UPDATE CURRENT_TIMESTAMP(); ALTER TABLE leaderboard CHANGE score primaryScore FLOAT NOT NULL DEFAULT 0; ALTER TABLE leaderboard CHANGE time secondaryScore FLOAT NOT NULL DEFAULT 0 AFTER primaryScore; @@ -14,3 +12,7 @@ ALTER TABLE leaderboard CHANGE time secondaryScore FLOAT NOT NULL DEFAULT 0 AFTE UPDATE leaderboard SET primaryScore = secondaryScore, secondaryScore = 0 WHERE game_id IN (1, 44, 46, 47, 48, 49, 53, 103, 104, 108, 1901); + +/* Do this last so we dont update entry times erroneously */ +ALTER TABLE leaderboard + CHANGE last_played last_played TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP() ON UPDATE CURRENT_TIMESTAMP();