예제 #1
0
    //=====================================================

    public void OnAttack(eBossAttack attackType, int repeatAttacks = 1)
    {
        if (attackType == eBossAttack.NULL || (int)attackType > (int)eBossAttack.NUM_ATTACKS)
        {
            attackType = eBossAttack.ATTACK_01;
        }

        repeatAttacks = Mathf.Clamp(repeatAttacks, 0, 3);

        // Select grid layout for attack
        if (_gridLayouts.Length > 0)
        {
            var layout = Random.Range(0, _gridLayouts.Length);

            ParseGridLayout(_gridLayouts[layout]);
        }
        else
        {
            Debug.LogError("Boss Grid Manager: missing layouts for attack grid!");
            return;
        }

        // Activate grid boxes for current layout
        if (_activeBoxes.Count == 0)
        {
            return;
        }

        foreach (var box in _activeBoxes)
        {
            box.OnAttack(attackType, repeatAttacks);
        }

        //Debug.Log( "GridManager: OnAttack" );
    }
예제 #2
0
    //=====================================================

    void Awake()
    {
        _thisTransform = this.transform;
        _trigger       = _thisTransform.FindChild("Trigger").gameObject;

        // Inject this gridBox as parent
        _trigger.GetComponent <TriggerGridBox>().Init(this);

        _currentState = eState.DISABLED;
        _incomingFx.SetActive(false);
        _currentBossAttack = eBossAttack.NULL;
        _numAttacks        = 0;
        _isPlayerInRange   = false;
    }
예제 #3
0
    //=====================================================

    public void OnAttack(eBossAttack attack, int numAttacks = 1)
    {
        if (_currentState != eState.DISABLED)
        {
            return;
        }

        // Set alternate attacks
        _currentBossAttack = attack;

        _numAttacks = numAttacks;

        ChangeState(eState.INCOMING);
    }
예제 #4
0
    //=====================================================

    private float ActivateAttackFx(eBossAttack attack)
    {
        if (_attackFxArray.Length < ((int)attack + 1))
        {
            return(0.0f);
        }

        var particle = _attackFxArray[(int)attack];

        if (particle == null)
        {
            return(0.0f);
        }

        particle.SetActive(true);

        // Return particle duration
        return(particle.GetComponent <ParticleSystem>().duration);
    }
예제 #5
0
    //=====================================================

    private float ActivateIncomingFx(eBossAttack attack)
    {
        if (_projectileFxArray.Length < ((int)attack + 1))
        {
            return(0.0f);
        }

        var particle = _projectileFxArray[(int)attack];

        if (particle == null)
        {
            return(0.0f);
        }

        particle.SetActive(true);

        // Return particle duration with small reduction to trigger next state early
        return(Mathf.Clamp(particle.GetComponent <ParticleSystem>().duration - 0.1f, 0.0f, 10.0f));
    }
예제 #6
0
    //=====================================================

    //private void Update()
    //{
    //	if( Input.GetKeyDown( KeyCode.Q ) )
    //		OnAttack( eBossAttack.ATTACK_01, 3 );
    //}

    //=====================================================

    private void ChangeState(eState state)
    {
        float stateDuration;

        switch (state)
        {
        case eState.DISABLED:
            //if( _trigger == null ) break;

            // Deactivate trigger and particle fx
            _trigger.SetActive(false);
            _incomingFx.SetActive(false);

            foreach (var particle in _projectileFxArray)
            {
                particle.SetActive(false);
            }

            foreach (var particle in _attackFxArray)
            {
                particle.SetActive(false);
            }

            // Reset variables
            _currentBossAttack = eBossAttack.NULL;
            _numAttacks        = 0;
            _isPlayerInRange   = false;
            break;

        case eState.INCOMING:
            //if( _trigger == null ) ChangeState( eState.DISABLED ); break;

            // Activate trigger
            _trigger.SetActive(true);

            // Consume number of attacks
            _numAttacks = Mathf.Clamp(_numAttacks - 1, 0, 10);

            // Introduce short random delay
            var startDelay = UnityEngine.Random.Range(0.0f, 0.3f);

            // Get particle duration with small reduction to trigger next state early
            stateDuration = Mathf.Clamp(_incomingFx.GetComponent <ParticleSystem>().duration - 0.5f, 0.0f, 10.0f);

            // Start incoming particle fx
            _incomingFx.SetActive(true);

            // Set state duration
            StartCoroutine(StartInterval(startDelay, stateDuration, () => { ChangeState(eState.PROJECTILE); }));
            break;

        case eState.PROJECTILE:
            // Get particle duration and start projectile fx
            stateDuration = ActivateIncomingFx(_currentBossAttack);

            // Set state duration
            StartCoroutine(StartInterval(0.0f, stateDuration, () => { ChangeState(eState.ATTACK); }));
            break;

        case eState.ATTACK:
            // Start projectile fx
            stateDuration = ActivateAttackFx(_currentBossAttack);

            // Set state duration
            StartCoroutine(StartInterval(0.0f, stateDuration, () =>
            {
                if (_numAttacks > 0)
                {
                    // Disable particles before next attack
                    _incomingFx.SetActive(false);

                    foreach (var particle in _projectileFxArray)
                    {
                        particle.SetActive(false);
                    }

                    foreach (var particle in _attackFxArray)
                    {
                        particle.SetActive(false);
                    }

                    ChangeState(eState.INCOMING);
                }
                else
                {
                    ChangeState(eState.DISABLED);
                }
            }));
            // Attack player
            if (_isPlayerInRange)
            {
                PlayerManager.OnObstacleHit(eDamageType.LOW, Vector3.zero);
            }
            break;
        }

        _currentState = state;
    }