Exemplo n.º 1
0
        protected override bool CanDisrupt(IMyCubeBlock block)
        {
            IMyJumpDrive jumpDrive    = (IMyJumpDrive)block;
            float        chargedRatio = jumpDrive.CurrentStoredPower / jumpDrive.MaxStoredPower;

            return(chargedRatio > 0.5f);
        }
Exemplo n.º 2
0
        public double GetMaxJumpDistance(IMyJumpDrive jumpDrive)
        {
            string maxDist = jumpDrive.DetailedInfo.ToString().Split('\n')[6];

            maxDist = maxDist.Split(':')[1];
            double maxDistance = GetNum(maxDist);

            return(maxDistance);
        }
Exemplo n.º 3
0
        protected override void StartEffect(IMyCubeBlock block)
        {
            IMyJumpDrive jumpDrive       = (IMyJumpDrive)block;
            float        maxChargeRateMW = jumpDrive.ResourceSink.MaxRequiredInputByType(Globals.Electricity);
            float        maxDrainMWs     = 1.1f * maxChargeRateMW * (float)Hacker.s_hackLength.TotalSeconds;
            float        chargedRatio    = jumpDrive.CurrentStoredPower / jumpDrive.MaxStoredPower;
            float        drainMWh        = maxDrainMWs * chargedRatio / 3600;

            jumpDrive.CurrentStoredPower = Math.Max(jumpDrive.CurrentStoredPower - drainMWh, 0f);
        }
Exemplo n.º 4
0
        public override void Init(MyObjectBuilder_EntityBase objectBuilder)
        {
            NeedsUpdate   |= MyEntityUpdateEnum.EACH_FRAME | MyEntityUpdateEnum.BEFORE_NEXT_FRAME;
            _objectBuilder = objectBuilder;

            hyperDriveBlock = Entity as IMyJumpDrive;

            if (!hyperDriveBlock.Components.TryGet <MyResourceSinkComponent>(out HyperFunctions.ResourceSink))
            {
                HyperFunctions.ResourceSink = new MyResourceSinkComponent();
                var sinkInfo = new MyResourceSinkInfo();
                sinkInfo.ResourceTypeId = HyperFunctions._electricity;
                HyperFunctions.ResourceSink.AddType(ref sinkInfo);

                hyperDriveBlock.Components.Add(HyperFunctions.ResourceSink);
            }
        }
Exemplo n.º 5
0
    private List <IMyJumpDrive> GetJumpDrives(IMyGridTerminalSystem gts, IMyCubeGrid desiredGrid)
    {
        List <IMyJumpDrive> jdList = new List <IMyJumpDrive>();

        List <IMyTerminalBlock> jdBlocks = new List <IMyTerminalBlock> {
        };

        gts.GetBlocksOfType <IMyJumpDrive>(jdBlocks);

        for (int i = 0; i < jdBlocks.Count; i++)
        {
            IMyJumpDrive currentJD = (IMyJumpDrive)jdBlocks[i];
            if (currentJD.CubeGrid != desiredGrid)
            {
                continue;  // Ignore drives not on this grid
            }
            jdList.Add(currentJD);
        }
        return(jdList);
    }
