Esempio n. 1
0
        public virtual bool Init(IMyRemoteControl rc = null)
        {
            Rc = rc ?? Term.GetBlocksOfType <IMyRemoteControl>(collect: x => x.IsFunctional).FirstOrDefault();
            if (rc == null)
            {
                return(false);
            }
            DroneName = DroneNameProvider;

            Antennae = Term.GetBlocksOfType <IMyRadioAntenna>(collect: x => x.IsFunctional);

            bool hasSetup = ParseSetup();

            if (!hasSetup)
            {
                return(false);
            }

            AiSessionCore.AddDamageHandler(Grid, (block, damage) => { OnDamaged?.Invoke(block, damage); });

            Grid.OnBlockAdded += block => { OnBlockPlaced?.Invoke(block); };

            _ownerFaction = Grid.GetOwnerFaction(true);

            BotOperable = true;

            return(true);
        }
Esempio n. 2
0
        public Ship(IMyCubeGrid ent, long id, String fleetName)
        {
            this.fleetname     = fleetName;
            _cubeGrid          = ent;
            GridTerminalSystem = MyAPIGateway.TerminalActionsHelper.GetTerminalSystemForGrid(_cubeGrid);

            SetOwner(id);
            List <Sandbox.ModAPI.IMyTerminalBlock> remoteControls = new List <Sandbox.ModAPI.IMyTerminalBlock>();

            GridTerminalSystem.GetBlocksOfType <IMyRemoteControl>(remoteControls);
            GridTerminalSystem.GetBlocksOfType <IMyCubeBlock>(AllBlocks);
            ShipControls = remoteControls.FirstOrDefault() != null?remoteControls.First() as Sandbox.Game.Entities.IMyControllableEntity : null;

            _ownerId = id;

            if (ShipControls == null)
            {
                return;
            }

            DetectReactors();
            LocateShipComponets();
            ResetHealthMax();
            SetupRescanDelay();
            FindAntennasAndBeacons();
            ConfigureAntennas();
        }
Esempio n. 3
0
        public void LocateTargetHardpoints()
        {
            IMyCubeGrid grid = Ship;

            var centerPosition = Ship.GetPosition();

            _keyPoints.Clear();
            //get position, get lenier velocity in each direction
            //add them like 10 times and add that to current coord
            if (grid != null)
            {
                Sandbox.ModAPI.IMyGridTerminalSystem gridTerminal =
                    Sandbox.ModAPI.MyAPIGateway.TerminalActionsHelper.GetTerminalSystemForGrid(grid);

                gridTerminal.GetBlocksOfType <Sandbox.ModAPI.IMyTerminalBlock>(terminalBlocks);
                terminalBlocks = terminalBlocks.Where(x => x.IsFunctional).ToList();


                if (terminalBlocks.Count > 0)
                {
                    weapons  = terminalBlocks.Where(x => x is Sandbox.ModAPI.IMyUserControllableGun || x is IMyLargeTurretBase || x is IMySmallMissileLauncherReload).ToList();
                    ShipSize = terminalBlocks.Max(x => (x.GetPosition() - Ship.GetPosition()).Length()) * 2;

                    //now that we have a list of reactors and guns lets primary one.
                    //try to find a working gun, if none are found then find a reactor to attack
                    if (weapons.Count > 0)
                    {
                        _keyPoints.AddRange(weapons);
                    }

                    _keyPoints.AddRange(terminalBlocks);
                }
            }
        }
Esempio n. 4
0
        //this percent is based on IMyTerminalBlocks so it does not take into account the status of armor blocks
        //any blocks not functional decrease the overall %
        //having less blocks than when the drone was built will also result in less hp (parts destoried)
        private void CalculateDamagePercent()
        {
            try
            {
                List <IMyTerminalBlock> allTerminalBlocks =
                    new List <IMyTerminalBlock>();


                GridTerminalSystem.GetBlocksOfType <IMyCubeBlock>(allTerminalBlocks);


                double runningPercent = 0;
                foreach (var block in allTerminalBlocks)
                {
                    runningPercent += block.IsWorking || block.IsFunctional ? 100d : 0d;
                }
                runningPercent = runningPercent / allTerminalBlocks.Count;

                _healthPercent = ((int)((allTerminalBlocks.Count / HealthBlockBase) * (runningPercent)) + "%");//*(runningPercent);
            }
            catch (Exception e)
            {
                //this is to catch the exception where the block blows up mid read bexcause its under attack or whatever
            }
        }
