From 8ceabadcded407f424c65c7cacc825c761840daf Mon Sep 17 00:00:00 2001 From: Aaron Kimbrell Date: Mon, 8 May 2023 04:38:08 -0500 Subject: [PATCH] Removed some hardcoded logic for racing (#1075) Including return world and what activity ID to use for rewards --- dGame/dComponents/RacingControlComponent.cpp | 36 +++++-------------- .../dComponents/ScriptedActivityComponent.cpp | 6 ++-- dGame/dUtilities/SlashCommandHandler.cpp | 17 ++------- dGame/dUtilities/SlashCommandHandler.h | 2 -- dZoneManager/dZoneManager.cpp | 13 +++++++ dZoneManager/dZoneManager.h | 1 + 6 files changed, 27 insertions(+), 48 deletions(-) diff --git a/dGame/dComponents/RacingControlComponent.cpp b/dGame/dComponents/RacingControlComponent.cpp index 703ec7f3..3134d5fe 100644 --- a/dGame/dComponents/RacingControlComponent.cpp +++ b/dGame/dComponents/RacingControlComponent.cpp @@ -23,6 +23,8 @@ #include "dConfig.h" #include "Loot.h" #include "eMissionTaskType.h" +#include "dZoneManager.h" +#include "CDActivitiesTable.h" #ifndef M_PI #define M_PI 3.14159265358979323846264338327950288 @@ -45,36 +47,14 @@ RacingControlComponent::RacingControlComponent(Entity* parent) m_EmptyTimer = 0; m_SoloRacing = Game::config->GetValue("solo_racing") == "1"; - // Select the main world ID as fallback when a player fails to load. - + m_MainWorld = 1200; const auto worldID = Game::server->GetZoneID(); + if (dZoneManager::Instance()->CheckIfAccessibleZone((worldID/10)*10)) m_MainWorld = (worldID/10)*10; - switch (worldID) { - case 1203: - m_ActivityID = 42; - m_MainWorld = 1200; - break; - - case 1261: - m_ActivityID = 60; - m_MainWorld = 1260; - break; - - case 1303: - m_ActivityID = 39; - m_MainWorld = 1300; - break; - - case 1403: - m_ActivityID = 54; - m_MainWorld = 1400; - break; - - default: - m_ActivityID = 42; - m_MainWorld = 1200; - break; - } + m_ActivityID = 42; + CDActivitiesTable* activitiesTable = CDClientManager::Instance().GetTable(); + std::vector activities = activitiesTable->Query([=](CDActivities entry) {return (entry.instanceMapID == worldID); }); + for (CDActivities activity : activities) m_ActivityID = activity.ActivityID; } RacingControlComponent::~RacingControlComponent() {} diff --git a/dGame/dComponents/ScriptedActivityComponent.cpp b/dGame/dComponents/ScriptedActivityComponent.cpp index eb4ab761..555332f4 100644 --- a/dGame/dComponents/ScriptedActivityComponent.cpp +++ b/dGame/dComponents/ScriptedActivityComponent.cpp @@ -27,6 +27,7 @@ #include "CDCurrencyTableTable.h" #include "CDActivityRewardsTable.h" #include "CDActivitiesTable.h" +#include "LeaderboardManager.h" ScriptedActivityComponent::ScriptedActivityComponent(Entity* parent, int activityID) : Component(parent) { m_ActivityID = activityID; @@ -35,10 +36,7 @@ ScriptedActivityComponent::ScriptedActivityComponent(Entity* parent, int activit for (CDActivities activity : activities) { m_ActivityInfo = activity; - - const auto mapID = m_ActivityInfo.instanceMapID; - - if ((mapID == 1203 || mapID == 1261 || mapID == 1303 || mapID == 1403) && Game::config->GetValue("solo_racing") == "1") { + if (static_cast(activity.leaderboardType) == LeaderboardType::Racing && Game::config->GetValue("solo_racing") == "1") { m_ActivityInfo.minTeamSize = 1; m_ActivityInfo.minTeams = 1; } diff --git a/dGame/dUtilities/SlashCommandHandler.cpp b/dGame/dUtilities/SlashCommandHandler.cpp index 07950d7a..16db62a6 100644 --- a/dGame/dUtilities/SlashCommandHandler.cpp +++ b/dGame/dUtilities/SlashCommandHandler.cpp @@ -279,7 +279,7 @@ void SlashCommandHandler::HandleChatCommand(const std::u16string& command, Entit if (chatCommand == "leave-zone") { const auto currentZone = dZoneManager::Instance()->GetZone()->GetZoneID().GetMapID(); - auto newZone = 0; + LWOMAPID newZone = 0; if (currentZone % 100 == 0) { ChatPackets::SendSystemMessage(sysAddr, u"You are not in an instanced zone."); return; @@ -287,7 +287,7 @@ void SlashCommandHandler::HandleChatCommand(const std::u16string& command, Entit newZone = (currentZone / 100) * 100; } // If new zone would be inaccessible, then default to Avant Gardens. - if (!CheckIfAccessibleZone(newZone)) newZone = 1100; + if (!dZoneManager::Instance()->CheckIfAccessibleZone(newZone)) newZone = 1100; ChatPackets::SendSystemMessage(sysAddr, u"Leaving zone..."); @@ -1559,7 +1559,7 @@ void SlashCommandHandler::HandleChatCommand(const std::u16string& command, Entit const auto objid = entity->GetObjectID(); - if (force || CheckIfAccessibleZone(reqZone)) { // to prevent tomfoolery + if (force || dZoneManager::Instance()->CheckIfAccessibleZone(reqZone)) { // to prevent tomfoolery ZoneInstanceManager::Instance()->RequestZoneTransfer(Game::server, reqZone, cloneId, false, [objid](bool mythranShift, uint32_t zoneID, uint32_t zoneInstance, uint32_t zoneClone, std::string serverIP, uint16_t serverPort) { @@ -2021,17 +2021,6 @@ void SlashCommandHandler::HandleChatCommand(const std::u16string& command, Entit } } -bool SlashCommandHandler::CheckIfAccessibleZone(const unsigned int zoneID) { - //We're gonna go ahead and presume we've got the db loaded already: - CDZoneTableTable* zoneTable = CDClientManager::Instance().GetTable(); - const CDZoneTable* zone = zoneTable->Query(zoneID); - if (zone != nullptr) { - return Game::assetManager->HasFile(("maps/" + zone->zoneName).c_str()); - } else { - return false; - } -} - void SlashCommandHandler::SendAnnouncement(const std::string& title, const std::string& message) { AMFArrayValue args; auto* titleValue = new AMFStringValue(); diff --git a/dGame/dUtilities/SlashCommandHandler.h b/dGame/dUtilities/SlashCommandHandler.h index 9ef09a2f..85b7c697 100644 --- a/dGame/dUtilities/SlashCommandHandler.h +++ b/dGame/dUtilities/SlashCommandHandler.h @@ -13,8 +13,6 @@ class Entity; namespace SlashCommandHandler { void HandleChatCommand(const std::u16string& command, Entity* entity, const SystemAddress& sysAddr); - bool CheckIfAccessibleZone(const unsigned int zoneID); - void SendAnnouncement(const std::string& title, const std::string& message); }; diff --git a/dZoneManager/dZoneManager.cpp b/dZoneManager/dZoneManager.cpp index 1a40748d..a26e912f 100644 --- a/dZoneManager/dZoneManager.cpp +++ b/dZoneManager/dZoneManager.cpp @@ -12,6 +12,8 @@ #include "CDZoneTableTable.h" #include #include "eObjectBits.h" +#include "CDZoneTableTable.h" +#include "AssetManager.h" #include "../dWorldServer/ObjectIDManager.h" @@ -227,6 +229,17 @@ uint32_t dZoneManager::GetUniqueMissionIdStartingValue() { return m_UniqueMissionIdStart; } +bool dZoneManager::CheckIfAccessibleZone(LWOMAPID zoneID) { + //We're gonna go ahead and presume we've got the db loaded already: + CDZoneTableTable* zoneTable = CDClientManager::Instance().GetTable(); + const CDZoneTable* zone = zoneTable->Query(zoneID); + if (zone != nullptr) { + return Game::assetManager->HasFile(("maps/" + zone->zoneName).c_str()); + } else { + return false; + } +} + void dZoneManager::LoadWorldConfig() { Game::logger->Log("dZoneManager", "Loading WorldConfig into memory"); diff --git a/dZoneManager/dZoneManager.h b/dZoneManager/dZoneManager.h index c1776e79..3086e6d7 100644 --- a/dZoneManager/dZoneManager.h +++ b/dZoneManager/dZoneManager.h @@ -50,6 +50,7 @@ public: Entity* GetZoneControlObject() { return m_ZoneControlObject; } bool GetPlayerLoseCoinOnDeath() { return m_PlayerLoseCoinsOnDeath; } uint32_t GetUniqueMissionIdStartingValue(); + bool CheckIfAccessibleZone(LWOMAPID zoneID); // The world config should not be modified by a caller. const WorldConfig* GetWorldConfig() {