Пример #1
0
    public Entity[] GetEnemiesInRange(PlayerModel enemyPlayer, float radius)
    {
        // Collect all the colliders in a capsule of the given radius covering all units on the y axis.
        Vector3 bottom, top;

        CombatUtils.GetCapsulePointsFromPosition(transform.position, out bottom, out top);

        Collider[] colliders = Physics.OverlapCapsule(bottom, top, radius, CombatUtils.EntityMask);

        List <Entity> entities = new List <Entity>();

        for (int i = 0; i < colliders.Length; i++)
        {
            Entity targetEntity = colliders[i].GetComponent <Entity> ();

            // If there is no entity script attached to the gameobject, go on to the next collider.
            if (targetEntity != null)
            {
                // If it's an enemy unit, do damage to it.
                if (targetEntity.Owner == enemyPlayer)
                {
                    entities.Add(targetEntity);
                }
            }
        }

        return(entities.ToArray());
    }
Пример #2
0
    private void triggerEffect()
    {
        Vector3 bottom, top;

        CombatUtils.GetCapsulePointsFromPosition(transform.position, out bottom, out top);

        // Collect all the colliders in a sphere from the shell's current position to a radius of the explosion radius.
        Collider[] colliders = Physics.OverlapCapsule(bottom, top, _effectRadius, CombatUtils.EntityMask);
        _workingSet.Clear();

        for (int i = 0; i < colliders.Length; i++)
        {
            Entity targetEntity = colliders[i].GetComponent <Entity> ();

            // If it's an enemy unit, do damage to it.
            if (isAffectedEntity(_entity.Owner, targetEntity))
            {
                targetEntity.TakeDamage(_entity.AreaAttackDamage);

                if (!_affectedEntities.Contains(targetEntity))
                {
                    foreach (var effect in _effects)
                    {
                        _affectedEntities.Add(targetEntity);
                        targetEntity.ApplyEffect(effect);
                    }
                }

                _workingSet.Add(targetEntity);
            }
        }

        var oldList = _affectedEntities;

        _affectedEntities = new List <Entity>();
        foreach (var entity in oldList)
        {
            if (!_workingSet.Contains(entity))
            {
                foreach (var effect in _effects)
                {
                    entity.RemoveEffect(effect);
                }
            }
            else if (entity != null)
            {
                _affectedEntities.Add(entity);
            }
        }
    }
Пример #3
0
    // Question, will this be sufficient for flying enemies?  Or do we want a box check?
    private Entity[] getAllEnemiesInRange(float radius)
    {
        Vector3 bottom, top;

        CombatUtils.GetCapsulePointsFromPosition(transform.position, out bottom, out top);

        Collider[]    allColliders = Physics.OverlapCapsule(bottom, top, radius, CombatUtils.EntityMask);
        List <Entity> enemies      = new List <Entity>();

        foreach (var collider in allColliders)
        {
            var entity = collider.GetComponent <Entity>();

            // If it's an enemy entity
            if (entity != null && entity.Owner != _entity.Owner)
            {
                enemies.Add(entity);
            }
        }
        return(enemies.ToArray());
    }