Ejemplo n.º 1
0
        public static CardCost Parse(CostTypes ct, string strct)
        {
            CardCost cc = new CardCost(ct);

            int    start  = strct.IndexOf("<") + 1;
            int    end    = strct.IndexOf(">", start);
            string result = strct.Substring(start, end - start);

            string[] tmp = result.Split('/');
            if (tmp.Length != 2)
            {
                throw new Exception("cost card target parsing error");
            }
            if (tmp [0] == "X")
            {
                //TODO: unknow what to do with this X
            }
            else
            {
                cc.Count = int.Parse(tmp [0]);
            }
            cc.validTargets = CardTarget.ParseTargets(tmp [1]);
            if (cc.CostType == CostTypes.Discard)
            {
                foreach (CardTarget c in cc.validTargets.OfType <CardTarget>())
                {
                    c.ValidGroup += CardGroupEnum.Hand;
                    c.Controler   = ControlerType.You;
                }
            }
            else
            {
                foreach (CardTarget c in cc.validTargets.OfType <CardTarget>())
                {
                    c.ValidGroup += CardGroupEnum.InPlay;
                    c.Controler   = ControlerType.You;
                }
            }
            return(cc);
        }
Ejemplo n.º 2
0
        public override Cost Pay(ref CardInstance ci, CardInstance source)
        {
            CardCost tmp = this.Clone() as CardCost;

            if (ValidTargets != null)
            {
                foreach (CardTarget t in ValidTargets.OfType <CardTarget>())
                {
                    if (t.Accept(ci, source))
                    {
                        tmp.Count--;
                        if (this.CostType == CostTypes.Discard || this.CostType == CostTypes.Sacrifice)
                        {
                            ci.ChangeZone(CardGroupEnum.Graveyard);
                        }
                        ci = null;
                        break;
                    }
                }
            }
            else if (this.CostType == CostTypes.Discard)
            {
                if (ci.CurrentGroup.GroupName == CardGroupEnum.Hand)
                {
                    ci.ChangeZone(CardGroupEnum.Graveyard);
                    tmp.Count--;
                    ci = null;
                }
            }
            else if (this.CostType == CostTypes.Sacrifice)
            {
                if (ci.CurrentGroup.GroupName == CardGroupEnum.InPlay)
                {
                    ci.ChangeZone(CardGroupEnum.Graveyard);
                    tmp.Count--;
                    ci = null;
                }
            }
            return(tmp.Count == 0 ? null : tmp);
        }
Ejemplo n.º 3
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);
        }