Beispiel #1
0
        public static int CalculateGainAttackerWouldGetIfPowerAndThoughnessWouldIncrease(Card attacker,
          IEnumerable<Card> blockers, int powerIncrease, int toughnessIncrease)
        {
            if ((blockers.None()) && powerIncrease > 0)
            {
                return CalculateDefendingPlayerLifeloss(attacker, blockers) > 0 ? 2 : 0;
            }

            if (toughnessIncrease < 1 && !attacker.Has().Charge)
                return 0;

            var p = new AttackerEvaluationParameters(attacker, blockers);

            var canBeDealtLeathalDamageWithoutBoost = CanAttackerBeDealtLeathalDamage(p);

            if (canBeDealtLeathalDamageWithoutBoost == false)
                return 0;

            p.AttackerPowerIncrease = powerIncrease;
            p.AttackerToughnessIncrease = toughnessIncrease;

            var canBeDealtLeathalDamageWithBoost = CanAttackerBeDealtLeathalDamage(p);

            return canBeDealtLeathalDamageWithBoost ? 0 : attacker.Score;
        }
        public static int CalculatePermanentScore(Card permanent)
        {
            var score = 0;

            if (permanent.OverrideScore.Battlefield.HasValue)
                return permanent.OverrideScore.Battlefield.Value;

            if (permanent.Level > 0)
                score += 10 * permanent.Level.Value;

            if (permanent.ManaCost != null)
            {
                //score += CalculatePermanentScoreFromManaCost(permanent);

                if (permanent.Is().Creature)
                {
                    score += (permanent.Power.Value * 10 + permanent.Toughness.Value * 3);

                    if (permanent.HasSummoningSickness)
                        score -= 1;
                }
            }
            else if (permanent.Is().Creature)
            {
                score += CalculatePermanentScoreFromPowerToughness(permanent.Power.Value, permanent.Toughness.Value);
            }
            else if (permanent.Is().Land)
            {
                score += GetLandOnBattlefieldScore(permanent);
                if (!permanent.Is().BasicLand)
                    score += 10;
            }

            return score;
        }
Beispiel #3
0
        public Attacker(Card card, Engine game)
        {
            Game = game;
            _card = card;

            _blockers.Initialize(ChangeTracker);
            _assignedDamage.Initialize(ChangeTracker);
            _isBlocked.Initialize(ChangeTracker);
        }
Beispiel #4
0
        public Blocker(Card card, Attacker attacker, Engine game)
        {
            Card = card;
            Game = game;

            _attacker = new Trackable<Attacker>(attacker);
            _attacker.Initialize(ChangeTracker);

            _assignedDamage.Initialize(ChangeTracker);
            _damageAssignmentOrder.Initialize(ChangeTracker);
        }
Beispiel #5
0
 public void PutOnTop(Card card)
 {
     if (card.Zone == Name)
     {
         MoveToFront(card);
     }
     else
     {
         AddToFront(card);
     }
 }
Beispiel #6
0
 public void PutOnBottom(Card card)
 {
     if (card.Zone == Name)
     {
         MoveToEnd(card);
     }
     else
     {
         AddToEnd(card);
     }
 }
Beispiel #7
0
        public static int CalculateDefendingPlayerLifeloss(Card attacker, IEnumerable<Card> blockers)
        {
            var total = 0;

            if (blockers.None())
            {
                total = attacker.CalculateCombatDamageAmount(singleDamageStep: false);
            }
            //else if (attacker.Has().Trample)
            //{
            //    total = CalculateTrampleDamage(attacker, blockers);
            //}

            var prevented = attacker.Controller.Opponent.CalculatePreventedReceivedDamageAmount(total, attacker,
              isCombat: true);
            return total - prevented;
        }
Beispiel #8
0
 public static bool CanAttackerBeDealtLeathalDamage(Card attacker, IEnumerable<Card> blockers)
 {
     return CanAttackerBeDealtLeathalDamage(new AttackerEvaluationParameters(attacker, blockers));
 }
 public ZoneChangedEvent(Card card, Zone @from, Zone to)
 {
     Card = card;
     From = @from;
     To = to;
 }
Beispiel #10
0
        //public List<ActivationPrerequisites> CanActivateAbilities(bool ignoreManaAbilities = false)
        //{
        //    return _activatedAbilities.CanActivate(ignoreManaAbilities);
        //}
        public bool CanBeBlockedBy(Card card)
        {
            if (card.IsTapped)
                return false;

            if (Has().Immunity)
                return false;

            if (Has().SpellShield)
                return false;

            if (HasProtectionFrom(card))
                return false;

            return true;
        }
