Support for Heal function for Creatures.
continuous-integration/drone/push Build is passing
Details
continuous-integration/drone/push Build is passing
Details
This commit is contained in:
parent
2dcb197191
commit
8d4860f553
|
@ -28,6 +28,20 @@ namespace CreatureLib::Battling {
|
|||
uint32_t GetOriginalHealth() const { return _originalHealth; }
|
||||
uint32_t GetNewHealth() const { return _newHealth; }
|
||||
};
|
||||
|
||||
class HealEvent : public EventData {
|
||||
Creature* _creature;
|
||||
uint32_t _originalHealth;
|
||||
uint32_t _newHealth;
|
||||
|
||||
public:
|
||||
HealEvent(Creature* c, uint32_t oHealth, uint32_t newHealth)
|
||||
: _creature(c), _originalHealth(oHealth), _newHealth(newHealth) {}
|
||||
EventDataKind GetKind() override { return EventDataKind ::Damage; }
|
||||
Creature* GetCreature() const { return _creature; }
|
||||
uint32_t GetOriginalHealth() const { return _originalHealth; }
|
||||
uint32_t GetNewHealth() const { return _newHealth; }
|
||||
};
|
||||
}
|
||||
|
||||
#endif // CREATURELIB_EVENTDATA_HPP
|
||||
|
|
|
@ -112,6 +112,19 @@ void Battling::Creature::Damage(uint32_t damage, Battling::DamageSource source)
|
|||
}
|
||||
}
|
||||
|
||||
void Battling::Creature::Heal(uint32_t amount) {
|
||||
if (amount > GetMaxHealth() - _currentHealth) {
|
||||
amount = GetMaxHealth() - _currentHealth;
|
||||
}
|
||||
// HOOK: On Heal
|
||||
auto newHealth = _currentHealth + amount;
|
||||
auto battle = this->GetBattle();
|
||||
if (battle != nullptr) {
|
||||
battle->TriggerEventListener(new HealEvent(this, _currentHealth, newHealth));
|
||||
}
|
||||
_currentHealth = newHealth;
|
||||
}
|
||||
|
||||
void Battling::Creature::OverrideActiveTalent(const std::string& talent) {
|
||||
_hasOverridenTalent = true;
|
||||
_activeTalent->OnRemove();
|
||||
|
|
|
@ -98,8 +98,10 @@ namespace CreatureLib::Battling {
|
|||
[[nodiscard]] const std::vector<uint8_t>& GetTypes() const;
|
||||
[[nodiscard]] bool HasType(uint8_t type) const;
|
||||
|
||||
uint32_t GetMaxHealth() const { return _boostedStats.GetHealth(); }
|
||||
void ChangeLevel(int8_t amount);
|
||||
void Damage(uint32_t damage, DamageSource source);
|
||||
void Heal(uint32_t amount);
|
||||
void OverrideActiveTalent(const std::string& talent);
|
||||
void AddExperience(uint32_t amount);
|
||||
|
||||
|
|
Loading…
Reference in New Issue