void ExecuteAttack()
    {
        // if (currentTarget != null) currentTarget.TakeDamage(meleeDamage);

        Collider[] visibleColliders = Physics.OverlapSphere(myEntity.transform.TransformPoint(hitPosition), hitSphereRadius);

        for (int i = 0; i < visibleColliders.Length; i++)
        {
            IDamageable <float> damageable = visibleColliders[i].gameObject.GetComponent <IDamageable <float> >();


            if (damageable != null)
            {
                // check who did we hit, check if he has an gameEntity
                GameEntity entity = visibleColliders[i].gameObject.GetComponent <GameEntity>();
                // Debug.Log("damegable entity: " + entity);
                if (entity != null)
                {
                    if (!Settings.Instance.friendlyFire)
                    {
                        DiplomacyStatus diplomacyStatus = Settings.Instance.GetDiplomacyStatus(weaponTeamID, entity.teamID);
                        if (diplomacyStatus == DiplomacyStatus.War)
                        {
                            damageable.TakeDamage(meleeDamage);
                        }
                    }
                    else
                    {
                        damageable.TakeDamage(meleeDamage);
                    }
                }
                else
                {
                    damageable.TakeDamage(meleeDamage);
                }

                if (pushes)
                {
                    IPusheable <Vector3> pusheable = visibleColliders[i].gameObject.GetComponent <IPusheable <Vector3> >();

                    if (pusheable != null)
                    {
                        Vector3 direction = (visibleColliders[i].gameObject.transform.position - myEntity.transform.position).normalized;
                        // Debug.Log("push: " + pusheable);
                        pusheable.Push(direction * pushForce);
                    }
                }


                return;
            }
        }
    }
Exemple #2
0
    private void OnCollisionEnter(Collision collision)
    {
        IDamageable <float>  damageable = collision.gameObject.GetComponent <IDamageable <float> >();
        IPusheable <Vector3> pusheable  = collision.gameObject.GetComponent <IPusheable <Vector3> >();

        if (damageable != null)
        {
            // check who did we hit, check if he has an gameEntity
            GameEntity entity = collision.gameObject.GetComponent <GameEntity>();
            if (entity != null)
            {
                if (!Settings.Instance.friendlyFire)
                {
                    DiplomacyStatus diplomacyStatus = Settings.Instance.GetDiplomacyStatus(projectileTeamID, entity.teamID);
                    if (diplomacyStatus == DiplomacyStatus.War)
                    {
                        damageable.TakeDamage(damage);
                    }
                }
                else
                {
                    damageable.TakeDamage(damage);
                }
            }
            else
            {
                damageable.TakeDamage(damage);
            }
        }

        if (pusheable != null)
        {
            if (defaultPushForce)
            {
                pusheable.Push(velocityLastFrame);
            }
            else
            {
                pusheable.Push(velocityLastFrame.normalized * pushForce);
                // Debug.Log(rb.velocity);
                //Debug.Log("actual: " + rb.velocity.normalized * pushForce);
            }
        }

        Destroy(gameObject);
    }