In the process of making some more advanced character systems I found it to be way simpler to just code the math than doing all the operator actions. This is the first action I made with the intention of condensing some of the work you need to do in order to compute stats.
It's intended to calculate the natural stats of a character based on their level.
// (c) Copyright HutongGames, LLC 2010-2013. All rights reserved.
using UnityEngine;
namespace HutongGames.PlayMaker.Actions
{
[ActionCategory(ActionCategory.Math)]
[Tooltip("Designed to set a stat value based on character level and increase rate per level.")]
public class StatByLevel : FsmStateAction
{
[RequiredField]
[UIHint(UIHint.Variable)]
[Tooltip("The final stat variable.")]
public FsmFloat statVariable;
[Tooltip("The 'base' starting value of the stat at Level 1.")]
public FsmFloat statBaseValue;
[Tooltip("How much the stat increases per level.")]
public FsmFloat increasePerLevel;
[UIHint(UIHint.Variable)]
[Tooltip("Level of the character.")]
public FsmInt level;
[UIHint(UIHint.Variable)]
[Tooltip("Other float variables to add.")]
public FsmFloat[] otherVariables;
[Tooltip("Repeat every frame while the state is active.")]
public bool everyFrame;
public override void Reset()
{
statVariable = null;
statBaseValue = null;
increasePerLevel = null;
level = null;
otherVariables = null;
everyFrame = false;
}
public override void OnEnter()
{
DoStatCalc();
if (!everyFrame)
{
Finish();
}
}
public override void OnUpdate()
{
DoStatCalc();
}
void DoStatCalc()
{
statVariable.Value = (increasePerLevel.Value * level.Value + statBaseValue.Value);
if (otherVariables.Length > 0)
{
for (var i = 0; i < otherVariables.Length; i++)
{
statVariable.Value += otherVariables[i].Value;
}
}
}
}
}