public void InitFromCheckpoint(MyObjectBuilder_Checkpoint checkpoint)
        {
            var cooldowns = checkpoint.RespawnCooldowns;

            m_lastUpdate = MySandboxGame.TotalGamePlayTimeInMilliseconds;
            m_globalRespawnTimesMs.Clear();

            if (cooldowns == null)
            {
                return;
            }

            foreach (var item in cooldowns)
            {
                var controllerId = new MyPlayer.PlayerId()
                {
                    SteamId = item.PlayerSteamId, SerialId = item.PlayerSerialId
                };
                var key = new RespawnKey()
                {
                    ControllerId = controllerId, RespawnShipId = item.RespawnShipId
                };
                m_globalRespawnTimesMs.Add(key, item.Cooldown + m_lastUpdate, immediate: true);
            }
        }
示例#2
0
        public void RegisterComponent(MySessionComponentBase component, MyUpdateOrder updateOrder, int priority)
        {
            m_sessionComponents.Add(component.ComponentType, component);

            AddComponentForUpdate(updateOrder, MyUpdateOrder.BeforeSimulation, component);
            AddComponentForUpdate(updateOrder, MyUpdateOrder.Simulation, component);
            AddComponentForUpdate(updateOrder, MyUpdateOrder.AfterSimulation, component);
            AddComponentForUpdate(updateOrder, MyUpdateOrder.NoUpdate, component);
        }
示例#3
0
        public override void Init(MyObjectBuilder_SessionComponent sessionComponent)
        {
            base.Init(sessionComponent);

            var ob = sessionComponent as MyObjectBuilder_PirateAntennas;

            m_piratesIdentityId = ob.PiratesIdentity;

            int currentTime = MySandboxGame.TotalGamePlayTimeInMilliseconds;

            if (ob.Drones != null)
            {
                foreach (var entry in ob.Drones)
                {
                    m_droneInfos.Add(entry.EntityId, DroneInfo.Allocate(entry.AntennaEntityId, currentTime + entry.DespawnTimer), immediate: true);
                }
            }
        }
示例#4
0
        public void AddExtension(IMyToolbarExtension newExtension)
        {
            if (m_extensions == null)
            {
                m_extensions = new CachingDictionary <Type, IMyToolbarExtension>();
            }

            m_extensions.Add(newExtension.GetType(), newExtension);
            newExtension.AddedToToolbar(this);
        }
        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;
                }
            }
        }
