Ejemplo n.º 1
0
 private bool TurnAskPause(int playerTurn, short senderId)
 {
     if (_gameServer.PauseCtrl.IsPaused)
     {
         if (_gameServer.PauseCtrl.PauseTurn == playerTurn)
         {
             DoTurnMessage dtMsg = (DoTurnMessage)MessageFactory.Create(MessageType.DoTurn);
             dtMsg.Pause = (byte)PauseAction.Pause;
             InfoLog.WriteInfo("Adding player to pause queue!");
             _gameServer.PauseCtrl.AddPausedPlayer(senderId);
             SendMessage(dtMsg, senderId);
             return(true);
         }
     }
     return(false);
 }
Ejemplo n.º 2
0
        private void IncreaseTurn(Player p)
        {
            int minTurnBefore = _gameServer.Simulation.GetMinTurn();

            _gameServer.Simulation.IncPlayerTurn(p.Id);
            int minTurn = _gameServer.Simulation.GetMinTurn();
            // if this is slowest player then tell him to speed up
            DoTurnMessage dtm = (DoTurnMessage)MessageFactory.Create(MessageType.DoTurn);

            if (minTurn != minTurnBefore)
            {
                dtm.SpeedUp = true;
            }
            //
            p.SendMessage(dtm);
            if (minTurn != minTurnBefore)
            {
                ResumeWaitingPlayers();
            }
        }
Ejemplo n.º 3
0
        private void IncreaseTurn(short id, PauseAction pauseAction)
        {
            InfoLog.WriteInfo("Increasing turn for player: " + id, EPrefix.GameMessageProccesing);
            int minTurnBefore = _gameServer.Simulation.GetMinTurn();
            int maxTurn       = _gameServer.Simulation.GetMaxTurn();
            int actualTurn    = _gameServer.Simulation.GetPlayerTurn(id);
            int delta         = 1;

            if (actualTurn < maxTurn)
            {
                delta = maxTurn - actualTurn;
            }
            _gameServer.Simulation.IncPlayerTurn(id, delta);

            int minTurnAfter = _gameServer.Simulation.GetMinTurn();

            // if this is slowest player then tell him to speed up
            DoTurnMessage dtm = (DoTurnMessage)MessageFactory.Create(MessageType.DoTurn);

            dtm.Pause     = (byte)pauseAction;
            dtm.TurnsToGo = (short)delta;
            if (minTurnBefore != minTurnAfter)
            {
                dtm.SpeedUp = true;
            }
            //
            SendMessage(dtm, id);
            if (minTurnAfter != minTurnBefore)
            {
                InfoLog.WriteInfo("Waking waiting players", EPrefix.GameMessageProccesing);
                short[] stoppedWaiting = _gameServer.Simulation.StopWaiting();
                InfoLog.WriteInfo("Players to wake: " + stoppedWaiting.ToString(), EPrefix.GameMessageProccesing);
                for (int i = 0; i < stoppedWaiting.Length; ++i)
                {
                    _gameServer.Simulation.IncPlayerTurn(stoppedWaiting[i]);
                    SendMessage(MessageFactory.Create(MessageType.DoTurn), stoppedWaiting[i]);
                }
            }
        }
Ejemplo n.º 4
0
        void Instance_DoTurnPermission(object sender, DoTurnMessage dtm)
        {
            //InfoLog.WriteInfo("Turn permitted", EPrefix.SimulationInfo);
            PauseAction paction = (PauseAction)dtm.Pause;

            switch (paction)
            {
            case PauseAction.Resume:
                //_isPaused = false;
                if (dtm.SpeedUp)
                {
                    _sim.SpeedUp = true;
                    InfoLog.WriteInfo("Speeding Up", EPrefix.GameLogic);
                }
                if (PauseResume != null)
                {
                    PauseResume(false);
                }
                _sim.DoTurn(dtm.TurnsToGo);
                break;

            case PauseAction.None:
                if (dtm.SpeedUp)
                {
                    _sim.SpeedUp = true;
                    InfoLog.WriteInfo("Speeding Up", EPrefix.GameLogic);
                }
                _sim.DoTurn(dtm.TurnsToGo);
                break;

            case PauseAction.Pause:
                //this._isPaused = true;
                if (PauseResume != null)
                {
                    PauseResume(true);
                }
                break;
            }
        }