Пример #1
0
    private void AggroPlayer(bool aggroSurrounding, int recursions = 0)
    {
        _hasAggro = true;
        _target   = _player.gameObject;
        SoundManager.Instance.PlayMonsterAggro();

        if (aggroSurrounding)
        {
            List <Enemy> enemies   = MapManager.Instance.CurrentMap.GetEnemiesInCircle(transform.position, _aggroDistance);
            int          layerMask = Layers.CombinedLayerMask(Layers.Map, Layers.Enemy, Layers.FlyingEnemy);
            int          rec       = recursions - 1;
            _collider.enabled = false;

            enemies.ForEach(x =>
            {
                if (!x.HasAggro)
                {
                    if (IsVisible(_aggroDistance * 3.0f, x.transform.position.ToVector2(), layerMask,
                                  new List <int>()
                    {
                        Layers.Enemy, Layers.FlyingEnemy
                    }))
                    {
                        x.AggroPlayer(recursions > 0, rec);
                    }
                }
            });

            _collider.enabled = true;
        }
    }
Пример #2
0
    private void OnTriggerStay2D(Collider2D collision)
    {
        if (collision.gameObject.layer == Layers.Map)
        {
            RaycastHit2D hit = Physics2D.Raycast(_lastPosition, _direction, 1.0f,
                                                 Layers.CombinedLayerMask(Layers.Map));

            if (_reflectionNormal != hit.normal)
            {
                _reflectionNormal  = hit.normal;
                _direction         = Vector2.Reflect(_direction.normalized, _reflectionNormal);
                transform.position = _lastPosition;
            }
        }
    }
Пример #3
0
    public virtual bool PlayerIsVisible(float viewDistance)
    {
        int layerMask = 0;

        if (_hasAggro)
        {
            layerMask     = Layers.CombinedLayerMask(Layers.Map, Layers.Pits, Layers.Player);
            viewDistance *= 3.0f;
        }
        else
        {
            layerMask = Layers.CombinedLayerMask(Layers.Map, Layers.Player);
        }

        return(IsVisible(viewDistance, _player.transform.position.ToVector2(), layerMask, new List <int>()
        {
            Layers.Player
        }));
    }
Пример #4
0
    public override bool PlayerIsVisible(float viewDistance)
    {
        int layerMask = 0;

        if (_hasAggro && _currentForm == Form.Humanoid)
        {
            layerMask     = Layers.CombinedLayerMask(Layers.Map, Layers.Pits, Layers.Player);
            viewDistance *= 3.0f;
        }
        else
        {
            layerMask = Layers.CombinedLayerMask(Layers.Map, Layers.Player);
        }

        return(IsVisible(viewDistance, _player.transform.position.ToVector2(), layerMask, new List <int>()
        {
            Layers.Player
        }));
    }
Пример #5
0
    protected override void OnTriggerEnter2D(Collider2D collision)
    {
        if (collision.gameObject == _owner)
        {
            return;
        }

        bool active = true;

        if (collision.gameObject.layer == Layers.Map)
        {
            RaycastHit2D hit = Physics2D.Raycast(_lastPosition, _direction, 1.0f,
                                                 Layers.CombinedLayerMask(Layers.Map));

            _reflectionNormal  = hit.normal;
            _direction         = Vector2.Reflect(_direction.normalized, _reflectionNormal);
            transform.position = _lastPosition;
        }
        else if (collision.gameObject.layer == Layers.Enemy || collision.gameObject.layer == Layers.FlyingEnemy)
        {
            Enemy enemy = collision.gameObject.GetComponent <Enemy>();
            if (enemy.IsAlive)
            {
                collision.gameObject.GetComponent <Enemy>().ReceiveDamage((int)_currentDamage, _direction);

                if (pierceCount <= 0)
                {
                    BeforeDestroyed(collision.gameObject);
                    active = false;
                }

                pierceCount--;
                _currentDamage -= _currentDamage * 0.33f;
            }
        }

        gameObject.SetActive(active);
    }
Пример #6
0
    protected override void OnTriggerEnter2D(Collider2D collision)
    {
        if (collision.gameObject == _owner)
        {
            return;
        }

        bool active = true;

        if (collision.gameObject.layer == Layers.Map)
        {
            RaycastHit2D hit = Physics2D.Raycast(_lastPosition, _direction, 4.0f,
                                                 Layers.CombinedLayerMask(Layers.Map));

            _reflectionNormal = hit.normal;
            SplitBullet(hit.point, false);

            BeforeDestroyed(collision.gameObject);
            active = false;
        }
        else if (collision.gameObject.layer == Layers.Enemy || collision.gameObject.layer == Layers.FlyingEnemy)
        {
            Enemy enemy = collision.gameObject.GetComponent <Enemy>();
            if (enemy.IsAlive)
            {
                collision.gameObject.GetComponent <Enemy>().ReceiveDamage((int)_currentDamage, _direction);
                BeforeDestroyed(collision.gameObject);

                SplitBullet(transform.position, true);

                active = false;
            }
        }

        gameObject.SetActive(active);
    }