diff --git a/dGame/dComponents/InventoryComponent.cpp b/dGame/dComponents/InventoryComponent.cpp index 076625164..cba009546 100644 --- a/dGame/dComponents/InventoryComponent.cpp +++ b/dGame/dComponents/InventoryComponent.cpp @@ -1688,12 +1688,14 @@ bool InventoryComponent::SetSkill(BehaviorSlot slot, uint32_t skillId) { void InventoryComponent::UpdateGroup(const GroupUpdate& groupUpdate) { if (groupUpdate.groupId.empty()) return; - if (groupUpdate.inventory != eInventoryType::BRICKS && groupUpdate.inventory != eInventoryType::MODELS) { + // The model vault shares the models' groups (the client's m_VaultToPlayerInventory: VAULT_MODELS -> MODELS) + const auto inventory = groupUpdate.inventory == eInventoryType::VAULT_MODELS ? eInventoryType::MODELS : groupUpdate.inventory; + if (inventory != eInventoryType::BRICKS && inventory != eInventoryType::MODELS) { LOG("Invalid inventory type for grouping %s", StringifiedEnum::ToString(groupUpdate.inventory).data()); return; } - auto& groups = m_Groups[groupUpdate.inventory]; + auto& groups = m_Groups[inventory]; auto groupItr = std::ranges::find_if(groups, [&groupUpdate](const Group& group) { return group.groupId == groupUpdate.groupId; }); diff --git a/dGame/dComponents/InventoryComponent.h b/dGame/dComponents/InventoryComponent.h index d7b67cfc2..a46954937 100644 --- a/dGame/dComponents/InventoryComponent.h +++ b/dGame/dComponents/InventoryComponent.h @@ -409,6 +409,8 @@ public: void UpdateGroup(const GroupUpdate& groupUpdate); + const std::map>& GetGroups() const { return m_Groups; } + std::unordered_map& GetPetsMut() { return m_Pets; }; void FixInvisibleItems(); diff --git a/tests/dGameTests/dComponentsTests/CMakeLists.txt b/tests/dGameTests/dComponentsTests/CMakeLists.txt index f73f1214c..776074a5b 100644 --- a/tests/dGameTests/dComponentsTests/CMakeLists.txt +++ b/tests/dGameTests/dComponentsTests/CMakeLists.txt @@ -1,5 +1,7 @@ set(DCOMPONENTS_TESTS "DestroyableComponentTests.cpp" + "InventoryGroupTests.cpp" + "ModelComponentTests.cpp" "PetComponentTests.cpp" "SimplePhysicsComponentTests.cpp" "SavingTests.cpp" diff --git a/tests/dGameTests/dComponentsTests/InventoryGroupTests.cpp b/tests/dGameTests/dComponentsTests/InventoryGroupTests.cpp new file mode 100644 index 000000000..acb7a73bb --- /dev/null +++ b/tests/dGameTests/dComponentsTests/InventoryGroupTests.cpp @@ -0,0 +1,56 @@ +#include "GameDependencies.h" + +#include "CDClientManager.h" +#include "CDComponentsRegistryTable.h" +#include "Entity.h" +#include "InventoryComponent.h" + +#include + +class InventoryGroupTests : public GameDependenciesTest { +protected: + std::unique_ptr entity; + InventoryComponent* inventory{}; + + void SetUp() override { + SetUpDependencies(); + CDClientManager::GetEntriesMutable().insert_or_assign(static_cast(info.lot), 0); + entity = std::make_unique(1, info); + inventory = entity->AddComponent(-1); + } + + void TearDown() override { + entity.reset(); + TearDownDependencies(); + } + + void Update(const InventoryComponent::GroupUpdateCommand command, const std::string& id, const eInventoryType type, const LOT lot = LOT_NULL) { + InventoryComponent::GroupUpdate update{}; + update.groupId = id; + update.groupName = "name"; + update.lot = lot; + update.inventory = type; + update.command = command; + inventory->UpdateGroup(update); + } +}; + +// The client's LWOInventoryComponent_Common::msgUpdateInventoryGroup (0x00c955b0) and msgUpdateInventoryGroupContents +// (0x00ce1f50) map the model vault to the models inventory (m_VaultToPlayerInventory) +TEST_F(InventoryGroupTests, TheModelVaultUsesTheModelsGroups) { + Update(InventoryComponent::GroupUpdateCommand::ADD, "user_group1", eInventoryType::VAULT_MODELS); + Update(InventoryComponent::GroupUpdateCommand::ADD_LOT, "user_group1", eInventoryType::VAULT_MODELS, 3001); + + const auto& groups = inventory->GetGroups(); + ASSERT_EQ(groups.at(eInventoryType::MODELS).size(), 1u); + EXPECT_EQ(groups.at(eInventoryType::MODELS)[0].lots.size(), 1u); + EXPECT_FALSE(groups.contains(eInventoryType::VAULT_MODELS)); +} + +TEST_F(InventoryGroupTests, OnlyBricksAndModelsHaveGroups) { + Update(InventoryComponent::GroupUpdateCommand::ADD, "user_group1", eInventoryType::ITEMS); + EXPECT_FALSE(inventory->GetGroups().contains(eInventoryType::ITEMS)); + + Update(InventoryComponent::GroupUpdateCommand::ADD, "user_group1", eInventoryType::BRICKS); + EXPECT_EQ(inventory->GetGroups().at(eInventoryType::BRICKS).size(), 1u); +}