示例#1
0
        public override void BeforeStart()
        {
            base.BeforeStart();

            // Make sure that the pirate identity exists
            if (m_piratesIdentityId != 0)
            {
                MyIdentity pirateIdentity = Sync.Players.TryGetIdentity(m_piratesIdentityId);
                Debug.Assert(pirateIdentity != null, "The pirate identity does not exist, although its ID was saved!");

                if (Sync.IsServer && pirateIdentity == null)
                {
                    Sync.Players.CreateNewIdentity(IDENTITY_NAME, m_piratesIdentityId, null);
                }
            }
            else
            {
                var identity = Sync.Players.CreateNewIdentity(IDENTITY_NAME);
                m_piratesIdentityId = identity.IdentityId;
            }

            if (!Sync.Players.IdentityIsNpc(m_piratesIdentityId))
            {
                Sync.Players.MarkIdentityAsNPC(m_piratesIdentityId);
            }

            // Make sure that all the drone entities exist
            foreach (var drone in m_droneInfos)
            {
                MyEntity entity;
                MyEntities.TryGetEntityById(drone.Key, out entity);
                if (entity == null)
                {
                    DroneInfo.Deallocate(drone.Value);
                    m_droneInfos.Remove(drone.Key);
                }
                else
                {
                    if (!MySession.Static.Settings.EnableDrones)
                    {
                        MyCubeGrid grid   = entity as MyCubeGrid;
                        var        remote = entity as MyRemoteControl;
                        if (grid == null)
                        {
                            grid = remote.CubeGrid;
                        }

                        UnregisterDrone(entity, immediate: false);
                        grid.SyncObject.SendCloseRequest();
                    }
                    else
                    {
                        RegisterDrone(drone.Value.AntennaEntityId, entity, immediate: false);
                    }
                }
            }
            m_droneInfos.ApplyRemovals();
        }
        public static void UpdatePirateAntenna(long antennaEntityId, bool remove, bool activeState, StringBuilder antennaName)
        {
            Debug.Assert(Sync.IsServer, "Pirate antennas can only be registered on the server");

            // This can happen while unloading the game, because this component unloads before entities.
            if (m_pirateAntennas == null)
            {
                return;
            }

            if (remove == true)
            {
                m_pirateAntennas.Remove(antennaEntityId, immediate: !m_iteratingAntennas);
                return;
            }

            string antennaNameStr = antennaName.ToString();

            PirateAntennaInfo antennaInfo = null;

            if (!m_pirateAntennas.TryGetValue(antennaEntityId, out antennaInfo))
            {
                MyPirateAntennaDefinition antennaDef = null;
                if (m_definitionsByAntennaName.TryGetValue(antennaNameStr, out antennaDef))
                {
                    antennaInfo          = PirateAntennaInfo.Allocate(antennaDef);
                    antennaInfo.IsActive = activeState;
                    m_pirateAntennas.Add(antennaEntityId, antennaInfo, immediate: !m_iteratingAntennas);
                }
            }
            else
            {
                if (antennaInfo.AntennaDefinition.Name != antennaNameStr)
                {
                    MyPirateAntennaDefinition antennaDef = null;
                    if (!m_definitionsByAntennaName.TryGetValue(antennaNameStr, out antennaDef))
                    {
                        PirateAntennaInfo.Deallocate(antennaInfo);
                        m_pirateAntennas.Remove(antennaEntityId, immediate: !m_iteratingAntennas);
                    }
                    else
                    {
                        antennaInfo.Reset(antennaDef);
                        antennaInfo.IsActive = activeState;
                    }
                }
                else
                {
                    antennaInfo.IsActive = activeState;
                }
            }
        }
        private void RemoveOldRespawnTimes()
        {
            var respawnShips = MyDefinitionManager.Static.GetRespawnShipDefinitions();
            int currentTime  = MySandboxGame.TotalGamePlayTimeInMilliseconds;

            foreach (var key in m_globalRespawnTimesMs.Keys)
            {
                int time = m_globalRespawnTimesMs[key];
                if (currentTime - time >= 0)
                {
                    m_globalRespawnTimesMs.Remove(key);
                }
            }
            m_globalRespawnTimesMs.ApplyRemovals();
        }
