playMaker

Author Topic: Stat By Level  (Read 2245 times)

Lane

  • Administrator
  • Hero Member
  • *****
  • Posts: 2511
  • Mender of the past
    • Cleverous
Stat By Level
« on: July 14, 2014, 08:45:46 AM »
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.

Code: [Select]
// (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;
}
}
        }
    }
}
« Last Edit: July 14, 2014, 01:00:48 PM by Lane »
Products by Cleverous
|| Vault Core : Database
|| Vault Inventory : Multiplayer Inventory
|| Vault Attributes : Character Stats
|| That Hurt! : Dmg Floaties
|| Quinn : 3D