Adds support for History data, allowing us to store specific interesting occurrences in the data flow, and recall them later.
All checks were successful
continuous-integration/drone/push Build is passing

Signed-off-by: Deukhoofd <Deukhoofd@gmail.com>
This commit is contained in:
2020-08-14 15:18:00 +02:00
parent 939fee3f50
commit cb4765e0cc
12 changed files with 150 additions and 19 deletions

View File

@@ -3,6 +3,7 @@
#include <unordered_set>
#include "../../Library/Exceptions/NotImplementedException.hpp"
#include "../EventHooks/EventDataClasses.hpp"
#include "../History/HistoryElements/AttackUseHistory.hpp"
#include "../ScriptHandling/ScriptMacros.hpp"
#include "ResolveTarget.hpp"
@@ -68,8 +69,9 @@ void TurnHandler::ExecuteChoice(ArbUt::BorrowedPtr<BaseTurnChoice> choice) {
}
}
void TurnHandler::ExecuteAttackChoice(ArbUt::BorrowedPtr<AttackTurnChoice> choice) {
void TurnHandler::ExecuteAttackChoice(const ArbUt::BorrowedPtr<AttackTurnChoice>& choice) {
AssertNotNull(choice)
auto battle = choice->GetUser()->GetBattle();
auto attackName = choice->GetAttack()->GetAttack()->GetName();
HOOK(ChangeAttack, choice, choice.GetRaw(), &attackName);
if (attackName != choice->GetAttack()->GetAttack()->GetName()) {
@@ -78,24 +80,25 @@ void TurnHandler::ExecuteAttackChoice(ArbUt::BorrowedPtr<AttackTurnChoice> choic
auto targetType = choice->GetAttack()->GetAttack()->GetTarget();
ArbUt::List<ArbUt::BorrowedPtr<Creature>> targets;
try_creature(targets =
TargetResolver::ResolveTargets(choice->GetTarget(), targetType, choice->GetUser()->GetBattle());
try_creature(targets = TargetResolver::ResolveTargets(choice->GetTarget(), targetType, battle);
, "Exception during target determination");
auto attack = new ExecutingAttack(targets, 1, choice->GetUser(), choice->GetAttack(), choice->GetAttackScript());
bool prevented = false;
HOOK(PreventAttack, attack, attack, &prevented);
if (prevented) {
delete attack;
return;
}
// HOOK: override targets
if (!choice->GetAttack()->TryUse(1)) {
delete attack;
return;
}
attack->GetUser()->GetBattle()->TriggerEventListener<AttackUseEvent>(attack);
battle->TriggerEventListener<AttackUseEvent>(attack);
battle->RegisterHistoryElement<AttackUseHistory>(attack);
// HOOK: check if attack fails
bool fail = false;
@@ -116,8 +119,6 @@ void TurnHandler::ExecuteAttackChoice(ArbUt::BorrowedPtr<AttackTurnChoice> choic
auto target = attack->GetTargets()[i];
try_creature(HandleAttackForTarget(attack, target), "Exception occurred during handling attack for target");
}
delete attack;
}
void TurnHandler::HandleAttackForTarget(ExecutingAttack* attack, const ArbUt::BorrowedPtr<Creature>& target) {

View File

@@ -13,7 +13,7 @@ namespace CreatureLib::Battling {
class TurnHandler {
static void ExecuteChoice(ArbUt::BorrowedPtr<BaseTurnChoice> choice);
static void ExecuteAttackChoice(ArbUt::BorrowedPtr<AttackTurnChoice> choice);
static void ExecuteAttackChoice(const ArbUt::BorrowedPtr<AttackTurnChoice>& choice);
static void HandleAttackForTarget(ExecutingAttack* attack, const ArbUt::BorrowedPtr<Creature>& target);
static void ExecuteSwitchChoice(ArbUt::BorrowedPtr<SwitchTurnChoice> choice);