Ejemplo n.º 1
0
        public static bool TryToParseAndSetValue(string _id, string datas)
        {
            if (!SVarToResolve.UnresolvedSVars.ContainsKey(_id))
            {
                return(false);
            }

            List <SVarToResolve> svars = UnresolvedSVars [_id];
            object o     = svars.FirstOrDefault().instance;
            object value = null;

            if (o is Ability)
            {
                value = Ability.Parse(datas);
            }
            else if (o is Trigger)
            {
                value = Ability.Parse(datas, o as Trigger);
            }
            else
            {
                string[] tmp = datas.Split('$');
                switch (tmp[0])
                {
                case "Count":
                    CardCounter cc   = new CardCounter();
                    string[]    div  = tmp [1].Split('/');
                    string[]    tmp2 = div [0].Split(' ');
                    if (tmp2 [0] == "Valid")
                    {
                        cc.CardsToCount = Target.ParseTargets(tmp2 [1]);
                    }
                    else if (tmp2 [0].StartsWith("Kicked"))
                    {
                        string[]         tmp3 = tmp2 [0].Split('.');
                        KickedOrNotValue kov  = new KickedOrNotValue(int.Parse(tmp3 [1]), int.Parse(tmp3 [2]));
                        value = kov;
                        break;
                    }
                    else
                    {
                        cc.CardsToCount = Target.ParseTargets(tmp2 [0]);
                    }

                    if (div.Count() == 2)
                    {
                        tmp2 = div [1].Split('.');
                        int v = 0;
                        if (tmp2 [0] == "Times")
                        {
                            if (int.TryParse(tmp2 [1], out v))
                            {
                                cc.Multiplier = v;
                            }
                            else
                            {
                                SVarToResolve.RegisterSVar(tmp2 [1], cc, cc.GetType().GetField("Multiplier"));
                            }
                        }
                    }
                    value = cc;
                    break;

                case "LifeAmount":
                    break;

                default:
                    Debug.WriteLine("unandle svar: " + datas);
                    break;
                }
            }
            try {
                return(TryToSetValue(_id, value));
            } catch (Exception ex) {
                Debug.WriteLine(ex.Message);
                return(false);
            }
        }
Ejemplo n.º 2
0
        public static MagicCard LoadCardData(Stream s)
        {
            MagicCard c = new MagicCard();

            using (StreamReader sr = new StreamReader(s))
            {
                while (!sr.EndOfStream)
                {
                    string line = sr.ReadLine();

                    string[] tmp = line.Split(new char[] { ':' });

                    switch (tmp[0].ToLower())
                    {
                    case "name":
                        c.Name = tmp [1];
                        break;

                    case "manacost":
                        c.Cost = Mana.Parse(tmp[1]);
                        break;

                    case "types":
                        string[] types = tmp[1].Split(new char[] { ' ' });
                        foreach (string t in types)
                        {
                            if (string.IsNullOrEmpty(t))
                            {
                                continue;
                            }
                            string tt = t.Replace('\'', '_');
                            tt       = tt.Replace('-', '_');
                            c.Types += (CardTypes)Enum.Parse(typeof(CardTypes), tt, true);
                        }
                        break;

                    case "a":
                        c.Abilities.Add(Ability.Parse(tmp[1]));
                        break;

                    case "oracle":
                        c.Oracle = string.Join("\n", tmp.ToList().GetRange(1, tmp.Length - 1).ToArray());
                        break;

                    case "pt":
                        string[] pt = tmp[1].Split(new char[] { '/' });

                        int intPT;

                        if (int.TryParse(pt[0], out intPT))
                        {
                            c.Power = intPT;
                        }
                        else
                        {
                            Debug.WriteLine("power:" + pt[0]);
                        }

                        if (int.TryParse(pt[1], out intPT))
                        {
                            c.Toughness = intPT;
                        }
                        else
                        {
                            Debug.WriteLine("toughness:" + pt[1]);
                        }
                        break;

                    case "s":
//							Ability aa = c.Abilities.FirstOrDefault ();
//							if (aa == null) {
//								aa = new Ability ();
//								c.Abilities.Add (aa);
//							} else
//								Debugger.Break;

                        c.SpellEffects.Add(EffectGroup.Parse(tmp[1]));
                        break;

                    case "t":
                        c.Triggers.Add(Trigger.Parse(tmp[1]));
                        break;

                    case "svar":

                        if (SVarToResolve.TryToParseAndSetValue(tmp [1], tmp [2]))
                        {
                            break;
                        }

                        switch (tmp[1].ToLower())
                        {
                        case "darkeffect":
                            break;

                        case "darkpower":
                            break;

                        case "darkmana":
                            break;

                        case "picture":
                            c.picturePath = tmp[3];
                            break;

                        case "remaideck":
                            break;

                        case "piccount":
                            c.nbrImg = int.Parse(tmp[2]);
                            break;

                        default:
                            Debug.WriteLine("Unknow SVAR: " + tmp[1]);
                            break;
                        }
                        break;

                    case "k":
                        Ability a = Ability.ParseKeyword(tmp[1], c);
                        if (a != null)
                        {
                            c.Abilities.Add(a);
                        }
                        break;

                    case "r":
                        c.R.Add(tmp[1]);
                        break;

                    case "deckneeds":
                        c.DeckNeeds.Add(tmp[1]);
                        break;

                    case "text":
                        c.TextField.Add(tmp[1]);
                        break;

                    case "alternatemode":
                        c.AlternateMode = tmp[1];
                        break;

                    case "alternate":
                        c.Alternate = true;
                        break;

                    case "colors":
                        c.Colors += (ManaTypes)Enum.Parse(typeof(ManaTypes), tmp[1], true);
                        break;

                    case "loyalty":
                        c.Loyalty = tmp[1];
                        break;

                    case "handlifemodifier":
                        c.HandLifeModifier = tmp[1];
                        break;

                    case "deckhints":
                        c.DeckHints = tmp[1];
                        break;

                    case "var":
                        Debug.WriteLine("var: {0} {1} {2}", c.Name, tmp[1], tmp[2]);
                        break;

                    default:
                        if (tmp[0].StartsWith("#"))
                        {
                            c.Comments.Add(tmp[0]);
                        }
                        else if (!string.IsNullOrEmpty(tmp[0]))
                        {
                            string txt = "";
                            for (int i = 0; i < tmp.Length; i++)
                            {
                                txt += ":" + tmp[i];
                            }

                            Debug.WriteLine("? => {0} {1}", c.Name, txt);
                        }
                        break;
                    }
                }
                SVarToResolve.UnresolvedSVars.Clear();
            }

            #region add mana ability to basic lands
            if (c.Types == CardTypes.Land)
            {
                if (c.Abilities.Count == 0)
                {
                    Mana m = null;
                    switch (c.Name.ToLower())
                    {
                    case "plains":
                    case "snow-covered plains":
                        m = ManaTypes.White;
                        break;

                    case "mountain":
                    case "snow-covered mountain":
                        m = ManaTypes.Red;
                        break;

                    case "swamp":
                    case "snow-covered swamp":
                        m = ManaTypes.Black;
                        break;

                    case "forest":
                    case "snow-covered forest":
                        m = ManaTypes.Green;
                        break;

                    case "island":
                    case "snow-covered island":
                        m = ManaTypes.Blue;
                        break;
                    }
                    if (m != null)
                    {
                        c.Abilities.Add(
                            new Ability(new ManaEffect(m))
                        {
                            ActivationCost = CostTypes.Tap
                        });
                    }
                }
            }
            #endregion

            return(c);
        }
Ejemplo n.º 3
0
        public static Trigger Parse(string str)
        {
            Trigger t = new Trigger(MagicEventType.Unset);

            string[] tmp = str.Trim().Split(new char[] { '|' });

            foreach (string i in tmp)
            {
                string[] f    = i.Trim().Split(new char[] { '$' });
                string   data = f [1].Trim();
                switch (f [0])
                {
                case "Mode":
                    switch (data)
                    {
                    case "ChangesZone":
                        t.Type = MagicEventType.ChangeZone;
                        break;

                    case "Phase":
                        t.Type = MagicEventType.BeginPhase;
                        break;

                    case "Attacks":
                        t.Type = MagicEventType.Attack;
                        break;

                    case "SpellCast":
                        t.Type = MagicEventType.CastSpell;
                        break;

                    default:
                        Debug.WriteLine("Unknown trigger " + f [0] + " value:" + data);
                        break;
                    }
                    break;

                case "Origin":
                    t.Origine = CardGroup.ParseZoneName(data);
                    break;

                case "Destination":
                    t.Destination = CardGroup.ParseZoneName(data);
                    break;

                case "ValidCard":
                    t.ValidTarget = Target.ParseTargets(data);
                    break;

                case "Execute":
                    SVarToResolve.RegisterSVar(data, t, t.GetType().GetField("Exec"));
                    break;

                case "TriggerDescription":
                    t.Description = data;
                    break;

                case "Phase":
                    t.Type = MagicEventType.BeginPhase;
                    switch (data)
                    {
                    case "End of Turn":
                        t.Phase = GamePhases.EndOfTurn;
                        break;

                    default:
                        Debug.WriteLine("Trigger parsing: Unknown phase:" + data);
                        break;
                    }
                    break;

                case "TriggerZones":
                    t.TriggerZone = CardGroup.ParseZoneName(data);
                    break;

                case "CheckSVar":
                    break;

                case "SVarCompare":
                    break;

                case "OptionalDecider":
                    break;

                case "ValidActivatingPlayer":
                    break;

                case "Secondary":
                    break;

                default:
                    Debug.WriteLine("Unknown trigger var:" + f [0]);
                    break;
                }
            }
            return(t);
        }
