Monad Engine da02fba2
> Undercity Codex_
Loading...
Searching...
No Matches
mnd::HealthComponent Class Referenceabstract

#include <HealthComponent.h>

+ Inheritance diagram for mnd::HealthComponent:
+ Collaboration diagram for mnd::HealthComponent:

Public Types

using DamageFn = std::function< void(const DamageInfo &)>
 
using DeathFn = std::function< void(const DamageInfo &)>
 

Public Member Functions

void Update (f32 deltaTime) override
 
void LoadProperties (const nlohmann::json &json) override
 
void ApplyDamage (const DamageInfo &info)
 Apply damage. Routed through DamageSystem::Apply, do not call directly.
 
int GetMax () const
 
int GetCurrent () const
 
bool IsDead () const
 
bool IsInvulnerable () const
 
void SetMax (int hp)
 
void SetCurrent (int hp)
 
void SetInvulnerable (bool inv)
 
void SetDestroyOnDeath (bool b)
 
void Heal (int amount)
 Heal up to max. No-op if dead (use Revive for that).
 
void Revive ()
 Reset to full HP and clear dead state.
 
void OnDamage (DamageFn fn)
 Subscribe to damage events. Listeners fire on every non-zero damage tick.
 
void OnDeath (DeathFn fn)
 Subscribe to death event. Fires once per transition from alive→dead.
 
void SetShowBar (bool show)
 Toggle on-screen 2D bar.
 
bool ShowsBar () const
 
virtual void Init ()
 
virtual size_t GetTypeId () const =0
 
GameObjectGetOwner ()
 

Static Public Member Functions

template<typename T >
static size_t StaticTypeId ()
 

Protected Attributes

GameObjectm_owner = nullptr
 

Detailed Description

Definition at line 30 of file HealthComponent.h.

Member Typedef Documentation

◆ DamageFn

using mnd::HealthComponent::DamageFn = std::function<void(const DamageInfo &)>

Definition at line 34 of file HealthComponent.h.

◆ DeathFn

using mnd::HealthComponent::DeathFn = std::function<void(const DamageInfo &)>

Definition at line 35 of file HealthComponent.h.

Member Function Documentation

◆ ApplyDamage()

void mnd::HealthComponent::ApplyDamage ( const DamageInfo info)

Apply damage. Routed through DamageSystem::Apply, do not call directly.

Definition at line 212 of file HealthComponent.cpp.

References mnd::DamageInfo::amount, IsDead(), mnd::Component::m_owner, and mnd::GameObject::MarkForDestroy().

◆ GetCurrent()

int mnd::HealthComponent::GetCurrent ( ) const
inline

Definition at line 44 of file HealthComponent.h.

◆ GetMax()

int mnd::HealthComponent::GetMax ( ) const
inline

Definition at line 43 of file HealthComponent.h.

◆ GetOwner()

GameObject * mnd::Component::GetOwner ( )
inherited

◆ GetTypeId()

virtual size_t mnd::Component::GetTypeId ( ) const
pure virtualinherited

◆ Heal()

void mnd::HealthComponent::Heal ( int  amount)

Heal up to max. No-op if dead (use Revive for that).

Definition at line 198 of file HealthComponent.cpp.

References IsDead().

◆ Init()

void mnd::Component::Init ( )
virtualinherited

Reimplemented in mnd::PhysicsComponent, and mnd::PlayerControllerComponent.

Definition at line 10 of file Component.cpp.

Referenced by mnd::GameObject::AddComponent().

◆ IsDead()

bool mnd::HealthComponent::IsDead ( ) const
inline

Definition at line 45 of file HealthComponent.h.

Referenced by ApplyDamage(), and Heal().

◆ IsInvulnerable()

bool mnd::HealthComponent::IsInvulnerable ( ) const
inline

Definition at line 46 of file HealthComponent.h.

◆ LoadProperties()

void mnd::HealthComponent::LoadProperties ( const nlohmann::json &  json)
overridevirtual

Reimplemented from mnd::Component.

Definition at line 162 of file HealthComponent.cpp.

◆ OnDamage()

void mnd::HealthComponent::OnDamage ( DamageFn  fn)
inline

Subscribe to damage events. Listeners fire on every non-zero damage tick.

Definition at line 60 of file HealthComponent.h.

◆ OnDeath()

void mnd::HealthComponent::OnDeath ( DeathFn  fn)
inline

Subscribe to death event. Fires once per transition from alive→dead.

Definition at line 62 of file HealthComponent.h.

◆ Revive()

void mnd::HealthComponent::Revive ( )

Reset to full HP and clear dead state.

Definition at line 207 of file HealthComponent.cpp.

◆ SetCurrent()

void mnd::HealthComponent::SetCurrent ( int  hp)

Definition at line 193 of file HealthComponent.cpp.

◆ SetDestroyOnDeath()

void mnd::HealthComponent::SetDestroyOnDeath ( bool  b)
inline

Definition at line 51 of file HealthComponent.h.

◆ SetInvulnerable()

void mnd::HealthComponent::SetInvulnerable ( bool  inv)
inline

Definition at line 50 of file HealthComponent.h.

◆ SetMax()

void mnd::HealthComponent::SetMax ( int  hp)

Definition at line 187 of file HealthComponent.cpp.

◆ SetShowBar()

void mnd::HealthComponent::SetShowBar ( bool  show)
inline

Toggle on-screen 2D bar.

Definition at line 65 of file HealthComponent.h.

◆ ShowsBar()

bool mnd::HealthComponent::ShowsBar ( ) const
inline

Definition at line 66 of file HealthComponent.h.

◆ StaticTypeId()

template<typename T >
static size_t mnd::Component::StaticTypeId ( )
inlinestaticinherited

Definition at line 50 of file Component.h.

◆ Update()

void mnd::HealthComponent::Update ( f32  deltaTime)
overridevirtual

Implements mnd::Component.

Definition at line 28 of file HealthComponent.cpp.

Member Data Documentation

◆ m_owner


The documentation for this class was generated from the following files: