PlayerHealth
A class in Root.Township, the global namespace.
A player's health. The server applies PvP, damage multiplier and immortality rules; reaching zero health downs the player instead of killing them. The local client shows hurt, hunger and nightmare effects.
- Listed in Global namespace: P
- Inherits or implements
HealthObject - Documented in Health and damage
Constructors
| Member | What it is |
|---|---|
PlayerHealth() | Unity makes components itself; use AddComponent or spawn a prefab instead of new. |
Fields
| Member | What it is |
|---|---|
static ToggleBool ArePlayersAvoidingDamage | The immortals toggle. While on, players' health can't drop below its maximum. |
17 private and internal fields
| Member | What it is |
|---|---|
private float baseSaturation | Unused saturation value (1). |
private Coroutine hungerBlurCoroutine | Running BlurEffect, or null. |
private Stat hungerStat | The player's hunger stat, local player only. |
private Coroutine hurtVignette | Running HurtVignette, or null. |
private bool isInvincibleToImpacts | Server: true during GrantInvincibilityToImpacts; impact damage is ignored. |
private int lastHungerLevel | Hunger level last seen by UpdateHunger. |
private PlayerController player | Backing field for Player. |
private IPlayerControllerMultiLockModel playerControllerMultiLockModel | Injected model that says whether the player's controls are locked. |
private DamageState playerDamageState | Server: reused state passed to HandleDamage handlers so they can block damage. |
private IPostProcessController postProcessController | Injected controller for blur, vignette and saturation. |
private Stat recentDamageStat | Server: stat set to 1 while the player was recently damaged. |
private float recentDamageTimer | Seconds left before the recent damage stat clears. |
private Coroutine recentDamageTimerCoroutine | Running RecentDamageTimer, or null. |
private bool repeatBlurry | True while the hunger blur should keep repeating. |
private PlayerHealthVisualEffectsSettings settings | Visual effect settings: hunger, saturation, vignette and blur curves. |
private Coroutine visionSaturationLerp | Running SaturationLerp, or null. |
private Coroutine woundedRegenCoroutine | Declared but not used in this class. |
Properties
| Member | What it is |
|---|---|
PlayerController Player { get; } | The player controller this health belongs to. |
protected override HealthObject.DeathAnalytics AnalyticsRecord { get; } | A death analytics record with the player's name, last hit and position. |
Events
| Member | What it is |
|---|---|
event Action<DamageData> Downed | Raised with the last hit when the player is downed. |
event Action<DamageState> HandleDamage | Server: raised before damage is applied. Mark the state handled to block the damage. |
Methods
| Member | What it is |
|---|---|
async void GrantInvincibilityToImpacts(float invincibilityTimeInSeconds) | Server: ignores impact damage for a number of seconds. |
void OnDowned() | Raises Downed. |
override void ReceiveDamage(float healthDamage, float crippleDamage, DamageData impact = null) | Server: applies damage unless blocked, dead, ignoring damage or invincible. Player hits need PvP on and use the PvP multipliers. |
void SetOwner(PlayerController player) | Sets the player controller. |
void StopPlayerEffects() | Client: sets the dead colour saturation and stops the hunger blur. |
void UpdateSaturation(float saturationTarget) | Client: fades the screen colour saturation to a value. |
protected override void Awake() | Sets up local player effects once linked to the local player. |
protected override void HandleObjectReachedZeroHealth() | Downs the player instead of the default death. |
protected void Inject(IPostProcessController postProcessController, IPlayerControllerMultiLockModel playerControllerMultiLockModel) | Receives the post processing and controller lock services by injection. |
protected override void Start() | Server: sets up the recent damage stat, immortals toggle and the block while controls are locked. |
15 private and internal methods
| Member | What it is |
|---|---|
private void BlockDamageIfControlsAreLocked(DamageState damageState) | Server: marks damage as handled (ignored) while the player's controls are locked. |
private IEnumerator BlurEffect() (iterator) | Client coroutine for hunger: blurs the screen corners with a curve and plays stomach rumbles, repeating while very hungry. |
private void CheckForDamage(HealthObject healthObject, float changeAmount, DamageData impact) | Server: on any health loss, sets the recent damage stat to 1 and restarts its cooldown timer. |
private void DisableResetVisuals() | Local player: stops the effect coroutines and resets post processing and the atmosphere. |
private void HandleLocalPlayerHit(ImpactHit impact) | Local player: records combat with another player in recent players when they hit you. |
private IEnumerator HurtVignette() (iterator) | Client coroutine that flashes the injured vignette along the settings curve, then clears it. |
private void OnDestroy() | Unhooks the immortals toggle and resets visuals. |
private void OnDisable() | Resets the local player's post-processing visuals. |
private void OnLinkedToplayer() | Local player only: hooks health and hunger to the screen effects and sets the starting saturation. |
private IEnumerator RecentDamageTimer() (iterator) | Server coroutine that counts down, then sets the recent damage stat back to 0. |
private IEnumerator SaturationLerp(float saturationTarget) (iterator) | Client coroutine that eases the screen colour saturation to a target. |
private void StopBlur() | Lets the hunger blur finish its current cycle and stop. |
private void ToggleImmortals(bool arePlayersImmortal) | Handles the immortals toggle: sets the health minimum to the maximum (no damage) or back to 0. |
private void UpdateHunger(Stat stat) | Starts or stops the hunger blur when the hunger level changes. |
private void UpdateVisuals(Stat stat) | On health loss plays the hurt vignette; always updates saturation from the health curve. |
Used in
Members of other types that take, return or hold a PlayerHealth: