示例#1
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);
        }
示例#2
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);
            }
        }
示例#3
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);
        }