fix: prevent negative imagination (#1083)

* fix: prevent negative imagination
And fail switch if we don't have enough imagination

* Make better
This commit is contained in:
Aaron Kimbrell
2023-05-11 06:37:02 -05:00
committed by GitHub
parent bf0ae6f181
commit 6e6a05fc1d
2 changed files with 8 additions and 8 deletions

View File

@@ -196,18 +196,18 @@ void RebuildComponent::Update(float deltaTime) {
DestroyableComponent* destComp = builder->GetComponent<DestroyableComponent>();
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) {