using System.Collections.Generic; using UnityEngine; namespace MontanaJohns.Core { public static class StatsExtensions { public static Stats Sum(this IEnumerable source) { var sum = default(Stats); using (var iter = source.GetEnumerator()) { if (!iter.MoveNext()) return sum; while (iter.MoveNext()) sum += iter.Current; return sum; } } } [System.Serializable] public struct Stats { [SerializeField] public int maxHealth; [SerializeField] public float speedMultiplier; [SerializeField] public float maxSpeed; [SerializeField] public int maxJumps; [SerializeField] public float jumpForce; [SerializeField] public int damage; public static Stats operator +(Stats x, Stats y) { return new Stats { maxHealth = x.maxHealth + y.maxHealth, speedMultiplier = x.speedMultiplier + y.speedMultiplier, maxJumps = x.maxJumps + y.maxJumps, jumpForce = x.jumpForce + y.jumpForce, damage = x.damage + y.damage, maxSpeed = x.maxSpeed + y.maxSpeed, }; } public static Stats DefaultBaseStats() { return new Stats { maxHealth = 3, speedMultiplier = 1, maxSpeed = 25f, maxJumps = 1, jumpForce = 500f, damage = 0, }; } } }