public virtual Cost Pay(ref Cost c) { Cost result = null; if (c != null) { c.OrderFirst(this.GetDominantMana()); Costs cl = c as Costs; if (cl != null) { for (int i = 0; i < cl.CostList.Count; i++) { Cost cli = cl.CostList[i]; if (Pay(ref cli) == null) { cl.CostList.RemoveAt(i); return(null); } } } if (CostType == c.CostType) { c = null; return(null); } } return(this); }
public static bool operator <(Cost c1, Cost c2) { if (c2 == null) { return(false); } if (c1 == null) { if (c2.CostType == CostTypes.Mana) { if ((c2 as Mana).count == 0) { return(false); } } return(true); } Cost right = c2.Clone(); ManaTypes dominant = right.GetDominantMana(); Cost left = c1.Clone(); left.OrderFirst(dominant); right.OrderFirst(dominant); Cost result = right.Pay(ref left); return(result == null || result == CostTypes.Tap ? false : true); }
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); }