Beispiel #1
0
      protected virtual void Update()
      {
          if (continuousDamage && targets != null && targets.Count > 0)
          {
              if (currentTime > 0)
              {
                  currentTime -= Time.deltaTime;
              }
              else
              {
                  currentTime = damageFrequency;
                  foreach (Collider collider in targets)
                  {
                      if (collider != null)
                      {
                          if (collider.enabled)
                          {
                              onHit.Invoke(collider);
                              ApplyDamage(collider.transform, transform.position);   // apply damage to enabled collider
                          }
                          else
                          {
                              disabledTarget.Add(collider);  // add disabled collider to list of disabled
                          }
                      }
                  }
                  //remove all disabled colliders of target list
                  if (disabledTarget.Count > 0)
                  {
                      for (int i = disabledTarget.Count; i >= 0; i--)
                      {
                          if (disabledTarget.Count == 0)
                          {
                              break;
                          }
                          try
                          {
                              if (targets.Contains(disabledTarget[i]))
                              {
                                  targets.Remove(disabledTarget[i]);
                              }
                          }
                          catch
                          {
                              break;
                          }
                      }
                  }

                  if (disabledTarget.Count > 0)
                  {
                      disabledTarget.Clear();
                  }
              }
          }
      }
Beispiel #2
0
    }/// Set active Single Part to attack

    public virtual void OnDamageHit(HitInfo hitInfo)
    {
        Damage damage = new Damage(hitInfo.attackObject.damage);

        damage.sender      = transform;
        damage.reaction_id = currentReactionID;
        damage.recoil_id   = currentRecoilID;
        if (this.activeRagdoll)
        {
            damage.activeRagdoll = this.activeRagdoll;
        }
        if (this.attackName != string.Empty)
        {
            damage.attackName = this.attackName;
        }
        if (this.ignoreDefense)
        {
            damage.ignoreDefense = this.ignoreDefense;
        }
        /// Calc damage with multiplier
        /// and Call ApplyDamage of attackObject
        damage.damageValue *= damageMultiplier > 1 ? damageMultiplier : 1;
        hitInfo.attackObject.ApplyDamage(hitInfo.hitBox, hitInfo.targetCollider, damage);
        onDamageHit.Invoke(hitInfo);
    }// Listener of Damage Event
Beispiel #3
0
    protected override void onHit(GameObject g)
    {
        hitList.Add(g);
        UnitStats targetStats     = g.GetComponent <UnitStats>();
        float     increasedDamage = damage + damage * (1 - targetStats.PercentageHealth()); //deal increased damage equal to percentage missing health

        if (slowMulti > 1 && targetStats.isSlowed())
        {
            increasedDamage *= slowMulti;
        }
        targetStats.TakeDamage(increasedDamage);
        if (targetStats.CurrentHealth() <= 0)
        {
            owner.GetComponent <UnitStats>().GainArmor(armorOnKillAmount);
            owner.GetComponent <UnitStats>().Heal(healOnKillAmount);
        }
        if (bleed > 0)
        {
            targetStats.Bleed(bleed);
        }
        if (slow > 0)
        {
            targetStats.Slow(slow);
        }
        if (bleedConsumeMultiplier > 0)
        {
            targetStats.ConsumeBleed(bleedConsumeMultiplier);
        }
        WeaponCollisionEnterEvent.Invoke(g);
        OnHitEvent.Invoke();
        OnHitHeal.Invoke(heal);
    }
Beispiel #4
0
 protected virtual void ApplyDamage(Collider target, Vector3 hitPoint)
 {
     damage.hitReaction = true;
     damage.sender      = overrideDamageSender ? overrideDamageSender : transform;
     damage.hitPosition = hitPoint;
     damage.receiver    = target.transform;
     target.gameObject.ApplyDamage(new vDamage(damage));
     onHit.Invoke(target);
 }
Beispiel #5
0
 public virtual void Hit(GameObject target)
 {
     DoDamage(target);
     onHit?.Invoke(target);
     if (destoryAfterCollision)
     {
         ObjectDestroy();
     }
 }
        public void OnCollisionEnter(Collision other)
        {
            var magnitude = other.impulse.magnitude;

            if (!(minImpulse < magnitude))
            {
                return;
            }

            var normMagnitude    = magnitude - minImpulse;
            var normMaxMagnitude = Mathf.Max(maxImpulse - minImpulse, 1f);
            var strength         = Mathf.Min(normMagnitude / normMaxMagnitude, 1f);

            onImpact.Invoke(strength);
        }
 public void Update()
 {
     if (_isLaunched)
     {
         _progress          = Mathf.Clamp01(_progress + speed);
         transform.position = GetPosition(_progress);
         if (_progress >= 1.0F)
         {
             _isLaunched = false;
             if (resetPositionOnImpact)
             {
                 Reset();
             }
             onHit.Invoke();
         }
     }
 }
    //When the planet receives the damage.
    public void Hit(float damage)
    {
        if (isStar)
        {
            return;
        }

        controller.sfx.PlaySound("hit");
        saveData.health -= damage;
        UpdateHud();
        OnHitEvent?.Invoke();

        //If the planet runs out of life - destroys itself.
        if (saveData.health <= 0)
        {
            saveData.health = 0;
            Death();
        }
    }
