Beispiel #1
0
 protected override void OnTriggerStay2D(Collider2D collision)
 {
     if (collision.tag.Equals("Terrain"))
     {
         if (collision.gameObject.layer.Equals(LayerMask.NameToLayer("Wall")))
         {
             OnHitEvent.RemoveAllListeners();
             OnHitHeal.RemoveAllListeners();
             Destroy(gameObject);
         }
     }
     else
     {
         UnitController u = collision.transform.root.GetComponent <UnitController>();
         if (u.unitType != unitType && canDetect)
         {
             if (!ForwardHitList.Contains(u.gameObject) && !returning)
             {
                 onHit(u.gameObject);
             }
             else if (!ReturnHitList.Contains(u.gameObject) && returning)
             {
                 onHit(u.gameObject);
             }
             if (!StationaryHitList.Contains(u.gameObject) && stationary)
             {
                 StationaryHitList.Add(u.gameObject);
                 u.GetComponent <UnitStats>().TakeDamage(StationaryDamage);
             }
             OnHitHeal.RemoveAllListeners(); // heal can only trigger once per projectile
         }
     }
 }
Beispiel #2
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 #3
0
 void Initialize()
 {
     onPlayerJoinEvent        = new OnPlayerJoinEvent();
     onPlayerLeaveEvent       = new OnPlayerLeaveEvent();
     onCharacterSelectEvent   = new OnCharacterSelectEvent();
     onCharacterDeSelectEvent = new OnCharacterDeSelectEvent();
     onHitEvent      = new OnHitEvent();
     onGrabEvent     = new OnGrabEvent();
     onDamageEvent   = new OnDamageEvent();
     onHitStunEvent  = new OnHitStunEvent();
     onEdgeGrabEvent = new OnEdgeGrabEvent();
     onDeathEvent    = new OnDeathEvent();
     onGameOverEvent = new OnGameOverEvent();
 }
    //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();
        }
    }
 private void OnCollisionEnter2D(Collision2D collision)
 {
     OnHitEvent?.Invoke();
 }
Beispiel #6
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 RemoveOnHitEvent(OnHitEvent _event)
 {
     onHitEvent -= _event;
 }
 public void AddOnHitEvent(OnHitEvent _event)
 {
     onHitEvent += _event;
 }
Beispiel #9
0
 protected virtual void OnTriggerEnter2D(Collider2D col)
 {
     OnHitEvent?.Invoke(col.transform);
     Destroy(gameObject);
 }