示例#1
0
 private void FireItemResponseTimerStarted(IGameSequencerItem item)
 {
     if (ItemResponseTimerStartedInvoker != null)
     {
         ItemResponseTimerStartedInvoker(item);
     }
 }
示例#2
0
        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);
        }
示例#3
0
 private void FireItemExecuted(IGameSequencerItem item, bool result, string msg)
 {
     if (ItemExecutedInvoker != null)
     {
         ItemExecutedInvoker(item, result, msg);
     }
 }
示例#4
0
 private void FireCurrentItemChanged(IGameSequencerItem oldItem, IGameSequencerItem newItem)
 {
     if (CurrentItemChangedInvoker != null)
     {
         CurrentItemChangedInvoker(oldItem, newItem);
     }
 }
示例#5
0
        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;
            }
        }
示例#6
0
        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);
            }
        }
示例#7
0
 private void FirePhaseEntered(Game game, IGameSequencerItem item, PacketPhaseUpdate.UpdateKind kind)
 {
     if (PhasePhaseEnteredInvoker != null)
     {
         PhasePhaseEnteredInvoker(game, item, kind);
     }
 }
示例#8
0
        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].");
        }
示例#9
0
        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);
            }
        }
示例#10
0
 public void ClearSequence()
 {
     lock (CurrentItemSyncRoot)
     {
         CurrentItem = null;
         if (m_Queue != null)
         {
             m_Queue.Clear();
         }
         else
         {
             m_Stack.Clear();
         }
     }
 }
示例#11
0
 /// <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);
         }
     }
 }
示例#12
0
        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);
        }
示例#13
0
 private void FireCurrentItemChanged(IGameSequencerItem oldItem, IGameSequencerItem newItem)
 {
     if (CurrentItemChangedInvoker != null)
     {
         CurrentItemChangedInvoker(oldItem, newItem);
     }
 }
示例#14
0
 private void FireItemExecuted(IGameSequencerItem item, bool result, string msg)
 {
     if (ItemExecutedInvoker != null)
     {
         ItemExecutedInvoker(item, result, msg);
     }
 }
示例#15
0
 private void FireItemResponseTimerStarted(IGameSequencerItem item)
 {
     if (ItemResponseTimerStartedInvoker != null)
     {
         ItemResponseTimerStartedInvoker(item);
     }
 }
示例#16
0
        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;
            }
        }
示例#17
0
        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);
            }
        }
示例#18
0
        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].");
        }
示例#19
0
 /// <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);
         }
     }
 }