Пример #1
0
        /// <summary>
        /// Updates before simulation. Will add all persistent gpss to the players,
        /// that dont have them yet.
        /// </summary>
        public override void UpdateBeforeSimulation()
        {
            if (MySettingsSession.Static.IsEnabled())
            {
                foreach (var entry in m_globalGpss.Keys)
                {
                    foreach (var p in MySession.Static.Players.GetOnlinePlayers())
                    {
                        if (m_globalGpss[entry].Players.Contains(p.Identity.IdentityId))
                        {
                            continue;
                        }

                        MyGps gps = new MyGps
                        {
                            Name          = m_globalGpss[entry].Name,
                            Coords        = m_globalGpss[entry].Position,
                            GPSColor      = m_globalGpss[entry].Color,
                            ShowOnHud     = !m_globalGpss[entry].Hidden,
                            AlwaysVisible = false,
                            DiscardAt     = null
                        };

                        gps.CalculateHash();

                        MySession.Static.Gpss.SendAddGps(p.Identity.IdentityId, ref gps, playSoundOnCreation: false);
                        m_globalGpss[entry].Players.Add(p.Identity.IdentityId);
                    }
                }
            }
        }
Пример #2
0
        /// <summary>
        /// Adds a new Dynamic gps to the player
        /// </summary>
        /// <param name="name">Name of the gps</param>
        /// <param name="color">Color of the gps</param>
        /// <param name="pos">Position of the gps</param>
        /// <param name="playerId">Player, the gps belongs to</param>
        /// <param name="id">The id of the gps</param>
        /// <returns>False, if the gps is already added, else true</returns>
        public bool AddDynamicGps(string name, Color color, Vector3D pos, long playerId, Guid id)
        {
            Tuple <Guid, long> key = new Tuple <Guid, long>(id, playerId);

            if (m_dynamicGpss.ContainsKey(key))
            {
                RemoveDynamicGps(playerId, id);
            }
            MyGps gps = new MyGps
            {
                Name          = name,
                Coords        = pos,
                GPSColor      = color,
                ShowOnHud     = true,
                AlwaysVisible = false,
                DiscardAt     = null
            };

            gps.CalculateHash();
            gps.UpdateHash();

            MySession.Static.Gpss.SendAddGps(playerId, ref gps, playSoundOnCreation: false);
            m_dynamicGpss.Add(key, gps.Hash);

            return(true);
        }
Пример #3
0
        /// <summary>
        /// Removes the given persistent gps if it exists
        /// </summary>
        /// <param name="id">Id of persistent gps</param>
        public void RemovePersistentGps(Guid id)
        {
            if (PersistenGpsExists(id))
            {
                MyGps gps = new MyGps
                {
                    Name          = m_globalGpss[id].Name,
                    Coords        = m_globalGpss[id].Position,
                    GPSColor      = m_globalGpss[id].Color,
                    ShowOnHud     = true,
                    AlwaysVisible = false,
                    DiscardAt     = null
                };

                foreach (var playerId in m_globalGpss[id].Players)
                {
                    MySession.Static.Gpss.SendDelete(playerId, gps.CalculateHash());
                }

                m_globalGpss.Remove(id);
            }
        }
        /// <summary>
        /// Adds or updates a dynamic gps. If the dynamic gps with the given name currently is not
        /// added to the player with playerId, it will be added as a new one. If it already exists, it will
        /// be updated.
        /// </summary>
        /// <param name="gpsName">Name of the gps</param>
        /// <param name="playerId">Id of the player</param>
        /// <param name="position">Position of the gps</param>
        /// <param name="color">Color of the gps</param>
        public void AddOrUpdateDynamicGps(string gpsName, long playerId, Vector3D position, Color color)
        {
            DynamicGpsId id = new DynamicGpsId(playerId, gpsName);

            MyGps gps;

            if (!DynamicGpss.ContainsKey(id))
            {
                gps = new MyGps()
                {
                    Name          = gpsName,
                    Coords        = position,
                    ShowOnHud     = true,
                    GPSColor      = color,
                    AlwaysVisible = false,
                    DiscardAt     = null
                };
                gps.CalculateHash();
                gps.UpdateHash();
                MySession.Static.Gpss.SendAddGps(playerId, ref gps, playSoundOnCreation: false);
                DynamicGpss.Add(id, gps.Hash);
            }
            else
            {
                MySession.Static.Gpss[playerId].TryGetValue(DynamicGpss[id], out gps);
                if (gps == null)
                {
                    DynamicGpss.Remove(id);
                    AddOrUpdateDynamicGps(gpsName, playerId, position, color);
                    return;
                }

                gps.Coords = position;
                MySession.Static.Gpss.SendModifyGps(playerId, gps);
                gps.UpdateHash();
                DynamicGpss[id] = gps.Hash;
            }
        }