コード例 #1
0
ファイル: GameSequencer.cs プロジェクト: Amitkapadi/WISP
 private void FireItemResponseTimerStarted(IGameSequencerItem item)
 {
     if (ItemResponseTimerStartedInvoker != null)
     {
         ItemResponseTimerStartedInvoker(item);
     }
 }
コード例 #2
0
ファイル: GameSequencer.cs プロジェクト: Amitkapadi/WISP
        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
ファイル: GameSequencer.cs プロジェクト: Amitkapadi/WISP
 private void FireItemExecuted(IGameSequencerItem item, bool result, string msg)
 {
     if (ItemExecutedInvoker != null)
     {
         ItemExecutedInvoker(item, result, msg);
     }
 }
コード例 #4
0
ファイル: GameSequencer.cs プロジェクト: Amitkapadi/WISP
 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
ファイル: GameSequencer.cs プロジェクト: Amitkapadi/WISP
        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
ファイル: ClientGameTB.cs プロジェクト: Amitkapadi/WISP
 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
ファイル: GameSequencer.cs プロジェクト: Amitkapadi/WISP
        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
ファイル: GameSequencer.cs プロジェクト: Amitkapadi/WISP
 public void ClearSequence()
 {
     lock (CurrentItemSyncRoot)
     {
         CurrentItem = null;
         if (m_Queue != null)
         {
             m_Queue.Clear();
         }
         else
         {
             m_Stack.Clear();
         }
     }
 }
コード例 #11
0
ファイル: GameSequencer.cs プロジェクト: Amitkapadi/WISP
 /// <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
ファイル: GameSequencer.cs プロジェクト: kamilion/WISP
        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
ファイル: GameSequencer.cs プロジェクト: kamilion/WISP
 private void FireCurrentItemChanged(IGameSequencerItem oldItem, IGameSequencerItem newItem)
 {
     if (CurrentItemChangedInvoker != null)
     {
         CurrentItemChangedInvoker(oldItem, newItem);
     }
 }
コード例 #14
0
ファイル: GameSequencer.cs プロジェクト: kamilion/WISP
 private void FireItemExecuted(IGameSequencerItem item, bool result, string msg)
 {
     if (ItemExecutedInvoker != null)
     {
         ItemExecutedInvoker(item, result, msg);
     }
 }
コード例 #15
0
ファイル: GameSequencer.cs プロジェクト: kamilion/WISP
 private void FireItemResponseTimerStarted(IGameSequencerItem item)
 {
     if (ItemResponseTimerStartedInvoker != null)
     {
         ItemResponseTimerStartedInvoker(item);
     }
 }
コード例 #16
0
ファイル: TurnedGameServerGame.cs プロジェクト: kamilion/WISP
        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
ファイル: GameSequencer.cs プロジェクト: kamilion/WISP
        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
ファイル: TurnedGameServerGame.cs プロジェクト: kamilion/WISP
        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
ファイル: GameSequencer.cs プロジェクト: kamilion/WISP
 /// <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);
         }
     }
 }