Table of Contents

Struct ReductionContext

Namespace
ElectricDrill.AstraHealth.ReductionFunctions
Assembly
com.electricdrill.astra-health.Runtime.dll

The entities involved in a hit, handed to damage mitigation and defense penetration functions that depend on more than the stat values: a formula whose constant grows with the attacker's level, or one driven by another stat of the attacker or the target.

public readonly struct ReductionContext

Remarks

It carries references and derives what it exposes only when asked, so a function that needs nothing from it (flat, percentage, logarithmic) costs nothing. Future inputs are added as properties here, not as new parameters on the functions.

Entity-backed or value-backed. The damage pipeline builds an entity-backed context. Tools and tests that have no entities can state levels directly with ReductionContext(int, int), and the full constructor lets an explicit level take precedence over the entity's. default is a valid context: no entities, target level 1, no performer (the same as Default).

Contract for functions. The context is valid only during the call: do not store it or its references. Functions are pure, so treat the entities as read-only even though they are reachable. Read a stat with TryGet on TargetStats / PerformerStats and treat a missing stat as 0: those readers are null when the context was built from levels alone.

What is not a stat. TargetStats and PerformerStats exist to read stats the way the pipeline does: the attacker's through the ownership fallback chain, which an entity cannot derive on its own (hence the reader the pipeline injects for it; the target has no chain and is read directly). Anything else is reached through Target and Performer. The target's maximum health, for example, is not a stat but EntityHealth.MaxHp: context.Target.GetEntityHealth() returns it, or null when the context has no target entity or the target has no health component.

It is a readonly struct passed by in: building and passing it does not allocate, which matters on the per-hit damage path.

Constructors

ReductionContext(EntityCore, EntityCore, IStatReader, int, int)

Builds a context from the entities of a hit.

public ReductionContext(EntityCore target, EntityCore performer, IStatReader performerStats = null, int targetLevel = 0, int performerLevel = 0)

Parameters

target EntityCore

The entity taking the damage. May be null.

performer EntityCore

The entity the damage is attributed to: the performer itself, or its resolved owner under an ownership attribution. null for environmental damage.

performerStats IStatReader

The reader used for the attacker's stats, which under an ownership attribution falls back from the performer to its owner. When null, performer is used.

targetLevel int

An explicit target level that takes precedence over the entity's. 0 or less reads it from the entity.

performerLevel int

An explicit performer level that takes precedence over the entity's. 0 or less reads it from the entity.

ReductionContext(int, int)

Builds a context from levels alone, with no entities (so no stat readers).

public ReductionContext(int targetLevel, int performerLevel)

Parameters

targetLevel int

Level of the damage target. Values below 1 are raised to 1.

performerLevel int

Level of the attacker, or 0 (or less) when there is no performer.

Fields

Default

Context used when no entity is known (tools, callers of the context-free overloads): the target is level 1 and there is no performer, so every level source resolves to level 1.

public static readonly ReductionContext Default

Field Value

ReductionContext

Properties

HasPerformer

true when the hit has an attacker: a performer entity or an explicit performer level.

public bool HasPerformer { get; }

Property Value

bool

Performer

The entity the hit is attributed to: the performer itself, or its resolved owner under an ownership attribution (a level 1 weapon owned by a level 50 hero attacks as the hero). null for environmental damage, or when the context was built from levels alone.

public EntityCore Performer { get; }

Property Value

EntityCore

PerformerLevel

Level of the entity the hit is attributed to: the explicit one if given, otherwise the performer's, otherwise 0 when there is no performer.

public int PerformerLevel { get; }

Property Value

int

PerformerStats

Reader for the attacker's stats, consistent with the stats the piercing stat is read from: under an ownership attribution the performer's own stats come first and its owner's fill the gaps. null when there is no performer entity.

public IStatReader PerformerStats { get; }

Property Value

IStatReader

Target

The entity taking the damage, or null when the context was built from levels alone.

public EntityCore Target { get; }

Property Value

EntityCore

TargetLevel

Level of the entity taking the damage: the explicit one if given, otherwise the target's, otherwise 1. Never below 1.

public int TargetLevel { get; }

Property Value

int

TargetStats

Reader for the target's stats, or null when there is no target entity. Always the target entity itself: unlike the attacker's, there is no fallback chain.

public IStatReader TargetStats { get; }

Property Value

IStatReader