Table of Contents

Class ScalingFormula

Namespace
ElectricDrill.AstraRpgFramework.Scaling
Assembly
com.electricdrill.astra-rpg-framework.Runtime.dll

Represents a formula to calculate a value based on values returned by several scaling components. The calculation of each scaling component can either be based on the "self" entity (the entity that owns the formula) or the "target" entity (the entity that will be targeted by the action). For example, a scaling formula for an attack that deals the more damage the higher the enemy's armor is, can use the "self" entity to calculate the damage based on the attacker's stats and the "target" entity to calculate additional damage based on the target's armor. The final damage will be the sum of the value returned by the two scaling components.

public class ScalingFormula : ScriptableObject, IScalingFormula
Inheritance
object
ScalingFormula
Implements

Properties

HasSelfComponents

Whether this formula has any serialized self-scaling components.

public bool HasSelfComponents { get; }

Property Value

bool

HasTargetComponents

Whether this formula has any serialized target-scaling components.

public bool HasTargetComponents { get; }

Property Value

bool

SelfScalingComponents

Read-only view of the serialized self-scaling components.

public IReadOnlyList<ScalingComponent> SelfScalingComponents { get; }

Property Value

IReadOnlyList<ScalingComponent>

TargetScalingComponents

Read-only view of the serialized target-scaling components.

public IReadOnlyList<ScalingComponent> TargetScalingComponents { get; }

Property Value

IReadOnlyList<ScalingComponent>

TmpSelfScalingComponents

Gets the list of temporary scaling components for the "self" entity.

[Obsolete("Mutating temporary components on a shared ScriptableObject affects all entities that reference it. Create a ScalingFormulaInstance per entity and use its TmpSelfScalingComponents instead.")]
public List<ScalingComponent> TmpSelfScalingComponents { get; }

Property Value

List<ScalingComponent>

Remarks

Deprecated. Because ScalingFormula is a shared ScriptableObject, mutating this list affects every entity that references the same asset. Use TmpSelfScalingComponents instead to keep temporary components isolated per entity.

TmpTargetScalingComponents

Gets the list of temporary scaling components for the "target" entity.

[Obsolete("Mutating temporary components on a shared ScriptableObject affects all entities that reference it. Create a ScalingFormulaInstance per entity and use its TmpTargetScalingComponents instead.")]
public List<ScalingComponent> TmpTargetScalingComponents { get; }

Property Value

List<ScalingComponent>

Remarks

Deprecated. Because ScalingFormula is a shared ScriptableObject, mutating this list affects every entity that references the same asset. Use TmpTargetScalingComponents instead to keep temporary components isolated per entity.

UseScalingBaseValue

Whether this formula calculates its base value from a GrowthFormula at a given level.

public bool UseScalingBaseValue { get; }

Property Value

bool

Methods

CalculateValue(EntityCore)

Calculates the final value using only the "self" entity. This method assumes there are no target scaling components.

public long CalculateValue(EntityCore self)

Parameters

self EntityCore

The entity providing values for self-scaling components.

Returns

long

The calculated value.

CalculateValue(EntityCore, EntityCore)

Calculates the final value using both "self" and "target" entities.

public long CalculateValue(EntityCore self, EntityCore target)

Parameters

self EntityCore

The entity providing values for self-scaling components.

target EntityCore

The entity providing values for target-scaling components.

Returns

long

The calculated value.

CalculateValue(EntityCore, EntityCore, int)

Calculates the final value using both "self" and "target" entities, and a specific level for the base value. This method assumes the formula uses a scaling base value.

public long CalculateValue(EntityCore self, EntityCore target, int level)

Parameters

self EntityCore

The entity providing values for self-scaling components.

target EntityCore

The entity providing values for target-scaling components.

level int

The level to use for calculating the base value.

Returns

long

The calculated value.

CalculateValue(EntityCore, int)

Calculates the final value using the "self" entity and a specific level for the base scaling value. This method assumes there are no target scaling components and the formula uses a scaling base value.

public long CalculateValue(EntityCore self, int level)

Parameters

self EntityCore

The entity providing values for self-scaling components.

level int

The level to use for calculating the base value.

Returns

long

The calculated value.

GetBaseValue()

Returns the fixed base value of the formula. If useScalingBaseValue is true, an exception is thrown because a level is required.

public long GetBaseValue()

Returns

long

The fixed base value.

Exceptions

AssertionException

Thrown if useScalingBaseValue is true, since a level must be specified in that case.

GetBaseValue(int)

Returns the base value of the formula for the specified level. If useScalingBaseValue is true, the value is calculated using the associated growth formula. If useScalingBaseValue is false and a level is provided, an exception is thrown.

public long GetBaseValue(int level)

Parameters

level int

The level to use for calculating the base value.

Returns

long

The calculated base value.

Exceptions

AssertionException

Thrown if the growth formula is not set, if the level is less than or equal to zero, if the level exceeds the maximum allowed by the growth formula, or if useScalingBaseValue is false and a level is provided.

ResetTmpScalings()

Clears all temporary scaling components for both "self" and "target".

[Obsolete("Resetting temporary components on a shared ScriptableObject affects all entities that reference it. Create a ScalingFormulaInstance per entity and call ResetTmpScalings on the instance instead.")]
public void ResetTmpScalings()

Remarks

Deprecated. Because ScalingFormula is a shared ScriptableObject, this call clears temporary components for every entity that references the same asset. Use ResetTmpScalings() instead.