Support for Heal function for Creatures.
continuous-integration/drone/push Build is passing Details

This commit is contained in:
Deukhoofd 2020-02-13 14:48:09 +01:00
parent 2dcb197191
commit 8d4860f553
Signed by: Deukhoofd
GPG Key ID: ADF2E9256009EDCE
3 changed files with 29 additions and 0 deletions

View File

@ -28,6 +28,20 @@ namespace CreatureLib::Battling {
uint32_t GetOriginalHealth() const { return _originalHealth; } uint32_t GetOriginalHealth() const { return _originalHealth; }
uint32_t GetNewHealth() const { return _newHealth; } 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 #endif // CREATURELIB_EVENTDATA_HPP

View File

@ -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) { void Battling::Creature::OverrideActiveTalent(const std::string& talent) {
_hasOverridenTalent = true; _hasOverridenTalent = true;
_activeTalent->OnRemove(); _activeTalent->OnRemove();

View File

@ -98,8 +98,10 @@ namespace CreatureLib::Battling {
[[nodiscard]] const std::vector<uint8_t>& GetTypes() const; [[nodiscard]] const std::vector<uint8_t>& GetTypes() const;
[[nodiscard]] bool HasType(uint8_t type) const; [[nodiscard]] bool HasType(uint8_t type) const;
uint32_t GetMaxHealth() const { return _boostedStats.GetHealth(); }
void ChangeLevel(int8_t amount); void ChangeLevel(int8_t amount);
void Damage(uint32_t damage, DamageSource source); void Damage(uint32_t damage, DamageSource source);
void Heal(uint32_t amount);
void OverrideActiveTalent(const std::string& talent); void OverrideActiveTalent(const std::string& talent);
void AddExperience(uint32_t amount); void AddExperience(uint32_t amount);