Esempio n. 1
0
        //public SerializableDictionary<MyObjectBuilder_Checkpoint.PlayerId, MyObjectBuilder_Toolbar> GetSerDictionary()
        //{
        //    var ret = new SerializableDictionary<MyObjectBuilder_Checkpoint.PlayerId, MyObjectBuilder_Toolbar>();
        //    foreach (var item in m_playerToolbars)
        //    {
        //        var pid = new MyObjectBuilder_Checkpoint.PlayerId(item.Key.SteamId);
        //        pid.SerialId = item.Key.SerialId;

        //        var ob = item.Value.GetObjectBuilder();
        //        ret.Dictionary.Add(pid, ob);
        //    }
        //    return ret;
        //}

        public void SaveToolbars(MyObjectBuilder_Checkpoint checkpoint)
        {
            Dictionary <MyObjectBuilder_Checkpoint.PlayerId, MyObjectBuilder_Player> checkpointData = checkpoint.AllPlayersData.Dictionary;

            foreach (var toolbar in m_playerToolbars)
            {
                var pid = new MyObjectBuilder_Checkpoint.PlayerId(toolbar.Key.SteamId);
                pid.SerialId = toolbar.Key.SerialId;
                if (checkpointData.ContainsKey(pid))
                {
                    checkpointData[pid].Toolbar = toolbar.Value.GetObjectBuilder();
                }
            }
        }
        public void SavePlayers(MyObjectBuilder_Checkpoint checkpoint)
        {
            checkpoint.ConnectedPlayers = new SerializableDictionary<MyObjectBuilder_Checkpoint.PlayerId, MyObjectBuilder_Player>();
            checkpoint.DisconnectedPlayers = new SerializableDictionary<MyObjectBuilder_Checkpoint.PlayerId, long>();
            checkpoint.AllPlayersData = new SerializableDictionary<MyObjectBuilder_Checkpoint.PlayerId, MyObjectBuilder_Player>();

            foreach (var player in m_players.Values)
            {
                var id = new MyObjectBuilder_Checkpoint.PlayerId() { ClientId = player.Id.SteamId, SerialId = player.Id.SerialId };

                MyObjectBuilder_Player playerOb = new MyObjectBuilder_Player();
                playerOb.DisplayName = player.DisplayName;
                playerOb.IdentityId = player.Identity.IdentityId;
                playerOb.Connected = true;

                checkpoint.AllPlayersData.Dictionary.Add(id, playerOb);
            }

            foreach (var entry in m_playerIdentityIds)
            {
                if (m_players.ContainsKey(entry.Key) || entry.Key.SerialId != 0) continue;

                var id = new MyObjectBuilder_Checkpoint.PlayerId() { ClientId = entry.Key.SteamId, SerialId = entry.Key.SerialId };
                MyObjectBuilder_Player playerOb = new MyObjectBuilder_Player();
                playerOb.Connected = false;
                playerOb.IdentityId = entry.Value;
                var identity = TryGetIdentity(entry.Value);
                playerOb.DisplayName = identity != null ? identity.DisplayName : null;

                checkpoint.AllPlayersData.Dictionary.Add(id, playerOb);
            }

            //foreach (var entry in m_playerIdentityIds)
            //{
            //    // Skip connected players
            //    if (m_players.ContainsKey(entry.Key)) continue;

            //    var id = new MyObjectBuilder_Checkpoint.PlayerId() { ClientId = entry.Key.SteamId, SerialId = entry.Key.SerialId };

            //    checkpoint.DisconnectedPlayers.Dictionary.Add(id, entry.Value);
            //}
        }
        public SerializableDictionaryCompat<long, MyObjectBuilder_Checkpoint.PlayerId, ulong> SerializeControlledEntities()
        {
            var output = new SerializableDictionaryCompat<long,MyObjectBuilder_Checkpoint.PlayerId,ulong>();

            foreach (var entry in m_controlledEntities)
            {
                MyObjectBuilder_Checkpoint.PlayerId playerId = new MyObjectBuilder_Checkpoint.PlayerId();
                playerId.ClientId = entry.Value.SteamId;
                playerId.SerialId = entry.Value.SerialId;
                output.Dictionary.Add(entry.Key, playerId);
            }

            return output;
        }
        //public SerializableDictionary<MyObjectBuilder_Checkpoint.PlayerId, MyObjectBuilder_Toolbar> GetSerDictionary()
        //{ 
        //    var ret = new SerializableDictionary<MyObjectBuilder_Checkpoint.PlayerId, MyObjectBuilder_Toolbar>();
        //    foreach (var item in m_playerToolbars)
        //    {
        //        var pid = new MyObjectBuilder_Checkpoint.PlayerId(item.Key.SteamId);
        //        pid.SerialId = item.Key.SerialId;

        //        var ob = item.Value.GetObjectBuilder();
        //        ret.Dictionary.Add(pid, ob);
        //    }
        //    return ret;
        //}

        public void SaveToolbars(MyObjectBuilder_Checkpoint checkpoint)
        {
            Dictionary<MyObjectBuilder_Checkpoint.PlayerId, MyObjectBuilder_Player> checkpointData = checkpoint.AllPlayersData.Dictionary;
            foreach (var toolbar in m_playerToolbars)
            {
                var pid = new MyObjectBuilder_Checkpoint.PlayerId(toolbar.Key.SteamId);
                pid.SerialId = toolbar.Key.SerialId;
                if (checkpointData.ContainsKey(pid))
                {
                    checkpointData[pid].Toolbar = toolbar.Value.GetObjectBuilder();
                }
            }
        }
        public void SavePlayers(MyObjectBuilder_Checkpoint checkpoint)
        {
            checkpoint.ConnectedPlayers = new SerializableDictionary<MyObjectBuilder_Checkpoint.PlayerId, MyObjectBuilder_Player>();
            checkpoint.DisconnectedPlayers = new SerializableDictionary<MyObjectBuilder_Checkpoint.PlayerId, long>();
            checkpoint.AllPlayersData = new SerializableDictionary<MyObjectBuilder_Checkpoint.PlayerId, MyObjectBuilder_Player>();
            checkpoint.AllPlayersColors = new SerializableDictionary<MyObjectBuilder_Checkpoint.PlayerId, List<Vector3>>();

            foreach (var player in m_players.Values)
            {
                var id = new MyObjectBuilder_Checkpoint.PlayerId() { ClientId = player.Id.SteamId, SerialId = player.Id.SerialId };
                MyObjectBuilder_Player playerOb = player.GetObjectBuilder();

                checkpoint.AllPlayersData.Dictionary.Add(id, playerOb);
            }

            foreach (var identityPair in m_playerIdentityIds)
            {
                if (m_players.ContainsKey(identityPair.Key)) continue;

                var id = new MyObjectBuilder_Checkpoint.PlayerId() { ClientId = identityPair.Key.SteamId, SerialId = identityPair.Key.SerialId };
                var identity = TryGetIdentity(identityPair.Value);
                MyObjectBuilder_Player playerOb = new MyObjectBuilder_Player();
                playerOb.DisplayName = identity != null ? identity.DisplayName : null;
                playerOb.IdentityId = identityPair.Value;
                playerOb.Connected = false;
                if (MyCubeBuilder.AllPlayersColors != null)
                    MyCubeBuilder.AllPlayersColors.TryGetValue(identityPair.Key, out playerOb.BuildColorSlots);

                checkpoint.AllPlayersData.Dictionary.Add(id, playerOb);
            }

            if (MyCubeBuilder.AllPlayersColors != null)
            {
                foreach (var colorPair in MyCubeBuilder.AllPlayersColors)
                {
                    if (m_players.ContainsKey(colorPair.Key) || m_playerIdentityIds.ContainsKey(colorPair.Key)) continue;	// avoid data duplication in saves

                    var id = new MyObjectBuilder_Checkpoint.PlayerId() { ClientId = colorPair.Key.SteamId, SerialId = colorPair.Key.SerialId };
                    checkpoint.AllPlayersColors.Dictionary.Add(id, colorPair.Value);
                }
            }
        }