Beispiel #9
0
    //if hit by player weapon, add the target
    public override void hit()
    {
        //stop timer from recording
        timerActive = false;
        // Debug.Log("time: " + this.time);
        //add target to list
        TargetManager.addTarget(this);

        //play audio
        FindObjectOfType <AudioManager>().Play("MetalHit 1");
        AudioSource.PlayClipAtPoint(hitSound, this.transform.position);

        //create a particle
        GameObject burstObject = Instantiate(burst, this.transform.position, Quaternion.identity);

        //destroy particle upon complete
        Destroy(burstObject, 1f);

        onHit.Invoke(100);
    }
 private void OnCollisionEnter2D(Collision2D collision)
 {
     OnHitEvent?.Invoke();
 }
 public void ProcessTakeHit(float damage = 0)
 {
     Debug.Log($"{this.name}, has been hit");
     OnHit?.Invoke(damage);
 }
Beispiel #12
0
        private void DamageOther(Collider2D other)
        {
            Health otherHealth   = other.gameObject.GetComponent <Health>();
            bool   isInLayerMask = Utils.IsInLayerMask(m_layerMask, other.gameObject.layer);

            bool wasDead = otherHealth && otherHealth.IsDead;

            if (isInLayerMask && other.attachedRigidbody != null)
            {
                Vector2 toTarget = (other.transform.position - this.transform.position).normalized;
                m_attackDirection.x *= Mathf.Sign(toTarget.x);
                other.attachedRigidbody.AddForce(m_attackDirection, ForceMode2D.Impulse);

                Vector2 moveDirection = m_walker.Rb.velocity.magnitude > 0
                    ? m_walker.Rb.velocity
                    : m_attackDirection;

                /**a multiplier that depends on the speed at which the attacker hit*/
                float speedMult = Mathf.Log(
                    Utils.FilterMultiplier(Vector2.Dot(moveDirection, m_attackDirection), 50f)
                    );

                if (m_playerAttack.CurrentComboInstance != null)
                {
                    speedMult = speedMult * (1 + Mathf.Log(m_playerAttack.CurrentComboInstance.Count));
                }

                // do attack stuff
                if (otherHealth)
                {
                    otherHealth.TakeDamage(Mathf.CeilToInt(m_damageAmount * speedMult), m_attackDirection);
                }

                bool isFinalBlow = !wasDead && (otherHealth && otherHealth.IsDead);

                // invoke the hit event
                if (otherHealth && !otherHealth.IsDead)
                {
                    OnHitEvent?.Invoke(other.gameObject, speedMult, isFinalBlow);
                }


                if (m_attackSound)
                {
                    m_audioSource.PlayOneShot(m_attackSound);
                }

                if (m_hitStop > 0)
                {
                    float seconds = m_hitStop * speedMult;

                    if (isFinalBlow)
                    {
                        seconds *= m_killCoeff;
                    }
                    GameComponents.TimeManager.DoHitStop(seconds);
                }

                if (m_fisheye > 0)
                {
                    GameComponents.CameraController.DoFisheye(m_fisheye);
                }

                if (m_slomoFactor < 1)
                {
                    float theSlowdownFactor = m_slomoFactor / speedMult;
                    if (isFinalBlow)
                    {
                        theSlowdownFactor /= m_killCoeff;
                    }
                    GameComponents.TimeManager.DoSlowMotion(theSlowdownFactor);
                }

                if (m_explosive)
                {
                    m_playerAttack.CreateSlamExplosion();
                }

                GameComponents.CameraShake.DoJitter(m_jitter.x * Mathf.Log(speedMult), m_jitter.y);
            }
        }
 public void Launch()
 {
     Reset();
     _isLaunched = true;
     onLaunch.Invoke();
 }
Beispiel #14
0
 public void InvokeOnHitEvent(IAttackHitbox hitbox, GameObject entity)
 {
     Debug.Log("OnHitEvent Invoked");
     onHitEvent.Invoke(hitbox, entity);
 }
Beispiel #15
0
 public void Hit(double damage)
 {
     _onHitEvent.Invoke();
     _onDamageEvent.Invoke(damage);
 }
Beispiel #16
0
 protected virtual void OnTriggerEnter2D(Collider2D col)
 {
     OnHitEvent?.Invoke(col.transform);
     Destroy(gameObject);
 }