public override Cost Pay(ref Cost c) { if (c == null) { return(this); } c.OrderFirst(this.GetDominantMana()); Costs cl = c as Costs; if (cl != null) { Cost tmp = this.Clone(); for (int i = 0; i < cl.CostList.Count; i++) { Cost cli = cl.CostList [i]; tmp = tmp.Pay(ref cli); if (cli == null) { cl.CostList.RemoveAt(i); i--; } if (tmp == null) { break; } } if (cl.CostList.Count == 0) { c = null; } return(tmp); } Mana m = c as Mana; if (m == null) { return(this); } if (m is ManaChoice) { ManaChoice mc = m.Clone() as ManaChoice; for (int i = 0; i < mc.Manas.Count; i++) { Cost result = this.Clone(); Cost tmp = mc.Manas[i]; result = result.Pay(ref tmp); if (tmp == null) { c = null; } if (result == null) { return(null); } } } else { if (TypeOfMana == m.TypeOfMana || TypeOfMana == ManaTypes.Colorless) { count -= m.count; if (count == 0) { c = null; return(null); } else if (count < 0) { m.count = -count; return(null); } else { c = null; return(this); } } } return(this); }