Added canRevive parameter to Heal function, added Faint event.
This commit is contained in:
@@ -42,6 +42,16 @@ namespace CreatureLib::Battling {
|
||||
uint32_t GetOriginalHealth() const { return _originalHealth; }
|
||||
uint32_t GetNewHealth() const { return _newHealth; }
|
||||
};
|
||||
|
||||
class FaintEvent : public EventData {
|
||||
Creature* _creature;
|
||||
|
||||
public:
|
||||
FaintEvent(Creature* c) : _creature(c) {}
|
||||
EventDataKind GetKind() const override { return EventDataKind ::Faint; }
|
||||
Creature* GetCreature() const { return _creature; }
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif // CREATURELIB_EVENTDATA_HPP
|
||||
|
||||
@@ -3,7 +3,8 @@
|
||||
#include <Arbutils/Enum.hpp>
|
||||
|
||||
namespace CreatureLib::Battling {
|
||||
ENUM(EventDataKind, uint8_t, Damage, Heal)
|
||||
ENUM(EventDataKind, uint8_t, Damage, Heal, Faint)
|
||||
|
||||
}
|
||||
|
||||
#endif // CREATURELIB_EVENTDATAKIND_HPP
|
||||
|
||||
@@ -88,6 +88,9 @@ bool Battling::Creature::IsFainted() const { return this->_currentHealth <= 0; }
|
||||
|
||||
void Battling::Creature::OnFaint() {
|
||||
// HOOK: On Faint
|
||||
if (_battle != nullptr) {
|
||||
_battle->TriggerEventListener(new FaintEvent(this));
|
||||
}
|
||||
_library->GetExperienceLibrary()->HandleExperienceGain(this, _seenOpponents);
|
||||
|
||||
if (!_battle->CanSlotBeFilled(_side->GetSideIndex(), _side->GetCreatureIndex(this))) {
|
||||
@@ -113,7 +116,10 @@ void Battling::Creature::Damage(uint32_t damage, Battling::DamageSource source)
|
||||
}
|
||||
}
|
||||
|
||||
void Battling::Creature::Heal(uint32_t amount) {
|
||||
void Battling::Creature::Heal(uint32_t amount, bool canRevive) {
|
||||
if (_currentHealth == 0 && !canRevive) {
|
||||
return;
|
||||
}
|
||||
if (amount > GetMaxHealth() - _currentHealth) {
|
||||
amount = GetMaxHealth() - _currentHealth;
|
||||
}
|
||||
|
||||
@@ -111,7 +111,7 @@ namespace CreatureLib::Battling {
|
||||
uint32_t GetMaxHealth() const { return _boostedStats.GetHealth(); }
|
||||
void ChangeLevelBy(int8_t amount);
|
||||
void Damage(uint32_t damage, DamageSource source);
|
||||
void Heal(uint32_t amount);
|
||||
void Heal(uint32_t amount, bool canRevive = false);
|
||||
void OverrideActiveTalent(const ConstString& talent);
|
||||
void AddExperience(uint32_t amount);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user