From 6e6a05fc1d71d2292af6953366850bfd3815c031 Mon Sep 17 00:00:00 2001 From: Aaron Kimbrell Date: Thu, 11 May 2023 06:37:02 -0500 Subject: [PATCH] fix: prevent negative imagination (#1083) * fix: prevent negative imagination And fail switch if we don't have enough imagination * Make better --- dGame/dBehaviors/SwitchBehavior.cpp | 2 +- dGame/dComponents/RebuildComponent.cpp | 14 +++++++------- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/dGame/dBehaviors/SwitchBehavior.cpp b/dGame/dBehaviors/SwitchBehavior.cpp index c010f31b..bd261906 100644 --- a/dGame/dBehaviors/SwitchBehavior.cpp +++ b/dGame/dBehaviors/SwitchBehavior.cpp @@ -30,7 +30,7 @@ void SwitchBehavior::Handle(BehaviorContext* context, RakNet::BitStream* bitStre Game::logger->LogDebug("SwitchBehavior", "[%i] State: (%d), imagination: (%i) / (%f)", entity->GetLOT(), state, destroyableComponent->GetImagination(), destroyableComponent->GetMaxImagination()); - if (state || (entity->GetLOT() == 8092 && destroyableComponent->GetImagination() >= m_imagination)) { + if (state) { this->m_actionTrue->Handle(context, bitStream, branch); } else { this->m_actionFalse->Handle(context, bitStream, branch); diff --git a/dGame/dComponents/RebuildComponent.cpp b/dGame/dComponents/RebuildComponent.cpp index fcf2738c..acd84a64 100644 --- a/dGame/dComponents/RebuildComponent.cpp +++ b/dGame/dComponents/RebuildComponent.cpp @@ -196,18 +196,18 @@ void RebuildComponent::Update(float deltaTime) { DestroyableComponent* destComp = builder->GetComponent(); if (!destComp) break; - int newImagination = destComp->GetImagination() - 1; + int newImagination = destComp->GetImagination(); + if (newImagination <= 0) { + CancelRebuild(builder, eQuickBuildFailReason::OUT_OF_IMAGINATION, true); + break; + } + ++m_DrainedImagination; + --newImagination; destComp->SetImagination(newImagination); EntityManager::Instance()->SerializeEntity(builder); - ++m_DrainedImagination; - if (newImagination == 0 && m_DrainedImagination < m_TakeImagination) { - CancelRebuild(builder, eQuickBuildFailReason::OUT_OF_IMAGINATION, true); - - break; - } } if (m_Timer >= m_CompleteTime && m_DrainedImagination >= m_TakeImagination) {