private void FireItemResponseTimerStarted(IGameSequencerItem item) { if (ItemResponseTimerStartedInvoker != null) { ItemResponseTimerStartedInvoker(item); } }
protected virtual void OnItemExecute(IGameSequencerItem item) { if (CurrentItem != item) { // it's possible that another thread Pushed or Popped the CurrentItem while the timer went off on the last current item return; } GameSequencerItem ex = item as GameSequencerItem; if (ex != null) { if (ex.HasBegunExecution) // dont execute twice, just in case { return; } ex.HasBegunExecution = true; } string msg = ""; bool rslt = true; rslt = item.TryExecuteEffect(ref msg); FireItemExecuted(ex, rslt, msg); }
private void FireItemExecuted(IGameSequencerItem item, bool result, string msg) { if (ItemExecutedInvoker != null) { ItemExecutedInvoker(item, result, msg); } }
private void FireCurrentItemChanged(IGameSequencerItem oldItem, IGameSequencerItem newItem) { if (CurrentItemChangedInvoker != null) { CurrentItemChangedInvoker(oldItem, newItem); } }
void GamePhaseSequencer_ItemExecuted(IGameSequencerItem item, bool success, string msg) { if (!success) { return; } Phase p = item as Phase; BroadcastTurnPhaseUpdateToPlayer(p, PacketPhaseUpdate.UpdateKind.Entered); switch (p.PhaseID) { case (int)PhaseId.RoundStartup: case (int)PhaseId.RoundEnd: p.EndPhase(); break; case (int)PhaseId.Main: OnNextTurnPhase(p); break; case (int)PhaseId.BeginTurn: case (int)PhaseId.EndTurn: OnNextTurnPhase(p); p.EndPhase(); // we do not linger in the end-ofturn phase. break; } }
public IGameSequencerItem ActivateNextItem() { lock (CurrentItemSyncRoot) { IGameSequencerItem itm = null; if (m_Queue != null) { if (m_Queue.Count > 0) { itm = m_Queue.Dequeue(); } } else { if (m_Stack.Count > 0) { itm = m_Stack.Pop(); } } if (itm != null) { CurrentItem = itm; } return(itm); } }
private void FirePhaseEntered(Game game, IGameSequencerItem item, PacketPhaseUpdate.UpdateKind kind) { if (PhasePhaseEnteredInvoker != null) { PhasePhaseEnteredInvoker(game, item, kind); } }
void GamePhaseSequencer_ItemResponseTimerStarted(IGameSequencerItem itm) { Phase p = itm as Phase; BroadcastTurnPhaseUpdateToPlayer(p, PacketPhaseUpdate.UpdateKind.EnteredWithDelay); DateTime when = new DateTime(p.ResponseTime, DateTimeKind.Utc); TimeSpan len = when - DateTime.UtcNow; //Log.LogMsg("Broadcast Phase execute Delay for phase [" + p.PhaseName + "] in [" + len.TotalSeconds.ToString() + " seconds]."); }
protected virtual void OnCurrentItemChanged(IGameSequencerItem oldItem, IGameSequencerItem newItem) { if (oldItem != null) { oldItem.OnBecameNotCurrent(); } if (newItem != null) { newItem.OnBecameCurrent(); } FireCurrentItemChanged(oldItem, newItem); if (newItem == null) { return; } GameSequencerItem ex = newItem as GameSequencerItem; // Get the timeout int timeout = 0; if (ex.ResponseTimerMod == int.MaxValue) { timeout = Timeout.Infinite; } else if (ex.ResponseTimerMod > int.MinValue) { timeout = ex.ResponseTimeout + ex.ResponseTimerMod; } ex.ResponseTimeout = timeout; // Set the timer or execute in case of no timeout if (timeout > 0) { Log.LogMsg(" -> Waiting [" + TimeSpan.FromMilliseconds(timeout).TotalSeconds + "] seconds before executing."); ex.ResponseTime = DateTime.UtcNow.Ticks + TimeSpan.FromMilliseconds(timeout).Ticks; SetTimerForCurrentItem(timeout); OnItemResponseTimerStarted(ex); DateTime exeTime = new DateTime(ex.ResponseTime, DateTimeKind.Utc); TimeSpan len = exeTime - DateTime.UtcNow; Log.LogMsg("It is now [" + DateTime.UtcNow.ToLongTimeString() + "]. Execute time for [" + ((Phase)ex).PhaseName + "] is at [" + exeTime.ToLongTimeString() + "], i.e. in [" + len.TotalSeconds + " seconds]. Response timeout is [" + timeout + " ms]."); } else { OnItemExecute(ex); } }
public void ClearSequence() { lock (CurrentItemSyncRoot) { CurrentItem = null; if (m_Queue != null) { m_Queue.Clear(); } else { m_Stack.Clear(); } } }
/// <summary> /// Pushes a new item to the stack. /// </summary> /// <param name="itm">the item to push</param> /// <param name="responseTimerMod">You can add/remove time from the response timer by passing a possitive or negative value as responseTimerMod. Pass /// int.MinValue to disable the response timer and to cause the item to execute as soon as its on the stack. Pass int.MaxValue to never time the /// stack item out.</param> public void AddItem(IGameSequencerItem itm, int responseTimerMod) { lock (CurrentItemSyncRoot) { itm.Sequencer = this; GameSequencerItem ex = itm as GameSequencerItem; ex.ResponseTimerMod = responseTimerMod; if (m_Queue != null) { m_Queue.Enqueue(ex); } else { m_Stack.Push(ex); } } }