Exemplo n.º 1
0
        public static BeamCoreState FromApianSerialized(long seqNum, long timeStamp, string stateHash, string serializedData)
        {
            BeamCoreState newState = new BeamCoreState(null);

            JArray sData  = JArray.Parse(serializedData);
            long   newSeq = (long)sData[0];

            Dictionary <string, BeamPlayer> newPlayers = (sData[1] as JArray)
                                                         .Select(s => BeamPlayer.FromApianJson((string)s))
                                                         .ToDictionary(p => p.PeerId);

            List <string> peerIds = newPlayers.Values.OrderBy(p => p.PeerId).Select((p) => p.PeerId).ToList(); // to replace array indices in bikes
            Dictionary <string, IBike> newBikes = (sData[2] as JArray)
                                                  .Select(s => (IBike)BaseBike.FromApianJson((string)s, newState, peerIds, timeStamp))
                                                  .ToDictionary(p => p.bikeId);

            List <string> bikeIds = newBikes.Values.OrderBy(p => p.bikeId).Select((p) => p.bikeId).ToList(); // to replace array indices in places
            Dictionary <int, BeamPlace> newPlaces = (sData[3] as JArray)
                                                    .Select(s => BeamPlace.FromApianJson((string)s, bikeIds, newBikes))
                                                    .ToDictionary(p => p.PosHash);


            newState.Players      = newPlayers;
            newState.Bikes        = newBikes;
            newState.activePlaces = newPlaces;

            newState.UpdateCommandSequenceNumber(seqNum);

            return(newState);
        }
Exemplo n.º 2
0
        public void OnNewPlayerCmd(NewPlayerMsg msg)
        {
            BeamPlayer newPlayer = msg.newPlayer;

            logger.Info($"OnNewPlayerCmd() {((newPlayer.PeerId == LocalPeerId)?"Local":"Remote")} name: {newPlayer.Name}");
            _AddPlayer(newPlayer);
        }
Exemplo n.º 3
0
        // Peer-related
        protected bool _AddPlayer(BeamPlayer p)
        {
            logger.Debug($"_AddPlayer(). Name: {p.Name} ID: {p.PeerId}");
            if (CoreData.Players.ContainsKey(p.PeerId))
            {
                logger.Warn($"_AddPlayer(). Player already exists!!!!");
                return(false);
            }

            CoreData.Players[p.PeerId] = p;
            if (p.PeerId == LocalPeerId)
            {
                LocalPlayer = p;
            }
            PlayerJoinedEvt.Invoke(this, new PlayerJoinedArgs(CurrentGameId, p));
            return(true);
        }
Exemplo n.º 4
0
        public void OnPeerJoinedGameEvt(object sender, PeerJoinedGameArgs ga)
        {
            bool isLocal = ga.peer.PeerId == appl.LocalPeer.PeerId;

            if (isLocal && game == null)
            {
                logger.Info("practice game joined");
                // Create gameInstance and associated Apian
                game = new BeamAppCore(appl.frontend);
                game.PlayerJoinedEvt += OnMemberJoinedGroupEvt;
                game.NewBikeEvt      += OnNewBikeEvt;

                BeamApian apian = new BeamApianSinglePeer(appl.gameNet, game);
                appl.AddAppCore(game);
                // Dont need to check for groups in splash
                apian.CreateNewGroup(ApianGroupId, ApianGroupName);
                BeamPlayer mb = new BeamPlayer(appl.LocalPeer.PeerId, appl.LocalPeer.Name);
                apian.JoinGroup(ApianGroupId, mb.ApianSerialized());

                game.frontend?.OnStartMode(BeamModeFactory.kPractice, null);
                // waiting for OnGroupJoined()
            }
        }
Exemplo n.º 5
0
        public void OnPeerJoinedGameEvt(object sender, PeerJoinedGameArgs ga)
        {
            bool isLocal = ga.peer.PeerId == appl.LocalPeer.PeerId;

            if (isLocal && _CurrentState == ModeState.JoiningGame)
            {
                logger.Info("Splash game joined");
                // Create gameInstance and associated Apian
                game = new BeamAppCore(appl.frontend);
                game.PlayerJoinedEvt += OnPlayerJoinedEvt;
                game.NewBikeEvt      += OnNewBikeEvt;
                BeamApian apian = new BeamApianSinglePeer(appl.gameNet, game); // This is the REAL one
                // BeamApian apian = new BeamApianCreatorServer(core.gameNet, game); // Just for quick tests of CreatorServer
                appl.AddAppCore(game);
                // Dont need to check for groups in splash
                apian.CreateNewGroup(ApianGroupId, ApianGroupName);
                BeamPlayer mb = new BeamPlayer(appl.LocalPeer.PeerId, appl.LocalPeer.Name);
                game.GroupJoinedEvt += OnGroupJoinedEvt;
                apian.JoinGroup(ApianGroupId, mb.ApianSerialized());
                _CurrentState = ModeState.JoiningGroup;
                // waiting for OnPlayerJoined(localplayer)
            }
        }
Exemplo n.º 6
0
        private void _JoinGroup()
        {
            BeamPlayer mb = new BeamPlayer(appl.LocalPeer.PeerId, appl.LocalPeer.Name);

            game.apian.JoinGroup(apianGroupId, mb.ApianSerialized());
        }
Exemplo n.º 7
0
 public NewPlayerMsg(long ts, BeamPlayer _newPlayer) : base(kNewPlayer, ts) => newPlayer = _newPlayer;
Exemplo n.º 8
0
 public PlayerJoinedArgs(string g, BeamPlayer p)
 {
     gameChannel = g; player = p;
 }