Example #1
0
        void OnNet_PlayerInput(Player player, BaseFormater data)
        {
            if (State != ERoomState.PartLoaded && State != ERoomState.Playing)
            {
                return;
            }
            if (State == ERoomState.PartLoaded)
            {
                State = ERoomState.Playing;
            }

            var input = data as Msg_PlayerInput;

            //Debug.Log($"RecvInput actorID:{input.ActorId} inputTick:{input.Tick} Tick{Tick} count = {input.Commands.Length}");
            if (input.Tick < Tick)
            {
                return;
            }

            var tick  = input.Tick;
            var iTick = (int)tick;
            //扩充帧队列
            var frameCount = allHistoryFrames.Count;

            if (frameCount <= iTick)
            {
                var count = iTick - allHistoryFrames.Count + 1;
                for (int i = 0; i < count; i++)
                {
                    allHistoryFrames.Add(null);
                }
            }

            if (allHistoryFrames[iTick] == null)
            {
                allHistoryFrames[iTick] = new ServerFrame()
                {
                    Tick = tick
                };
            }

            var frame = allHistoryFrames[iTick];

            if (frame.Inputs == null || frame.Inputs.Length != MaxPlayerCount)
            {
                frame.Inputs = new Msg_PlayerInput[MaxPlayerCount];
            }

            var id = input.ActorId;

            if (!allNeedWaitInputPlayerIds.Contains(id))
            {
                allNeedWaitInputPlayerIds.Add(id);
            }

            frame.Inputs[id] = input;
            //if (input.Commands.Count > 0) {
            //    Debug.Log($"RecvInput actorID:{input.ActorId}  inputTick:{input.Tick}  cmd:{(ECmdType)(input.Commands[0].type)}");
            //}
        }
Example #2
0
        public void StartGame()
        {
            allNeedWaitInputPlayerIds = new List <byte>();
            foreach (var val in netId2LocalId.Values)
            {
                allNeedWaitInputPlayerIds.Add(val);
            }

            State = ERoomState.PartLoading;
            StartSimulationOnConnectedPeers();
        }
Example #3
0
 void RemovePlayer(Player player)
 {
     _allPlayers.Remove(player);
     _localId2Player.Remove(player.localId);
     if (_localId2Player.Count == 0)
     {
         Console.WriteLine("All players left, stopping current simulation...");
         IsRunning = false;
         State     = ERoomState.Idle;
         _gameServer.RemoveRoom(this);
     }
     else
     {
         Console.WriteLine(CurPlayerCount + " players remaining.");
     }
 }
Example #4
0
 public void OnPlayerLeave(Player player)
 {
     Debug.Log($"Player{player.PlayerId} Leave room {RoomId}");
     _allPlayers.Remove(player);
     _localId2Player.Remove(player.localId);
     netId2LocalId.Remove(player.netID);
     if (netId2LocalId.Count == 0)
     {
         Console.WriteLine("All players left, stopping current simulation...");
         IsRunning = false;
         State     = ERoomState.Idle;
         _lobby.RemoveRoom(this);
     }
     else
     {
         Console.WriteLine(CurPlayerCount + " players remaining.");
     }
 }
Example #5
0
        void OnNet_LoadingProgress(Player player, BaseFormater data)
        {
            if (State != ERoomState.PartLoading)
            {
                return;
            }
            var msg = data as Msg_LoadingProgress;

            if (playerLoadingProgress == null)
            {
                playerLoadingProgress = new byte[MaxPlayerCount];
            }

            playerLoadingProgress[player.localId] = msg.progress;

            Debug.Log($"palyer{player.localId} Load {msg.progress}");
            var isDone = true;

            foreach (var progress in playerLoadingProgress)
            {
                if (progress < 100)
                {
                    isDone = false;
                    break;
                }
            }

            var retmsg = new Msg_AllLoadingProgress();

            retmsg.isAllDone = isDone;
            retmsg.progress  = playerLoadingProgress;
            SendToAll(EMsgSC.G2C_LoadingProgress, retmsg);
            if (isDone)
            {
                for (int i = 0; i < playerLoadingProgress.Length; i++)
                {
                    playerLoadingProgress[i] = 0;
                }

                State = ERoomState.PartLoaded;
                Debug.Log("All Load done");
            }
        }
Example #6
0
        public void StartGame()
        {
            byte localId = 0;

            foreach (var player in _allPlayers)
            {
                player.localId = localId;
                _playerId2LocalId[player.PlayerId] = localId;
                _localId2Player[localId]           = player;
                localId++;
            }

            allNeedWaitInputPlayerIds = new List <byte>();
            foreach (var val in _playerId2LocalId.Values)
            {
                allNeedWaitInputPlayerIds.Add(val);
            }
            State = ERoomState.PartLoading;
            StartSimulationOnConnectedPeers();
        }
Example #7
0
        public void OnPlayerEnter(Player player)
        {
            if (State == ERoomState.Idle)
            {
                State = ERoomState.WaitingToPlay;
            }
            if (State != ERoomState.WaitingToPlay)
            {
                return;
            }
            if (_allPlayers.Contains(player))
            {
                Debug.LogError("Player already exist" + player.PlayerId);
                return;
            }

            Debug.Log($"Player{player.PlayerId} Enter room {RoomId}");
            player.room = this;
            _allPlayers.Add(player);
        }
Example #8
0
        public void OnPlayerEnter(Player player)
        {
            if (State == ERoomState.Idle)
            {
                State = ERoomState.WaitingToPlay;
            }
            if (_allPlayers.Contains(player))
            {
                Debug.LogError("Player already exist" + player.PlayerId);
                return;
            }

            Debug.Log($"Player{player.PlayerId} Enter room {RoomId}");
            player.room = this;
            var localId = curPlayerLocalId++;

            player.localId = localId;
            netId2LocalId[player.netID] = localId;
            _localId2Player[localId]    = player;
            _allPlayers.Add(player);
        }
Example #9
0
        public void RefreshState()
        {
            //删除所有结束订单
            for (int i = _unFinishRecords.Count - 1; i >= 0; i--)
            {
                if (_unFinishRecords[i].State == ERoomerState.退房 || _unFinishRecords[i].CheckOutDate < DateTime.Now)
                {
                    _unFinishRecords.RemoveAt(i);
                }
            }

            if (_unFinishRecords.Count == 0)
            {
                _state = ERoomState.空闲;
            }
            else
            {
                _unFinishRecords.Sort((p, q) => p.CheckInDate.CompareTo(q.CheckInDate));
                var firstRecord = _unFinishRecords[0];
                if (firstRecord.CheckOutDate.GetDays() == DateTime.Now.GetDays())
                {
                    _state = ERoomState.今天到期;
                }
                else
                {
                    if (firstRecord.CheckInDate < DateTime.Now)
                    {
                        _state = ERoomState.已入住;
                    }
                    else
                    {
                        _state = ERoomState.已预定;
                    }
                }
            }
        }