Adds helper function to get last damage event on a creature.
continuous-integration/drone/push Build is passing
Details
continuous-integration/drone/push Build is passing
Details
Signed-off-by: Deukhoofd <Deukhoofd@gmail.com>
This commit is contained in:
parent
20b53833c4
commit
ff67ab9e00
|
@ -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();
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
#ifndef CREATURELIB_DAMAGEHISTORY_HPP
|
||||
#define CREATURELIB_DAMAGEHISTORY_HPP
|
||||
#include "../../Models/DamageSource.hpp"
|
||||
#include "HistoryElement.hpp"
|
||||
|
||||
namespace CreatureLib::Battling {
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
#define CREATURELIB_HISTORYHOLDER_HPP
|
||||
|
||||
#include "../../Library/Exceptions/CreatureException.hpp"
|
||||
#include "HistoryElements/DamageHistory.hpp"
|
||||
#include "HistoryElements/HistoryElement.hpp"
|
||||
|
||||
template <class T>
|
||||
|
@ -26,15 +27,29 @@ namespace CreatureLib::Battling {
|
|||
|
||||
[[nodiscard]] ArbUt::OptionalBorrowedPtr<const HistoryElement> GetTopElement() const noexcept { return _top; }
|
||||
|
||||
ArbUt::OptionalBorrowedPtr<const HistoryElement> GetLastUsedAttack() const noexcept {
|
||||
[[nodiscard]] ArbUt::OptionalBorrowedPtr<const HistoryElement> 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<const HistoryElement>
|
||||
GetLastDamageOnTarget(const ArbUt::BorrowedPtr<const Creature>& creature) const noexcept {
|
||||
ArbUt::OptionalBorrowedPtr<const HistoryElement> c = _top;
|
||||
while (c.HasValue()) {
|
||||
if (c.GetValue()->GetKind() == HistoryElementKind::Damage &&
|
||||
c.ForceAs<const DamageHistory>().GetValue()->GetTarget() == creature) {
|
||||
return c;
|
||||
}
|
||||
c = c.GetValue()->GetPrevious();
|
||||
}
|
||||
return {};
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue