diff --git a/CInterface/Battling/HistoryHandler.cpp b/CInterface/Battling/HistoryHandler.cpp index c5e52d0..6a6f57f 100644 --- a/CInterface/Battling/HistoryHandler.cpp +++ b/CInterface/Battling/HistoryHandler.cpp @@ -10,6 +10,11 @@ export const HistoryElement* CreatureLib_HistoryHandler_GetLastUsedAttack(const return p->GetLastUsedAttack().GetValue(); } +export const HistoryElement* CreatureLib_HistoryHandler_GetLastDamageOnTarget(const HistoryHolder* p, + const Creature* c) { + return p->GetLastDamageOnTarget(c).GetValue(); +} + export HistoryElementKind CreatureLib_HistoryElement_GetKind(const HistoryElement* p) { return p->GetKind(); } export const HistoryElement* CreatureLib_HistoryElement_GetPrevious(const HistoryElement* p) { return p->GetPrevious().GetValue(); diff --git a/src/Battling/History/HistoryElements/DamageHistory.hpp b/src/Battling/History/HistoryElements/DamageHistory.hpp index 117acd5..637e2aa 100644 --- a/src/Battling/History/HistoryElements/DamageHistory.hpp +++ b/src/Battling/History/HistoryElements/DamageHistory.hpp @@ -1,5 +1,6 @@ #ifndef CREATURELIB_DAMAGEHISTORY_HPP #define CREATURELIB_DAMAGEHISTORY_HPP +#include "../../Models/DamageSource.hpp" #include "HistoryElement.hpp" namespace CreatureLib::Battling { diff --git a/src/Battling/History/HistoryHolder.hpp b/src/Battling/History/HistoryHolder.hpp index 335b667..d1c69d1 100644 --- a/src/Battling/History/HistoryHolder.hpp +++ b/src/Battling/History/HistoryHolder.hpp @@ -2,6 +2,7 @@ #define CREATURELIB_HISTORYHOLDER_HPP #include "../../Library/Exceptions/CreatureException.hpp" +#include "HistoryElements/DamageHistory.hpp" #include "HistoryElements/HistoryElement.hpp" template @@ -26,15 +27,29 @@ namespace CreatureLib::Battling { [[nodiscard]] ArbUt::OptionalBorrowedPtr GetTopElement() const noexcept { return _top; } - ArbUt::OptionalBorrowedPtr GetLastUsedAttack() const noexcept { + [[nodiscard]] ArbUt::OptionalBorrowedPtr GetLastUsedAttack() const noexcept { const auto* c = _top; while (c != nullptr) { - if (c->GetKind() == HistoryElementKind::AttackUse) + if (c->GetKind() == HistoryElementKind::AttackUse) { return c; + } c = c->GetPrevious(); } return {}; } + + [[nodiscard]] ArbUt::OptionalBorrowedPtr + GetLastDamageOnTarget(const ArbUt::BorrowedPtr& creature) const noexcept { + ArbUt::OptionalBorrowedPtr c = _top; + while (c.HasValue()) { + if (c.GetValue()->GetKind() == HistoryElementKind::Damage && + c.ForceAs().GetValue()->GetTarget() == creature) { + return c; + } + c = c.GetValue()->GetPrevious(); + } + return {}; + } }; }