HealthObject
A class in Root.Township, the global namespace.
Gives an entity health. Listens to its impact detectors, applies damage on the server through the health stat of its StatManager, and syncs death to clients. A component on creatures, players and breakable objects.
- Listed in Global namespace: E to H
- Inherits or implements
NetworkEntityBehaviour - Derived types
FakePlayerHealth,HealthObjectEvent,HealthObjectUnityEvent,PlayerHealth,Rock - Nested types
DeathAnalytics,HealthChangedHandler,RegenUnit - Documented in Health and damage, Impacts and hit detection
Constructors
| Member | What it is |
|---|---|
HealthObject() | Unity makes components itself; use AddComponent or spawn a prefab instead of new. |
Fields
| Member | What it is |
|---|---|
protected Stat healthStat | Cached health stat backing HealthStat. |
protected List<ImpactDetector> impactDetectors | Serialized list of impact detectors behind ImpactDetectors. |
14 private and internal fields
| Member | What it is |
|---|---|
private Transform core | Backing field for Core. Falls back to the object's own transform if empty. |
private Stat crippleDamageProtectionStat | Stat that divides incoming cripple damage, if the stat manager has it. |
private Stat crippleStat | Backing field for CrippleStat. |
private Stat damageProtectionStat | Stat that divides incoming health damage, if the stat manager has it. |
private HealthObjectEvent destroyed | Backing field for Destroyed, the event invoked when the object is killed. |
private EffectHandler effectHandler | Backing field for EffectHandler. |
private bool hasCrippleDamageProtection | True if the stat manager has the cripple damage protection stat. |
private bool hasDamageProtection | True if the stat manager has the damage protection stat. |
private Dictionary<ImpactType, float> impactTypeMultipliers | Damage multiplier per impact type, built from multipliers in Start. |
private bool isCombatant | Backing field for IsCombatant. Player hits on a combatant mark the player as in combat. |
private AttackTypeMultiplier[] multipliers | Backing field for Multipliers: damage multipliers per impact type. |
private PositionFromOriginHelper positionHelper | Helper passed to the PositionHandler created in Awake. |
private StatManager statManager | Backing field for StatManager. |
private MethodSync syncDeath | Method sync the server uses to tell clients the object died. |
Properties
| Member | What it is |
|---|---|
Transform Core { get; } | The central transform of the object, used as its main position. |
Stat CrippleStat { get; } | The cripple health stat, if the stat manager has one. |
HealthObjectEvent Destroyed { get; } | Unity event invoked when the object is killed, on both sides. |
EffectHandler EffectHandler { get; } | The alchemy effect handler for this object, if set. |
bool HasCrippleStat { get; private set; } | True if a cripple health stat was found on initialize. |
float Health { get; set; } | Current health value. Setting it sets the stat's base value. |
IEnumerable ImpactDetectors { get; } | The impact detectors that feed hits into this object. |
bool IsCombatant { get; } | If true, a player hitting this object is marked as having caused combat. |
DamageData LastHit { get; protected set; } | The most recent damage data, used to work out who or what killed it. |
float MaxHealth { get; set; } | Maximum health. Setting it keeps the object at full health if it was full. |
AttackTypeMultiplier[] Multipliers { get; } | Damage multipliers per attack type (blunt, slash and so on). |
PositionFromOriginHandler PositionHandler { get; private set; } | Gives the object's position relative to the world origin. |
StatManager StatManager { get; } | The stat manager that holds health and related stats. |
protected virtual HealthObject.DeathAnalytics AnalyticsRecord { get; } | Death analytics data (victim, killer name, position) built from the last hit. |
protected Stat HealthStat { get; } | The health stat. If there is no stat manager or no such stat, a temporary stat with max 1 is made. |
Events
| Member | What it is |
|---|---|
event HealthObject.HealthChangedHandler HealthChanged | Raised when health changes, with the change amount (negative for damage) and the last hit. |
event Action<DamageData> Killed | Raised when the object dies, with the killing hit. |
event ImpactHandler OnHit | Raised after each valid hit has been applied. |
Methods
| Member | What it is |
|---|---|
void DetectImpact(ImpactHit impact) | Handles a valid hit from a detector: applies attack type and armour multipliers, then ReceiveDamage, then raises OnHit. |
void Die() | Sets health to zero, which kills the object on the server. |
override void Initialize() | Sets up death sync and looks up the cripple and damage protection stats. |
void OnKilled() | Raises Killed. On the server also fires the console kill event, counts a task kill for the wielder and sends death to clients. |
virtual void OnValidate2() | Empty validation hook for subclasses. |
virtual void ReceiveDamage(float healthDamage, float crippleDamage, DamageData impact = null) | Server: lowers health and cripple health, divided by any damage protection stats. Does nothing once health is zero. |
protected virtual void Awake() | Points each listed impact detector's HealthTarget at this object. |
protected virtual void HandleObjectReachedZeroHealth() | Server: called when health hits zero. Calls OnKilled by default; subclasses override it (for example to down a player). |
protected void MarkAssailant(NetworkEntity assailant, float damage) | Tells the attacking player's character they caused combat, with the distance and damage. |
protected void OnHealthChanged(float changeAmount, ImpactHit impact) | Raises HealthChanged with a given amount and hit. |
protected virtual void Start() | Builds the attack type multiplier table and starts listening to the health stat. |
5 private and internal methods
| Member | What it is |
|---|---|
private void MarkAssailant(PlayerController assailant, float damage) | Tells the attacking player's character they caused combat, with the distance and damage. |
private void OnDisable() | Unhooks DetectImpact from the impact detectors' hit and particle hit events. |
private void OnEnable() | Hooks DetectImpact to every listed impact detector's hit and particle hit events. |
private void StatChanged(Stat stat) | Health stat handler: records the last hit, raises HealthChanged, and on the server handles reaching 0 health. |
private void SyncDeath(IPlayer player, Stream stream) | Method sync handler. Clients run OnKilled when the server reports the death. |
Used in
Members of other types that take, return or hold a HealthObject:
EffectHandler.health, EffectHandler.Health, HeatManager.damageTarget, EmbeddableManager.health, ImpactDetector.healthTarget, ImpactDetector.HealthTarget, TriggerImpactTool.hitHealthObjects, Agent.HealthChanged, Agent.Killed, Babu.Killed, DeathFern.Killed, Dragonfly.Killed, FireBug.Killed, Gotera.Killed, GreaterGotera.Killed, Phantom.Killed, SeedSpray.InitializeSpray, SeedSpray.Unchild, SeedSprayManager.healthObject, Spriggull.Killed, Target.healthObject, Target.HealthObject, Target.Killed, Turabada.Killed, Wyrm.Killed, ToCombatTransition<TFrom>.CheckEnterCombat, StaminaBarVisibility.PlayerDeath, StatBarVisibilityGroup.PlayerDeath, WoodcutTree.healthObject, WoodcutTree.HealthObject, Explosive.healths, HealthObject.HealthChangedHandler.BeginInvoke, HealthObject.HealthChangedHandler.Invoke, PlayerController.Health, PlayerController.healthTarget, PlayerEventsManager.OnHealthChanged, PlayerHealth.CheckForDamage.