From 34665f6f5c0ee60535192fee6a218a9306c0af3c Mon Sep 17 00:00:00 2001 From: ElectScholar Date: Fri, 23 May 2025 03:42:39 +0000 Subject: [PATCH] Fix: Double imaginite issue resolved on mini survival games (#1801) * Add checkcost as replacement for just inventory checks * Create headers for cost methods * clean comments --- dGame/dComponents/ActivityComponent.cpp | 16 ++++++++++++---- dGame/dComponents/ActivityComponent.h | 9 ++++++++- 2 files changed, 20 insertions(+), 5 deletions(-) diff --git a/dGame/dComponents/ActivityComponent.cpp b/dGame/dComponents/ActivityComponent.cpp index 0e6778b0..cd71c5cb 100644 --- a/dGame/dComponents/ActivityComponent.cpp +++ b/dGame/dComponents/ActivityComponent.cpp @@ -334,7 +334,7 @@ bool ActivityComponent::IsPlayedBy(LWOOBJID playerID) const { return false; } -bool ActivityComponent::TakeCost(Entity* player) const { +bool ActivityComponent::CheckCost(Entity* player) const { if (m_ActivityInfo.optionalCostLOT <= 0 || m_ActivityInfo.optionalCostCount <= 0) return true; @@ -345,11 +345,19 @@ bool ActivityComponent::TakeCost(Entity* player) const { if (inventoryComponent->GetLotCount(m_ActivityInfo.optionalCostLOT) < m_ActivityInfo.optionalCostCount) return false; - inventoryComponent->RemoveItem(m_ActivityInfo.optionalCostLOT, m_ActivityInfo.optionalCostCount); - return true; } +bool ActivityComponent::TakeCost(Entity* player) const{ + + auto* inventoryComponent = player->GetComponent(); + if (CheckCost(player)) { + inventoryComponent->RemoveItem(m_ActivityInfo.optionalCostLOT, m_ActivityInfo.optionalCostCount); + return true; + } + else return false; +} + void ActivityComponent::PlayerReady(Entity* player, bool bReady) { for (Lobby* lobby : m_Queue) { for (LobbyPlayer* lobbyPlayer : lobby->players) { @@ -382,7 +390,7 @@ ActivityInstance* ActivityComponent::NewInstance() { void ActivityComponent::LoadPlayersIntoInstance(ActivityInstance* instance, const std::vector& lobby) const { for (LobbyPlayer* player : lobby) { auto* entity = player->GetEntity(); - if (entity == nullptr || !TakeCost(entity)) { + if (entity == nullptr || !CheckCost(entity)) { continue; } diff --git a/dGame/dComponents/ActivityComponent.h b/dGame/dComponents/ActivityComponent.h index 296c6ccc..ec482a42 100644 --- a/dGame/dComponents/ActivityComponent.h +++ b/dGame/dComponents/ActivityComponent.h @@ -234,10 +234,17 @@ public: */ bool IsPlayedBy(LWOOBJID playerID) const; + /** + * Checks if the entity has enough cost to play this activity + * @param player the entity to check + * @return true if the entity has enough cost to play this activity, false otherwise + */ + bool CheckCost(Entity* player) const; + /** * Removes the cost of the activity (e.g. green imaginate) for the entity that plays this activity * @param player the entity to take cost for - * @return true if the cost was successfully deducted, false otherwise + * @return true if the cost was taken, false otherwise */ bool TakeCost(Entity* player) const;