mirror of
https://github.com/DarkflameUniverse/DarkflameServer.git
synced 2026-11-30 01:41:40 +00:00
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 <noreply@anthropic.com>
127 lines
7.3 KiB
C++
127 lines
7.3 KiB
C++
#include "Preconditions.h"
|
|
|
|
#include <map>
|
|
|
|
#include <gtest/gtest.h>
|
|
|
|
// The items a quickbuild's HasItem precondition takes when the build starts
|
|
// (the FV Stone Warrior pedestal: precondition 99, 5 of LOT 6194).
|
|
|
|
namespace {
|
|
std::function<uint32_t(LOT)> Holding(const std::map<LOT, uint32_t>& inventory) {
|
|
return [inventory](const LOT lot) {
|
|
const auto it = inventory.find(lot);
|
|
return it == inventory.end() ? 0u : it->second;
|
|
};
|
|
}
|
|
}
|
|
|
|
TEST(PreconditionItemCostTests, TakesTheCountOfTheHeldLot) {
|
|
EXPECT_EQ(Precondition::PickItemCost({ 6194 }, 5, Holding({ { 6194, 7 } })), (ItemCost{ 6194, 5 }));
|
|
EXPECT_EQ(Precondition::PickItemCost({ 6194 }, 5, Holding({ { 6194, 5 } })), (ItemCost{ 6194, 5 }));
|
|
}
|
|
|
|
TEST(PreconditionItemCostTests, NotEnoughTakesNothing) {
|
|
EXPECT_FALSE(Precondition::PickItemCost({ 6194 }, 5, Holding({ { 6194, 4 } })));
|
|
EXPECT_FALSE(Precondition::PickItemCost({ 6194 }, 5, Holding({})));
|
|
}
|
|
|
|
// A precondition that lists several LOTs is met by any of them: the first one held is taken
|
|
TEST(PreconditionItemCostTests, TakesTheFirstHeldOfSeveralLots) {
|
|
EXPECT_EQ(Precondition::PickItemCost({ 100, 200, 300 }, 2, Holding({ { 100, 1 }, { 200, 2 }, { 300, 9 } })), (ItemCost{ 200, 2 }));
|
|
}
|
|
|
|
// Precondition 3 (DoesNotHaveItem, LOT 2633, count 1) is met while the player holds none of the item: the client
|
|
// negates the HasItem count check for it
|
|
TEST(PreconditionItemCostTests, DoesNotHaveItemIsTheOppositeOfHasItem) {
|
|
EXPECT_TRUE(Precondition::ItemCountPasses(PreconditionType::DoesNotHaveItem, 0, 1));
|
|
EXPECT_FALSE(Precondition::ItemCountPasses(PreconditionType::DoesNotHaveItem, 1, 1));
|
|
EXPECT_FALSE(Precondition::ItemCountPasses(PreconditionType::DoesNotHaveItem, 3, 1));
|
|
EXPECT_TRUE(Precondition::ItemCountPasses(PreconditionType::DoesNotHaveItem, 4, 5));
|
|
|
|
EXPECT_FALSE(Precondition::ItemCountPasses(PreconditionType::HasItem, 0, 1));
|
|
EXPECT_TRUE(Precondition::ItemCountPasses(PreconditionType::HasItem, 1, 1));
|
|
EXPECT_FALSE(Precondition::ItemCountPasses(PreconditionType::HasItem, 4, 5));
|
|
}
|
|
|
|
// The client's list checks stop at the first value that meets them; the "not" types negate that, so every value
|
|
// has to pass. Precondition 66 (DoesNotHaveFaction "1,33") fails for a player of faction 1.
|
|
TEST(PreconditionItemCostTests, NotTypesNeedEveryValue) {
|
|
for (const auto type : { PreconditionType::ItemNotEquipped, PreconditionType::DoesNotHaveItem, PreconditionType::DoesNotHaveFaction,
|
|
PreconditionType::DoesNotHaveRacingLicence, PreconditionType::DoesNotHaveFlag }) {
|
|
EXPECT_FALSE(Precondition::MetByAnyValue(type)) << static_cast<int>(type);
|
|
}
|
|
for (const auto type : { PreconditionType::ItemEquipped, PreconditionType::HasItem, PreconditionType::HasAchievement,
|
|
PreconditionType::MissionAvailable, PreconditionType::OnMission, PreconditionType::MissionComplete, PreconditionType::HasFlag,
|
|
PreconditionType::HasFaction, PreconditionType::HasRacingLicence, PreconditionType::MissionActive, PreconditionType::HasLevel }) {
|
|
EXPECT_TRUE(Precondition::MetByAnyValue(type)) << static_cast<int>(type);
|
|
}
|
|
}
|
|
|
|
// LWOPreconditionComponent::msgCheckAllPreconditions splits a list at ",;:" into groups that all have to pass, and a
|
|
// group at "|" into alternatives
|
|
TEST(PreconditionItemCostTests, ListIsGroupsOfAlternatives) {
|
|
using Groups = std::vector<std::vector<uint32_t>>;
|
|
EXPECT_EQ(PreconditionExpression::Parse(""), Groups{});
|
|
EXPECT_EQ(PreconditionExpression::Parse("99"), (Groups{ { 99 } }));
|
|
EXPECT_EQ(PreconditionExpression::Parse("62|26"), (Groups{ { 62, 26 } }));
|
|
EXPECT_EQ(PreconditionExpression::Parse("110|26|62"), (Groups{ { 110, 26, 62 } }));
|
|
EXPECT_EQ(PreconditionExpression::Parse("228;62|26"), (Groups{ { 228 }, { 62, 26 } }));
|
|
// An item's "248;290|340;338": the last one is asked whatever the middle group says
|
|
EXPECT_EQ(PreconditionExpression::Parse("248;290|340;338"), (Groups{ { 248 }, { 290, 340 }, { 338 } }));
|
|
EXPECT_EQ(PreconditionExpression::Parse("1,2:3 ; 4"), (Groups{ { 1 }, { 2 }, { 3 }, { 4 } }));
|
|
EXPECT_EQ(PreconditionExpression::Parse(";5;"), (Groups{ { 5 } }));
|
|
}
|
|
|
|
// LWOPreconditionComponent::CheckPrecondition: with a context, a row is checked when its validContexts
|
|
// has the context's bit; where it is not checked, the precondition passes. The table holds 255, 253, 252, 249 and 3.
|
|
TEST(PreconditionItemCostTests, ValidContextsWithAContext) {
|
|
using enum PreconditionContext;
|
|
for (const auto context : { VendorBuy, VendorList, BoundItem }) EXPECT_TRUE(Precondition::AppliesIn(255, context));
|
|
// 253: not while a vendor lists its items
|
|
EXPECT_TRUE(Precondition::AppliesIn(253, VendorBuy));
|
|
EXPECT_FALSE(Precondition::AppliesIn(253, VendorList));
|
|
EXPECT_TRUE(Precondition::AppliesIn(253, BoundItem));
|
|
// 252: not at a vendor (the thinking hat and build mode requirements of bricks and models)
|
|
EXPECT_FALSE(Precondition::AppliesIn(252, VendorBuy));
|
|
EXPECT_FALSE(Precondition::AppliesIn(252, VendorList));
|
|
EXPECT_TRUE(Precondition::AppliesIn(252, BoundItem));
|
|
// 249: the level requirements, which a vendor's list and an item bound to the player leave out
|
|
EXPECT_TRUE(Precondition::AppliesIn(249, VendorBuy));
|
|
EXPECT_FALSE(Precondition::AppliesIn(249, VendorList));
|
|
EXPECT_FALSE(Precondition::AppliesIn(249, BoundItem));
|
|
// 3: at a vendor only
|
|
EXPECT_TRUE(Precondition::AppliesIn(3, VendorBuy));
|
|
EXPECT_TRUE(Precondition::AppliesIn(3, VendorList));
|
|
EXPECT_FALSE(Precondition::AppliesIn(3, BoundItem));
|
|
// Every bit set
|
|
EXPECT_TRUE(Precondition::AppliesIn(~0ULL, BoundItem));
|
|
EXPECT_TRUE(Precondition::AppliesIn(~0ULL, static_cast<PreconditionContext>(40)));
|
|
// The flag is 32 bits wide, taken from the context's low 5 bits and sign extended
|
|
EXPECT_TRUE(Precondition::AppliesIn(1ULL << 31, static_cast<PreconditionContext>(31)));
|
|
EXPECT_TRUE(Precondition::AppliesIn(1ULL << 40, static_cast<PreconditionContext>(31)));
|
|
EXPECT_FALSE(Precondition::AppliesIn(1ULL << 40, static_cast<PreconditionContext>(8)));
|
|
EXPECT_TRUE(Precondition::AppliesIn(1ULL << 8, static_cast<PreconditionContext>(40)));
|
|
}
|
|
|
|
// Without a context every row is checked, except those that only name the vendor or bound item contexts (under 5):
|
|
// preconditions 338 and 339 (a mission completed, validContexts 3) do not stop an item from being used
|
|
TEST(PreconditionItemCostTests, ValidContextsWithoutAContext) {
|
|
using enum PreconditionContext;
|
|
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<int>(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<int>(state);
|
|
}
|
|
}
|