Corgi Engine v8.2
MoreMountains.CorgiEngine.Health Class Reference

This class manages the health of an object, pilots its potential health bar, handles what happens when it takes damage, and what happens when it dies. More...

Inheritance diagram for MoreMountains.CorgiEngine.Health:
MoreMountains.Tools.MMMonoBehaviour MoreMountains.CorgiEngine.SuperHipsterBrosHealth

Classes

class  InterruptiblesDamageOverTimeCoroutine
 

Public Member Functions

delegate void OnHitDelegate ()
 
delegate void OnHitZeroDelegate ()
 
delegate void OnReviveDelegate ()
 
delegate void OnDeathDelegate ()
 
virtual void StoreInitialPosition ()
 
virtual bool CanTakeDamageThisFrame ()
 Returns true if this Health component can be damaged this frame, and false otherwise More...
 
virtual void Damage (float damage, GameObject instigator, float flickerDuration, float invincibilityDuration, Vector3 damageDirection, List< TypedDamage > typedDamages=null)
 Called when the object takes damage More...
 
virtual void Kill ()
 Kills the character, instantiates death effects, handles points, etc More...
 
virtual void Revive ()
 Revive this object. More...
 
virtual void InterruptAllDamageOverTime ()
 Interrupts all damage over time, regardless of type More...
 
virtual void InterruptAllDamageOverTimeOfType (DamageType damageType)
 Interrupts all damage over time of the specified type More...
 
virtual void DamageOverTime (float damage, GameObject instigator, float flickerDuration, float invincibilityDuration, Vector3 damageDirection, List< TypedDamage > typedDamages=null, int amountOfRepeats=0, float durationBetweenRepeats=1f, bool interruptible=true, DamageType damageType=null)
 Applies damage over time, for the specified amount of repeats (which includes the first application of damage, makes it easier to do quick maths in the inspector, and at the specified interval). Optionally you can decide that your damage is interruptible, in which case, calling InterruptAllDamageOverTime() will stop these from being applied, useful to cure poison for example. More...
 
virtual float ComputeDamageOutput (float damage, List< TypedDamage > typedDamages=null, bool damageApplied=false)
 Returns the damage this health should take after processing potential resistances More...
 
virtual void GetHealth (float health, GameObject instigator)
 Called when the character gets health (from a stimpack for example) More...
 
virtual void SetHealth (float newHealth, GameObject instigator)
 Sets the health of the character to the one specified in parameters More...
 
virtual void ResetHealthToMaxHealth ()
 Resets the character's health to its max value More...
 
virtual void UpdateHealthBar (bool show)
 Updates the character's health bar progress. More...
 
virtual void DamageDisabled ()
 Prevents the character from taking any damage More...
 
virtual void DamageEnabled ()
 Allows the character to take damage More...
 
virtual void EnablePostDamageInvulnerability ()
 Prevents the character from taking any damage More...
 
virtual void DisablePostDamageInvulnerability ()
 Allows the character to take damage More...
 
virtual IEnumerator DisablePostDamageInvulnerability (float delay)
 Allows the character to take damage More...
 
virtual IEnumerator DamageEnabled (float delay)
 makes the character able to take damage again after the specified delay More...
 

Public Attributes

float CurrentHealth
 the current health of the character More...
 
bool TemporarilyInvulnerable = false
 If this is true, this object can't take damage at the moment. More...
 
bool PostDamageInvulnerable = false
 If this is true, this object is in post damage invulnerability state. More...
 
float InitialHealth = 10
 the initial amount of health of the object More...
 
float MaximumHealth = 10
 the maximum amount of health of the object More...
 
bool Invulnerable = false
 if this is true, this object can't take damage More...
 
bool ImmuneToDamage = false
 whether or not this Health object can be damaged, you can play with this on top of Invulnerable, which will be turned on/off temporarily for temporary invulnerability. ImmuneToDamage is more of a permanent solution. More...
 
MMFeedbacks DamageFeedbacks
 the MMFeedbacks to play when the character gets hit More...
 
