Esempio n. 1
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);
        }
Esempio n. 2
0
        protected virtual void ApplySingle(CardInstance _source, object _target = null)
        {
            player = _target as Player;
            CardInstance cardTarget = _target as CardInstance;

            if (cardTarget == null)
            {
                cardTarget = _source;
            }
            if (player == null && _source != null)
            {
                player = _source.Controler;
            }

            switch (TypeOfEffect)
            {
            case EffectType.GainLife:
                player.LifePoints += (this as NumericEffect).Amount.GetValue(_source);
                break;

            case EffectType.LoseLife:
                player.LifePoints -= (this as NumericEffect).Amount.GetValue(_source);
                break;

            case EffectType.Unset:
                break;

            case EffectType.Loose:
                break;

            case EffectType.LooseAllAbilities:
                break;

            case EffectType.Gain:

                break;

            case EffectType.Discard:
                cardTarget?.ChangeZone(CardGroupEnum.Graveyard);
                break;

            case EffectType.Pump:
                break;

            case EffectType.Effect:
                break;

            case EffectType.Counter:
                (_target as MagicAction).IsCountered = true;
                break;

            case EffectType.Destroy:
                cardTarget.PutIntoGraveyard();
                break;

            case EffectType.Tap:
                cardTarget.tappedWithoutEvent = true;
                break;

            case EffectType.DoesNotUntap:
                break;

            case EffectType.TapAll:
                break;

            case EffectType.PreventDamage:
                break;

            case EffectType.Charm:
                break;

            case EffectType.DealDamage:
                MagicEngine.CurrentEngine.MagicStack.PushOnStack(new Damage(_target as IDamagable, _source, (this as NumericEffect).Amount.GetValue(_source)));
                break;

            case EffectType.ChangeZone:
                if ((this as ChangeZoneEffect).Destination == CardGroupEnum.Reveal)
                {
                    CardGroup cg = player.allGroups.Where(ag => ag.GroupName == (this as ChangeZoneEffect).Origin).FirstOrDefault();
                    for (int i = 0; i < (this as ChangeZoneEffect).NumCards; i++)
                    {
                        cg.Cards [cg.Cards.Count - 1].SwitchFocus();
                    }
                    break;
                }
                cardTarget.Reset();
                cardTarget.ChangeZone((this as ChangeZoneEffect).Destination);
                if ((this as ChangeZoneEffect).Tapped)
                {
                    cardTarget.tappedWithoutEvent = true;
                }
                else
                {
                    cardTarget.tappedWithoutEvent = false;
                }
                break;

            case EffectType.Draw:
                Animation.DelayMs = 300;
                for (int i = 0; i < (this as NumericEffect).Amount.GetValue(_source); i++)
                {
                    player.DrawOneCard();
                    Animation.DelayMs += i * 100;
                }
                Animation.DelayMs = 0;
                break;

            case EffectType.DestroyAll:
                break;

            case EffectType.RepeatEach:
                break;

            case EffectType.Token:
                TokenEffect tkEff = this as TokenEffect;
                MagicCard   tk    = new MagicCard()
                {
                    Name      = tkEff.Name,
                    Power     = tkEff.Power.GetValue(_source, _target),
                    Toughness = tkEff.Toughness.GetValue(_source, _target),
                    Colors    = tkEff.Colors,
                    Types     = tkEff.Types,
                };
                string picPath = System.IO.Path.Combine(MagicData.cardsArtPath, "tokens");
                if (string.IsNullOrEmpty(tkEff.Image))
                {
                    picPath = System.IO.Path.Combine(picPath,
                                                     new Mana(tkEff.Colors.FirstOrDefault()).ToString().ToLower() + "_" + tk.Power.ToString() + "_" + tk.Toughness.ToString() +
                                                     tk.Types.Where(tkt => tkt != CardTypes.Creature).
                                                     Aggregate <CardTypes, string> (String.Empty, (a, b) => a.ToString().ToLower() + '_' + b.ToString().ToLower()) + ".jpg");
                }
                else
                {
                    picPath = System.IO.Path.Combine(picPath, tkEff.Image + ".jpg").Replace(' ', '_').ToLower();
                }

                tk.picturePath = picPath;

                Player[] players;

                switch (tkEff.Owner)
                {
                case ControlerType.All:
                    players = MagicEngine.CurrentEngine.Players;
                    break;

                case ControlerType.You:
                    players = new Player[] { _source.Controler };
                    break;

                case ControlerType.Opponent:
                    players = new Player[] { _source.Controler.Opponent };
                    break;

                case ControlerType.Targeted:
                    players = new Player[] { _target as Player };
                    break;

                default:
                    players = new Player[] { _source.Controler };
                    break;
                }

                foreach (Player p in players)
                {
                    for (int i = 0; i < tkEff.Amount.GetValue(_source, _target); i++)
                    {
                        CardInstance tkinst = new CardInstance(tk)
                        {
                            Controler = p, IsToken = true, HasSummoningSickness = true
                        };
                        tkinst.CreateGLCard();
                        p.InPlay.AddCard(tkinst);
                    }
                    p.InPlay.UpdateLayout();
                    //engine.UpdateOverlays ();
                }

                break;

            case EffectType.GainControl:
                break;

            case EffectType.Repeat:
                break;

            case EffectType.Debuff:
                break;

            case EffectType.ChooseColor:
                break;

            case EffectType.Dig:
                break;

            case EffectType.PumpAll:
                break;

            case EffectType.RemoveCounterAll:
                break;

            case EffectType.ChangeZoneAll:
                CardGroup orig = cardTarget.Controler.allGroups.Where(ag => ag.GroupName == (this as ChangeZoneEffect).Origin).FirstOrDefault();
                while (orig.Cards.Count > 0)
                {
                    CardInstance cc = orig.Cards.FirstOrDefault();
                    cc.Reset();
                    cc.ChangeZone((this as ChangeZoneEffect).Destination);
                    if ((this as ChangeZoneEffect).Tapped)
                    {
                        cc.tappedWithoutEvent = true;
                    }
                    else
                    {
                        cc.tappedWithoutEvent = false;
                    }
                }
                orig.UpdateLayout();
                cardTarget.Controler.allGroups.Where(ag => ag.GroupName == (this as ChangeZoneEffect).Destination).FirstOrDefault().UpdateLayout();
                break;

            case EffectType.DamageAll:
                break;

            case EffectType.UntapAll:
                break;

            case EffectType.PutCounter:
                AddOrRemoveCounter pce = this as AddOrRemoveCounter;
                if (pce.Type == AddOrRemoveCounter.CounterType.P1P1)
                {
                    EffectGroup eg = new EffectGroup();
                    //eg.Mode = ModeEnum.Continuous;
                    eg.Affected = new CardTarget(TargetType.Self);
                    eg.Add(new NumericEffect(EffectType.AddTouchness, 1));
                    eg.Add(new NumericEffect(EffectType.AddPower, 1));
                    cardTarget.Effects.Add(eg);
                }
                break;

            case EffectType.PutCounterAll:
                break;

            case EffectType.StoreSVar:
                break;

            case EffectType.FlipACoin:
                break;

            case EffectType.SacrificeAll:
                break;

            case EffectType.Untap:
                break;

            case EffectType.Mill:
                break;

            case EffectType.Animate:
                break;

            case EffectType.Fog:
                break;

            case EffectType.RemoveCounter:
                break;

            case EffectType.ExchangeZone:
                break;

            case EffectType.AnimateAll:
                break;

            case EffectType.ChooseCard:
                break;

            case EffectType.Reveal:
                break;

            case EffectType.ChooseSource:
                break;

            case EffectType.MustBlock:
                break;

            case EffectType.ExchangeControl:
                break;

            case EffectType.RearrangeTopOfLibrary:
                break;

            case EffectType.CopyPermanent:
                break;

            case EffectType.SetState:
                break;

            case EffectType.Balance:
                break;

            case EffectType.RevealHand:
                break;

            case EffectType.Sacrifice:
                break;

            case EffectType.AddTurn:
                break;

            case EffectType.TwoPiles:
                break;

            case EffectType.ManaReflected:
                break;

            case EffectType.SetLife:
                break;

            case EffectType.DebuffAll:
                break;

            case EffectType.Fight:
                break;

            case EffectType.ChooseType:
                break;

            case EffectType.Shuffle:
                break;

            case EffectType.NameCard:
                break;

            case EffectType.PermanentNoncreature:
                break;

            case EffectType.PermanentCreature:
                break;

            case EffectType.TapOrUntap:
                break;

            case EffectType.GenericChoice:
                break;

            case EffectType.Play:
                break;

            case EffectType.BecomesBlocked:
                break;

            case EffectType.WinsGame:
                break;

            case EffectType.Proliferate:
                break;

            case EffectType.Scry:
                break;

            case EffectType.MoveCounter:
                break;

            case EffectType.GainOwnership:
                break;

            case EffectType.ChangeTargets:
                break;

            case EffectType.UnattachAll:
                break;

            case EffectType.PeekAndReveal:
                break;

            case EffectType.LosesGame:
                break;

            case EffectType.DigUntil:
                break;

            case EffectType.CopySpellAbility:
                break;

            case EffectType.RollPlanarDice:
                break;

            case EffectType.RegenerateAll:
                break;

            case EffectType.DelayedTrigger:
                break;

            case EffectType.MustAttack:
                break;

            case EffectType.ProtectionAll:
                break;

            case EffectType.RemoveFromCombat:
                break;

            case EffectType.RestartGame:
                break;

            case EffectType.PreventDamageAll:
                break;

            case EffectType.ExchangeLife:
                break;

            case EffectType.DeclareCombatants:
                break;

            case EffectType.ControlPlayer:
                break;

            case EffectType.Phases:
                break;

            case EffectType.Clone:
                break;

            case EffectType.Clash:
                break;

            case EffectType.ChooseNumber:
                break;

            case EffectType.EachDamage:
                break;

            case EffectType.ReorderZone:
                break;

            case EffectType.ChoosePlayer:
                break;

            case EffectType.EndTurn:
                break;

            case EffectType.MultiplePiles:
                break;

            default:
                throw new ArgumentOutOfRangeException();
            }
        }
