public List <SpellResourceCost> CalcPowerCost(Unit caster, SpellSchoolMask schoolMask) { var powers = PowerCosts; var costs = new List <SpellResourceCost>(PowerCosts.Count); int healthCost = 0; foreach (var power in powers) { // bse powerCost int powerCost = power.PowerCost; // percent cost from total amount if (power.PowerCostPercentage > 0) { switch (power.SpellResourceType) { // health as power used case SpellResourceType.Health: powerCost += caster.MaxHealth.CalculatePercentage(power.PowerCostPercentage); break; case SpellResourceType.Mana: powerCost += caster.BaseMana.CalculatePercentage(power.PowerCostPercentage); break; case SpellResourceType.Rage: case SpellResourceType.Focus: case SpellResourceType.Energy: powerCost += caster.GetMaxPower(power.SpellResourceType).CalculatePercentage(power.PowerCostPercentage); break; case SpellResourceType.Runes: case SpellResourceType.RunicPower: Debug.unityLogger.LogWarning("Spells", $"CalculateManaCost for {power.SpellResourceType}: Not implemented yet!"); break; default: Debug.unityLogger.LogError("Spells", $"CalculateManaCost: Unknown power type '{power.SpellResourceType}' in spell {Id}"); continue; } } if (power.SpellResourceType == SpellResourceType.Health) { healthCost += powerCost; continue; } bool found = false; for (int i = 0; i < costs.Count; i++) { if (costs[i].SpellResource == power.SpellResourceType) { costs[i] = new SpellResourceCost(costs[i].SpellResource, costs[i].Amount + powerCost); found = true; } } if (!found) { costs.Add(new SpellResourceCost(power.SpellResourceType, powerCost)); } } if (healthCost > 0) { costs.Add(new SpellResourceCost(SpellResourceType.Health, healthCost)); } costs.RemoveAll(cost => cost.SpellResource != SpellResourceType.Runes && cost.Amount <= 0); return(costs); }