protected virtual void Update()
    {
        try
        {
            if (_currentBaseControlHandler != null)
            {
                while (!_currentBaseControlHandler.Update())
                {
                    BaseControlHandler poppedHandler = _controlHandlers.Pop();
                    poppedHandler.Dispose();

                    Logger.Info("Popped handler: " + poppedHandler.ToString());
                    TryActivateCurrentControlHandler(poppedHandler);
                }

                // after we updated the control handler, we now want to notify all stack members (excluding the current handler/peek) that an update
                // has occurred. This is necessary in case stacked handlers need to react to actions, for example: melee attack is interrupted by wall jump handler
                for (int i = _controlHandlers.Count - 2; i >= 0; i--)
                {
                    _controlHandlers[i].OnAfterStackPeekUpdate();
                }
            }
        }
        catch (Exception err)
        {
            Logger.Error("Game object " + this.name + " misses default control handler.", err);
            throw;
        }
    }
    private void TryActivateCurrentControlHandler(BaseControlHandler previousControlHandler)
    {
        _currentBaseControlHandler = _controlHandlers.Peek();

        while (_currentBaseControlHandler != null &&
               !_currentBaseControlHandler.TryActivate(previousControlHandler))
        {
            previousControlHandler = _controlHandlers.Pop();
            Logger.Info("Popped handler: " + previousControlHandler.ToString());
            previousControlHandler.Dispose();

            _currentBaseControlHandler = _controlHandlers.Peek();
        }
    }
예제 #3
0
    public void KillPlayer()
    {
        if (_currentPowerUpItem.HasValue)
        {
            _orderedPowerUpInventory.Remove(_currentPowerUpItem.Value);

            _currentPowerUpControlHandler.Dispose();
            _gameManager.player.RemoveControlHandler(_currentPowerUpControlHandler);

            _currentPowerUpControlHandler = null;
            _currentPowerUpItem           = null;
            Logger.Info("Added damage, removed power up item. " + this.ToString());
        }

        // player died
        Logger.Info("Added damage, respawn. " + this.ToString());

        // TODO (Roman): this should be somewhere else - this is just test code
        GameObject deathParticles = ObjectPoolingManager.Instance.GetObject(GameManager.instance.gameSettings.pooledObjects.defaultPlayerDeathParticlePrefab.prefab.name);

        deathParticles.transform.position = _gameManager.player.gameObject.transform.position;

        _gameManager.player.Respawn();
    }
    /// <summary>
    /// Exchanges the control handler.
    /// </summary>
    /// <param name="index">The index.</param>
    /// <param name="controlHandler">The control handler.</param>
    public void ExchangeControlHandler(int index, BaseControlHandler controlHandler)
    {
        Logger.Info("Exchanging handler " + _controlHandlers[index].ToString() + " (index: " + index + ") with " + controlHandler.ToString());

        if (_controlHandlers[index] == _currentBaseControlHandler)
        {
            BaseControlHandler poppedHandler = _controlHandlers.Exchange(index, controlHandler);
            poppedHandler.Dispose();

            TryActivateCurrentControlHandler(poppedHandler);
        }
        else
        {
            _controlHandlers.Exchange(index, controlHandler);
        }
    }
    /// <summary>
    /// Removes the control handler.
    /// </summary>
    /// <param name="controlHandler">The control handler.</param>
    public void RemoveControlHandler(BaseControlHandler controlHandler)
    {
        Logger.Info("Removing handler: " + controlHandler.ToString());

        if (controlHandler == _currentBaseControlHandler)
        {
            BaseControlHandler poppedHandler = _controlHandlers.Pop();
            poppedHandler.Dispose();

            TryActivateCurrentControlHandler(poppedHandler);
        }
        else
        {
            _controlHandlers.Remove(controlHandler);
            controlHandler.Dispose();
        }
    }