示例#4
0
        internal void SyncClientEwarBlocks()
        {
            foreach (var ewarPair in CurrentClientEwaredCubes)
            {
                BlockState state;
                MyEntity   ent;
                var        entId = ewarPair.Key;
                if (MyEntities.TryGetEntityById(entId, out ent))
                {
                    var cube = (MyCubeBlock)ent;
                    var func = (IMyFunctionalBlock)cube;
                    func.RefreshCustomInfo();

                    if (!_activeEwarCubes.ContainsKey(entId))
                    {
                        state = new BlockState {
                            FunctBlock = func, FirstState = func.Enabled, Endtick = Tick + ewarPair.Value.EndTick, Session = this
                        };
                        _activeEwarCubes[entId] = state;
                        ActivateClientEwarState(ref state);
                    }
                }
                else if (_activeEwarCubes.TryGetValue(entId, out state))
                {
                    DeactivateClientEwarState(ref state);
                    _activeEwarCubes.Remove(entId);
                }

                ClientEwarStale = false;
            }

            _activeEwarCubes.ApplyChanges();
            foreach (var activeEwar in _activeEwarCubes)
            {
                if (!CurrentClientEwaredCubes.ContainsKey(activeEwar.Key))
                {
                    var state = activeEwar.Value;
                    DeactivateClientEwarState(ref state);
                    _activeEwarCubes.Remove(activeEwar.Key);
                }
            }
            _activeEwarCubes.ApplyRemovals();
        }
示例#5
0
        private void RemoveEntity(IMyEntity x)
        {
            TrackedEntity tracker;

            if (!m_trackedEntities.TryGetValue(x, out tracker))
            {
                return;
            }
            Log(MyLogSeverity.Debug, "Removing tracking for entity {0} ({1})", x, x.GetFriendlyName());
            m_dirtyVolumes.Enqueue(tracker.CurrentView);
            m_trackedEntities.Remove(x);
            x.OnMarkForClose -= RemoveEntity;
        }
        public override void BeforeStart()
        {
            base.BeforeStart();

            MyFaction pirateFaction = MySession.Static.Factions.TryGetFactionByTag(PIRATE_FACTION_TAG);

            Debug.Assert(pirateFaction != null, "No pirate faction in the world. Pirate antenan needs it.");

            if (pirateFaction != null)
            {
                // Make sure that the pirate identity exists
                if (m_piratesIdentityId != 0)
                {
                    if (Sync.IsServer)
                    {
                        MyIdentity pirateIdentity = Sync.Players.TryGetIdentity(m_piratesIdentityId);
                        Debug.Assert(pirateIdentity != null, "The pirate identity does not exist, although its ID was saved!");

                        if (pirateIdentity == null)
                        {
                            Sync.Players.CreateNewIdentity(IDENTITY_NAME, m_piratesIdentityId, null);
                        }

                        pirateIdentity.LastLoginTime = DateTime.Now;

                        // Check if he is already in a faction.
                        MyFaction oldPirateFaction = MySession.Static.Factions.GetPlayerFaction(m_piratesIdentityId);
                        if (oldPirateFaction == null)
                        {
                            MyFactionCollection.SendJoinRequest(pirateFaction.FactionId, m_piratesIdentityId);
                        }
                    }
                }
                else
                {
                    m_piratesIdentityId = pirateFaction.FounderId;
                }

                if (!Sync.Players.IdentityIsNpc(m_piratesIdentityId))
                {
                    Sync.Players.MarkIdentityAsNPC(m_piratesIdentityId);
                }
            }

            // Make sure that all the drone entities exist
            foreach (var drone in m_droneInfos)
            {
                MyEntity entity;
                MyEntities.TryGetEntityById(drone.Key, out entity);
                if (entity == null)
                {
                    DroneInfo.Deallocate(drone.Value);
                    m_droneInfos.Remove(drone.Key);
                }
                else
                {
                    if (!MySession.Static.Settings.EnableDrones)
                    {
                        MyCubeGrid grid   = entity as MyCubeGrid;
                        var        remote = entity as MyRemoteControl;
                        if (grid == null)
                        {
                            grid = remote.CubeGrid;
                        }

                        UnregisterDrone(entity, immediate: false);
                        grid.Close();
                        //grid.SyncObject.SendCloseRequest();
                    }
                    else
                    {
                        RegisterDrone(drone.Value.AntennaEntityId, entity, immediate: false);
                    }
                }
            }
            m_droneInfos.ApplyRemovals();
        }