Esempio n. 5
0
        private void SetUpDrone(IMyEntity entity)
        {
            Sandbox.ModAPI.IMyGridTerminalSystem          gridTerminal = MyAPIGateway.TerminalActionsHelper.GetTerminalSystemForGrid((IMyCubeGrid)entity);
            List <Sandbox.ModAPI.Ingame.IMyTerminalBlock> T            = new List <Sandbox.ModAPI.Ingame.IMyTerminalBlock>();

            gridTerminal.GetBlocksOfType <IMyTerminalBlock>(T);

            var droneType = IsDrone(T);

            if (droneType != 0)
            {
                try
                {
                    switch (droneType)
                    {
                    case DroneTypes.SpacePirateShip:
                    {
                        SpacePirateShip drone = new SpacePirateShip((IMyCubeGrid)entity);
                        Util.GetInstance().Log("[SetUpDrone] Found New Pirate Ship. id=" + drone.GetOwnerId(), logPath);
                        AddSpacePirate(drone);
                        break;
                    }

                    case DroneTypes.PlayerDrone:
                    {
                        //SpacePirateShip dro = new SpacePirateShip((IMyCubeGrid)entity);
                        //Util.GetInstance().Log("[MiningDrones.SetUpDrone] Found New Pirate Ship. id=" + dro.GetOwnerId(), "createDrone.txt");
                        //AddDrone(dro);
                        break;
                    }

                    case DroneTypes.NotADrone:
                    {
                        break;
                    }
                    }
                }
                catch (Exception e)
                {
                    //MyAPIGateway.Entities.RemoveEntity(entity);
                    Util.GetInstance().LogError(e.ToString());
                }
            }
        }
Esempio n. 6
0
        public void FindGyros()
        {
            _gyros            = new List <IMyTerminalBlock>();
            _gyroYaw          = new List <string>();
            _gyroPitch        = new List <string>();
            _gyroYawReverse   = new List <int>();
            _gyroPitchReverse = new List <int>();
            GridTerminalSystem.GetBlocksOfType <IMyGyro>(_gyros);
            for (int i = 0; i < _gyros.Count; i++)
            {
                if ((_gyros[i]).IsFunctional)
                {
                    Base6Directions.Direction gyroUp   = _gyros[i].Orientation.TransformDirectionInverse(_shipUp);
                    Base6Directions.Direction gyroLeft = _gyros[i].Orientation.TransformDirectionInverse(_shipLeft);


                    if (gyroUp == Base6Directions.Direction.Up)
                    {
                        _gyroYaw.Add("Yaw");
                        _gyroYawReverse.Add(1);
                    }
                    else if (gyroUp == Base6Directions.Direction.Down)
                    {
                        _gyroYaw.Add("Yaw");
                        _gyroYawReverse.Add(-1);
                    }
                    else if (gyroUp == Base6Directions.Direction.Left)
                    {
                        _gyroYaw.Add("Pitch");
                        _gyroYawReverse.Add(1);
                    }
                    else if (gyroUp == Base6Directions.Direction.Right)
                    {
                        _gyroYaw.Add("Pitch");
                        _gyroYawReverse.Add(-1);
                    }
                    else if (gyroUp == Base6Directions.Direction.Forward)
                    {
                        _gyroYaw.Add("Roll");
                        _gyroYawReverse.Add(-1);
                    }
                    else if (gyroUp == Base6Directions.Direction.Backward)
                    {
                        _gyroYaw.Add("Roll");
                        _gyroYawReverse.Add(1);
                    }

                    if (gyroLeft == Base6Directions.Direction.Up)
                    {
                        _gyroPitch.Add("Yaw");
                        _gyroPitchReverse.Add(1);
                    }
                    else if (gyroLeft == Base6Directions.Direction.Down)
                    {
                        _gyroPitch.Add("Yaw");
                        _gyroPitchReverse.Add(-1);
                    }
                    else if (gyroLeft == Base6Directions.Direction.Left)
                    {
                        _gyroPitch.Add("Pitch");
                        _gyroPitchReverse.Add(1);
                    }
                    else if (gyroLeft == Base6Directions.Direction.Right)
                    {
                        _gyroPitch.Add("Pitch");
                        _gyroPitchReverse.Add(-1);
                    }
                    else if (gyroLeft == Base6Directions.Direction.Forward)
                    {
                        _gyroPitch.Add("Roll");
                        _gyroPitchReverse.Add(-1);
                    }
                    else if (gyroLeft == Base6Directions.Direction.Backward)
                    {
                        _gyroPitch.Add("Roll");
                        _gyroPitchReverse.Add(1);
                    }
                }
            }
        }
Esempio n. 7
0
 private void ResetHealthMax()
 {
     GridTerminalSystem.GetBlocksOfType <IMyTerminalBlock>(allTerminalBlocks);
     _cubeGrid.OnBlockAdded += _cubeGrid_OnBlockAdded;
     HealthBlockBase         = allTerminalBlocks.Count;
 }
