Ejemplo n.º 1
0
        //Disables all beacons and antennas and deletes the ship.
        public void DeleteShip()
        {
            var lstSlimBlock = new List <IMySlimBlock>();

            _cubeGrid.GetBlocks(lstSlimBlock, (x) => x.FatBlock is Sandbox.ModAPI.IMyRadioAntenna);
            foreach (var block in lstSlimBlock)
            {
                Sandbox.ModAPI.IMyRadioAntenna antenna = (Sandbox.ModAPI.IMyRadioAntenna)block.FatBlock;
                ITerminalAction act = antenna.GetActionWithName("OnOff_Off");
                act.Apply(antenna);
            }

            lstSlimBlock = new List <IMySlimBlock>();
            _cubeGrid.GetBlocks(lstSlimBlock, (x) => x.FatBlock is Sandbox.ModAPI.IMyBeacon);
            foreach (var block in lstSlimBlock)
            {
                Sandbox.ModAPI.IMyBeacon beacon = (Sandbox.ModAPI.IMyBeacon)block.FatBlock;
                ITerminalAction          act    = beacon.GetActionWithName("OnOff_Off");
                act.Apply(beacon);
            }

            _cubeGrid.SyncObject.SendCloseRequest();
            MyAPIGateway.Entities.RemoveEntity(_cubeGrid as IMyEntity);

            //_cubeGrid = null;
        }
Ejemplo n.º 2
0
        public static Dictionary <string, List <IMyCubeBlock> > GetZonesInGrid(IMyCubeGrid cubeGrid)
        {
            Dictionary <String, List <IMyCubeBlock> > testList = new Dictionary <string, List <IMyCubeBlock> >();
            List <IMySlimBlock> cubeBlocks = new List <IMySlimBlock>();

            cubeGrid.GetBlocks(cubeBlocks);
            foreach (IMySlimBlock entityBlock in cubeBlocks)
            {
                if (entityBlock.FatBlock == null)
                {
                    continue;
                }

                if (!(entityBlock.FatBlock is IMyCubeBlock))
                {
                    continue;
                }

                IMyCubeBlock cubeBlock = (IMyCubeBlock)entityBlock.FatBlock;

                if (!(cubeBlock is IMyBeacon))
                {
                    continue;
                }

                IMyBeacon beacon = (IMyBeacon)cubeBlock;
                if (beacon.CustomName == null || beacon.CustomName == "")
                {
                    continue;
                }

                if (testList.ContainsKey(beacon.CustomName))
                {
                    testList[beacon.CustomName].Add(entityBlock.FatBlock);
                }
                else
                {
                    List <IMyCubeBlock> testBeaconList = new List <IMyCubeBlock>();
                    testBeaconList.Add(entityBlock.FatBlock);
                    testList.Add(beacon.CustomName, testBeaconList);
                }
            }

            Dictionary <String, List <IMyCubeBlock> > resultList = new Dictionary <string, List <IMyCubeBlock> >();

            foreach (KeyValuePair <String, List <IMyCubeBlock> > p in testList)
            {
                if (p.Value.Count == 4)
                {
                    resultList.Add(p.Key, p.Value);
                }
            }

            return(resultList);
        }
Ejemplo n.º 3
0
        //Disables all beacons and antennas and deletes the ship.
        public void DeleteShip()
        {
            var lstSlimBlock = new List <IMySlimBlock>();

            Ship.GetBlocks(lstSlimBlock, (x) => x.FatBlock is Sandbox.ModAPI.IMyRadioAntenna);
            foreach (var block in lstSlimBlock)
            {
                Sandbox.ModAPI.IMyRadioAntenna antenna = (Sandbox.ModAPI.IMyRadioAntenna)block.FatBlock;
                ITerminalAction act = antenna.GetActionWithName("OnOff_Off");
                act.Apply(antenna);
            }

            lstSlimBlock = new List <IMySlimBlock>();
            Ship.GetBlocks(lstSlimBlock, (x) => x.FatBlock is Sandbox.ModAPI.IMyBeacon);
            foreach (var block in lstSlimBlock)
            {
                Sandbox.ModAPI.IMyBeacon beacon = (Sandbox.ModAPI.IMyBeacon)block.FatBlock;
                ITerminalAction          act    = beacon.GetActionWithName("OnOff_Off");
                act.Apply(beacon);
            }

            MyAPIGateway.Entities.RemoveEntity(Ship as IMyEntity);
            Ship = null;
        }
Ejemplo n.º 4
0
        public Drone(IMyEntity ent)
        {
            var ship = (IMyCubeGrid)ent;

            Ship = ship;
            var lstSlimBlock = new List <IMySlimBlock>();

            GridTerminalSystem = MyAPIGateway.TerminalActionsHelper.GetTerminalSystemForGrid(ship);

            //If it has any type of cockipt
            ship.GetBlocks(lstSlimBlock, (x) => x.FatBlock is Sandbox.ModAPI.IMyRemoteControl);
            FindWeapons();
            SetupActions();

            //If no cockpit the ship is either no ship or is broken.
            if (lstSlimBlock.Count != 0)
            {
                //Make the controls be the cockpit
                ShipControls = lstSlimBlock[0].FatBlock as IMyControllableEntity;

                #region Activate Beacons && Antennas


                //Maximise radius on antennas and beacons.
                lstSlimBlock.Clear();
                ship.GetBlocks(lstSlimBlock, (x) => x.FatBlock is Sandbox.ModAPI.IMyRadioAntenna);
                foreach (var block in lstSlimBlock)
                {
                    Sandbox.ModAPI.IMyRadioAntenna antenna =
                        (Sandbox.ModAPI.IMyRadioAntenna)block.FatBlock;
                    if (antenna != null)
                    {
                        //antenna.GetActionWithName("SetCustomName").Apply(antenna, new ListReader<TerminalActionParameter>(new List<TerminalActionParameter>() { TerminalActionParameter.Get("Combat Drone " + _manualGats.Count) }));
                        antenna.SetValueFloat("Radius", 10000);//antenna.GetMaximum<float>("Radius"));
                        _blockOn.Apply(antenna);
                    }
                }

                lstSlimBlock = new List <IMySlimBlock>();
                ship.GetBlocks(lstSlimBlock, (x) => x.FatBlock is Sandbox.ModAPI.IMyBeacon);
                foreach (var block in lstSlimBlock)
                {
                    Sandbox.ModAPI.IMyBeacon beacon = (Sandbox.ModAPI.IMyBeacon)block.FatBlock;
                    if (beacon != null)
                    {
                        beacon.SetValueFloat("Radius", 10000);//beacon.GetMaximum<float>("Radius"));
                        _blockOn.Apply(beacon);
                    }
                }

                #endregion

                //SetWeaponPower(true);
                //AmmoManager.ReloadReactors(_allReactors);
                //AmmoManager.ReloadGuns(_manualGats);
                ship.GetBlocks(lstSlimBlock, x => x is IMyEntity);


                List <IMyTerminalBlock> allTerminalBlocks = new List <IMyTerminalBlock>();
                GridTerminalSystem.GetBlocksOfType <IMyCubeBlock>(allTerminalBlocks);
                HealthBlockBase = allTerminalBlocks.Count;


                if (ShipControls != null)
                {
                    navigation = new ThrusterGyroControls(ship, ShipControls);
                    _ownerId   = ((Sandbox.ModAPI.IMyTerminalBlock)ShipControls).OwnerId;
                    tc         = new TargetingControls(Ship, _ownerId);
                }
            }

            Ship.OnBlockAdded += RecalcMaxHp;
            myNumber           = numDrones;
            numDrones++;
        }