示例#7
0
 public void RemoveExtension(IMyToolbarExtension toRemove)
 {
     m_extensions.Remove(toRemove.GetType());
 }
示例#8
0
 public void UnregisterComponent(MySessionComponentBase component)
 {
     component.Session = null;
     m_sessionComponents.Remove(component.ComponentType);
 }
示例#9
0
文件: Saver.cs 项目: zrisher/ARMS
        private void RetryLastSeen()
        {
            foreach (KeyValuePair <long, CachingList <LastSeen.Builder_LastSeen> > storageLastSeen in m_failedLastSeen)
            {
                RelayNode node;
                if (Registrar.TryGetValue(storageLastSeen.Key, out node))
                {
                    RelayStorage store = node.Storage;
                    foreach (LastSeen.Builder_LastSeen builder in storageLastSeen.Value)
                    {
                        if (MyAPIGateway.Entities.EntityExists(builder.EntityId))
                        {
                            LastSeen ls = new LastSeen(builder);
                            if (ls.IsValid)
                            {
                                Logger.DebugLog("Successfully created a LastSeen. Primary node: " + storageLastSeen.Key + ", entity: " + ls.Entity.nameWithId());
                                storageLastSeen.Value.Remove(builder);
                            }
                            else
                            {
                                Logger.AlwaysLog("Unknown failure with last seen", Rynchodon.Logger.severity.ERROR);
                            }
                        }
                        else
                        {
                            Logger.DebugLog("Not yet available: " + builder.EntityId);
                        }
                    }
                    storageLastSeen.Value.ApplyRemovals();
                    if (storageLastSeen.Value.Count == 0)
                    {
                        Logger.DebugLog("Finished with: " + storageLastSeen.Key, Rynchodon.Logger.severity.DEBUG);
                        m_failedLastSeen.Remove(storageLastSeen.Key);
                    }
                    else
                    {
                        Logger.DebugLog("For " + storageLastSeen.Key + ", " + storageLastSeen.Value.Count + " builders remain");
                    }
                }
                else
                {
                    Logger.DebugLog("Failed to get node for " + storageLastSeen.Key, Rynchodon.Logger.severity.WARNING);
                }
            }
            m_failedLastSeen.ApplyRemovals();

            if (m_failedLastSeen.Count() == 0)
            {
                Logger.DebugLog("All LastSeen have been successfully added", Rynchodon.Logger.severity.INFO);
                m_failedLastSeen = null;
                UpdateManager.Unregister(100, RetryLastSeen);
            }
            else
            {
                Logger.DebugLog(m_failedLastSeen.Count() + " primary nodes still have last seen to be added");

                if (Globals.UpdateCount >= 3600)
                {
                    foreach (KeyValuePair <long, CachingList <LastSeen.Builder_LastSeen> > storageLastSeen in m_failedLastSeen)
                    {
                        foreach (LastSeen.Builder_LastSeen builder in storageLastSeen.Value)
                        {
                            Logger.AlwaysLog("Failed to add last seen to world. Primary node: " + storageLastSeen.Key + ", entity ID: " + builder.EntityId, Rynchodon.Logger.severity.WARNING);
                        }
                    }
                    m_failedLastSeen = null;
                    UpdateManager.Unregister(100, RetryLastSeen);
                }
            }
        }