示例#6
0
文件: Saver.cs 项目: zrisher/ARMS
        private void LoadSaveData(Builder_ArmsData data)
        {
            if (data == null)
            {
                Logger.DebugLog("No data to load");
                return;
            }

#pragma warning disable 612, 618
            if (Comparer <Version> .Default.Compare(data.ArmsVersion, default(Version)) == 0)
            {
                Logger.DebugLog("Old version: " + data.ModVersion);
                data.ArmsVersion = new Version(data.ModVersion);
            }
#pragma warning restore 612, 618

            Logger.AlwaysLog("Save version: " + data.ArmsVersion, Rynchodon.Logger.severity.INFO);

            // relay

            Dictionary <Message.Builder_Message, Message> messages = MyAPIGateway.Multiplayer.IsServer ? new Dictionary <Message.Builder_Message, Message>() : null;
            SerializableGameTime.Adjust = new TimeSpan(data.SaveTime);
            foreach (RelayStorage.Builder_NetworkStorage bns in data.AntennaStorage)
            {
                RelayNode node;
                if (!Registrar.TryGetValue(bns.PrimaryNode, out node))
                {
                    Logger.AlwaysLog("Failed to get node for: " + bns.PrimaryNode, Rynchodon.Logger.severity.WARNING);
                    continue;
                }
                RelayStorage store = node.Storage;
                if (store == null)                 // probably always true
                {
                    node.ForceCreateStorage();
                    store = node.Storage;
                    if (store == null)
                    {
                        Logger.AlwaysLog("failed to create storage for " + node.DebugName, Rynchodon.Logger.severity.ERROR);
                        continue;
                    }
                }

                foreach (LastSeen.Builder_LastSeen bls in bns.LastSeenList)
                {
                    LastSeen ls = new LastSeen(bls);
                    if (ls.IsValid)
                    {
                        store.Receive(ls);
                    }
                    else
                    {
                        Logger.AlwaysLog("failed to create a valid last seen from builder for " + bls.EntityId, Rynchodon.Logger.severity.WARNING);
                        if (m_failedLastSeen == null)
                        {
                            m_failedLastSeen = new CachingDictionary <long, CachingList <LastSeen.Builder_LastSeen> >();
                            UpdateManager.Register(100, RetryLastSeen);
                        }
                        CachingList <LastSeen.Builder_LastSeen> list;
                        if (!m_failedLastSeen.TryGetValue(bns.PrimaryNode, out list))
                        {
                            list = new CachingList <LastSeen.Builder_LastSeen>();
                            m_failedLastSeen.Add(bns.PrimaryNode, list, true);
                        }
                        list.Add(bls);
                        list.ApplyAdditions();
                    }
                }

                Logger.DebugLog("added " + bns.LastSeenList.Length + " last seen to " + store.PrimaryNode.DebugName, Rynchodon.Logger.severity.DEBUG);

                // messages in the save file belong on the server
                if (messages == null)
                {
                    continue;
                }

                foreach (Message.Builder_Message bm in bns.MessageList)
                {
                    Message msg;
                    if (!messages.TryGetValue(bm, out msg))
                    {
                        msg = new Message(bm);
                        messages.Add(bm, msg);
                    }
                    else
                    {
                        Logger.DebugLog("found linked message", Rynchodon.Logger.severity.TRACE);
                    }
                    if (msg.IsValid)
                    {
                        store.Receive(msg);
                    }
                    else
                    {
                        Logger.AlwaysLog("failed to create a valid message from builder for " + bm.DestCubeBlock + "/" + bm.SourceCubeBlock, Rynchodon.Logger.severity.WARNING);
                    }
                }

                Logger.DebugLog("added " + bns.MessageList.Length + " message to " + store.PrimaryNode.DebugName, Rynchodon.Logger.severity.DEBUG);
            }

            // past this point, only synchronized data
            if (!MyAPIGateway.Multiplayer.IsServer)
            {
                data = null;
                return;
            }

            // system disruption

            foreach (Disruption.Builder_Disruption bd in data.SystemDisruption)
            {
                Disruption disrupt;
                switch (bd.Type)
                {
                case "AirVentDepressurize":
                    disrupt = new AirVentDepressurize();
                    break;

                case "CryoChamberMurder":
                    disrupt = new CryoChamberMurder();
                    break;

                case "DisableTurret":
                    disrupt = new DisableTurret();
                    break;

                case "DoorLock":
                    disrupt = new DoorLock();
                    break;

                case "EMP":
                    disrupt = new EMP();
                    break;

                case "GravityReverse":
                    disrupt = new GravityReverse();
                    break;

                case "JumpDriveDrain":
                    disrupt = new JumpDriveDrain();
                    break;

                case "MedicalRoom":
                    disrupt = new MedicalRoom();
                    break;

                case "TraitorTurret":
                    disrupt = new TraitorTurret();
                    break;

                default:
                    Logger.AlwaysLog("Unknown disruption: " + bd.Type, Rynchodon.Logger.severity.WARNING);
                    continue;
                }
                disrupt.Start(bd);
            }

            // autopilot

            if (data.Autopilot != null)
            {
                foreach (ShipAutopilot.Builder_Autopilot ba in data.Autopilot)
                {
                    ShipAutopilot autopilot;
                    if (Registrar.TryGetValue(ba.AutopilotBlock, out autopilot))
                    {
                        autopilot.ResumeFromSave(ba);
                    }
                    else
                    {
                        Logger.AlwaysLog("failed to find autopilot block " + ba.AutopilotBlock, Rynchodon.Logger.severity.WARNING);
                    }
                }
            }

            // programmable block

            if (data.ProgrammableBlock != null)
            {
                foreach (ProgrammableBlock.Builder_ProgrammableBlock bpa in data.ProgrammableBlock)
                {
                    ProgrammableBlock pb;
                    if (Registrar.TryGetValue(bpa.BlockId, out pb))
                    {
                        pb.ResumeFromSave(bpa);
                    }
                    else
                    {
                        Logger.AlwaysLog("failed to find programmable block " + bpa.BlockId, Rynchodon.Logger.severity.WARNING);
                    }
                }
            }

            // text panel

            if (data.TextPanel != null)
            {
                foreach (TextPanel.Builder_TextPanel btp in data.TextPanel)
                {
                    TextPanel panel;
                    if (Registrar.TryGetValue(btp.BlockId, out panel))
                    {
                        panel.ResumeFromSave(btp);
                    }
                    else
                    {
                        Logger.AlwaysLog("failed to find text panel " + btp.BlockId, Rynchodon.Logger.severity.WARNING);
                    }
                }
            }

            // weapon

            if (data.Weapon != null)
            {
                foreach (WeaponTargeting.Builder_WeaponTargeting bwt in data.Weapon)
                {
                    WeaponTargeting targeting;
                    if (WeaponTargeting.TryGetWeaponTargeting(bwt.WeaponId, out targeting))
                    {
                        targeting.ResumeFromSave(bwt);
                    }
                    else
                    {
                        Logger.AlwaysLog("failed to find weapon " + bwt.WeaponId, Rynchodon.Logger.severity.WARNING);
                    }
                }
            }

            // entity values

            if (data.EntityValues != null)
            {
                UpgradeEntityValue.Load(data.EntityValues);
            }

            // sync

            if (data.Sync != null)
            {
                ASync.SetBuilder(data.Sync);
            }

            data = null;
        }