예제 #1
0
 public static void Add(ITurnBasedUnit unit)
 {
     if (!_queueActivate.Contains(unit) && GetNode(unit) == null)
     {
         _queueActivate.Add(unit);
     }
 }
예제 #2
0
 private static TurnNode GetNode(ITurnBasedUnit unit)
 {
     for (int i = 0; i < _active.Count; i++)
     {
         if (_active[i].Value == unit)
         {
             return(_active[i]);
         }
     }
     return(null);
 }
예제 #3
0
 public static void Remove(ITurnBasedUnit unit)
 {
     if (_queueActivate.Contains(unit))
     {
         _queueActivate.Remove(unit);
     }
     else
     {
         var node = GetNode(unit);
         if (node != null)
         {
             _active.Remove(node);
             _nodePool.Store(node);
         }
     }
 }
예제 #4
0
 private void TurnUpdate()
 {
     if (TurnCancel())
     {
         return;
     }
     _active.Sort(_nodeSorter);
     //_active.BubbleSort((i, i1) => i.Priority < i1.Priority);
     for (int i = 0; i < _active.Count; i++)
     {
         if (TurnCancel())
         {
             return;
         }
         if (_active[i] == null || _active[i].Value == null)
         {
             continue;
         }
         _active[i].Value.TurnUpdate(TurnRecoverAmount);
         //need to check it is the first activation
         if (_active[i].Value.TryStartTurn())
         {
             EntityController.GetEntity(_active[i].Value.Owner).Post(EntitySignals.TurnReady);
             if (GameOptions.TurnBased)
             {
                 _current = _active[i].Value;
                 break;
             }
         }
     }
     _turnLengthCounter += TurnRecoverAmount;
     if (_turnLengthCounter >= TurnBased.RecoveryNeededToEndTurn)
     {
         NewTurn();
     }
     else
     {
         SystemManager.TurnUpdate(false);
         _turnState = TurnBasedState.Performing;
     }
 }
예제 #5
0
 private bool TurnCancel()
 {
     if (_active.Count == 0)
     {
         _turnState = TurnBasedState.NoUnits;
         return(true);
     }
     if (_current != null)
     {
         if (_current.TryStartTurn())
         {
             _turnState = TurnBasedState.Performing;
             return(true);
         }
         _current = null;
     }
     if (!Game.GameActive || Game.Paused)
     {
         _turnState = Game.GameActive ? TurnBasedState.WaitingOnInput : TurnBasedState.Disabled;
         return(true);
     }
     return(false);
 }
예제 #6
0
 public void Clear()
 {
     Value    = null;
     Priority = 999;
 }