diff --git a/src/Battling/Flow/TurnHandler.cpp b/src/Battling/Flow/TurnHandler.cpp index 9c8541b..2cb9342 100644 --- a/src/Battling/Flow/TurnHandler.cpp +++ b/src/Battling/Flow/TurnHandler.cpp @@ -14,7 +14,14 @@ void TurnHandler::RunTurn(ArbUt::BorrowedPtr queue) { } while (queue->HasNext()) { auto item = queue->Dequeue(); - ExecuteChoice(item.get()); + try { + ExecuteChoice(item.get()); + } catch (const std::exception& e) { + THROW_CREATURE("Executing choice failed for choice by mon on side " + << item.get()->GetUser()->GetBattleSide()->GetSideIndex() << " and index " + << item.get()->GetUser()->GetBattleSide()->GetCreatureIndex(item->GetUser()) + << " with message '" << e.what() << "'."); + } } queue->HasCompletedQueue = true; } diff --git a/src/Battling/Models/Battle.cpp b/src/Battling/Models/Battle.cpp index 2409dfd..f99cad2 100644 --- a/src/Battling/Models/Battle.cpp +++ b/src/Battling/Models/Battle.cpp @@ -41,27 +41,35 @@ void Battle::CheckChoicesSetAndRun() { auto choices = std::vector>(_numberOfSides * _creaturesPerSide); auto i = 0; - for (auto side : _sides) { - for (const auto& choice : side->GetChoices()) { - AssertNotNull(choice) - if (choice->GetKind() == TurnChoiceKind::Attack) { - auto attack = ((AttackTurnChoice*)choice.get())->GetAttack(); - uint8_t uses = 1; - // HOOK: change number of uses needed. - if (attack->GetRemainingUses() < uses) { - // TODO: Implement default move - throw NotImplementedException("Not enough remaining uses, change to default move."); + try { + for (auto side : _sides) { + for (auto choice : side->GetChoices()) { + AssertNotNull(choice) + if (choice->GetKind() == TurnChoiceKind::Attack) { + auto attack = ((AttackTurnChoice*)choice.get())->GetAttack(); + uint8_t uses = 1; + // HOOK: change number of uses needed. + if (attack->GetRemainingUses() < uses) { + choice = std::shared_ptr(_library->GetMiscLibrary()->ReplacementAttack( + choice->GetUser().GetRaw(), ((AttackTurnChoice*)choice.get())->GetTarget())); + } + // HOOK: Check if we need to change the move } - // HOOK: Check if we need to change the move + choice->__SetRandomValue(_random.Get()); + choices[i] = choice; + i++; } - choice->__SetRandomValue(_random.Get()); - choices[i] = choice; - i++; + side->ResetChoices(); } - side->ResetChoices(); + } catch (const std::exception& e) { + THROW_CREATURE("Exception during turn initialization: '" << e.what() << "'.") } _currentTurn++; - TurnOrdering::OrderChoices(choices, _random.GetRNG()); + try { + TurnOrdering::OrderChoices(choices, _random.GetRNG()); + } catch (const std::exception& e) { + THROW_CREATURE("Exception during turn ordering: '" << e.what() << "'.") + } this->_currentTurnQueue.reset(new ChoiceQueue(choices)); TurnHandler::RunTurn(this->_currentTurnQueue); if (this->_currentTurnQueue->HasCompletedQueue) {