Skip to content

Instantly share code, notes, and snippets.

@CoffeeVampir3
Last active September 11, 2020 05:00
Show Gist options
  • Save CoffeeVampir3/b2a51e1927af2849cd40672a042d05f0 to your computer and use it in GitHub Desktop.
Save CoffeeVampir3/b2a51e1927af2849cd40672a042d05f0 to your computer and use it in GitHub Desktop.
//Example use would be Damage (source) to Health (target)
//which would lookup the sources Damage stat and deal that much damage to the target's Health stat.
public abstract class ScriptableStatInteractor : ScriptableObject
{
[SerializeField]
protected ModularStat sourceStat = null;
[SerializeField]
protected ModularStat targetStat = null;
public abstract int Apply(StatBlock sourceBlock, StatBlock targetBlock);
public abstract int ApplyInverse(StatBlock sourceBlock, StatBlock targetBlock);
public abstract bool CanApplyWithoutOverflowOrUnderflow(StatBlock sourceBlock, StatBlock targetBlock);
public abstract bool CanApplyInverseWithoutOverflowOrUnderflow(StatBlock sourceBlock, StatBlock targetBlock);
}
public class StatBlock : MonoBehaviour {
[SerializeField]
private List<StatWrap> stats = new List<StatWrap>();
private class StatWrap {
public ModularStat targetStat;
public int currentVal;
public int maxVal;
}
public bool TryGetStat(ModularStat stat, bool maxValue, out int statValue)
{
for (int i = 0; i < stats.Count; i++)
{
if (stats[i].targetStat == stat)
{
statValue = maxValue ? stats[i].currentVal : stats[i].maxVal;
return true;
}
}
statValue = int.MinValue;
return false;
}
}
[CreateAssetMenu(menuName = "ModularStats/Stat")]
[Serializable]
public class ModularStat : ScriptableObject {
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment