mirror of
https://github.com/DarkflameUniverse/DarkflameServer.git
synced 2026-11-30 01:41:40 +00:00
fix(preconditions): items sold to a vendor do not count as held
The client's HasItem and DoesNotHaveItem checks count the item with ignoreBuyBack set (LWOPreconditionComponent), so what was sold to a vendor and sits in the buy back list is not held. The count here took every inventory, buy back included; the item cost of a quickbuild is picked with the same count. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
This commit is contained in:
@@ -203,6 +203,18 @@ uint32_t InventoryComponent::GetLotCount(const LOT lot) const {
|
||||
return count;
|
||||
}
|
||||
|
||||
uint32_t InventoryComponent::GetLotCountWithoutBuyBack(const LOT lot) const {
|
||||
uint32_t count = 0;
|
||||
|
||||
for (const auto& inventory : m_Inventories) {
|
||||
if (inventory.second->GetType() == eInventoryType::VENDOR_BUYBACK) continue;
|
||||
|
||||
count += inventory.second->GetLotCount(lot);
|
||||
}
|
||||
|
||||
return count;
|
||||
}
|
||||
|
||||
uint32_t InventoryComponent::GetLotCountNonTransfer(LOT lot, bool includeVault) const {
|
||||
uint32_t count = 0;
|
||||
|
||||
|
||||
@@ -142,6 +142,14 @@ public:
|
||||
*/
|
||||
uint32_t GetLotCount(LOT lot) const;
|
||||
|
||||
/**
|
||||
* Returns the amount of items this entity possesses of a certain LOT, leaving out what it sold to a vendor and
|
||||
* can still buy back: the count the client's precondition check asks for (GetInvItemCount with ignoreBuyBack)
|
||||
* @param lot the lot to search for
|
||||
* @return the amount of items of the LOT outside the vendor buy back inventory
|
||||
*/
|
||||
uint32_t GetLotCountWithoutBuyBack(LOT lot) const;
|
||||
|
||||
/**
|
||||
* Returns the amount of items this entity possesses of a LOT, given that they're not in a temporary inventory
|
||||
* (vendor buyback, vault, etc).
|
||||
|
||||
@@ -145,7 +145,8 @@ bool Precondition::CheckValue(Entity* player, const uint32_t value) const {
|
||||
return !inventoryComponent->IsEquipped(value);
|
||||
case PreconditionType::HasItem:
|
||||
case PreconditionType::DoesNotHaveItem:
|
||||
return ItemCountPasses(type, inventoryComponent->GetLotCount(value), count);
|
||||
// an unnamed client function counts with ignoreBuyBack set: an item sold to a vendor is no longer held
|
||||
return ItemCountPasses(type, inventoryComponent->GetLotCountWithoutBuyBack(value), count);
|
||||
case PreconditionType::HasAchievement:
|
||||
if (missionComponent == nullptr) return false;
|
||||
return missionComponent->GetMissionState(value) >= eMissionState::COMPLETE;
|
||||
@@ -271,7 +272,7 @@ std::optional<ItemCost> Precondition::GetItemCost(Entity* player) const {
|
||||
if (type != PreconditionType::HasItem || count == 0) return std::nullopt;
|
||||
auto* const inventoryComponent = player->GetComponent<InventoryComponent>();
|
||||
if (!inventoryComponent) return std::nullopt;
|
||||
return PickItemCost(values, count, [inventoryComponent](const LOT lot) { return inventoryComponent->GetLotCount(lot); });
|
||||
return PickItemCost(values, count, [inventoryComponent](const LOT lot) { return inventoryComponent->GetLotCountWithoutBuyBack(lot); });
|
||||
}
|
||||
|
||||
std::vector<ItemCost> PreconditionExpression::GetItemCosts(Entity* player) const {
|
||||
|
||||
@@ -114,3 +114,24 @@ TEST_F(PreconditionCheckTests, RacingLicenceOfAPlayerWithoutTheMission) {
|
||||
EXPECT_FALSE(Preconditions::Check(player.get(), Row(PreconditionType::HasRacingLicence, "1", 1, 253)));
|
||||
EXPECT_TRUE(Preconditions::Check(player.get(), Row(PreconditionType::DoesNotHaveRacingLicence, "1", 1, 253)));
|
||||
}
|
||||
|
||||
// Types 2 and 3 count the item everywhere but in the vendor buy back inventory (the client's count sets ignoreBuyBack)
|
||||
TEST_F(PreconditionCheckTests, ItemsSoldToAVendorAreNotHeld) {
|
||||
const auto hasFive = Row(PreconditionType::HasItem, "6194", 5, 255);
|
||||
const auto hasNone = Row(PreconditionType::DoesNotHaveItem, "6194", 1, 255);
|
||||
|
||||
Give(eInventoryType::VENDOR_BUYBACK, 5);
|
||||
EXPECT_EQ(inventory->GetLotCount(BRICK), 5u);
|
||||
EXPECT_EQ(inventory->GetLotCountWithoutBuyBack(BRICK), 0u);
|
||||
EXPECT_FALSE(Preconditions::Check(player.get(), hasFive));
|
||||
EXPECT_TRUE(Preconditions::Check(player.get(), hasNone));
|
||||
// Nothing is taken as a cost from what the player no longer holds
|
||||
EXPECT_FALSE(Preconditions::Get(hasFive).GetItemCost(player.get()).has_value());
|
||||
|
||||
Give(eInventoryType::ITEMS, 3);
|
||||
Give(eInventoryType::VAULT_ITEMS, 2);
|
||||
EXPECT_EQ(inventory->GetLotCountWithoutBuyBack(BRICK), 5u);
|
||||
EXPECT_TRUE(Preconditions::Check(player.get(), hasFive));
|
||||
EXPECT_FALSE(Preconditions::Check(player.get(), hasNone));
|
||||
EXPECT_EQ(Preconditions::Get(hasFive).GetItemCost(player.get()), (ItemCost{ BRICK, 5 }));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user