2019-10-31 11:02:23 +00:00
|
|
|
#include "TurnOrdering.hpp"
|
2019-11-28 11:55:22 +00:00
|
|
|
#include "../Models/Battle.hpp"
|
|
|
|
#include "../TurnChoices/AttackTurnChoice.hpp"
|
2019-10-31 11:02:23 +00:00
|
|
|
|
2019-10-31 11:31:31 +00:00
|
|
|
using namespace CreatureLib;
|
|
|
|
using namespace Battling;
|
2019-10-31 11:02:23 +00:00
|
|
|
|
2020-04-22 19:20:07 +00:00
|
|
|
class ChoiceCompare {
|
|
|
|
public:
|
2020-06-02 11:06:24 +00:00
|
|
|
bool operator()(const std::shared_ptr<BaseTurnChoice>& a, const std::shared_ptr<BaseTurnChoice>& b) {
|
2020-04-22 19:20:07 +00:00
|
|
|
auto aKind = a->GetKind();
|
|
|
|
auto bKind = b->GetKind();
|
|
|
|
if (aKind != bKind)
|
|
|
|
return aKind > bKind;
|
|
|
|
if (aKind == TurnChoiceKind::Attack) {
|
2020-08-30 11:14:33 +00:00
|
|
|
auto aAttack = std::dynamic_pointer_cast<AttackTurnChoice>(a);
|
|
|
|
auto bAttack = std::dynamic_pointer_cast<AttackTurnChoice>(b);
|
2020-12-13 11:15:40 +00:00
|
|
|
EnsureNotNull(aAttack);
|
|
|
|
EnsureNotNull(bAttack);
|
2020-08-30 11:14:33 +00:00
|
|
|
auto aPriority = aAttack->GetPriority();
|
|
|
|
auto bPriority = bAttack->GetPriority();
|
2020-04-22 19:20:07 +00:00
|
|
|
if (aPriority != bPriority)
|
|
|
|
return aPriority > bPriority;
|
|
|
|
}
|
2020-08-30 11:14:33 +00:00
|
|
|
auto aUser = a->GetUser();
|
|
|
|
auto bUser = b->GetUser();
|
|
|
|
auto aSpeed = aUser->GetBoostedStat(Library::Statistic::Speed);
|
|
|
|
auto bSpeed = bUser->GetBoostedStat(Library::Statistic::Speed);
|
2020-04-22 19:20:07 +00:00
|
|
|
if (aSpeed != bSpeed)
|
|
|
|
return aSpeed > bSpeed;
|
|
|
|
|
2020-04-22 21:09:54 +00:00
|
|
|
return a->__GetRandomValue() > b->__GetRandomValue();
|
2020-04-22 19:20:07 +00:00
|
|
|
}
|
|
|
|
};
|
2019-10-31 11:02:23 +00:00
|
|
|
|
2020-08-30 11:14:33 +00:00
|
|
|
void TurnOrdering::OrderChoices(std::vector<std::shared_ptr<BaseTurnChoice>>& vec) {
|
|
|
|
for (const auto& item : vec) {
|
2020-12-13 11:15:40 +00:00
|
|
|
EnsureNotNull(item);
|
2020-06-20 17:51:34 +00:00
|
|
|
if (item->GetKind() == TurnChoiceKind::Attack) {
|
2020-08-30 11:14:33 +00:00
|
|
|
auto attackChoice = std::dynamic_pointer_cast<AttackTurnChoice>(item);
|
2020-12-13 11:15:40 +00:00
|
|
|
EnsureNotNull(attackChoice);
|
2020-06-20 17:51:34 +00:00
|
|
|
auto priority = attackChoice->GetPriority();
|
2020-08-30 11:14:33 +00:00
|
|
|
HOOK(ChangePriority, attackChoice, attackChoice.get(), &priority);
|
2020-06-20 17:51:34 +00:00
|
|
|
attackChoice->SetPriority(priority);
|
|
|
|
}
|
|
|
|
}
|
2020-04-22 21:03:16 +00:00
|
|
|
std::sort(vec.begin(), vec.end(), ChoiceCompare());
|
2019-10-31 11:02:23 +00:00
|
|
|
}
|