Example #1
0
        private void PrepareToStartGame()
        {
            peersNotReadyToStartYet = new List <NetPeer>();
            peersNotReadyToStartYet.AddRange(server.GetPeers());

            int mapId = random.Next(MapData.MapsCount);

            world = new GameWorld {
                maze = Cell.ParseData(MapData.GetMap(mapId))
            };
            int biomeId = random.Next(BiomeData.BiomesCount);

            NetDataWriter writer = new NetDataWriter();

            writer.Put((int)NetMessage.PrepareToStartGame);
            writer.Put(players.Count);
            writer.Put(mapId);
            writer.Put(biomeId);
            server.SendToAll(writer, SendOptions.ReliableOrdered);

            // instantiate characters
            foreach (KeyValuePair <NetPeer, List <string> > entry in playersPerClient)
            {
                NetPeer peer = entry.Key;
                foreach (string id in entry.Value)
                {
                    LobbyPlayer character = players[id];

                    ServerPj serverPj = new ServerPj(id);
                    serverPj.SpawnInAnEmptyPosition(world.maze);
                    world.Pjs.Add(id, serverPj);

                    float x = serverPj.x;
                    float y = serverPj.y;

                    NetDataWriter localCharacterWriter = new NetDataWriter();
                    localCharacterWriter.Put((int)NetMessage.InstantiateCharacter);
                    localCharacterWriter.Put(id);
                    localCharacterWriter.Put((int)character.PlayerControllerIndex);
                    localCharacterWriter.Put((int)Pj.Type.Local);
                    localCharacterWriter.Put(x);
                    localCharacterWriter.Put(y);
                    peer.Send(localCharacterWriter, SendOptions.ReliableOrdered);

                    NetDataWriter remoteCharacterWriter = new NetDataWriter();
                    remoteCharacterWriter.Put((int)NetMessage.InstantiateCharacter);
                    remoteCharacterWriter.Put(id);
                    remoteCharacterWriter.Put((int)character.PlayerControllerIndex);
                    remoteCharacterWriter.Put((int)Pj.Type.Remote);
                    remoteCharacterWriter.Put(x);
                    remoteCharacterWriter.Put(y);
                    server.SendToAll(remoteCharacterWriter, SendOptions.ReliableOrdered, peer);
                }
            }
        }
Example #2
0
 public StatePacket(long InputSequenceNumber, ServerPj pj)
 {
     this.CharacterID         = pj.ID;
     this.InputSequenceNumber = InputSequenceNumber;
     this.X         = pj.x;
     this.Y         = pj.y;
     this.Rotation  = pj.rotation;
     this.Palette   = pj.palette;
     this.Animation = pj.AnimationMachine.CurrentAnimationId;
     this.Timestamp = pj.LastProccessedInputTimestamp;
 }