Exemplo n.º 1
0
    public void Initialize(BattleSystem battleSystem)
    {
        _battleSystem = battleSystem;
        _battleSystem.ActionRegistered += OnActionRegistered;

        _linearQueues = new Queue <BattleQueueWrapper>();

        // This order maps to the order in which each queue is evaluated.
        // Generic updates are always checked first, then player commands, etc...
        _genericUpdates = new BattleQueueWrapper(BattleQueueType.GenericUpdate, null);

        _playerCommands = new BattleQueueWrapper(BattleQueueType.PlayerCommand, null);
        _statusUpdates  = new BattleQueueWrapper(BattleQueueType.StatusUpdate, OnEnterStatusUpdate, false);
        _weatherUpdates = new BattleQueueWrapper(BattleQueueType.Weather, OnEnterWeather, false);

        Reset();
    }
Exemplo n.º 2
0
    BaseAction Dequeue(ExecutionType executionType)
    {
        GenerateQueue(executionType);

        if (_genericUpdates.Queue.Count != 0)
        {
            return(_genericUpdates.Queue.Dequeue());
        }

        if (_linearQueues.Count == 0)
        {
            return(null);
        }
        else
        {
            if (_linearQueues.Peek().Queue.Count != 0)
            {
                return(_linearQueues.Peek().Queue.Dequeue());
            }
            else
            {
                // Find the next non-empty queue.
                BattleQueueWrapper next = null;

                while (next == null || next.Queue.Count == 0 && _linearQueues.Count != 0)
                {
                    next = _linearQueues.Dequeue();

                    // Activate the next queue.
                    if (next.OnActivation != null)
                    {
                        next.OnActivation(_battleSystem);
                    }
                }

                if (next != null)
                {
                    LogEx.Log <BattleQueue>("Moving to next non-empty queue: " + next.Type);
                }

                return(next != null && next.Queue.Count != 0 ? next.Queue.Dequeue() : null);
            }
        }
    }