Table of Contents

Class DeathReason

Namespace
TinyLife.Objects
Assembly
Tiny Life.dll

A death reason is a potential cause for a PersonLike's death. The set of all registered death reasons is stored in Reasons, and custom death reasons can be registered using Register(DeathReason). Each death reason has a unique name and can have additional properties such as particle spawners, gravestone particle spawners, tint functions and death animation overrides.

[JsonConverter(typeof(MigratingStaticJsonConverter<DeathReason>), new object[] { typeof(DeathReason), "PrivateReasons" })]
public class DeathReason
Inheritance
DeathReason
Inherited Members
Extension Methods

Constructors

DeathReason(string)

Creates a new death reason with the given name.

public DeathReason(string name)

Parameters

name string

The death reason's internal name, which is also used for localization.

Fields

Electrocution

A death reason that represents that a person died from electric shock. This value is used by TinyLife.Actions.RepairAction.

public static readonly DeathReason Electrocution

Field Value

DeathReason

InexplicableReasons

A death reason that represents that a person died from an unknown reason. This is only used by the "Die" cheat.

public static readonly DeathReason InexplicableReasons

Field Value

DeathReason

Name

This death reason's internal name, which is also used for localization.

public readonly string Name

Field Value

string

Overexertion

A death reason that represents that a person died from overexertion.

public static readonly DeathReason Overexertion

Field Value

DeathReason

Reasons

The set of registered death reasons from the game and mods. New death reasons can be registered using Register(DeathReason).

public static readonly ReadOnlyDictionary<string, DeathReason> Reasons

Field Value

ReadOnlyDictionary<string, DeathReason>

Starvation

A death reason that represents that a person died from hunger. This value is used by TinyLife.Actions.StarveAction.

public static readonly DeathReason Starvation

Field Value

DeathReason

TooMuchBrew

A death reason that represents that a person died from drinking too much brew, which represents alcohol.

public static readonly DeathReason TooMuchBrew

Field Value

DeathReason

TooMuchProtein

A death reason that represents that a person died from drinking too many protein shakes

public static readonly DeathReason TooMuchProtein

Field Value

DeathReason

Properties

DeathAnimationOverride

A function that can be used to override the death animation of a person who died from this reason. If this is null, the default death animation is used. The passed arguments are the death action, the current game time, the amount of time passed in-game since the last update, and the current game speed multiplier.

public Action<Action, GameTime, TimeSpan, float> DeathAnimationOverride { get; init; }

Property Value

Action<Action, GameTime, TimeSpan, float>

GravestoneParticleSpawner

This death reason's gravestone particle spawner, which is invoked periodically on a Gravestone that has a person inside who died from this reason. The first item in the tuple is a function that returns the chance of spawning a particle each frame, and the second item is the spawner itself, which is expected to spawn particles using Spawn(Map, Vector2, Func<Vector2, Particle>).

public (Func<Gravestone, float> Chance, Action<Gravestone, Random> Spawner) GravestoneParticleSpawner { get; init; }

Property Value

(Func<Gravestone, float> Chance, Action<Gravestone, Random> Spawner)

ParticleSpawner

This death reason's particle spawner, which is invoked during the death animation to spawn particles. The first item in the tuple is a function that returns the chance of spawning a particle each frame, and the second item is the spawner itself, which is expected to spawn particles using Spawn(Map, Vector2, Func<Vector2, Particle>).

public (Func<Action, float> Chance, Action<Action, Random> Spawner) ParticleSpawner { get; init; }

Property Value

(Func<Action, float> Chance, Action<Action, Random> Spawner)

TintFunction

A function that can be used to change a person's color during their death animation, which is also when the ParticleSpawner is invoked.

public Func<Action, Color> TintFunction { get; init; }

Property Value

Func<Action, Color>

Methods

Register(DeathReason)

Registers the given death reason into the Reasons collection, which allows it to be stored and retrieved from disk.

public static DeathReason Register(DeathReason reason)

Parameters

reason DeathReason

The reason to register.

Returns

DeathReason

The registered reason, for chaining.