Ejemplo n.º 1
0
 public static int Depressurize(IMyCubeGrid grid, int strength, TimeSpan duration, long effectOwner)
 {
     AirVentDepressurize av;
     if (!Registrar.TryGetValue(grid, out av))
         av = new AirVentDepressurize(grid);
     return av.AddEffect(duration, strength, effectOwner);
 }
Ejemplo n.º 2
0
        public void Update10()
        {
            if (Globals.ElapsedTime < m_nextHack)
                return;
            if (!m_hackBlock.IsWorking)
            {
                m_strengthLeft = 0f;
                return;
            }
            IMyCubeGrid attached = m_hackBlock.GetAttachedEntity() as IMyCubeGrid;
            if (attached == null)
            {
                m_strengthLeft = 0f;
                return;
            }
            if (m_hackBlock.BreakForce > allowedBreakForce)
            {
                m_logger.debugLog("break force too high: " + m_hackBlock.BreakForce);
                ITerminalProperty<float> prop = m_hackBlock.GetProperty("BreakForce") as ITerminalProperty<float>;
                if (prop == null)
                {
                    m_logger.debugLog("break force is disabled in SE", Logger.severity.INFO);
                    allowedBreakForce = float.PositiveInfinity;
                }
                else
                    prop.SetValue(m_hackBlock, allowedBreakForce);
            }
            if (allowedBreakForce == float.PositiveInfinity)
                // landing gear is unbreakable, disconnect / fail if not otherwise attached
                if (!AttachedGrid.IsGridAttached(m_hackBlock.CubeGrid as IMyCubeGrid, attached, AttachedGrid.AttachmentKind.Physics))
                {
                    m_logger.debugLog("no other connection to attached, hacker must disconnect", Logger.severity.DEBUG);
                    ITerminalProperty<bool> autolock = m_hackBlock.GetProperty("Autolock") as ITerminalProperty<bool>;
                    if (autolock.GetValue(m_hackBlock))
                        autolock.SetValue(m_hackBlock, false);
                    m_hackBlock.GetActionWithName("Unlock").Apply(m_hackBlock);
                    return;
                }

            m_nextHack = Globals.ElapsedTime + s_hackFrequency;

            m_strengthLeft += s_hackStrength;

            foreach (int i in Enumerable.Range(0, 8).OrderBy(x => Globals.Random.Next()))
            {
                Disruption disrupt;
                switch (i)
                {
                    case 0:
                        disrupt = new AirVentDepressurize();
                        break;
                    case 1:
                        disrupt = new DoorLock();
                        break;
                    case 2:
                        disrupt = new GravityReverse();
                        break;
                    case 3:
                        disrupt = new DisableTurret();
                        break;
                    case 4:
                        // vanilla turret controls are not respecting the change in ownership
                        continue;
                        disrupt = new TraitorTurret();
                        break;
                    case 5:
                        disrupt = new CryoChamberMurder();
                        break;
                    case 6:
                        disrupt = new JumpDriveDrain();
                        break;
                    case 7:
                        disrupt = new MedicalRoom();
                        break;
                    default:
                        m_logger.alwaysLog("Case not implemented: " + i, Logger.severity.FATAL);
                        continue;
                }
                AttachedGrid.RunOnAttached(attached, AttachedGrid.AttachmentKind.Terminal, grid => {
                    disrupt.Start(grid, s_hackLength, ref m_strengthLeft, m_hackBlock.OwnerId);
                    return false;
                }, true);
            }
        }
Ejemplo n.º 3
0
        private void LoadData()
        {
            if (m_data == null)
            {
                m_logger.debugLog("No data to load");
                return;
            }

            m_logger.alwaysLog("Save version: " + m_data.ModVersion, Logger.severity.INFO);

            // network

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

                foreach (LastSeen.Builder_LastSeen bls in bns.LastSeenList)
                {
                    LastSeen ls = new LastSeen(bls);
                    if (ls.IsValid)
                        store.Receive(ls);
                    else
                        m_logger.debugLog("failed to create a valid last seen from builder for " + bls.EntityId, Logger.severity.WARNING);
                }

                m_logger.debugLog("added " + bns.LastSeenList.Length + " last seen to " + store.PrimaryNode.LoggingName, Logger.severity.DEBUG);

                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
                    {
                        m_logger.debugLog("found linked message", Logger.severity.TRACE);
                    }
                    if (msg.IsValid)
                        store.Receive(msg);
                    else
                        m_logger.debugLog("failed to create a valid message from builder for " + bm.DestCubeBlock, Logger.severity.WARNING);
                }

                m_logger.debugLog("added " + bns.MessageList.Length + " message to " + store.PrimaryNode.LoggingName, Logger.severity.DEBUG);
            }

            // system disruption

            foreach (Disruption.Builder_Disruption bd in m_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:
                        m_logger.alwaysLog("Unknown disruption: " + bd.Type, Logger.severity.WARNING);
                        continue;
                }
                disrupt.Start(bd);
            }

            // autopilot

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

            // programmable block

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

            // text panel

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

            // weapon

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

            // entity values

            if (m_data.EntityValues != null)
                EntityValue.ResumeFromSave(m_data.EntityValues);

            m_data = null;
        }
Ejemplo n.º 4
0
        public void Update10()
        {
            if (Globals.ElapsedTime < m_nextHack)
            {
                return;
            }
            if (!m_hackBlock.IsWorking)
            {
                m_strengthLeft = 0f;
                return;
            }
            IMyCubeGrid attached = m_hackBlock.GetAttachedEntity() as IMyCubeGrid;

            if (attached == null)
            {
                m_strengthLeft = 0f;
                return;
            }

            // break force might be removed from game entirely
            //if (m_hackBlock.BreakForce > allowedBreakForce)
            //{
            //	Log.DebugLog("break force too high: " + m_hackBlock.BreakForce);
            //	ITerminalProperty<float> prop = m_hackBlock.GetProperty("BreakForce") as ITerminalProperty<float>;
            //	if (prop == null)
            //	{
            //		Log.DebugLog("break force is disabled in SE", Logger.severity.INFO);
            //		allowedBreakForce = float.PositiveInfinity;
            //	}
            //	else
            //		prop.SetValue(m_hackBlock, allowedBreakForce);
            //}
            //if (allowedBreakForce == float.PositiveInfinity)

            // landing gear is unbreakable, disconnect / fail if not otherwise attached
            if (!AttachedGrid.IsGridAttached(m_hackBlock.CubeGrid as IMyCubeGrid, attached, AttachedGrid.AttachmentKind.Physics))
            {
                Log.DebugLog("no other connection to attached, hacker must disconnect", Logger.severity.DEBUG);
                ITerminalProperty <bool> autolock = m_hackBlock.GetProperty("Autolock") as ITerminalProperty <bool>;
                if (autolock.GetValue(m_hackBlock))
                {
                    autolock.SetValue(m_hackBlock, false);
                }
                m_hackBlock.GetActionWithName("Unlock").Apply(m_hackBlock);
                return;
            }

            m_nextHack = Globals.ElapsedTime + s_hackFrequency;

            m_strengthLeft += s_hackStrength;

            foreach (int i in Enumerable.Range(0, 8).OrderBy(x => Globals.Random.Next()))
            {
                Disruption disrupt;
                switch (i)
                {
                case 0:
                    disrupt = new AirVentDepressurize();
                    break;

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

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

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

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

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

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

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

                default:
                    Log.AlwaysLog("Case not implemented: " + i, Logger.severity.FATAL);
                    continue;
                }
                foreach (IMyCubeGrid grid in AttachedGrid.AttachedGrids(attached, AttachedGrid.AttachmentKind.Terminal, true))
                {
                    disrupt.Start(grid, s_hackLength, ref m_strengthLeft, m_hackBlock.OwnerId);
                }
            }
        }