Adds Miss event.
continuous-integration/drone/push Build is passing Details

Signed-off-by: Deukhoofd <Deukhoofd@gmail.com>
This commit is contained in:
Deukhoofd 2020-08-13 11:17:04 +02:00
parent bb35248174
commit 50236f4ece
Signed by: Deukhoofd
GPG Key ID: F63E044490819F6F
3 changed files with 12 additions and 2 deletions

View File

@ -102,6 +102,15 @@ namespace CreatureLib::Battling {
const ArbUt::StringView& GetText() const noexcept { return _text; }
};
class MissEvent : public EventData {
ArbUt::BorrowedPtr<Creature> _creature;
public:
MissEvent(const ArbUt::BorrowedPtr<Creature>& creature) noexcept : _creature(creature) {}
EventDataKind GetKind() const noexcept override { return EventDataKind ::Miss; }
const ArbUt::BorrowedPtr<Creature>& GetCreature() const noexcept { return _creature; }
};
}
#endif // CREATURELIB_EVENTDATA_HPP

View File

@ -3,7 +3,7 @@
#include <Arbutils/Enum.hpp>
namespace CreatureLib::Battling {
ENUM(EventDataKind, uint8_t, Damage, Heal, Faint, Switch, TurnStart, TurnEnd, ExperienceGain, DisplayText)
ENUM(EventDataKind, uint8_t, Damage, Heal, Faint, Switch, TurnStart, TurnEnd, ExperienceGain, Miss, DisplayText)
}
#endif // CREATURELIB_EVENTDATAKIND_HPP

View File

@ -122,7 +122,7 @@ void TurnHandler::HandleAttackForTarget(ExecutingAttack* attack, const ArbUt::Bo
if (user->GetBattle()->HasEnded())
return;
auto targetSource = target;
const auto& targetSource = target;
auto userSource = attack;
bool fail = false;
@ -142,6 +142,7 @@ void TurnHandler::HandleAttackForTarget(ExecutingAttack* attack, const ArbUt::Bo
auto numberOfHits = attack->GetNumberOfHits();
if (numberOfHits == 0) {
HOOK(OnAttackMiss, targetSource, attack, target.GetRaw());
user->GetBattle()->TriggerEventListener<MissEvent>(user);
return;
}