public void Damage(TPSCharacterCoordinator owner, Vector3 position, float damageMultiplier)
        {
            Debug.Log("Damaged by " + owner.name);
            var finalDamage = damageMultiplier * receiverDamageMultiplier;

            if (Coordinator.AvatarAnimator)
            {
                Coordinator.AvatarAnimator.Hit(position);
            }


            owner.OnDamaged(Coordinator, finalDamage);

            var health = Coordinator.Health;

            if (Coordinator.Health)
            {
                Coordinator.Health.OnDamaged(finalDamage);;
                if (!Coordinator.Health.IsAlive)
                {
                    owner.OnKilled(Coordinator);
                }
            }

            onDamageReceived.Invoke(owner, position, finalDamage);
        }
Ejemplo n.º 2
0
        public float Damage(DamageRequest damageRequest)
        {
            if (IsDead)
            {
                return(0);
            }

            var damageAmount = damageRequest.CalculateAmount(System.AttributeSystem);

            currentHealth -= damageAmount;

            if (currentHealth > 0)
            {
                damageRequest.AmountDealt = damageAmount;
                OnDamageReceived?.Invoke(damageRequest);
                OnHealthChanged?.Invoke(CurrentHealth);
                return(damageAmount);
            }

            var actualDamageDealt = damageAmount + currentHealth;

            currentHealth             = 0;
            damageRequest.AmountDealt = actualDamageDealt;
            OnDamageReceived?.Invoke(damageRequest);
            OnHealthChanged?.Invoke(CurrentHealth);
            OnDied?.Invoke(damageRequest);
            return(actualDamageDealt);
        }
Ejemplo n.º 3
0
 public virtual void TakeDamage(float damageAmount)
 {
     damageTaken += damageAmount;
     OnDamageReceived?.Invoke();
     if (GetHitPointsRemaining() <= 0)
     {
         Die();
     }
 }
Ejemplo n.º 4
0
        private void OnTriggerEnter(Collider other)
        {
            var projectileController = other.GetComponent <ProjectileController>();

            if (projectileController)
            {
                var dmg = projectileController.Damage;
                OnHit.Invoke();
                OnDamageReceived.Invoke(dmg);
                executor.Hurt((uint)dmg);
            }
        }
Ejemplo n.º 5
0
        public void DoDamage(CreatureObject other, float damage, bool isMagic = false)
        {
            if (_creature.IsDead)
            {
                return;
            }
            StatValue hStat = _stats[Stats.Health];
            StatValue pStat = isMagic ? _stats[Stats.MagicResist] : _stats[Stats.Armor];

            hStat.DecreaseCurrent(damage = CalculateDamage(other.Stats.Level, damage, pStat.Max));
            OnDamageReceived?.Invoke(other, damage);
            _view.SendStatUpdate(Stats.Health, hStat);
            if (hStat.Current == 0f)
            {
                _creature.Kill(other);
            }
        }
Ejemplo n.º 6
0
    public void ApplyDamage(float amount, GameObject from = null)
    {
        float damage = amount;

        foreach (var item in before)
        {
            damage = item.BeforeDamage(damage, from);
        }

        value -= damage;

        foreach (var item in after)
        {
            item.AfterDamage(damage, value, from);
        }

        OnDamageReceived?.Invoke(damage, value, from);
    }
Ejemplo n.º 7
0
        public void ApplyDamage(int damage)
        {
            // Don't allow damage to be applied when health is already 0.
            if (CurrentHealth == 0)
            {
                return;
            }

            SetHealth(CurrentHealth - damage);

            OnDamageReceived?.Invoke(damage);
            OnHealthChanged?.Invoke();

            if (CurrentHealth <= 0)
            {
                CurrentHealth = 0;
                OnDeath?.Invoke();
            }
        }
Ejemplo n.º 8
0
    public void TakeDamage(float damage)
    {
        if (IsAlive == false || damage <= 0f)
        {
            return;
        }

        currentHealth = Mathf.Max(currentHealth - damage, 0f);

        if (currentHealth <= 0f)
        {
            IsAlive = false;
            OnDeath.Invoke();
        }
        else
        {
            OnDamageReceived.Invoke();
        }
    }
Ejemplo n.º 9
0
        public void GetDamaged(Damage damage)
        {
            if (amount <= 0f)
            {
                return;
            }

            if (!IsMatchingDamageType(damage.type))
            {
                damage.amount = 0f;
            }

            amount -= damage.amount;

            OnDamageReceived?.Invoke(this, damage);

            if (amount <= 0f)
            {
                Destroy(gameObject);
            }
        }
Ejemplo n.º 10
0
    public void ApplyDamage(float dmg)
    {
        if (currentState == State.Dead)
        {
            return;
        }
        health -= dmg;

        if (OnDamageReceived != null)
        {
            OnDamageReceivedHealth.Invoke(this.health, this.maxHealth);
        }

        if (health <= 0f)
        {
            Die();
        }
        if (OnDamageReceived != null)
        {
            OnDamageReceived.Invoke();
        }
    }
Ejemplo n.º 11
0
 public void TriggerOnDamageReceived(Node damageReceiver, float amount, bool isPlayer)
 {
     OnDamageReceived?.Invoke(damageReceiver, amount, isPlayer);
 }
Ejemplo n.º 12
0
 /// <summary>
 /// Called to execute damage receive event
 /// </summary>
 /// <param name="pendingDamage"></param>
 public void OnDamaged(PendingDamage pendingDamage)
 {
     OnDamageReceived?.Invoke(this, pendingDamage);
 }