bool FeedbackIsProportionalToDamage = false
 if this is true, the damage value will be passed to the MMFeedbacks as its Intensity parameter, letting you trigger more intense feedbacks as damage increases More...
 
bool FlickerSpriteOnHit = true
 should the sprite (if there's one) flicker when getting damage ? More...
 
Color FlickerColor = new Color32(255, 20, 20, 255)
 the color the sprite should flicker to More...
 
bool ImmuneToKnockback = false
 whether or not this object can get knockback More...
 
bool ImmuneToKnockbackIfZeroDamage = false
 whether or not this object is immune to damage knockback if the damage received is zero More...
 
MMFeedbacks DeathFeedbacks
 the MMFeedbacks to play when the character dies More...
 
bool DestroyOnDeath = true
 if this is not true, the object will remain there after its death More...
 
float DelayBeforeDestruction = 0f
 the time (in seconds) before the character is destroyed or disabled More...
 
bool CollisionsOffOnDeath = true
 if this is true, collisions will be turned off when the character dies More...
 
bool GravityOffOnDeath = false
 if this is true, gravity will be turned off on death More...
 
int PointsWhenDestroyed
 the points the player gets when the object's health reaches zero More...
 
bool RespawnAtInitialLocation = false
 if this is set to false, the character will respawn at the location of its death, otherwise it'll be moved to its initial position (when the scene started) More...
 
bool ApplyDeathForce = true
 whether or not to apply a force on death More...
 
Vector2 DeathForce = new Vector2(0, 10)
 the force applied when the character dies More...
 
bool ResetForcesOnDeath = false
 whether or not the controller's forces should be set to 0 on death More...
 
bool ResetColorOnRevive = true
 if this is true, color will be reset on revive More...
 
string ColorMaterialPropertyName = "_Color"
 the name of the property on your renderer's shader that defines its color More...
 
bool UseMaterialPropertyBlocks = false
 if this is true, this component will use material property blocks instead of working on an instance of the material. More...
 
Health MasterHealth
 another Health component (usually on another character) towards which all health will be redirected More...
 
DamageResistanceProcessor TargetDamageResistanceProcessor
 a DamageResistanceProcessor this Health will use to process damage when it's received More...
 
OnDeathDelegate OnDeath
 
OnHitDelegate OnHit
 
OnHitZeroDelegate OnHitZero
 
OnReviveDelegate OnRevive
 

Protected Member Functions

virtual void Start ()
 On Start, we initialize our health More...
 
virtual void Initialization ()
 Grabs useful components, enables damage and gets the inital color More...
 
virtual void InitializeSpriteColor ()
 Stores the inital color of the Character's sprite. More...
 
virtual void ResetSpriteColor ()
 Restores the original sprite color More...
 
virtual void DestroyObject ()
 Destroys the object, or tries to, depending on the character's settings More...
 
virtual IEnumerator DamageOverTimeCo (float damage, GameObject instigator, float flickerDuration, float invincibilityDuration, Vector3 damageDirection, List< TypedDamage > typedDamages=null, int amountOfRepeats=0, float durationBetweenRepeats=1f, bool interruptible=true, DamageType damageType=null)
 A coroutine used to apply damage over time More...
 
virtual void ComputeCharacterConditionStateChanges (List< TypedDamage > typedDamages)
 Goes through resistances and applies condition state changes if needed More...
 
virtual void ComputeCharacterMovementMultipliers (List< TypedDamage > typedDamages)
 Goes through the resistance list and applies movement multipliers if needed More...
 
virtual void OnEnable ()
 When the object is enabled (on respawn for example), we restore its initial health levels More...
 
virtual void OnDisable ()
 Cancels all running invokes on disable More...
 

Protected Attributes

CharacterHorizontalMovement _characterHorizontalMovement
 
Vector3 _initialPosition
 
Color _initialColor
 
Renderer _renderer
 
Character _character
 
CorgiController _controller
 
MMHealthBar _healthBar
 
Collider2D _collider2D
 
bool _initialized = false
 
AutoRespawn _autoRespawn
 
Animator _animator
 
CharacterPersistence _characterPersistence = null
 
MaterialPropertyBlock _propertyBlock
 
bool _hasColorProperty = false
 
List< InterruptiblesDamageOverTimeCoroutine_interruptiblesDamageOverTimeCoroutines
 

Properties

float LastDamage [getset]
 
Vector3 LastDamageDirection [getset]
 

Detailed Description

This class manages the health of an object, pilots its potential health bar, handles what happens when it takes damage, and what happens when it dies.

Member Function Documentation

◆ CanTakeDamageThisFrame()

virtual bool MoreMountains.CorgiEngine.Health.CanTakeDamageThisFrame ( )
virtual

Returns true if this Health component can be damaged this frame, and false otherwise

Returns

◆ ComputeCharacterConditionStateChanges()

virtual void MoreMountains.CorgiEngine.Health.ComputeCharacterConditionStateChanges ( List< TypedDamage typedDamages)
protectedvirtual

Goes through resistances and applies condition state changes if needed

Parameters
typedDamages

◆ ComputeCharacterMovementMultipliers()

virtual void MoreMountains.CorgiEngine.Health.ComputeCharacterMovementMultipliers ( List< TypedDamage typedDamages)
protectedvirtual

Goes through the resistance list and applies movement multipliers if needed

Parameters
typedDamages

◆ ComputeDamageOutput()

virtual float MoreMountains.CorgiEngine.Health.ComputeDamageOutput ( float  damage,
List< TypedDamage typedDamages = null,
bool  damageApplied = false 
)
virtual

Returns the damage this health should take after processing potential resistances

Parameters
damage
Returns

◆ Damage()

virtual void MoreMountains.CorgiEngine.Health.Damage ( float  damage,
GameObject  instigator,
float  flickerDuration,
float  invincibilityDuration,
Vector3  damageDirection,
List< TypedDamage typedDamages = null 
)
virtual

Called when the object takes damage

Parameters
damageThe amount of health points that will get lost.
instigatorThe object that caused the damage.
flickerDurationThe time (in seconds) the object should flicker after taking the damage.
invincibilityDurationThe duration of the short invincibility following the hit.

Reimplemented in MoreMountains.CorgiEngine.SuperHipsterBrosHealth.

◆ DamageDisabled()

virtual void MoreMountains.CorgiEngine.Health.DamageDisabled ( )
virtual

Prevents the character from taking any damage

◆ DamageEnabled() [1/2]

virtual void MoreMountains.CorgiEngine.Health.DamageEnabled ( )
virtual

Allows the character to take damage

◆ DamageEnabled() [2/2]

virtual IEnumerator MoreMountains.CorgiEngine.Health.DamageEnabled ( float  delay)
virtual

makes the character able to take damage again after the specified delay

Returns
The layer collision.

◆ DamageOverTime()

virtual void MoreMountains.CorgiEngine.Health.DamageOverTime ( float  damage,
GameObject  instigator,
float  flickerDuration,
float  invincibilityDuration,
Vector3  damageDirection,
List< TypedDamage typedDamages = null,
int  amountOfRepeats = 0,
float  durationBetweenRepeats = 1f,
bool  interruptible = true,
DamageType  damageType = null 
)
virtual

Applies damage over time, for the specified amount of repeats (which includes the first application of damage, makes it easier to do quick maths in the inspector, and at the specified interval). Optionally you can decide that your damage is interruptible, in which case, calling InterruptAllDamageOverTime() will stop these from being applied, useful to cure poison for example.

Parameters
damage
instigator
flickerDuration
invincibilityDuration
damageDirection
typedDamages
amountOfRepeats
durationBetweenRepeats
interruptible

◆ DamageOverTimeCo()

virtual IEnumerator MoreMountains.CorgiEngine.Health.DamageOverTimeCo ( float  damage,
GameObject  instigator,
float  flickerDuration,
float  invincibilityDuration,
Vector3  damageDirection,
List< TypedDamage typedDamages = null,
int  amountOfRepeats = 0,
float  durationBetweenRepeats = 1f,
bool  interruptible = true,
DamageType  damageType = null 
)
protectedvirtual

A coroutine used to apply damage over time

Parameters
damage
instigator
flickerDuration
invincibilityDuration
damageDirection
typedDamages
amountOfRepeats
durationBetweenRepeats
interruptible
damageType
Returns

◆ DestroyObject()

virtual void MoreMountains.CorgiEngine.Health.DestroyObject ( )
protectedvirtual

Destroys the object, or tries to, depending on the character's settings

◆ DisablePostDamageInvulnerability() [1/2]

virtual void MoreMountains.CorgiEngine.Health.DisablePostDamageInvulnerability ( )
virtual

Allows the character to take damage

◆ DisablePostDamageInvulnerability() [2/2]

virtual IEnumerator MoreMountains.CorgiEngine.Health.DisablePostDamageInvulnerability ( float  delay)
virtual

Allows the character to take damage

◆ EnablePostDamageInvulnerability()

virtual void MoreMountains.CorgiEngine.Health.EnablePostDamageInvulnerability ( )
virtual

Prevents the character from taking any damage

◆ GetHealth()

virtual void MoreMountains.CorgiEngine.Health.GetHealth ( float  health,
GameObject  instigator 
)
virtual

Called when the character gets health (from a stimpack for example)

Parameters
healthThe health the character gets.
instigatorThe thing that gives the character health.

◆ Initialization()

virtual void MoreMountains.CorgiEngine.Health.Initialization ( )
protectedvirtual

Grabs useful components, enables damage and gets the inital color

Reimplemented in MoreMountains.CorgiEngine.SuperHipsterBrosHealth.

◆ InitializeSpriteColor()

virtual void MoreMountains.CorgiEngine.Health.InitializeSpriteColor ( )
protectedvirtual

Stores the inital color of the Character's sprite.

◆ InterruptAllDamageOverTime()

virtual void MoreMountains.CorgiEngine.Health.InterruptAllDamageOverTime ( )
virtual

Interrupts all damage over time, regardless of type

◆ InterruptAllDamageOverTimeOfType()

virtual void MoreMountains.CorgiEngine.Health.InterruptAllDamageOverTimeOfType ( DamageType  damageType)
virtual

Interrupts all damage over time of the specified type

Parameters
damageType

◆ Kill()

virtual void MoreMountains.CorgiEngine.Health.Kill ( )
virtual

Kills the character, instantiates death effects, handles points, etc

Reimplemented in MoreMountains.CorgiEngine.SuperHipsterBrosHealth.

◆ OnDeathDelegate()

delegate void MoreMountains.CorgiEngine.Health.OnDeathDelegate ( )

◆ OnDisable()

virtual void MoreMountains.CorgiEngine.Health.OnDisable ( )
protectedvirtual

Cancels all running invokes on disable

◆ OnEnable()

virtual void MoreMountains.CorgiEngine.Health.OnEnable ( )
protectedvirtual

When the object is enabled (on respawn for example), we restore its initial health levels

◆ OnHitDelegate()

delegate void MoreMountains.CorgiEngine.Health.OnHitDelegate ( )

◆ OnHitZeroDelegate()

delegate void MoreMountains.CorgiEngine.Health.OnHitZeroDelegate ( )

◆ OnReviveDelegate()

delegate void MoreMountains.CorgiEngine.Health.OnReviveDelegate ( )

◆ ResetHealthToMaxHealth()

virtual void MoreMountains.CorgiEngine.Health.ResetHealthToMaxHealth ( )
virtual

Resets the character's health to its max value

◆ ResetSpriteColor()

virtual void MoreMountains.CorgiEngine.Health.ResetSpriteColor ( )
protectedvirtual

Restores the original sprite color

◆ Revive()

virtual void MoreMountains.CorgiEngine.Health.Revive ( )
virtual

Revive this object.

◆ SetHealth()

virtual void MoreMountains.CorgiEngine.Health.SetHealth ( float  newHealth,
GameObject  instigator 
)
virtual

Sets the health of the character to the one specified in parameters

Parameters
newHealth
instigator

◆ Start()

virtual void MoreMountains.CorgiEngine.Health.Start ( )
protectedvirtual

On Start, we initialize our health

◆ StoreInitialPosition()

virtual void MoreMountains.CorgiEngine.Health.StoreInitialPosition ( )
virtual

◆ UpdateHealthBar()

virtual void MoreMountains.CorgiEngine.Health.UpdateHealthBar ( bool  show)
virtual

Updates the character's health bar progress.

Member Data Documentation

◆ _animator

Animator MoreMountains.CorgiEngine.Health._animator
protected

◆ _autoRespawn

AutoRespawn MoreMountains.CorgiEngine.Health._autoRespawn
protected

◆ _character

Character MoreMountains.CorgiEngine.Health._character
protected

◆ _characterHorizontalMovement

CharacterHorizontalMovement MoreMountains.CorgiEngine.Health._characterHorizontalMovement
protected

◆ _characterPersistence

CharacterPersistence MoreMountains.CorgiEngine.Health._characterPersistence = null
protected

◆ _collider2D

Collider2D MoreMountains.CorgiEngine.Health._collider2D
protected

◆ _controller

CorgiController MoreMountains.CorgiEngine.Health._controller
protected

◆ _hasColorProperty

bool MoreMountains.CorgiEngine.Health._hasColorProperty = false
protected

◆ _healthBar

MMHealthBar MoreMountains.CorgiEngine.Health._healthBar
protected

◆ _initialColor

Color MoreMountains.CorgiEngine.Health._initialColor
protected

◆ _initialized

bool MoreMountains.CorgiEngine.Health._initialized = false
protected

◆ _initialPosition

Vector3 MoreMountains.CorgiEngine.Health._initialPosition
protected

◆ _interruptiblesDamageOverTimeCoroutines

List<InterruptiblesDamageOverTimeCoroutine> MoreMountains.CorgiEngine.Health._interruptiblesDamageOverTimeCoroutines
protected

◆ _propertyBlock

MaterialPropertyBlock MoreMountains.CorgiEngine.Health._propertyBlock
protected

◆ _renderer

Renderer MoreMountains.CorgiEngine.Health._renderer
protected

◆ ApplyDeathForce

bool MoreMountains.CorgiEngine.Health.ApplyDeathForce = true

whether or not to apply a force on death

◆ CollisionsOffOnDeath

bool MoreMountains.CorgiEngine.Health.CollisionsOffOnDeath = true

if this is true, collisions will be turned off when the character dies

◆ ColorMaterialPropertyName

string MoreMountains.CorgiEngine.Health.ColorMaterialPropertyName = "_Color"

the name of the property on your renderer's shader that defines its color

◆ CurrentHealth

float MoreMountains.CorgiEngine.Health.CurrentHealth

the current health of the character

◆ DamageFeedbacks

MMFeedbacks MoreMountains.CorgiEngine.Health.DamageFeedbacks

the MMFeedbacks to play when the character gets hit

◆ DeathFeedbacks

MMFeedbacks MoreMountains.CorgiEngine.Health.DeathFeedbacks

the MMFeedbacks to play when the character dies

◆ DeathForce

Vector2 MoreMountains.CorgiEngine.Health.DeathForce = new Vector2(0, 10)

the force applied when the character dies

◆ DelayBeforeDestruction

float MoreMountains.CorgiEngine.Health.DelayBeforeDestruction = 0f

the time (in seconds) before the character is destroyed or disabled

◆ DestroyOnDeath

bool MoreMountains.CorgiEngine.Health.DestroyOnDeath = true

if this is not true, the object will remain there after its death

◆ FeedbackIsProportionalToDamage

bool MoreMountains.CorgiEngine.Health.FeedbackIsProportionalToDamage = false

if this is true, the damage value will be passed to the MMFeedbacks as its Intensity parameter, letting you trigger more intense feedbacks as damage increases

◆ FlickerColor

Color MoreMountains.CorgiEngine.Health.FlickerColor = new Color32(255, 20, 20, 255)

the color the sprite should flicker to

◆ FlickerSpriteOnHit

bool MoreMountains.CorgiEngine.Health.FlickerSpriteOnHit = true

should the sprite (if there's one) flicker when getting damage ?

◆ GravityOffOnDeath

bool MoreMountains.CorgiEngine.Health.GravityOffOnDeath = false

if this is true, gravity will be turned off on death

◆ ImmuneToDamage

bool MoreMountains.CorgiEngine.Health.ImmuneToDamage = false

whether or not this Health object can be damaged, you can play with this on top of Invulnerable, which will be turned on/off temporarily for temporary invulnerability. ImmuneToDamage is more of a permanent solution.

◆ ImmuneToKnockback

bool MoreMountains.CorgiEngine.Health.ImmuneToKnockback = false

whether or not this object can get knockback

◆ ImmuneToKnockbackIfZeroDamage

bool MoreMountains.CorgiEngine.Health.ImmuneToKnockbackIfZeroDamage = false

whether or not this object is immune to damage knockback if the damage received is zero

◆ InitialHealth

float MoreMountains.CorgiEngine.Health.InitialHealth = 10

the initial amount of health of the object

◆ Invulnerable

bool MoreMountains.CorgiEngine.Health.Invulnerable = false

if this is true, this object can't take damage

◆ MasterHealth

Health MoreMountains.CorgiEngine.Health.MasterHealth

another Health component (usually on another character) towards which all health will be redirected

◆ MaximumHealth

float MoreMountains.CorgiEngine.Health.MaximumHealth = 10

the maximum amount of health of the object

◆ OnDeath

OnDeathDelegate MoreMountains.CorgiEngine.Health.OnDeath

◆ OnHit

OnHitDelegate MoreMountains.CorgiEngine.Health.OnHit

◆ OnHitZero

OnHitZeroDelegate MoreMountains.CorgiEngine.Health.OnHitZero

◆ OnRevive

OnReviveDelegate MoreMountains.CorgiEngine.Health.OnRevive

◆ PointsWhenDestroyed

int MoreMountains.CorgiEngine.Health.PointsWhenDestroyed

the points the player gets when the object's health reaches zero

◆ PostDamageInvulnerable

bool MoreMountains.CorgiEngine.Health.PostDamageInvulnerable = false

If this is true, this object is in post damage invulnerability state.

◆ ResetColorOnRevive

bool MoreMountains.CorgiEngine.Health.ResetColorOnRevive = true

if this is true, color will be reset on revive

◆ ResetForcesOnDeath

bool MoreMountains.CorgiEngine.Health.ResetForcesOnDeath = false

whether or not the controller's forces should be set to 0 on death

◆ RespawnAtInitialLocation

bool MoreMountains.CorgiEngine.Health.RespawnAtInitialLocation = false

if this is set to false, the character will respawn at the location of its death, otherwise it'll be moved to its initial position (when the scene started)

◆ TargetDamageResistanceProcessor

DamageResistanceProcessor MoreMountains.CorgiEngine.Health.TargetDamageResistanceProcessor

a DamageResistanceProcessor this Health will use to process damage when it's received

◆ TemporarilyInvulnerable

bool MoreMountains.CorgiEngine.Health.TemporarilyInvulnerable = false

If this is true, this object can't take damage at the moment.

◆ UseMaterialPropertyBlocks

bool MoreMountains.CorgiEngine.Health.UseMaterialPropertyBlocks = false

if this is true, this component will use material property blocks instead of working on an instance of the material.

Property Documentation

◆ LastDamage

float MoreMountains.CorgiEngine.Health.LastDamage
getset

◆ LastDamageDirection

Vector3 MoreMountains.CorgiEngine.Health.LastDamageDirection
getset

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