Esempio n. 8
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++;
        }
Esempio n. 9
0
        private void SetUpDrone(IMyEntity entity)
        {
            Logger.Debug("SetUpDrone");
            Sandbox.ModAPI.IMyGridTerminalSystem          gridTerminal = MyAPIGateway.TerminalActionsHelper.GetTerminalSystemForGrid((IMyCubeGrid)entity);
            List <Sandbox.ModAPI.Ingame.IMyTerminalBlock> T            = new List <Sandbox.ModAPI.Ingame.IMyTerminalBlock>();

            gridTerminal.GetBlocksOfType <IMyTerminalBlock>(T);

            var droneType = IsDrone(T);

            Logger.Debug("Setting up " + droneType);
            try
            {
                Logger.Debug("Found Drone of type: " + droneType);

                switch (droneType)
                {
                case ShipTypes.NavyFighter:
                {
                    Ship ship = new Ship((IMyCubeGrid)entity, navy.PlayerId, navy.LogPath);
                    Logger.Debug("[SetUpDrone] Found New Pirate Ship. id=" + ship.GetOwnerId());

                    navy.AddFighterToFleet(ship, droneType);
                    // AddDiscoveredShip(ship);
                    break;
                }

                case ShipTypes.AIDrone:
                {
                    Ship ship = new Ship((IMyCubeGrid)entity, drones.PlayerId, drones.LogPath);
                    Logger.Debug("[SetUpDrone] Found New Pirate Ship. id=" + ship.GetOwnerId());
                    drones.AddFighterToFleet(ship, droneType);
                    //AddDiscoveredShip(ship);
                    break;
                }

                case ShipTypes.NavyFrigate:
                {
                    Ship ship = new Ship((IMyCubeGrid)entity, navy.PlayerId, navy.LogPath);
                    Logger.Debug("[SetUpDrone] Found New Pirate Ship. id=" + ship.GetOwnerId());

                    navy.AddShipToFleet(ship, droneType);
                    // AddDiscoveredShip(ship);
                    break;
                }

                case ShipTypes.AILeadShip:
                {
                    Ship ship = new Ship((IMyCubeGrid)entity, drones.PlayerId, drones.LogPath);
                    Logger.Debug("[SetUpDrone] Found New Pirate Ship. id=" + ship.GetOwnerId());
                    drones.AddShipToFleet(ship, droneType);
                    //AddDiscoveredShip(ship);
                    break;
                }
                }
            }
            catch (Exception e)
            {
                Logger.LogException(e);
            }
        }
Esempio n. 10
0
        private void RefreshGyros()
        {
            _gyros.Clear();
            _gyroYaw.Clear();
            _gyroPitch.Clear();
            _gyroYawReverse.Clear();
            _gyroPitchReverse.Clear();
            _gridTerminalSystem.GetBlocksOfType <MyGyro>(_gyros);
            for (int i = 0; i < _gyros.Count; i++)
            {
                if ((_gyros[i]).IsFunctional)
                {
                    Base6Directions.Direction gyroUp      = _gyros[i].Orientation.TransformDirectionInverse(_shipUp);
                    Base6Directions.Direction gyroLeft    = _gyros[i].Orientation.TransformDirectionInverse(_shipLeft);
                    Base6Directions.Direction gyroForward = _gyros[i].Orientation.TransformDirectionInverse(_shipForward);

                    if (gyroUp == Base6Directions.Direction.Up)
                    {
                        _gyroYaw.Add("Yaw");
                        _gyroYawReverse.Add(1);
                    }
                    else if (gyroUp == Base6Directions.Direction.Down)
                    {
                        _gyroYaw.Add("Yaw");
                        _gyroYawReverse.Add(-1);
                    }
                    else if (gyroUp == Base6Directions.Direction.Left)
                    {
                        _gyroYaw.Add("Pitch");
                        _gyroYawReverse.Add(1);
                    }
                    else if (gyroUp == Base6Directions.Direction.Right)
                    {
                        _gyroYaw.Add("Pitch");
                        _gyroYawReverse.Add(-1);
                    }
                    else if (gyroUp == Base6Directions.Direction.Forward)
                    {
                        _gyroYaw.Add("Roll");
                        _gyroYawReverse.Add(-1);
                    }
                    else if (gyroUp == Base6Directions.Direction.Backward)
                    {
                        _gyroYaw.Add("Roll");
                        _gyroYawReverse.Add(1);
                    }

                    if (gyroLeft == Base6Directions.Direction.Up)
                    {
                        _gyroPitch.Add("Yaw");
                        _gyroPitchReverse.Add(1);
                    }
                    else if (gyroLeft == Base6Directions.Direction.Down)
                    {
                        _gyroPitch.Add("Yaw");
                        _gyroPitchReverse.Add(-1);
                    }
                    else if (gyroLeft == Base6Directions.Direction.Left)
                    {
                        _gyroPitch.Add("Pitch");
                        _gyroPitchReverse.Add(1);
                    }
                    else if (gyroLeft == Base6Directions.Direction.Right)
                    {
                        _gyroPitch.Add("Pitch");
                        _gyroPitchReverse.Add(-1);
                    }
                    else if (gyroLeft == Base6Directions.Direction.Forward)
                    {
                        _gyroPitch.Add("Roll");
                        _gyroPitchReverse.Add(-1);
                    }
                    else if (gyroLeft == Base6Directions.Direction.Backward)
                    {
                        _gyroPitch.Add("Roll");
                        _gyroPitchReverse.Add(1);
                    }

                    if (gyroForward == Base6Directions.Direction.Up)
                    {
                        _gyroRoll.Add("Yaw");
                        _gyroRollReverse.Add(1);
                    }
                    else if (gyroForward == Base6Directions.Direction.Down)
                    {
                        _gyroRoll.Add("Yaw");
                        _gyroRollReverse.Add(-1);
                    }
                    else if (gyroForward == Base6Directions.Direction.Left)
                    {
                        _gyroRoll.Add("Pitch");
                        _gyroRollReverse.Add(1);
                    }
                    else if (gyroForward == Base6Directions.Direction.Right)
                    {
                        _gyroRoll.Add("Pitch");
                        _gyroRollReverse.Add(-1);
                    }
                    else if (gyroForward == Base6Directions.Direction.Forward)
                    {
                        _gyroRoll.Add("Roll");
                        _gyroRollReverse.Add(-1);
                    }
                    else if (gyroForward == Base6Directions.Direction.Backward)
                    {
                        _gyroRoll.Add("Roll");
                        _gyroRollReverse.Add(1);
                    }
                }
            }
        }
