Last active
September 11, 2020 05:00
-
-
Save CoffeeVampir3/b2a51e1927af2849cd40672a042d05f0 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//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); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[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