From 970ca8ddd5b0c37f880603675fe47c0371510b1a Mon Sep 17 00:00:00 2001 From: Deukhoofd Date: Sun, 22 Mar 2020 10:30:45 +0100 Subject: [PATCH] Fixed replacementattack not being complete. --- src/Battling/Library/MiscLibrary.cpp | 4 +++- src/Battling/Models/BattleSide.cpp | 4 ++++ src/Battling/Models/BattleSide.hpp | 2 ++ 3 files changed, 9 insertions(+), 1 deletion(-) diff --git a/src/Battling/Library/MiscLibrary.cpp b/src/Battling/Library/MiscLibrary.cpp index 35459ee..39f0605 100644 --- a/src/Battling/Library/MiscLibrary.cpp +++ b/src/Battling/Library/MiscLibrary.cpp @@ -34,5 +34,7 @@ CreatureLib::Battling::MiscLibrary::ReplacementAttack(Creature* user, CreatureIn auto sideTarget = 0; if (user->GetBattleSide()->GetSideIndex() == 0) sideTarget = 1; - return new AttackTurnChoice(user, GetReplacementAttack(), target); + auto side = user->GetBattle()->GetSides()[sideTarget]; + auto random_mon = side->GetRandomCreatureIndex(); + return new AttackTurnChoice(user, GetReplacementAttack(), CreatureIndex(side->GetSideIndex(), random_mon)); } diff --git a/src/Battling/Models/BattleSide.cpp b/src/Battling/Models/BattleSide.cpp index d686f7d..f7c415e 100644 --- a/src/Battling/Models/BattleSide.cpp +++ b/src/Battling/Models/BattleSide.cpp @@ -68,3 +68,7 @@ void BattleSide::GetActiveScripts(std::vector& scripts) { scripts.emplace_back(&_volatile); _battle->GetActiveScripts(scripts); } +uint8_t BattleSide::GetRandomCreatureIndex() { + // TODO: Consider adding parameter to only get index for available creatures. + return _battle->GetRandom()->Get(_creaturesPerSide); +} diff --git a/src/Battling/Models/BattleSide.hpp b/src/Battling/Models/BattleSide.hpp index 4f6e67e..2dada24 100644 --- a/src/Battling/Models/BattleSide.hpp +++ b/src/Battling/Models/BattleSide.hpp @@ -79,6 +79,8 @@ namespace CreatureLib::Battling { bool HasFled() { return _hasFled; } void MarkAsFled() { _hasFled = true; } + + uint8_t GetRandomCreatureIndex(); }; }