Esempio n. 1
0
        public override Cost Clone()
        {
            ManaChoice c = new ManaChoice();

            foreach (Cost ct in Manas)
            {
                c.Manas.Add(ct.Clone() as Mana);
            }
            return(c);
        }
Esempio n. 2
0
        public virtual bool Contains(Cost c)
        {
            Costs cst = this as Costs;

            if (cst != null)
            {
                foreach (Cost cc in cst.CostList)
                {
                    if (cc.Contains(c))
                    {
                        return(true);
                    }
                }
                return(false);
            }
            ManaChoice mc = this as ManaChoice;

            if (mc != null)
            {
                foreach (Mana i in mc.Manas)
                {
                    if (i.Contains(c))
                    {
                        return(true);
                    }
                }
                return(false);
            }
            Mana m = this as Mana;

            if (m != null)
            {
                Mana cm = c as Mana;
                if (cm == null)
                {
                    return(false);
                }
                if ((cm.TypeOfMana == m.TypeOfMana ||
                     (cm.TypeOfMana == ManaTypes.Colorless && m.TypeOfMana <= ManaTypes.Colorless) ||
                     (m.TypeOfMana == ManaTypes.Colorless && cm.TypeOfMana <= ManaTypes.Colorless)) &&
                    m.count >= cm.count)
                {
                    return(true);
                }
                else
                {
                    return(false);
                }
            }
            return(this == c ? true : false);
        }
Esempio n. 3
0
        public override bool IsSameType(Mana m)
        {
            ManaChoice choice = m as ManaChoice;

            if (choice == null)
            {
                return(false);
            }
            if (choice.Manas.Count != Manas.Count)
            {
                return(false);
            }

            for (int i = 0; i < Manas.Count; i++)
            {
                if (!choice.Manas[i].IsSameType(Manas[i]))
                {
                    return(false);
                }
            }

            return(true);
        }
Esempio n. 4
0
        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);
        }
Esempio n. 5
0
        public static Cost Parse(string costString)
        {
            if (costString.ToLower() == "no cost")
            {
                return(null);
            }
            if (costString.ToLower() == "any")
            {
                return(new Mana(ManaTypes.Any));
            }
            if (costString.ToLower() == "combo any")
            {
                return(new Mana(ManaTypes.ComboAny));
            }

            Costs sum = new Costs();

            string[] tmp = costString.Split(new char[] { });

            foreach (string c in tmp)
            {
                if (string.IsNullOrWhiteSpace(c))
                {
                    continue;
                }

                switch (c)
                {
                case "T":
                    sum += new Cost(CostTypes.Tap);
                    continue;
                }

                if (c.StartsWith("Discard"))
                {
                    sum += CardCost.Parse(CostTypes.Discard, c);
                    continue;
                }
                else if (c.StartsWith("Sac"))
                {
                    sum += CardCost.Parse(CostTypes.Sacrifice, c);
                    continue;
                }
                else if (c.StartsWith("SubCounter"))
                {
                    sum += CardCost.Parse(CostTypes.SubCounter, c);
                    continue;
                }

                string     number = "";
                ManaChoice choice = new ManaChoice();

                for (int i = 0; i < c.Length; i++)
                {
                    if (char.IsDigit(c[i]))
                    {
                        number += c[i];

                        if (i < c.Length - 1)
                        {
                            if (char.IsDigit(c[i + 1]))
                            {
                                continue;
                            }
                        }

                        choice += new Mana(int.Parse(number));
                        number  = null;
                    }
                    else
                    {
                        switch (c[i])
                        {
                        case 'W':
                            choice += ManaTypes.White;
                            break;

                        case 'R':
                            choice += ManaTypes.Red;
                            break;

                        case 'G':
                            choice += ManaTypes.Green;
                            break;

                        case 'B':
                            choice += ManaTypes.Black;
                            break;

                        case 'U':
                            choice += ManaTypes.Blue;
                            break;

                        case 'P':
                            choice += ManaTypes.Life;
                            break;

                        case 'X':
                            choice += new Mana(-1);
                            break;

                        case '/':
                            continue;

                        default:
                            break;
                        }
                    }
                }

                if (choice.Manas.Count == 1)
                {
                    sum += choice.Manas[0];
                }
                else
                {
                    sum += choice;
                }
            }

            if (sum.CostList.Count == 0)
            {
                return(null);
            }
            if (sum.CostList.Count == 1)
            {
                return(sum.CostList[0]);
            }
            else
            {
                return(sum);
            }
            return(sum);
        }