Example #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);
        }
Example #2
0
//		static List<string> list = new List<String> ();

        public static AttributGroup <Target> ParseTargets(string str)
        {
            AttributGroup <Target> result = new AttributGroup <Target>(AttributeType.Choice);

            string[] tmp = str.Trim().Split(new char[] { ',' });
            foreach (string t in tmp)
            {
                if (string.IsNullOrWhiteSpace(t))
                {
                    continue;
                }

                string[] cardTypes = t.Trim().Split(new char[] { '.', '+' });

                switch (cardTypes[0].Trim())
                {
                case "Opponent":
                    result |= TargetType.Opponent;
                    break;

                case "Player":
                    result |= TargetType.Player;
                    break;

                case "CHARGE":
                    result |= TargetType.Charge;
                    break;

                default:
                    CardTarget ctar = new CardTarget();

                    foreach (string ct in cardTypes)
                    {
                        switch (ct)
                        {
                        case "Card":
                            break;

                        case "Permanent":
                            ctar.TypeOfTarget = TargetType.Permanent;
                            break;

                        case "YouCtrl":
                            ctar.Controler = ControlerType.You;
                            break;

                        case "YouDontCtrl":
                            ctar.Controler = ControlerType.Opponent;
                            break;

                        case "OppCtrl":
                            ctar.Controler = ControlerType.Opponent;
                            break;

                        case "Other":
                            ctar.CanBeTargetted = false;
                            break;

                        case "TypeYouCtrl":
                            ctar.TypeOfTarget = TargetType.Permanent;
                            ctar.Controler    = ControlerType.You;
                            break;

                        case "attacking":
                            ctar.CombatState = CombatImplication.Attacking;
                            break;

                        case "blocking":
                            ctar.CombatState = CombatImplication.Blocking;
                            break;

                        case "CARDNAME":
                        case "Self":
                            ctar.TypeOfTarget = TargetType.Self;
                            break;

                        case "EnchantedBy":
                            ctar.TypeOfTarget = TargetType.EnchantedBy;
                            break;

                        case "equipped":
                            ctar.HavingAttachedCards += CardTypes.Equipment;
                            break;

                        case "kicked":
                            ctar.TypeOfTarget = TargetType.Kicked;
                            break;

                        case "Attached":
                            ctar.TypeOfTarget = TargetType.Attached;
                            break;

                        case "EquippedBy":
                            ctar.TypeOfTarget = TargetType.EquipedBy;
                            break;

                        case "White":
                            ctar.ValidCardColors += ManaTypes.White;
                            break;

                        default:
                            #region ability inclusion/exclusion
                            if (ct.StartsWith("without"))
                            {
                                ctar.WithoutAbilities += Ability.ParseKeyword(ct.Substring(7));
                                break;
                            }
                            if (ct.StartsWith("with"))
                            {
                                ctar.HavingAbilities += Ability.ParseKeyword(ct.Substring(4));
                                break;
                            }
                            #endregion
                            #region numeric contrain
                            NumericConstrain nc     = null;
                            string           strTmp = "";
                            if (ct.ToLower().StartsWith("power"))
                            {
                                ctar.PowerConstrain = new NumericConstrain();
                                nc     = ctar.PowerConstrain;
                                strTmp = ct.Substring(5);
                            }
                            else if (ct.ToLower().StartsWith("toughness"))
                            {
                                ctar.ToughnessConstrain = new NumericConstrain();
                                nc     = ctar.ToughnessConstrain;
                                strTmp = ct.Substring(9);
                            }

                            if (nc != null)
                            {
                                string strRelation = strTmp.Substring(0, 2);
                                switch (strRelation)
                                {
                                case "EQ":
                                    nc.Relation = NumericRelations.Equal;
                                    break;

                                case "LT":
                                    nc.Relation = NumericRelations.Less;
                                    break;

                                case "LE":
                                    nc.Relation = NumericRelations.LessOrEqual;
                                    break;

                                case "GT":
                                    nc.Relation = NumericRelations.Greater;
                                    break;

                                case "GE":
                                    nc.Relation = NumericRelations.GreaterOrEqual;
                                    break;

                                case "NE":
                                    nc.Relation = NumericRelations.NotEqual;
                                    break;

                                default:
                                    break;
                                }
                                strTmp = strTmp.Substring(2);

                                if (strTmp != "X" && !string.IsNullOrWhiteSpace(strTmp))
                                {
                                    nc.Value = int.Parse(strTmp);
                                }

                                break;
                            }
                            #endregion
                            #region card types constrains
                            CardTypes cts;
                            if (Enum.TryParse <CardTypes>(ct, true, out cts))
                            {
                                ctar.ValidCardTypes += (CardTypes)Enum.Parse(typeof(CardTypes), ct, true);
                            }
                            else
                            {
                                Debug.WriteLine("Unknow card type: " + ct);
                            }
                            #endregion
                            break;
                        }
                    }
                    result |= ctar;
                    break;
                }
            }

            return(result);
        }