Esempio n. 3
0
        public void ClickOnCard(CardInstance c)
        {
            //Magic.CurrentGameWin.CursorVisible = true;

            if (pp != ip)
            {
                return;
            }

            if (MagicStack.TryToHandleClick(c))
            {
                return;
            }

            switch (c.CurrentGroup.GroupName)
            {
            case CardGroupEnum.Library:
                break;

            case CardGroupEnum.Hand:
                #region hand
                //player controling interface may only click in his own hand
                if (c.Controler != ip)
                {
                    return;
                }
                if (!MagicStack.CancelLastActionOnStack())
                {
                    return;
                }
                if (CurrentPhase == GamePhases.Main1 || CurrentPhase == GamePhases.Main2)
                {
                    if (c.HasType(CardTypes.Land))
                    {
                        if (cp.AllowedLandsToBePlayed > 0)
                        {
                            c.ChangeZone(CardGroupEnum.InPlay);
                            cp.AllowedLandsToBePlayed--;
                            MagicEvent(new MagicEventArg(MagicEventType.PlayLand, c));
                        }
                    }
                    else
                    {
                        //Magic.CurrentGameWin.CursorVisible = true;
                        MagicStack.PushOnStack(new Spell(c));
                    }
                }
                else if (CurrentPhase != GamePhases.CleanUp && CurrentPhase != GamePhases.Untap)
                {
                    //play instant and abilities
                    if (c.HasType(CardTypes.Instant))
                    {
                        MagicStack.PushOnStack(new Spell(c));
                    }
                }
                break;

                #endregion
            case CardGroupEnum.InPlay:
                #region inPlay
                if (CurrentPhase == GamePhases.DeclareAttacker)
                {
                    if (c.CanAttack && ip == cp && c.Controler == ip)
                    {
                        c.Combating = !c.Combating;
                        c.CurrentGroup.UpdateLayout();
                        return;
                    }
                }
                else if (CurrentPhase == GamePhases.DeclareBlocker)
                {
                    if (ip != cp)                     //ip may declare blockers if it's not the current player
                    {
                        if (c.Controler == ip)
                        {
                            if (c.CanBlock())
                            {
                                if (c.Combating)
                                {
                                    c.Combating = false;
                                    c.BlockedCreature.BlockingCreatures.Remove(c);
                                    c.BlockedCreature = null;
                                    c.Controler.InPlay.UpdateLayout();
                                }
                                c.Controler.CurrentBlockingCreature = c;
                                return;
                            }
                        }
                        else if (ip.CurrentBlockingCreature != null && c.Combating)
                        {
                            //TODO:there's a redundant test here
                            if (ip.CurrentBlockingCreature.Combating)
                            {
                                //remove blocker
                                ip.CurrentBlockingCreature.Combating = false;
                                ip.CurrentBlockingCreature.BlockedCreature.BlockingCreatures.Remove(ip.CurrentBlockingCreature);
                                ip.CurrentBlockingCreature.BlockedCreature = null;
                            }
                            else if (ip.CurrentBlockingCreature.CanBlock(c))
                            {
                                //try to add blocker
                                c.BlockingCreatures.Add(ip.CurrentBlockingCreature);
                                ip.CurrentBlockingCreature.BlockedCreature = c;
                                ip.CurrentBlockingCreature.Combating       = true;
                                ip.CurrentBlockingCreature = null;
                            }
                            ip.InPlay.UpdateLayout();
                            return;
                        }
                    }
                }
                else if (CurrentPhase == GamePhases.CombatDamage)
                {
                }
                if (c.Controler == ip)
                {
                    #region activable abilities
                    if (!(c.IsTapped || c.HasSummoningSickness))
                    {
                        Ability[] activableAbs = c.Model.Abilities.Where(
                            sma => sma.IsActivatedAbility).ToArray();

                        if (activableAbs.Count() == 1)
                        {
                            MagicStack.PushOnStack(new AbilityActivation(c, activableAbs[0]));
                        }
                        else if (activableAbs.Count() > 1)
                        {
                            MagicChoice aachoice = new MagicChoice()
                            {
                                Player = ip
                            };
                            foreach (Ability aa in activableAbs)
                            {
                                aachoice.Choices.Add(new AbilityActivation(c, aa, true));
                            }

                            MagicStack.PushOnStack(aachoice);
                        }
                    }
                    #endregion
                }
                #endregion
                break;

            case CardGroupEnum.Graveyard:
                c.CurrentGroup.toogleShowAll();
                break;

            case CardGroupEnum.Exhiled:
                c.CurrentGroup.toogleShowAll();
                break;

            default:
                break;
            }
        }