Esempio n. 11
0
        private void DeleteReverse(SettingsBlockEnforcementItem blockEnforcementSetting, int remove, IMyCubeGrid grid)
        {
            int count = 0;
            IMyGridTerminalSystem gridTerminal = MyAPIGateway.TerminalActionsHelper.GetTerminalSystemForGrid(grid);

            List <Sandbox.ModAPI.IMyTerminalBlock> blocksToRemove = new List <Sandbox.ModAPI.IMyTerminalBlock>( );
            List <IMyTerminalBlock> blockstoProcess = new List <IMyTerminalBlock>();

            gridTerminal.GetBlocksOfType <IMyTerminalBlock>(blockstoProcess);
            for (int r = blockstoProcess.Count - 1; r >= 0; r--)
            {
                Sandbox.ModAPI.IMyTerminalBlock block = (Sandbox.ModAPI.IMyTerminalBlock)blockstoProcess[r];
                switch (blockEnforcementSetting.Mode)
                {
                case SettingsBlockEnforcementItem.EnforcementMode.BlockSubtypeId:
                    if (!string.IsNullOrEmpty(block.BlockDefinition.SubtypeId) && block.BlockDefinition.SubtypeId.Contains(blockEnforcementSetting.BlockSubtypeId))
                    {
                        blocksToRemove.Add(block);
                        count++;
                    }
                    break;

                case SettingsBlockEnforcementItem.EnforcementMode.BlockTypeId:
                    if (block.BlockDefinition.TypeIdString.Contains(blockEnforcementSetting.BlockTypeId))
                    {
                        blocksToRemove.Add(block);
                        count++;
                    }
                    break;
                }

                if (count == remove)
                {
                    break;
                }
            }

            /*
             * List<MyObjectBuilder_CubeBlock> blocksToRemove = new List<MyObjectBuilder_CubeBlock>();
             * for (int r = gridBuilder.CubeBlocks.Count - 1; r >= 0; r--)
             * {
             *      MyObjectBuilder_CubeBlock block = gridBuilder.CubeBlocks[r];
             *      if (block.GetId().ToString().Contains(id))
             *      {
             *              blocksToRemove.Add(block);
             *              count++;
             *      }
             *
             *      if (count == remove)
             *              break;
             * }
             */

            if (blocksToRemove.Count < 1)
            {
                return;
            }

            List <Vector3I> razeList = new List <Vector3I>( );

            foreach (Sandbox.ModAPI.IMyTerminalBlock block in blocksToRemove)
            {
                razeList.Add(block.Min);
            }

            Wrapper.GameAction(() =>
            {
                grid.RazeBlocks(razeList);
            });
        }