Ejemplo n.º 1
0
    public void Deal(Health health, Resistances resistances)
    {
        DamageSources filteredDamageTypes = resistances.FilterDamage(sources);
        float         totalDamage         = filteredDamageTypes.CalculateTotalDamage();

        health.Subtract(totalDamage);
    }
Ejemplo n.º 2
0
 /// <summary>
 /// prevents teammatesFrom blocking attacks
 /// </summary>
 /// <param name="damageSorce"></param>
 /// <param name="damageType"></param>
 /// <returns></returns>
 public bool ignoreDamage(DamageSources damageSorce, DamageTypes damageType)
 {
     if ((team & damageSorce) == damageSorce)
     {
         return(true);
     }
     return(false);
 }
Ejemplo n.º 3
0
    public virtual void Damage(float damage, DamageSources damageSource, Vector2 knockback = default(Vector2))
    {
        if (CanBeDamagedBy(damageSource))
        {
            Health -= damage;

            if (Health < 0)
                Die();
        }
    }
Ejemplo n.º 4
0
 public virtual bool CanBeDamagedBy(DamageSources damageSource)
 {
     switch (damageSource)
     {
         case DamageSources.Player: return DamagedBy.Player;
         case DamageSources.Crabs: return DamagedBy.Crabs;
         case DamageSources.Population: return DamagedBy.Population;
         default: return false;
     }
 }
Ejemplo n.º 5
0
    public DamageSources FilterDamage(DamageSources toFilter)
    {
        Dictionary <DamageType, DamageSource> .KeyCollection keys = toFilter.Dictionary.Keys;

        foreach (DamageType rt in keys)
        {
            toFilter.Dictionary[rt].value -= (_dictionary[rt].value / 100) * toFilter.Dictionary[rt].value;
        }

        return(toFilter);
    }
Ejemplo n.º 6
0
        public void BuildReturnsCorrectResult()
        {
            var expectedCount = FullResultCount;
            var sut           = CreateSut();

            var stats = BuildToStats(sut, expectedCount);

            Assert.That(stats, Has.Exactly(expectedCount).Items);
            foreach (var(i, attackDamageHand) in AttackDamageHands.Index())
            {
                var expected = $"test.{DamageSource.Attack}.{attackDamageHand}.Skill";
                Assert.AreEqual(expected, stats[i].Identity);
            }
            var offset = AttackDamageHands.Count;

            foreach (var(i, damageSource) in DamageSources.Except(DamageSource.Attack).Index())
            {
                var expected = $"test.{damageSource}.Skill";
                Assert.AreEqual(expected, stats[i + offset].Identity);
            }
            offset += DamageSources.Count - 1;
            foreach (var attackDamageHand in AttackDamageHands)
            {
                foreach (var(i, ailment) in Ailments.Index())
                {
                    var expected = $"test.{DamageSource.Attack}.{attackDamageHand}.{ailment}";
                    Assert.AreEqual(expected, stats[offset + i].Identity);
                }
                offset += Ailments.Count;
            }
            foreach (var damageSource in DamageSources.Except(DamageSource.Attack, DamageSource.OverTime))
            {
                foreach (var(i, ailment) in Ailments.Index())
                {
                    var expected = $"test.{damageSource}.{ailment}";
                    Assert.AreEqual(expected, stats[offset + i].Identity);
                }
                offset += Ailments.Count;
            }
        }
Ejemplo n.º 7
0
 /// <summary>
 /// apply the specified damage to this Actor
 /// </summary>
 /// <param name="amount">amount of damage</param>
 /// <returns>true if damage is taken</returns>
 public bool takeDamage(float amount, DamageTypes damageType, DamageSources damageSorce)
 {
     if (ignoreDamage(damageSorce, damageType))
     {
         return(false);
     }
     health -= amount;
     if (health < health_MIN)
     {
         health = health_MIN;
     }
     if (health <= 0)
     {
         actorDies();
     }
     takeDamageGrapic_flashColor(.8f);
     if (healthUI != null)
     {
         healthUI.updateHealthDispley(health_MAX, health);
     }
     return(true);
 }
        /// <summary>Heals this unit and returns the points healed, or -1 if the unit died before it could be healed.</summary>
        public virtual int ReceiveHeal(Unit caster, uint healAmount, float healHatredScale = 1.0f)
        {
            uint oldHealth;
            uint resultantHealth;

            if (IsDead || PendingDisposal)
            {
                return(-1);
            }

            lock (DamageApplicationLock)
            {
                if (IsDead)
                {
                    return(-1);
                }
                oldHealth       = _health;
                _health         = Math.Min(MaxHealth, _health + healAmount);
                resultantHealth = _health;

                if (_health == MaxHealth && oldHealth < MaxHealth)
                {
                    DamageSources.Clear();
                }
            }

            if (caster != null)
            {
                CbtInterface.OnTakeHeal(caster);
                caster.CbtInterface.OnDealHeal(this, resultantHealth - oldHealth);
            }

            LastHealOid = caster?.Oid ?? Oid;

            return((int)(resultantHealth - oldHealth));
        }
Ejemplo n.º 9
0
    public override void Damage(float damage, DamageSources damageSource, Vector2 knockback = default(Vector2))
    {
        base.Damage(damage, damageSource, knockback);

        Rigidbody.AddForce(knockback, ForceMode2D.Impulse);
    }
Ejemplo n.º 10
0
 public bool takeDamage(float amount, DamageTypes damageType, DamageSources damageSorce)
 {
     return(false);
 }
Ejemplo n.º 11
0
 public bool ignoreDamage(DamageSources damageSorce, DamageTypes damageType)
 {
     return(false);
 }
Ejemplo n.º 12
0
 //set methods to update properties with the using actors effects
 public void setDamage(float damage, DamageTypes damageType, DamageSources team)
 {
     damageAmount    = damage;
     this.damageType = damageType;
     sourceTeam      = team;
 }