From 64ea61325674b9ce0905aea41f2e45890f084ce9 Mon Sep 17 00:00:00 2001 From: Aaron Kimbrell Date: Tue, 10 Nov 2026 21:00:37 -0600 Subject: [PATCH] fix(preconditions): the racing licence types follow the licence mission LWOPreconditionComponent::CheckPrecondition answers type 16 with "the racing licence level is at least the value" and type 17 with the opposite. The level comes from the mission component: 1 once mission 637 has been completed, 0 before (LWORacingMissions::SendMessage). Both types always failed here, so the item that asks for a licence (precondition 67) could not be used by anybody. Co-Authored-By: Claude Fable 5.2 --- dGame/dUtilities/Preconditions.cpp | 11 +++++++++-- dGame/dUtilities/Preconditions.h | 8 ++++++++ tests/dGameTests/PreconditionItemCostTests.cpp | 13 +++++++++++++ 3 files changed, 30 insertions(+), 2 deletions(-) diff --git a/dGame/dUtilities/Preconditions.cpp b/dGame/dUtilities/Preconditions.cpp index 4f1b9a06a..81fdc6dfa 100644 --- a/dGame/dUtilities/Preconditions.cpp +++ b/dGame/dUtilities/Preconditions.cpp @@ -115,6 +115,13 @@ bool Precondition::MetByAnyValue(const PreconditionType type) { } } +uint32_t Precondition::RacingLicenceLevel(const eMissionState licenceMission) { + // The state's COMPLETE bit (UNKNOWN, -1, is no state) + const auto state = static_cast(licenceMission); + const bool completed = state > 0 && (state & static_cast(eMissionState::COMPLETE)) != 0; + return completed ? 1 : 0; +} + bool Precondition::ItemCountPasses(const PreconditionType type, const uint32_t held, const uint32_t count) { // LWOPreconditionComponent::CheckPrecondition: type 3 is the opposite of type 2's count check return type == PreconditionType::DoesNotHaveItem ? held < count : held >= count; @@ -183,9 +190,9 @@ bool Precondition::CheckValue(Entity* player, const uint32_t value) const { return true; case PreconditionType::HasRacingLicence: - return false; // TODO: requires a racing licence level on the player; DLU does not track this + return RacingLicenceLevel(missionComponent->GetMissionState(RACING_LICENCE_MISSION)) >= value; case PreconditionType::DoesNotHaveRacingLicence: - return false; // TODO: requires a racing licence level on the player; DLU does not track this + return RacingLicenceLevel(missionComponent->GetMissionState(RACING_LICENCE_MISSION)) < value; case PreconditionType::LegoClubMember: return true; // Live LU opened LEGO CLUB to All players at some point, so always return true case PreconditionType::NoInteraction: diff --git a/dGame/dUtilities/Preconditions.h b/dGame/dUtilities/Preconditions.h index 37399e2a5..ac4551282 100644 --- a/dGame/dUtilities/Preconditions.h +++ b/dGame/dUtilities/Preconditions.h @@ -4,6 +4,7 @@ #include #include "Entity.h" +#include "eMissionState.h" enum class PreconditionType @@ -72,6 +73,13 @@ public: // Whether a precondition listing several values is met by any one of them (true) or needs every one (false) static bool MetByAnyValue(PreconditionType type); + // The racing licence level the HasRacingLicence types compare their value with: 1 once the mission that makes + // the player a licensed racer has been completed, 0 before (LWORacingMissions::SendMessage) + static uint32_t RacingLicenceLevel(eMissionState licenceMission); + + // That mission + static constexpr uint32_t RACING_LICENCE_MISSION = 637; + // Whether holding this many of a LOT meets a HasItem (enough) or a DoesNotHaveItem (fewer) precondition static bool ItemCountPasses(PreconditionType type, uint32_t held, uint32_t count); diff --git a/tests/dGameTests/PreconditionItemCostTests.cpp b/tests/dGameTests/PreconditionItemCostTests.cpp index e5b68ad36..63e25ed93 100644 --- a/tests/dGameTests/PreconditionItemCostTests.cpp +++ b/tests/dGameTests/PreconditionItemCostTests.cpp @@ -111,3 +111,16 @@ TEST(PreconditionItemCostTests, ValidContextsWithoutAContext) { for (const uint64_t all : { 255ULL, 253ULL, 252ULL, 249ULL, 5ULL, 8ULL, ~0ULL }) EXPECT_TRUE(Precondition::AppliesIn(all, None)) << all; for (const uint64_t few : { 1ULL, 2ULL, 3ULL, 4ULL }) EXPECT_FALSE(Precondition::AppliesIn(few, None)) << few; } + +// Types 16 and 17 compare their value with the player's racing licence level, which the client's mission component +// answers (LWORacingMissions::SendMessage): 1 once mission 637 has been completed, repeatable or not +TEST(PreconditionItemCostTests, RacingLicenceLevelFollowsTheLicenceMission) { + EXPECT_EQ(Precondition::RACING_LICENCE_MISSION, 637u); + for (const auto state : { eMissionState::UNKNOWN, eMissionState::AVAILABLE, eMissionState::ACTIVE, eMissionState::READY_TO_COMPLETE }) { + EXPECT_EQ(Precondition::RacingLicenceLevel(state), 0u) << static_cast(state); + } + for (const auto state : { eMissionState::COMPLETE, eMissionState::COMPLETE_AVAILABLE, eMissionState::COMPLETE_ACTIVE, + eMissionState::COMPLETE_READY_TO_COMPLETE }) { + EXPECT_EQ(Precondition::RacingLicenceLevel(state), 1u) << static_cast(state); + } +}