Ejemplo n.º 4
0
        public static EffectGroup Parse(string s)
        {
            string[] tmp = s.Split(new char[] { '|' });

            EffectGroup effects = new EffectGroup();


            foreach (string t in tmp)
            {
                string[]      tmp2  = t.Split(new char[] { '$' });
                string        value = tmp2[1].Trim();
                int           v;
                NumericEffect numEff = null;

                switch (tmp2[0].Trim())
                {
                case "Mode":
                    effects.Mode = (Effect.ModeEnum)Enum.Parse(typeof(Effect.ModeEnum), tmp2 [1]);
                    break;

                case "Affected":
                    effects.Affected = Target.ParseTargets(value);
                    break;

                case "GainControl":
                    effects.Add(new Effect(EffectType.GainControl));
                    break;

                case "Description":
                    break;

                case "AddKeyword":
                    AbilityEnum ae = AbilityEnum.Unset;
                    if (Enum.TryParse(value, true, out ae))
                    {
                        effects.Add(new AbilityEffect(new Ability(ae)));
                        break;
                    }
                    switch (value)
                    {
                    case "Double Strike":
                        effects.Add(new AbilityEffect(new Ability(AbilityEnum.DoubleStrike)));
                        break;

                    default:
                        Debug.WriteLine("unknown AddKeyword in effect: " + value);
                        break;
                    }
                    break;

                case "Condition":
                    break;

                case "AddAbility":
                    break;

                case "AddPower":
                    numEff = new NumericEffect(EffectType.AddPower);
                    if (int.TryParse(value, out v))
                    {
                        numEff.Amount = v;
                    }
                    else
                    {
                        SVarToResolve.RegisterSVar(value, numEff, numEff.GetType().GetField("Amount"));
                    }

                    effects.Add(numEff);
                    numEff = null;
                    break;

                case "AddToughness":
                    numEff = new NumericEffect(EffectType.AddTouchness);
                    if (int.TryParse(value, out v))
                    {
                        numEff.Amount = v;
                    }
                    else
                    {
                        SVarToResolve.RegisterSVar(value, numEff, numEff.GetType().GetField("Amount"));
                    }

                    effects.Add(numEff);
                    numEff = null;
                    break;

                case "SetPower":
                    if (!int.TryParse(value, out v))
                    {
                        break;
                    }
                    effects.Add(new NumericEffect
                    {
                        TypeOfEffect = EffectType.SetPower,
                        Amount       = v,
                    });
                    break;

                case "SetToughness":
                    if (!int.TryParse(value, out v))
                    {
                        break;
                    }
                    effects.Add(new NumericEffect
                    {
                        TypeOfEffect = EffectType.SetTouchness,
                        Amount       = v,
                    });
                    break;

                case "EffectZone":
                    break;

                case "CharacteristicDefining":
                    break;

                case "AddType":
                    break;

                case "References":
                    break;

                case "ValidCard":
                    break;

                case "AddHiddenKeyword":
                    switch (value)
                    {
                    case "CARDNAME can't attack or block.":
                        effects.Add(EffectType.CantAttack);
                        effects.Add(EffectType.CantBlock);
                        break;

                    default:
                        Debug.WriteLine("Unkwnown HiddenKeyword: " + value);
                        break;
                    }
                    break;

                case "CheckSVar":
                    break;

                case "SVarCompare":
                    break;

                case "AffectedZone":
                    break;

                case "Activator":
                    break;

                case "Type":
                    break;

                case "Color":
                    break;

                case "Amount":
                    break;

                case "SetColor":
                    break;

                case "Caster":
                    break;

                case "OpponentAttackedWithCreatureThisTurn":
                    break;

                case "AddColor":
                    break;

                case "AddSVar":
                    break;

                case "Spell":
                    break;

                case "SetMaxHandSize":
                    break;

                case "AddTrigger":
                    break;

                case "RemoveKeyword":
                    break;

                case "GlobalRule":
                    break;

                case "Attacker":
                    break;

                case "Cost":
                    break;

                case "Player":
                    break;

                case "Phases":
                    break;

                case "Target":
                    break;

                case "Optional":
                    break;

                case "AILogic":
                    break;

                case "CheckSecondSVar":
                    break;

                case "SecondSVarCompare":
                    break;

                case "RemoveSubTypes":
                    break;

                case "RemoveAllAbilities":
                    break;

                case "AddStaticAbility":
                    break;

                case "SharedKeywordsZone":
                    break;

                case "SharedRestrictions":
                    break;

                case "MaxDamage":
                    break;

                case "Source":
                    break;

                case "RemoveCreatureTypes":
                    break;

                case "TopCardOfLibraryIs":
                    break;

                case "NonMana":
                    break;

                case "GainsAbilitiesOf":
                    break;

                case "GainsAbilitiesOfZones":
                    break;

                case "RemoveCardTypes":
                    break;

                case "CombatDamage":
                    break;

                case "ValidTarget":
                    break;

                case "RemoveType":
                    break;

                case "ValidSource":
                    break;

                case "RaiseMaxHandSize":
                    break;

                case "Origin":
                    break;

                case "MinMana":
                    break;

                case "ValidSpellTarget":
                    break;

                case "TapAbility":
                    break;

                case "KeywordMultiplier":
                    break;

                case "CheckThirdSVar":
                    break;

                case "CheckFourthSVar":
                    break;

                case "AddReplacementEffects":
                    break;

                case "OnlySorcerySpeed":
                    break;

                default:
                    break;
                }
            }


            return(effects);
        }