Exemplo n.º 6
0
        public void InitializationCheck()
        {
            CustomData();
            error = false;
            Echo(errors);
            errors = "ERROR\n";

            //LCDs
            GridTerminalSystem.GetBlocksOfType <IMyTextPanel>(LCDs, filterThis);
            if (LCDs.Count > 0)
            {
                for (int i = 0; i < LCDs.Count; i++)
                {
                    if (LCDs[i].CustomName.IndexOf(mainLCDname) > -1)
                    {
                        mainLCD = LCDs[i];
                    }
                    if (LCDs[i].CustomName.IndexOf(statusLCDname) > -1)
                    {
                        statusLCD = LCDs[i];
                    }
                }
                if (mainLCD == null)
                {
                    Echo("no LCD blocks with name including [" + mainLCDname + "]\n");
                    error = true;
                }
                if (statusLCD == null)
                {
                    Echo("no LCD blocks with name including [" + statusLCDname + "]\n");
                    error = true;
                }
            }
            else
            {
                errors += "no LCD blocks found\n";
                error   = true;
            }
            //Cockpit
            GridTerminalSystem.GetBlocksOfType <IMyCockpit>(Cockpits, filterThis);
            if (Cockpits.Count > 0)
            {
                for (int i = 0; i < Cockpits.Count; i++)
                {
                    if (Cockpits[i].CustomName.IndexOf(cockpitName) > -1)
                    {
                        cockpit = Cockpits[i];
                    }
                }
                if (cockpit == null)
                {
                    errors += "no Cockpit blocks with name including [" + cockpitName + "]\n";
                    error   = true;
                }
            }
            else
            {
                errors += "no Cockpit blocks found\n";
                error   = true;
            }
            //Jump drives
            GridTerminalSystem.GetBlocksOfType <IMyJumpDrive>(Jumpers, filterThis);
            if (Jumpers.Count > 0)
            {
                for (int i = 0; i < Jumpers.Count; i++)
                {
                    if (Jumpers[i].CustomName.IndexOf(jumperName) > -1)
                    {
                        jumper = Jumpers[i];
                    }
                }
                if (jumper == null)
                {
                    errors += "no Jump drive blocks with name including [" + jumperName + "]\n";
                    error   = true;
                }
            }
            else
            {
                errors += "no Jump drive blocks found\n";
                error   = true;
            }
            //Remote
            GridTerminalSystem.GetBlocksOfType <IMyRemoteControl>(Remotes, filterThis);
            if (Remotes.Count > 0)
            {
                for (int i = 0; i < Remotes.Count; i++)
                {
                    if (Remotes[i].CustomName.IndexOf(remoteName) > -1)
                    {
                        remote = Remotes[i];
                    }
                }
                if (remote == null)
                {
                    errors += "no Remote Control blocks with name including [" + remoteName + "]\n";
                    error   = true;
                }
            }
            else
            {
                errors += "no Remote Control blocks found\n";
                error   = true;
            }
            //Gyros
            GridTerminalSystem.GetBlocksOfType <IMyGyro>(Allgyros, filterThis);
            if (Allgyros.Count > 0)
            {
                for (int i = 0; i < Allgyros.Count; i++)
                {
                    if (Allgyros[i].CustomName.IndexOf(gyroName) > -1)
                    {
                        gyros.Add(Allgyros[i]);
                    }
                }
                if (Allgyros.Count == 0)
                {
                    errors += "no Gyroscope blocks with name including [" + gyroName + "]\n";
                    error   = true;
                }
            }
            else
            {
                errors += "no Gyroscope blocks found\n";
                error   = true;
            }

            statusLCD.Alignment       = TextAlignment.CENTER;
            statusLCD.ContentType     = ContentType.TEXT_AND_IMAGE;
            statusLCD.FontColor       = Color.Gray;
            statusLCD.BackgroundColor = Color.Black;
            remote.GetWaypointInfo(waypoints);

            if (error && (GridTerminalSystem.GetBlockWithName(mainLCDname) as IMyTextPanel != null) && (GridTerminalSystem.GetBlockWithName(statusLCDname) as IMyTextPanel != null))
            {
                mainLCD.WriteText(errors);
                systemStatus = "ERROR";
                Echo(errors);
                statusLCD.WriteText(systemStatus);
                statusLCD.BackgroundColor = Color.Red;
            }
        }
        private void WormholeTransferOutFile(string sendto, IMyCubeGrid grid, IMyJumpDrive WormholeDrive, Vector3D gatepoint, List <IMyJumpDrive> WormholeDrives)
        {
            if (!Config.JumpDriveSubid.Split(',').Any(s => s.Trim() == WormholeDrive.BlockDefinition.SubtypeId) && !Config.WorkWithAllJD)
            {
                return;
            }

            Request request = default;

            try
            {
                request = MyAPIGateway.Utilities.SerializeFromXML <Request>(WormholeDrive.CustomData);
            }
            catch { }

            string pickeddestination = default;

            if (request != null)
            {
                if (request.PluginRequest)
                {
                    if (request.Destination != null)
                    {
                        if (sendto.Split(',').Any(s => s.Trim() == request.Destination.Trim()))
                        {
                            pickeddestination = request.Destination.Trim();
                        }
                    }
                    Request reply = new Request
                    {
                        PluginRequest = false,
                        Destination   = null,
                        Destinations  = sendto.Split(',').Select(s => s.Trim()).ToArray()
                    };
                    WormholeDrive.CustomData = MyAPIGateway.Utilities.SerializeToXML <Request>(reply);
                }
            }
            else
            {
                Request reply = new Request
                {
                    PluginRequest = false,
                    Destination   = null,
                    Destinations  = sendto.Split(',').Select(s => s.Trim()).ToArray()
                };
                WormholeDrive.CustomData = MyAPIGateway.Utilities.SerializeToXML <Request>(reply);
            }

            if (Config.AutoSend && sendto.Split(',').Length == 1)
            {
                pickeddestination = sendto.Split(',')[0].Trim();
            }

            if (pickeddestination == null)
            {
                return;
            }

            if (!WormholeDrive.IsWorking || WormholeDrive.CurrentStoredPower != WormholeDrive.MaxStoredPower)
            {
                return;
            }

            var playerInCharge = MyAPIGateway.Players.GetPlayerControllingEntity(grid);

            if (playerInCharge == null || !Utilities.HasRightToMove(playerInCharge, grid as MyCubeGrid))
            {
                return;
            }

            WormholeDrive.CurrentStoredPower = 0;
            foreach (var DisablingWormholeDrive in WormholeDrives)
            {
                if (Config.JumpDriveSubid.Split(',').Any(s => s.Trim() == DisablingWormholeDrive.BlockDefinition.SubtypeId) || Config.WorkWithAllJD)
                {
                    DisablingWormholeDrive.Enabled = false;
                }
            }
            List <MyCubeGrid> grids = Utilities.FindGridList(grid.EntityId.ToString(), playerInCharge as MyCharacter, Config.IncludeConnectedGrids);

            if (grids == null)
            {
                return;
            }

            if (grids.Count == 0)
            {
                return;
            }

            MyVisualScriptLogicProvider.CreateLightning(gatepoint);

            //NEED TO DROP ENEMY GRIDS
            if (Config.WormholeGates.Any(s => s.Name.Trim() == pickeddestination.Split(':')[0]))
            {
                foreach (WormholeGate internalwormhole in Config.WormholeGates)
                {
                    if (internalwormhole.Name.Trim() == pickeddestination.Split(':')[0].Trim())
                    {
                        var box         = WormholeDrive.GetTopMostParent().WorldAABB;
                        var togatepoint = new Vector3D(internalwormhole.X, internalwormhole.Y, internalwormhole.Z);
                        var togate      = new BoundingSphereD(togatepoint, Config.RadiusGate);
                        Utilities.UpdateGridsPositionAndStopLive(WormholeDrive.GetTopMostParent(), Utilities.FindFreePos(togate, (float)(Vector3D.Distance(box.Center, box.Max) + 50)));
                        MyVisualScriptLogicProvider.CreateLightning(togatepoint);
                    }
                }
            }
            else
            {
                var destination = pickeddestination.Split(':');

                if (3 != destination.Length)
                {
                    throw new ArgumentException("failed parsing destination '" + destination + "'");
                }

                var transferFileInfo = new Utilities.TransferFileInfo
                {
                    destinationWormhole = destination[0],
                    steamUserId         = playerInCharge.SteamUserId,
                    playerName          = playerInCharge.DisplayName,
                    gridName            = grid.DisplayName,
                    time = DateTime.Now
                };

                Log.Info("creating filetransfer:" + transferFileInfo.ToString());
                var filename = transferFileInfo.createFileName();

                List <MyObjectBuilder_CubeGrid> objectBuilders = new List <MyObjectBuilder_CubeGrid>();
                foreach (MyCubeGrid mygrid in grids)
                {
                    if (!(mygrid.GetObjectBuilder(true) is MyObjectBuilder_CubeGrid objectBuilder))
                    {
                        throw new ArgumentException(mygrid + " has a ObjectBuilder thats not for a CubeGrid");
                    }
                    objectBuilders.Add(objectBuilder);
                }
                MyObjectBuilder_ShipBlueprintDefinition definition = MyObjectBuilderSerializer.CreateNewObject <MyObjectBuilder_ShipBlueprintDefinition>();

                definition.Id = new MyDefinitionId(new MyObjectBuilderType(typeof(MyObjectBuilder_ShipBlueprintDefinition)), filename);

                definition.CubeGrids = objectBuilders.Select(x => (MyObjectBuilder_CubeGrid)x.Clone()).ToArray();

                HashSet <ulong> sittingPlayerSteamIds = new HashSet <ulong>();
                foreach (MyObjectBuilder_CubeGrid cubeGrid in definition.CubeGrids)
                {
                    foreach (MyObjectBuilder_CubeBlock cubeBlock in cubeGrid.CubeBlocks)
                    {
                        cubeBlock.Owner   = 0L;
                        cubeBlock.BuiltBy = 0L;

                        if (!Config.ExportProjectorBlueprints)
                        {
                            if (cubeBlock is MyObjectBuilder_ProjectorBase projector)
                            {
                                projector.ProjectedGrids = null;
                            }
                        }
                        if (cubeBlock is MyObjectBuilder_Cockpit cockpit)
                        {
                            if (cockpit.Pilot != null)
                            {
                                var playerSteamId = cockpit.Pilot.PlayerSteamId;
                                sittingPlayerSteamIds.Add(playerSteamId);
                                ModCommunication.SendMessageTo(new JoinServerMessage(destination[1] + ":" + destination[2]), playerSteamId);
                            }
                        }
                    }
                }

                MyObjectBuilder_Definitions builderDefinition = MyObjectBuilderSerializer.CreateNewObject <MyObjectBuilder_Definitions>();
                builderDefinition.ShipBlueprints = new[] { definition };
                foreach (var playerSteamId in sittingPlayerSteamIds)
                {
                    KillCharacter(playerSteamId);
                }
                if (MyObjectBuilderSerializer.SerializeXML(Utilities.CreateBlueprintPath(Path.Combine(Config.Folder, admingatesfolder), filename), false, builderDefinition))
                {
                    // Saves the game if enabled in config.
                    if (Config.SaveOnExit)
                    {
                        grids.ForEach(b => b.Close());
                        // (re)Starts the task if it has never been started o´r is done
                        if ((saveOnExitTask is null) || saveOnExitTask.IsCompleted)
                        {
                            saveOnExitTask = Torch.Save();
                        }
                    }
                    else
                    {
                        grids.ForEach(b => b.Close());
                    }
                    DirectoryInfo gridDirsent = new DirectoryInfo(Config.Folder + "/" + admingatesconfirmsentfolder);
                    //creates just in case fir send
                    gridDirsent.Create();
                    File.Create(Utilities.CreateBlueprintPath(gridDirsent.FullName, filename));
                }
            }
        }