예제 #1
0
 public virtual void ApplyDamage(float value, Unit source)
 {
     health -= value;
     if (health > 0)
     {
         ai?.OnDamageTaken(value, source);
         DamageApplied?.Invoke(this, value);
     }
 }
예제 #2
0
 public void ApplyDamage(int damage)
 {
     health = Mathf.Clamp(health - damage, 0, maxHealth);
     DamageApplied?.Invoke(new DamageAppliedEventArgs(damage, Card));
     if (health == 0)
     {
         //TODO add end of the game
         Debug.Log("GAME OVER!");
     }
 }
예제 #3
0
 public void ApplyDamage(int damage)
 {
     health = Mathf.Clamp(health - damage, 0, maxHealth);
     healthChanged.Invoke(health, maxHealth);
     DamageApplied?.Invoke(new DamageAppliedEventArgs((int)damage, this));
     if (health <= 0)
     {
         Die();
         return;
     }
     damageApplied.Invoke((int)damage, this);
 }
 public override void ApplyDamage(int amount)
 {
     if (_health - amount <= 0)
     {
         Die();
     }
     else
     {
         _health -= 1;
         Lives[_countLive].enabled = false;
         _countLive--;
         DamageApplied?.Invoke(amount);
     }
 }
예제 #5
0
    public override void ApplyDamage(int amount)
    {
        if (amount < 0)
        {
            return;
        }

        health -= amount;

        if (health <= 0)
        {
            Die();
        }
        DamageApplied?.Invoke(amount);
    }
        // Animation event
        public void Hit()
        {
            Vector2      attackDirection = Vector2.right * ((flip.isFacingRight) ? 1 : -1);
            Vector2      rayOrigin       = new Vector2(transform.position.x, transform.position.y + 0.5f);
            RaycastHit2D hit             = Physics2D.Raycast(rayOrigin, attackDirection, attackRange, layerMask);

            if (hit)
            {
                var target        = hit.transform.gameObject;
                var currentDamage = baseDamage;
                applyDamageModifiers?.Invoke(ref currentDamage);
                target.GetComponent <Health>().ApplyDamage(currentDamage);
                applyEffectsOnTarget?.Invoke(target);
                DamageApplied?.Invoke();
            }
        }
예제 #7
0
        // Animation event
        public void Hit()
        {
            var currentDamage = baseDamage;

            applyDamageModifiers?.Invoke(ref currentDamage);
            Vector2 centerInRelationUnitDirection =
                transform.position + applicationAreaCenter * ((flip.isFacingRight) ? 1 : -1);

            Collider2D[] enemiesInApplicationArea = Physics2D.OverlapBoxAll(
                centerInRelationUnitDirection,
                applicationArea,
                0f,
                layerMask);
            foreach (var enemie in enemiesInApplicationArea)
            {
                enemie.GetComponent <Health>().ApplyDamage(currentDamage);
                applyEffectsOnTarget?.Invoke(enemie.gameObject);
                DamageApplied?.Invoke();
            }
        }
예제 #8
0
        public void OnDamageApplied(DamageApplied message)
        {
            var position             = ((ITransform)Manager.GetComponent(message.Entity, TransformTypeId)).Position;
            var value                = (int)Math.Round(message.Amount);
            var scale                = message.IsCriticalHit ? 1f : 0.5f;
            var faction              = Manager.GetComponent(message.Entity, Faction.TypeId) as Faction;
            var isLocalPlayerFaction = faction != null && (_localPlayerFaction & faction.Value) != Factions.None;

            if (value > 0)
            {
                // Normal damage.
                var color = isLocalPlayerFaction
                                ? Color.Red
                                : (message.IsCriticalHit ? Color.Yellow : Color.White);
                ((FloatingTextSystem)Manager.GetSystem(FloatingTextSystem.TypeId))
                .Display(value, position, color, scale);
            }
            else
            {
                value = (int)Math.Round(message.ShieldedAmount);
                if (value > 0)
                {
                    // Shield damage.
                    var color = isLocalPlayerFaction
                                    ? Color.Violet
                                    : (message.IsCriticalHit ? Color.Yellow : Color.LightBlue);
                    ((FloatingTextSystem)Manager.GetSystem(FloatingTextSystem.TypeId))
                    .Display(value, position, color, scale);
                }
                else
                {
                    // No damage.
                    var color = isLocalPlayerFaction
                                    ? Color.LightBlue
                                    : (message.IsCriticalHit ? Color.Yellow : Color.Purple);
                    ((FloatingTextSystem)Manager.GetSystem(FloatingTextSystem.TypeId))
                    .Display("Absorbed", position, color, scale);
                }
            }
        }
예제 #9
0
 public void ApplyDamage(int damage)
 {
     OnDamageApplied(damage);
     DamageApplied?.Invoke(new DamageAppliedEventArgs(damage, Card));
 }