Code Examples

v4.0

Customizing periodic effects at runtime

Without modification, the periodic effects are calcuated when the GameCondition object is created. If you'd like to specify the impact, you can use the SetPeriodicEffectValue() method.

The "Instant Health" condition is "Instant", and affects the "Health" of the target. However, the min/max value for points are both 0, meaning without modification, this will not have any impact at all.

The code below in DamageActor() will create a new GameCondition from the Instant Health Condition, and then set the value using the gameCondition.SetPeriodicEffectValue() method, passing in the Health Stat object, and the min/max values.

The method will choose a random value between min and max, and assign that value to the effect, and also return the value chosen.

public GameModulesActor actor;

// This property will return the Condition stored in _instantHealthCondition. If it
// has not yet been cached, the value will be set with the Properties lookup, and
// then returned.
public Condition InstantHealthCondition 
    => _instantHealthCondition ??= Properties.Conditions.Instant.InstantHealth;
private Condition _instantHealthCondition;
    
// A generic "Damage" method, which uses a condition called "Instant Health" which
// has one instant impact on the points of a "Health" stat, on the target actor.
public void DamageActor(float damageAmount, GameModulesActor target)
{
    // Create the GameCondition, and then set the impact
    var newGameCondition = new GameCondition(InstantHealthCondition
        , target.conditions, actor);
    var damageInflicted = newGameCondition.
        SetPeriodicEffectValue(Properties.Stats.MainStats.Health, -damageAmount
            , -damageAmount); // Method takes in a min and max; randomizes the impact

    // The method will return the final value, so you can do something with that.
    Debug.Log($"Inflicted {damageInflicted} damage to {target.GetOwnerName()}");
        
    // Don't forget to pass the GameCondition to the target!
    target.ReceiveCondition(newGameCondition);
}

Last updated