diff --git a/CInterface/Battling/Creature.cpp b/CInterface/Battling/Creature.cpp index ea59590..216d0a3 100644 --- a/CInterface/Battling/Creature.cpp +++ b/CInterface/Battling/Creature.cpp @@ -48,24 +48,18 @@ export size_t CreatureLib_Creature_GetTypesCount(Creature* p) { return p->GetTyp export const uint8_t* CreatureLib_Creature_GetTypes(Creature* p) { return p->GetTypes().data(); } export bool CreatureLib_Creature_HasType(Creature* p, uint8_t type) { return p->HasType(type); } SIMPLE_GET_FUNC(Creature, GetMaxHealth, uint32_t); -export void CreatureLib_Creature_ChangeLevelBy(Creature* p, int8_t level) { - return p->ChangeLevelBy(level); -} -export void CreatureLib_Creature_Damage(Creature* p, uint32_t damage, DamageSource source){ +export void CreatureLib_Creature_ChangeLevelBy(Creature* p, int8_t level) { return p->ChangeLevelBy(level); } +export void CreatureLib_Creature_Damage(Creature* p, uint32_t damage, DamageSource source) { p->Damage(damage, source); } -export void CreatureLib_Creature_Heal(Creature* p, uint32_t health){ - p->Heal(health); -} -export void CreatureLib_Creature_OverrideActiveTalent(Creature* p, const char* talent){ +export void CreatureLib_Creature_Heal(Creature* p, uint32_t health, bool canRevive) { p->Heal(health, canRevive); } +export void CreatureLib_Creature_OverrideActiveTalent(Creature* p, const char* talent) { p->OverrideActiveTalent(ConstString(talent)); } export void CreatureLib_Creature_AddExperience(Creature* p, uint32_t experience) { return p->AddExperience(experience); } -export void CreatureLib_Creature_ClearVolatileScripts(Creature* p) { - return p->ClearVolatileScripts(); -} +export void CreatureLib_Creature_ClearVolatileScripts(Creature* p) { return p->ClearVolatileScripts(); } export void CreatureLib_Creature_AddVolatileScriptByName(Creature* p, const char* scriptName) { return p->AddVolatileScript(ConstString(scriptName)); } diff --git a/src/Battling/EventHooks/EventData.hpp b/src/Battling/EventHooks/EventData.hpp index 1ff7bc9..f2dc95e 100644 --- a/src/Battling/EventHooks/EventData.hpp +++ b/src/Battling/EventHooks/EventData.hpp @@ -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 diff --git a/src/Battling/EventHooks/EventDataKind.hpp b/src/Battling/EventHooks/EventDataKind.hpp index 29d1a46..86a9a74 100644 --- a/src/Battling/EventHooks/EventDataKind.hpp +++ b/src/Battling/EventHooks/EventDataKind.hpp @@ -3,7 +3,8 @@ #include namespace CreatureLib::Battling { - ENUM(EventDataKind, uint8_t, Damage, Heal) + ENUM(EventDataKind, uint8_t, Damage, Heal, Faint) + } #endif // CREATURELIB_EVENTDATAKIND_HPP diff --git a/src/Battling/Models/Creature.cpp b/src/Battling/Models/Creature.cpp index 728a5f2..51bdccd 100644 --- a/src/Battling/Models/Creature.cpp +++ b/src/Battling/Models/Creature.cpp @@ -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; } diff --git a/src/Battling/Models/Creature.hpp b/src/Battling/Models/Creature.hpp index c803118..71e35a1 100644 --- a/src/Battling/Models/Creature.hpp +++ b/src/Battling/Models/Creature.hpp @@ -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);