public static void Add(ITurnBasedUnit unit) { if (!_queueActivate.Contains(unit) && GetNode(unit) == null) { _queueActivate.Add(unit); } }
private static TurnNode GetNode(ITurnBasedUnit unit) { for (int i = 0; i < _active.Count; i++) { if (_active[i].Value == unit) { return(_active[i]); } } return(null); }
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); } } }
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; } }
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); }
public void Clear() { Value = null; Priority = 999; }