コード例 #1
0
ファイル: Cost.cs プロジェクト: jpbruyere/MagicCrow
        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);
        }
コード例 #2
0
ファイル: Cost.cs プロジェクト: jpbruyere/MagicCrow
        public static bool operator >(Cost c1, Cost c2)
        {
            if (c1 == null)
            {
                return(false);
            }
            Cost left  = c2.Clone();
            Cost right = c1.Clone();

            return(left.Pay(ref right) == null ? true : false);
        }
コード例 #3
0
ファイル: Cost.cs プロジェクト: jpbruyere/MagicCrow
        public override Cost Pay(ref Cost c)
        {
            if (c.CostType == CostTypes.Composite)
            {
                Costs composite = c as Costs;
                Cost  result    = this.Clone();
                for (int i = 0; i < composite.CostList.Count; i++)
                {
                    Cost tmp = composite.CostList[i];

                    result = result.Pay(ref tmp);

                    if (tmp == null)
                    {
                        composite.CostList.RemoveAt(i);
                        i--;
                    }

                    if (result == null)
                    {
                        return(null);
                    }
                }
                if ((result as Costs) != null)
                {
                    if ((result as Costs).CostList.Count == 0)
                    {
                        return(null);
                    }
                }
                return(result);
            }
            else
            {
                for (int i = 0; i < CostList.Count; i++)
                {
                    Cost result = CostList[i].Pay(ref c);
                    if (result == null)
                    {
                        CostList.RemoveAt(i);
                        i--;
                    }
                    else
                    {
                        CostList[i] = result;
                    }
                }
            }
            return(CostList.Count == 0 ? null : this);
        }
コード例 #4
0
ファイル: Mana.cs プロジェクト: jpbruyere/MagicCrow
        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);
        }