Added canRevive parameter to Heal function, added Faint event.

This commit is contained in:
Deukhoofd 2020-03-09 16:29:41 +01:00
parent 3efd7a6974
commit 06336c64cd
Signed by: Deukhoofd
GPG Key ID: ADF2E9256009EDCE
5 changed files with 25 additions and 14 deletions

View File

@ -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 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); } export bool CreatureLib_Creature_HasType(Creature* p, uint8_t type) { return p->HasType(type); }
SIMPLE_GET_FUNC(Creature, GetMaxHealth, uint32_t); SIMPLE_GET_FUNC(Creature, GetMaxHealth, uint32_t);
export void CreatureLib_Creature_ChangeLevelBy(Creature* p, int8_t level) { export void CreatureLib_Creature_ChangeLevelBy(Creature* p, int8_t level) { return p->ChangeLevelBy(level); }
return p->ChangeLevelBy(level); export void CreatureLib_Creature_Damage(Creature* p, uint32_t damage, DamageSource source) {
}
export void CreatureLib_Creature_Damage(Creature* p, uint32_t damage, DamageSource source){
p->Damage(damage, source); p->Damage(damage, source);
} }
export void CreatureLib_Creature_Heal(Creature* p, uint32_t health){ export void CreatureLib_Creature_Heal(Creature* p, uint32_t health, bool canRevive) { p->Heal(health, canRevive); }
p->Heal(health); export void CreatureLib_Creature_OverrideActiveTalent(Creature* p, const char* talent) {
}
export void CreatureLib_Creature_OverrideActiveTalent(Creature* p, const char* talent){
p->OverrideActiveTalent(ConstString(talent)); p->OverrideActiveTalent(ConstString(talent));
} }
export void CreatureLib_Creature_AddExperience(Creature* p, uint32_t experience) { export void CreatureLib_Creature_AddExperience(Creature* p, uint32_t experience) {
return p->AddExperience(experience); return p->AddExperience(experience);
} }
export void CreatureLib_Creature_ClearVolatileScripts(Creature* p) { export void CreatureLib_Creature_ClearVolatileScripts(Creature* p) { return p->ClearVolatileScripts(); }
return p->ClearVolatileScripts();
}
export void CreatureLib_Creature_AddVolatileScriptByName(Creature* p, const char* scriptName) { export void CreatureLib_Creature_AddVolatileScriptByName(Creature* p, const char* scriptName) {
return p->AddVolatileScript(ConstString(scriptName)); return p->AddVolatileScript(ConstString(scriptName));
} }

View File

@ -42,6 +42,16 @@ 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 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 #endif // CREATURELIB_EVENTDATA_HPP

View File

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

View File

@ -88,6 +88,9 @@ bool Battling::Creature::IsFainted() const { return this->_currentHealth <= 0; }
void Battling::Creature::OnFaint() { void Battling::Creature::OnFaint() {
// HOOK: On Faint // HOOK: On Faint
if (_battle != nullptr) {
_battle->TriggerEventListener(new FaintEvent(this));
}
_library->GetExperienceLibrary()->HandleExperienceGain(this, _seenOpponents); _library->GetExperienceLibrary()->HandleExperienceGain(this, _seenOpponents);
if (!_battle->CanSlotBeFilled(_side->GetSideIndex(), _side->GetCreatureIndex(this))) { 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) { if (amount > GetMaxHealth() - _currentHealth) {
amount = GetMaxHealth() - _currentHealth; amount = GetMaxHealth() - _currentHealth;
} }

View File

@ -111,7 +111,7 @@ namespace CreatureLib::Battling {
uint32_t GetMaxHealth() const { return _boostedStats.GetHealth(); } uint32_t GetMaxHealth() const { return _boostedStats.GetHealth(); }
void ChangeLevelBy(int8_t amount); void ChangeLevelBy(int8_t amount);
void Damage(uint32_t damage, DamageSource source); 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 OverrideActiveTalent(const ConstString& talent);
void AddExperience(uint32_t amount); void AddExperience(uint32_t amount);