From e4469f997ec10c63e9e1c3972542ae6b0cfdfe94 Mon Sep 17 00:00:00 2001 From: David Markowitz <39972741+EmosewaMC@users.noreply.github.com> Date: Sun, 7 Jan 2024 05:43:53 -0800 Subject: [PATCH] fix: activity id not using overridden id (#1400) * patch activity id not using overridden id Update ActivityComponent.h * Update ActivityComponent.cpp * Update ActivityComponent.cpp --- dGame/dComponents/ActivityComponent.cpp | 45 ++++++++++++++++--------- dGame/dComponents/ActivityComponent.h | 2 ++ 2 files changed, 31 insertions(+), 16 deletions(-) diff --git a/dGame/dComponents/ActivityComponent.cpp b/dGame/dComponents/ActivityComponent.cpp index 7ea7500b..7d9e37da 100644 --- a/dGame/dComponents/ActivityComponent.cpp +++ b/dGame/dComponents/ActivityComponent.cpp @@ -30,23 +30,17 @@ #include "LeaderboardManager.h" ActivityComponent::ActivityComponent(Entity* parent, int32_t activityID) : Component(parent) { - if (activityID > 0) m_ActivityID = activityID; - else m_ActivityID = parent->GetVar(u"activityID"); - CDActivitiesTable* activitiesTable = CDClientManager::Instance().GetTable(); - std::vector activities = activitiesTable->Query([this](CDActivities entry) {return (entry.ActivityID == m_ActivityID); }); + /* + * This is precisely what the client does functionally + * Use the component id as the default activity id and load its data from the database + * if activityID is specified and if that column exists in the activities table, update the activity info with that data. + */ - for (CDActivities activity : activities) { - m_ActivityInfo = activity; - if (static_cast(activity.leaderboardType) == Leaderboard::Type::Racing && Game::config->GetValue("solo_racing") == "1") { - m_ActivityInfo.minTeamSize = 1; - m_ActivityInfo.minTeams = 1; - } - if (m_ActivityInfo.instanceMapID == -1) { - const auto& transferOverride = parent->GetVarAsString(u"transferZoneID"); - if (!transferOverride.empty()) { - GeneralUtils::TryParse(transferOverride, m_ActivityInfo.instanceMapID); - } - } + m_ActivityID = activityID; + LoadActivityData(activityID); + if (m_Parent->HasVar(u"activityID")) { + m_ActivityID = parent->GetVar(u"activityID"); + LoadActivityData(m_ActivityID); } auto* destroyableComponent = m_Parent->GetComponent(); @@ -74,6 +68,25 @@ ActivityComponent::ActivityComponent(Entity* parent, int32_t activityID) : Compo } } } +void ActivityComponent::LoadActivityData(const int32_t activityId) { + CDActivitiesTable* activitiesTable = CDClientManager::Instance().GetTable(); + std::vector activities = activitiesTable->Query([activityId](CDActivities entry) {return (entry.ActivityID == activityId); }); + + bool soloRacing = Game::config->GetValue("solo_racing") == "1"; + for (CDActivities activity : activities) { + m_ActivityInfo = activity; + if (static_cast(activity.leaderboardType) == Leaderboard::Type::Racing && soloRacing) { + m_ActivityInfo.minTeamSize = 1; + m_ActivityInfo.minTeams = 1; + } + if (m_ActivityInfo.instanceMapID == -1) { + const auto& transferOverride = m_Parent->GetVarAsString(u"transferZoneID"); + if (!transferOverride.empty()) { + GeneralUtils::TryParse(transferOverride, m_ActivityInfo.instanceMapID); + } + } + } +} void ActivityComponent::Serialize(RakNet::BitStream* outBitStream, bool bIsInitialUpdate) { outBitStream->Write(m_DirtyActivityInfo); diff --git a/dGame/dComponents/ActivityComponent.h b/dGame/dComponents/ActivityComponent.h index 96dbd5fb..de63b343 100644 --- a/dGame/dComponents/ActivityComponent.h +++ b/dGame/dComponents/ActivityComponent.h @@ -152,6 +152,8 @@ class ActivityComponent : public Component { public: ActivityComponent(Entity* parent, int32_t activityID); + void LoadActivityData(const int32_t activityId); + void Update(float deltaTime) override; void Serialize(RakNet::BitStream* outBitStream, bool bIsInitialUpdate) override;