protected override bool Redirect(Damage damage, ITarget target)
        {
            if (target == _from)
              {
            _to.ReceiveDamage(damage);
            return true;
              }

              return false;
        }
        public bool RedirectDamage(Damage damage, ITarget target)
        {
            if (damage.WasAlreadyRedirected(this))
            return false;

              var wasRedirected = Redirect(damage, target);

              if (wasRedirected)
            damage.AddRedirection(this);

              return wasRedirected;
        }
        public bool RedirectDamage(Damage damage, ITarget target)
        {
            foreach (var redirection in _redirections.ToList())
              {
            if (redirection.RedirectDamage(damage, target))
            {
              return true;
            }
              }

              return false;
        }
Beispiel #4
0
        public static void ReceiveDamage(this ITarget target, Damage damage)
        {
            var damageable = target as IDamageable;

              if (damageable != null)
              {
            damageable.ReceiveDamage(damage);
              }
        }
 protected abstract bool Redirect(Damage damage, ITarget target);
Beispiel #6
0
        public void ReceiveDamage(Damage damage)
        {
            var p = new PreventDamageParameters
            {
              Amount = damage.Amount,
              Source = damage.Source,
              Target = this,
              IsCombat = damage.IsCombat,
              QueryOnly = false
            };

              var prevented = Game.PreventDamage(p);
              damage.Amount -= prevented;

              if (damage.Amount == 0)
            return;

              var wasRedirected = Game.RedirectDamage(damage, this);

              if (wasRedirected)
            return;

              var preventedLifeloss = Game.PreventLifeloss(damage.Amount, this, queryOnly: false);

              Life -= (damage.Amount - preventedLifeloss);

              if (damage.Source.Has().Lifelink)
              {
            var controller = damage.Source.Controller;
            controller.Life += damage.Amount;
              }

              Publish(new DamageDealtEvent(this, damage));
        }
Beispiel #7
0
 public bool RedirectDamage(Damage damage, ITarget target)
 {
     return(_damageRedirections.RedirectDamage(damage, target));
 }
Beispiel #8
0
        public void DealDamageTo(int amount, IDamageable damageable, bool isCombat)
        {
            if (amount <= 0)
            return;

              var damage = new Damage(
            amount: amount,
            source: this,
            isCombat: isCombat);

              damage.Initialize(ChangeTracker);
              damageable.ReceiveDamage(damage);
        }
Beispiel #9
0
        public void ReceiveDamage(Damage damage)
        {
            if (!Is().Creature || !IsPermanent)
            return;

              if (HasProtectionFrom(damage.Source))
              {
            return;
              }

              var amountToPrevent = Game.PreventDamage(new PreventDamageParameters
            {
              Amount = damage.Amount,
              Source = damage.Source,
              Target = this,
              IsCombat = damage.IsCombat,
              QueryOnly = false
            });

              damage.Amount -= amountToPrevent;

              if (damage.Amount == 0)
            return;

              var wasRedirected = Game.RedirectDamage(damage, this);

              if (wasRedirected)
            return;

              Damage += damage.Amount;

              if (Damage >= Toughness || damage.IsLeathal)
              {
            _hasLeathalDamage.Value = true;
              }

              if (damage.Source.Has().Lifelink)
              {
            var controller = damage.Source.Controller;
            controller.Life += damage.Amount;
              }

              Publish(new DamageDealtEvent(this, damage));
        }