Beispiel #11
0
        public static int GetAmountOfDamageThatNeedsToBePreventedToSafeBlockerFromDying(Card blocker, Card attacker)
        {
            var evaluation = new BlockerEvaluation(new BlockerEvaluationParameters { Blocker = blocker, Attacker = attacker });
            var results = evaluation.Evaluate();

            if (results.ReceivesLeathalDamage)
                return results.DamageDealt;

            return 0;
        }
Beispiel #12
0
        public static int GetAmountOfDamageCreature1WillDealToCreature2(Card creature1, Card creature2,
          int powerIncrease = 0)
        {
            var amountDealt = creature1.CalculateCombatDamageAmount(powerIncrease: powerIncrease);
            var preventedReceived = creature2.CalculatePreventedDamageAmount(amountDealt, creature1, isCombat: true);

            return amountDealt - preventedReceived;
        }
Beispiel #13
0
 public CardViewModel(Card card)
 {
     Card = card;
     Colors = new CardColor[] { };
 }
Beispiel #14
0
 public SpellCastEvent(Card card, Targets targets)
 {
     Card = card;
     Targets = targets;
 }
Beispiel #15
0
 public override void AfterRemove(Card card)
 {
     card.OnCardLeftBattlefield();
 }
Beispiel #16
0
 public override void AfterAdd(Card card)
 {
     card.OnCardJoinedBattlefield();
 }
Beispiel #17
0
 //public void ActivateAbility(int index, ActivationParameters activationParameters)
 //{
 //    _activatedAbilities.Activate(index, activationParameters);
 //    IncreaseUsageScore();
 //}
 //public void IncreaseUsageScore()
 //{
 //    // to avoid useless moves every move lowers the score a bit
 //    // this factor increases linearily with elapsed turns
 //    // AI will prefer playing spells as soon as possible
 //    var increase = Turn.TurnCount;
 //    if (Turn.Step < Step.SecondMain)
 //        increase += 1;
 //    UsageScore += increase;
 //}
 public bool HasProtectionFrom(Card card)
 {
     return false;
     //return HasProtectionFromTypes(card._type.Value);
 }
Beispiel #18
0
 public bool HasAttachment(Card card)
 {
     return _attachments.Contains(card);
 }
Beispiel #19
0
        public void Detach(Card card)
        {
            _attachments.Remove(card);
            card.AttachedTo = null;

            Publish(new AttachmentDetachedEvent(attachment: card, attachedTo: this));
        }
Beispiel #20
0
 public static bool CanAttackerKillAnyBlocker(Card attacker, IEnumerable<Card> blockers)
 {
     return blockers.Any(blocker => CanBlockerBeDealtLeathalCombatDamage(attacker, blocker));
 }
Beispiel #21
0
 //public static int CalculateTrampleDamage(Card attacker, Card blocker)
 //{
 //    return CalculateTrampleDamage(attacker, blocker.ToEnumerable());
 //}
 public static bool CanBlockerBeDealtLeathalCombatDamage(Card attacker, Card blocker)
 {
     return
       CanBlockerBeDealtLeathalCombatDamage(new BlockerEvaluationParameters { Attacker = attacker, Blocker = blocker });
 }
Beispiel #22
0
        public bool OnMouseOver(Card card, Vector2 mousePosition)
        {
            int offSet = 20;

            int width = card.ImageTexture.Width * (int)card.Scale + offSet;
            int height = card.ImageTexture.Height * (int)card.Scale + offSet;

            int xOffSet = (int)card.Position.X;// -(int)(width / 2);
            int yOffSet = (int)card.Position.Y;// -(int)(height / 2);

            var sceneCoords = mousePosition / Resolution.ScreenScale;

            if (sceneCoords.X >= (xOffSet - offSet) &&
                sceneCoords.X <= (xOffSet + width) &&

                sceneCoords.Y >= (yOffSet - offSet) &&
                sceneCoords.Y <= (yOffSet + height))
            {
                return true;
            }
            else
            {
                return false;
            }
        }
