private void EvaluateStat() { if (targetStat == null) { return; } if (statBlock == null) { ConditionalGraph condGraph = graph as ConditionalGraph; if (condGraph.GetStateMachineOwner() == null) { return; } statBlock = condGraph.GetStateMachineOwner().GetComponent <StatBlock>(); if (statBlock == null) { return; } } Stat retreivedStat = null; if (statBlock.TryGetValue(targetStat, out retreivedStat)) { currentValue = retreivedStat.value; outputValue = retreivedStat.value; statValue = retreivedStat; } }
static void ApplyAll(StatBlock stats, DamageType damageType, int amount) { for (int i = 0; i < damageType.damagesStats.Count; i++) { Stat stat = null; if (stats.TryGetValue(damageType.damagesStats[i], out stat)) { if (stat.value > 0) { stat.value = Mathf.Clamp(stat - amount, 0, int.MaxValue); } } } }
static bool CostModeAll(StatBlock costStatBlock, StatBlock paysCostStatBlock, CostType costType, bool apply = false) { bool retVal = true; for (int i = 0; i < costType.costStats.Count; i++) { CostType.CostAssociation costAssoc = costType.costStats[i]; Stat costStat = null; Stat payStat = null; if (!costStatBlock.TryGetValue(costAssoc.cost, out costStat)) { Debug.LogError("No cost stat associated with cost for obj" + costStatBlock.gameObject.name); return(false); } if (!paysCostStatBlock.TryGetValue(costAssoc.payedWith, out payStat)) { Debug.LogError("No cost stat associated with cost for obj" + paysCostStatBlock.gameObject.name); return(false); } if (costStat > payStat) { if (!apply) { //Our cost is more expensive than we can afford and we're not applying it retVal = false; } } else { //We can afford our cost and we're applying it if (apply) { payStat.value -= costStat; } } } return(retVal); }
static void ApplyFirstNonZeroSpillover(StatBlock stats, DamageType damageType, int amount) { int newAmount = amount; for (int i = 0; i < damageType.damagesStats.Count; i++) { Debug.Log("yeet"); Stat stat = null; if (stats.TryGetValue(damageType.damagesStats[i], out stat)) { if (stat.value - newAmount >= 0) { stat.value -= newAmount; return; } else { newAmount -= stat.value; stat.value = 0; } } } }