Beispiel #23
0
        public static int GetAmountOfDamageThatNeedsToBePreventedToSafeAttackerFromDying(Card attacker,
          IEnumerable<Card> blockers)
        {
            var p = new AttackerEvaluationParameters(attacker, blockers);
            var results = new AttackerEvaluation(p).Evaluate();

            if (!results.ReceivesLeathalDamage)
                return 0;

            if (results.DeathTouchDamage > 0)
                return results.DeathTouchDamage;

            var prevented = results.TotalDamage - attacker.Life + 1;
            return prevented;
        }
Beispiel #24
0
        public static int CalculateGainBlockerWouldGetIfPowerAndThougnessWouldIncrease(Card attacker,
          Card blocker, int powerIncrease, int toughnessIncrease)
        {
            if (attacker == null)
                return 0;

            var p = new BlockerEvaluationParameters
            {
                Attacker = attacker,
                Blocker = blocker,
            };

            var canBeDealtLeathalDamageWithoutBoost = CanBlockerBeDealtLeathalCombatDamage(p);

            if (canBeDealtLeathalDamageWithoutBoost == false)
                return 0;

            p.BlockerPowerIncrease += powerIncrease;
            p.BlockerToughnessIncrease += toughnessIncrease;

            var canBeDealtLeathalDamageWithBoost = CanBlockerBeDealtLeathalCombatDamage(p);
            return canBeDealtLeathalDamageWithBoost == false ? blocker.Score : 1;
        }
Beispiel #25
0
        public static Card GetBlockerThatDealsLeathalDamageToAttacker(Card attacker, IEnumerable<Card> blockers)
        {
            var p = new AttackerEvaluationParameters(attacker, blockers);

            var performance = new AttackerEvaluation(p);
            var results = performance.Evaluate();

            return results.LeathalBlocker;
        }
Beispiel #26
0
        //public bool HasProtectionFromTypes(IEnumerable<string> types)
        //{
        //    return _protections.HasProtectionFromAnyTypes() &&
        //      types.Any(x => _protections.HasProtectionFrom(x));
        //}
        public void Attach(Card attachment)
        {
            if (attachment.IsAttached)
            {
                var controller = attachment.AttachedTo.Controller;

                attachment.AttachedTo.Detach(attachment);

                if (controller != Controller)
                {
                    Controller.PutCardToBattlefield(attachment);
                }
            }

            attachment.AttachedTo = this;
            _attachments.Add(attachment);
            Publish(new AttachmentAttachedEvent(attachment));
        }
Beispiel #27
0
 public void ShuffleIntoLibrary(Card card)
 {
     PutOnBottomOfLibrary(card);
     _library.Shuffle();
 }
Beispiel #28
0
        public int CalculatePreventedDamageAmount(int totalAmount, Card source, bool isCombat = false)
        {
            if (HasProtectionFrom(source))
            {
                return totalAmount;
            }

            var damage = new PreventDamageParameters
            {
                Amount = totalAmount,
                QueryOnly = true,
                Source = source,
                IsCombat = isCombat,
                Target = this,
            };

            return Game.PreventDamage(damage);
        }
Beispiel #29
0
        public void DrawCard(SpriteBatch spriteBatch, SpriteFont spriteFont, Card card)
        {
            Color color = new Color((byte)255, (byte)255, (byte)255, (byte)255);

            //Cost
            Vector2 costPosition = new Vector2(card.Source.Left - card.costPreview.Width / 2, card.Source.Top - card.costPreview.Height / 2);

            spriteBatch.Draw(
                card.costPreview,
                costPosition,
                null, color, 0.0f, Vector2.Zero, card.Scale, SpriteEffects.None, 0.0f);

            if (card.ManaCost.HasValue)
            {
                TextureContent.DrawText(spriteBatch, spriteFont, card.ManaCost.Value.ToString(), Color.Black, color, card.Scale,
                    new Vector2(costPosition.X + card.costPreview.Width / 2, costPosition.Y + card.costPreview.Height / 2));
            }

            //Name
            Vector2 borderPosition = new Vector2(card.Source.Left - card.ImageTexture.Width / 2, card.Source.Center.Y - card.ImageTexture.Height / 2);

            TextureContent.DrawText(spriteBatch, spriteFont, card.Name.ToString(), Color.Black, color, card.Scale / 2,
                new Vector2(borderPosition.X + card.ImageTexture.Width, card.Position.Y));
        }
Beispiel #30
0
 public bool CanBeBlockedBy(Card creature)
 {
     return _card.CanBeBlockedBy(creature);
 }