Пример #1
0
        private static void FilterEntitiesForMedbayCheck(ulong steamId, HashSet <IMyEntity> entitiesFound, HashSet <IMyEntity> entitiesToConceal)
        {
            foreach (IMyEntity entity in entitiesFound)
            {
                if (!(entity is IMyCubeGrid))
                {
                    continue;
                }

                if (entity.DisplayName.Contains("CommRelay"))
                {
                    continue;
                }

                if (!entity.InScene)
                {
                    continue;
                }

                if (((IMyCubeGrid)entity).GridSizeEnum != MyCubeSize.Small && !PluginSettings.Instance.ConcealIncludeLargeGrids)
                {
                    continue;
                }

                IMyCubeGrid grid     = (IMyCubeGrid)entity;
                long        playerId = PlayerMap.Instance.GetFastPlayerIdFromSteamId(steamId);
                if (!grid.BigOwners.Contains(playerId) && !grid.SmallOwners.Contains(playerId))
                {
                    continue;
                }

                bool found = false;
                // Check to see if grid is close to dock / shipyard
                foreach (IMyCubeGrid checkGrid in ProcessDockingZone.ZoneCache)
                {
                    try
                    {
                        if (Vector3D.Distance(checkGrid.GetPosition( ), grid.GetPosition( )) < 100d)
                        {
                            found = true;
                            break;
                        }
                    }
                    catch
                    {
                        continue;
                    }
                }

                if (!found)
                {
                    // Check for block type rules
                }

                if (!found)
                {
                    entitiesToConceal.Add(entity);
                }
            }
        }
Пример #2
0
        public static bool ToggleMedbayGrids(ulong steamId)
        {
            if (_checkConceal || _checkReveal)
            {
                Communication.SendPrivateInformation(steamId, "Server busy");
                return(false);
            }

            _checkConceal = true;
            _checkReveal  = true;
            try
            {
                DateTime start = DateTime.Now;

                // Toggle off
                HashSet <IMyEntity> entities      = new HashSet <IMyEntity>();
                HashSet <IMyEntity> entitiesFound = new HashSet <IMyEntity>();

                try
                {
                    MyAPIGateway.Entities.GetEntities(entities);
                }
                catch
                {
                    Logging.WriteLineAndConsole("CheckAndConcealEntities(): Error getting entity list, skipping check");
                    return(false);
                }

                CubeGrids.GetGridsUnconnected(entitiesFound, entities);

                HashSet <IMyEntity> entitiesToConceal = new HashSet <IMyEntity>();
                foreach (IMyEntity entity in entitiesFound)
                {
                    if (!(entity is IMyCubeGrid))
                    {
                        continue;
                    }

                    if (entity.DisplayName.Contains("CommRelay"))
                    {
                        continue;
                    }

                    if (!entity.InScene)
                    {
                        continue;
                    }

                    if (((IMyCubeGrid)entity).GridSizeEnum != MyCubeSize.Small && !PluginSettings.Instance.ConcealIncludeLargeGrids)
                    {
                        continue;
                    }

                    IMyCubeGrid grid     = (IMyCubeGrid)entity;
                    long        playerId = PlayerMap.Instance.GetFastPlayerIdFromSteamId(steamId);
                    if (!grid.BigOwners.Contains(playerId) && !grid.SmallOwners.Contains(playerId))
                    {
                        continue;
                    }

                    bool found = false;
                    // Check to see if grid is close to dock / shipyard
                    foreach (IMyCubeGrid checkGrid in ProcessDockingZone.ZoneCache)
                    {
                        try
                        {
                            if (Vector3D.Distance(checkGrid.GetPosition(), grid.GetPosition()) < 100d)
                            {
                                found = true;
                                break;
                            }
                        }
                        catch
                        {
                            continue;
                        }
                    }

                    if (!found)
                    {
                        // Check for block type rules
                    }

                    if (!found)
                    {
                        entitiesToConceal.Add(entity);
                    }
                }

                if (entitiesToConceal.Count > 0)
                {
                    //if (PluginSettings.Instance.DynamicClientConcealEnabled)
                    //{
                    //ClientEntityManagement.Refresh(steamId);
                    //}

                    Communication.SendClientMessage(steamId, string.Format("/conceal {0}", string.Join(",", entitiesToConceal.Select(x => x.EntityId.ToString() + ":" + ((MyObjectBuilder_CubeGrid)x.GetObjectBuilder()).CubeBlocks.Count.ToString() + ":" + x.DisplayName).ToArray())));
                    Thread.Sleep(1500);
                    ConcealEntities(entitiesToConceal);
                    //CheckAndRevealEntities();
                }

                if ((DateTime.Now - start).TotalMilliseconds > 2000)
                {
                    Logging.WriteLineAndConsole(string.Format("Completed Toggle: {0}ms", (DateTime.Now - start).TotalMilliseconds));
                }
            }
            catch (Exception ex)
            {
                Logging.WriteLineAndConsole(string.Format("CheckAndConceal(): {0}", ex.ToString()));
            }
            finally
            {
                _checkConceal = false;
                _checkReveal  = false;
            }

            return(true);
        }
Пример #3
0
        private static bool CheckRevealBlockRules(IMyCubeGrid grid, List <IMyPlayer> players, out string reason)
        {
            reason = "";
            // This is actually faster, but doesn't include power checks

            // Live dangerously
            List <IMySlimBlock> blocks = new List <IMySlimBlock>();

            grid.GetBlocks(blocks, x => x.FatBlock != null);
            //CubeGrids.GetAllConnectedBlocks(_processedGrids, grid, blocks, x => x.FatBlock != null);
            //bool found = false;
            //bool powered = false;
            foreach (IMySlimBlock block in blocks)
            {
                IMyCubeBlock cubeBlock = block.FatBlock;

                if (cubeBlock.BlockDefinition.TypeId == typeof(MyObjectBuilder_Beacon))
                {
                    //MyObjectBuilder_Beacon beacon = (MyObjectBuilder_Beacon)cubeBlock.GetObjectBuilderCubeBlock();
                    IMyBeacon beacon = (IMyBeacon)cubeBlock;
                    if (!beacon.Enabled)
                    {
                        continue;
                    }

                    //Sandbox.ModAPI.Ingame.IMyFunctionalBlock functionalBlock = (Sandbox.ModAPI.Ingame.IMyFunctionalBlock)cubeBlock;
                    //if (!functionalBlock.Enabled)
                    //	continue;

                    //Console.WriteLine("Beacon: {0} {1} {2}", beacon.BroadcastRadius, terminalBlock.IsWorking, terminalBlock.IsFunctional);
                    //if (!terminalBlock.IsWorking)
                    //	continue;


                    foreach (IMyPlayer player in players)
                    {
                        double distance = 0d;
                        if (Entity.GetDistanceBetweenPointAndPlayer(grid.GetPosition(), player, out distance))
                        {
                            if (distance < beacon.Radius)
                            {
                                //found = true;
                                //break;
                                reason = string.Format("{0} distance to beacon broadcast: {1}", player.DisplayName, distance);
                                return(true);
                            }
                        }
                    }
                }

                if (cubeBlock.BlockDefinition.TypeId == typeof(MyObjectBuilder_RadioAntenna))
                {
                    //MyObjectBuilder_RadioAntenna antenna = (MyObjectBuilder_RadioAntenna)cubeBlock.GetObjectBuilderCubeBlock();
                    IMyRadioAntenna antenna = (IMyRadioAntenna)cubeBlock;

                    if (!antenna.Enabled)
                    {
                        continue;
                    }

                    //Sandbox.ModAPI.Ingame.IMyFunctionalBlock functionalBlock = (Sandbox.ModAPI.Ingame.IMyFunctionalBlock)cubeBlock;
                    //if (!functionalBlock.Enabled)
                    //	continue;

                    foreach (IMyPlayer player in players)
                    {
                        double distance = 0d;
                        if (Entity.GetDistanceBetweenPointAndPlayer(grid.GetPosition(), player, out distance))
                        {
                            if (distance < antenna.Radius)
                            {
                                //found = true;
                                //break;
                                reason = string.Format("{0} distance to antenna broadcast: {1}", player.DisplayName, distance);
                                return(true);
                            }
                        }
                    }
                }

                if (cubeBlock.BlockDefinition.TypeId == typeof(MyObjectBuilder_MedicalRoom))
                {
                    //MyObjectBuilder_MedicalRoom medical = (MyObjectBuilder_MedicalRoom)cubeBlock.GetObjectBuilderCubeBlock();
                    IMyMedicalRoom medical = (IMyMedicalRoom)cubeBlock;
                    if (!medical.Enabled)
                    {
                        continue;
                    }

                    IMyFunctionalBlock functionalBlock = (IMyFunctionalBlock)cubeBlock;
                    if (!functionalBlock.IsFunctional)
                    {
                        continue;
                    }

                    //if (!functionalBlock.Enabled)
                    //	continue;

                    if (PluginSettings.Instance.DynamicConcealIncludeMedBays)
                    {
                        lock (Online)
                        {
                            foreach (ulong connectedPlayer in Online)
                            {
                                long playerId = PlayerMap.Instance.GetFastPlayerIdFromSteamId(connectedPlayer);
                                //if (medical.Owner == playerId || (medical.ShareMode == MyOwnershipShareModeEnum.Faction && Player.CheckPlayerSameFaction(medical.Owner, playerId)))
                                if (functionalBlock.OwnerId == playerId)
                                {
                                    reason = string.Format("Grid has medbay and player is logged in - playerid: {0}", playerId);
                                    return(true);
                                }

                                if (functionalBlock.GetUserRelationToOwner(playerId) == MyRelationsBetweenPlayerAndBlock.FactionShare)
                                {
                                    reason = string.Format("Grid has medbay and player is factionshare - playerid: {0}", playerId);
                                    return(true);
                                }
                            }
                        }

                        /*
                         * foreach (ulong connectedPlayer in PlayerManager.Instance.ConnectedPlayers)
                         * {
                         *      long playerId = PlayerMap.Instance.GetFastPlayerIdFromSteamId(connectedPlayer);
                         *      //if (medical.Owner == playerId || (medical.ShareMode == MyOwnershipShareModeEnum.Faction && Player.CheckPlayerSameFaction(medical.Owner, playerId)))
                         *      //if (functionalBlock.OwnerId == playerId || (functionalBlock.GetUserRelationToOwner(playerId) == Sandbox.Common.MyRelationsBetweenPlayerAndBlock.FactionShare))
                         *      if(medical.HasPlayerAccess(playerId))
                         *      {
                         *              reason = string.Format("Grid has medbay and player is logged in - playerid: {0}", playerId);
                         *              return true;
                         *      }
                         * }
                         */
                    }
                    else
                    {
                        reason = string.Format("Grid has medbay and conceal can not include medbays");
                        return(true);
                    }
                }

                if (cubeBlock.BlockDefinition.TypeId == typeof(MyObjectBuilder_ProductionBlock))
                {
                    MyObjectBuilder_ProductionBlock production = (MyObjectBuilder_ProductionBlock)cubeBlock.GetObjectBuilderCubeBlock();
                    if (!production.Enabled)
                    {
                        continue;
                    }

                    IMyProductionBlock productionBlock = (IMyProductionBlock)cubeBlock;
                    if (production.Queue.Length > 0)
                    {
                        reason = string.Format("Grid has production facility that has a queue");
                        return(true);
                    }
                }
            }

            return(false);
        }
Пример #4
0
        public static void CheckAndConcealEntities()
        {
            if (_checkConceal)
            {
                return;
            }

            _checkConceal = true;
            try
            {
                DateTime start      = DateTime.Now;
                double   distCheck  = 0d;
                double   blockRules = 0d;
                double   getGrids   = 0d;
                double   co         = 0f;

                ProcessedGrids.Clear();
                List <IMyPlayer>    players          = new List <IMyPlayer>();
                HashSet <IMyEntity> entities         = new HashSet <IMyEntity>();
                HashSet <IMyEntity> entitiesFiltered = new HashSet <IMyEntity>();
                HashSet <IMyEntity> entitiesFound    = new HashSet <IMyEntity>();

                try
                {
                    MyAPIGateway.Players.GetPlayers(players);
                }
                catch (Exception ex)
                {
                    Logging.WriteLineAndConsole(string.Format("Error getting players list.  Check and Conceal failed: {0}", ex.ToString()));
                    return;
                }

                try
                {
                    MyAPIGateway.Entities.GetEntities(entities);
                }
                catch
                {
                    Logging.WriteLineAndConsole("CheckAndConcealEntities(): Error getting entity list, skipping check");
                    return;
                }

                foreach (IMyEntity entity in entities)
                {
                    if (!(entity is IMyCubeGrid))
                    {
                        continue;
                    }

                    if (!entity.InScene)
                    {
                        continue;
                    }

                    entitiesFiltered.Add(entity);
                }

                DateTime getGridsStart = DateTime.Now;
                CubeGrids.GetGridsUnconnected(entitiesFound, entitiesFiltered);
                getGrids += (DateTime.Now - getGridsStart).TotalMilliseconds;

                HashSet <IMyEntity> entitiesToConceal = new HashSet <IMyEntity>();
                foreach (IMyEntity entity in entitiesFound)
                {
                    if (!(entity is IMyCubeGrid))
                    {
                        continue;
                    }

                    if (entity.DisplayName.Contains("CommRelay"))
                    {
                        continue;
                    }

                    if (entity.Physics == null)                     // Projection
                    {
                        continue;
                    }

                    if (!entity.InScene)
                    {
                        continue;
                    }

                    if (((IMyCubeGrid)entity).GridSizeEnum != MyCubeSize.Small && !PluginSettings.Instance.ConcealIncludeLargeGrids)
                    {
                        continue;
                    }

                    IMyCubeGrid grid = (IMyCubeGrid)entity;

                    bool     found     = false;
                    DateTime distStart = DateTime.Now;
                    foreach (IMyPlayer player in players)
                    {
                        double distance = 0f;
                        if (Entity.GetDistanceBetweenGridAndPlayer(grid, player, out distance))
                        {
                            if (distance < PluginSettings.Instance.DynamicConcealDistance)
                            {
                                found = true;
                            }
                        }
                    }
                    distCheck += (DateTime.Now - distStart).TotalMilliseconds;

                    if (!found)
                    {
                        // Check to see if grid is close to dock / shipyard
                        foreach (IMyCubeGrid checkGrid in ProcessDockingZone.ZoneCache)
                        {
                            try
                            {
                                if (Vector3D.Distance(checkGrid.GetPosition(), grid.GetPosition()) < 100d)
                                {
                                    found = true;
                                    break;
                                }
                            }
                            catch
                            {
                                continue;
                            }
                        }
                    }

                    if (!found)
                    {
                        // Check for block type rules
                        DateTime blockStart = DateTime.Now;
                        if (CheckConcealBlockRules(grid, players))
                        {
                            found = true;
                        }

                        blockRules += (DateTime.Now - blockStart).TotalMilliseconds;
                    }

                    if (!found)
                    {
                        entitiesToConceal.Add(entity);
                    }
                }

                DateTime coStart = DateTime.Now;
                if (entitiesToConceal.Count > 0)
                {
                    ConcealEntities(entitiesToConceal);
                }
                co += (DateTime.Now - coStart).TotalMilliseconds;

                if ((DateTime.Now - start).TotalMilliseconds > 2000)
                {
                    Logging.WriteLineAndConsole(string.Format("Completed Conceal Check: {0}ms (gg: {3}, dc: {2} ms, br: {1}ms, co: {4}ms)", (DateTime.Now - start).TotalMilliseconds, blockRules, distCheck, getGrids, co));
                }
            }
            catch (Exception ex)
            {
                Logging.WriteLineAndConsole(string.Format("CheckAndConceal(): {0}", ex.ToString()));
            }
            finally
            {
                _checkConceal = false;
            }
        }
Пример #5
0
        private static bool CheckConcealBlockRules(IMyCubeGrid grid, List <IMyPlayer> players)
        {
            List <IMySlimBlock> blocks = new List <IMySlimBlock>();

            // Live dangerously
            grid.GetBlocks(blocks, x => x.FatBlock != null);
            //CubeGrids.GetAllConnectedBlocks(_processedGrids, grid, blocks, x => x.FatBlock != null);

            int beaconCount = 0;

            //bool found = false;
            //bool powered = false;
            foreach (IMySlimBlock block in blocks)
            {
                IMyCubeBlock cubeBlock = block.FatBlock;

                if (cubeBlock.BlockDefinition.TypeId == typeof(MyObjectBuilder_Beacon))
                {
                    IMyBeacon beacon = (IMyBeacon)cubeBlock;
                    //MyObjectBuilder_Beacon beacon = (MyObjectBuilder_Beacon)cubeBlock.GetObjectBuilderCubeBlock();
                    beaconCount++;
                    // Keep this return here, as 4 beacons always means true
                    if (beaconCount >= 4)
                    {
                        return(true);
                    }

                    if (!beacon.Enabled)
                    {
                        continue;
                    }

                    IMyTerminalBlock terminalBlock = (IMyTerminalBlock)cubeBlock;
//					Console.WriteLine("Found: {0} {1} {2}", beacon.BroadcastRadius, terminalBlock.IsWorking, terminalBlock.IsFunctional);
                    //if (!terminalBlock.IsWorking)
                    //{
//						continue;
                    //}

                    foreach (IMyPlayer player in players)
                    {
                        double distance = 0d;
                        if (Entity.GetDistanceBetweenPointAndPlayer(grid.GetPosition(), player, out distance))
                        {
                            if (distance < beacon.Radius)
                            {
//								Console.WriteLine("Not concealed due to broadcast radius");
                                //found = true;
                                //break;
                                return(true);
                            }
                        }
                    }
                }

                if (cubeBlock.BlockDefinition.TypeId == typeof(MyObjectBuilder_RadioAntenna))
                {
                    //MyObjectBuilder_RadioAntenna antenna = (MyObjectBuilder_RadioAntenna)cubeBlock.GetObjectBuilderCubeBlock();
                    IMyRadioAntenna antenna = (IMyRadioAntenna)cubeBlock;

                    if (!antenna.Enabled)
                    {
                        continue;
                    }

                    IMyTerminalBlock terminalBlock = (IMyTerminalBlock)cubeBlock;
                    //if (!terminalBlock.IsWorking)
                    //	continue;

                    foreach (IMyPlayer player in players)
                    {
                        double distance = 0d;
                        if (Entity.GetDistanceBetweenPointAndPlayer(grid.GetPosition(), player, out distance))
                        {
                            if (distance < antenna.Radius)
                            {
//								Console.WriteLine("Not concealed due to antenna broadcast radius");
                                //found = true;
                                //break;
                                return(true);
                            }
                        }
                    }
                }

                if (cubeBlock.BlockDefinition.TypeId == typeof(MyObjectBuilder_MedicalRoom))
                {
                    //MyObjectBuilder_MedicalRoom medical = (MyObjectBuilder_MedicalRoom)cubeBlock.GetObjectBuilderCubeBlock();
                    IMyMedicalRoom medical = (IMyMedicalRoom)cubeBlock;

                    if (!medical.Enabled)
                    {
                        continue;
                    }

                    IMyFunctionalBlock functionalBlock = (IMyFunctionalBlock)cubeBlock;
                    //if (!terminalBlock.IsWorking)
                    //	continue;

                    if (PluginSettings.Instance.DynamicConcealIncludeMedBays)
                    {
                        lock (Online)
                        {
                            foreach (ulong connectedPlayer in Online)
                            {
                                //if (PlayerMap.Instance.GetPlayerIdsFromSteamId(connectedPlayer).Count < 1)
                                //continue;

                                //long playerId = PlayerMap.Instance.GetPlayerIdsFromSteamId(connectedPlayer).First();
                                long playerId = PlayerMap.Instance.GetFastPlayerIdFromSteamId(connectedPlayer);

                                if (functionalBlock.OwnerId == playerId || (functionalBlock.GetUserRelationToOwner(playerId) == MyRelationsBetweenPlayerAndBlock.FactionShare))
                                //if (functionalBlock.Owner == playerId || (functionalBlock.ShareMode == MyOwnershipShareModeEnum.Faction && Player.CheckPlayerSameFaction(functionalBlock.Owner, playerId)))
                                //if (medical.HasPlayerAccess(playerId))
                                {
                                    return(true);
                                }
                            }
                        }

                        /*
                         * foreach (ulong connectedPlayer in PlayerManager.Instance.ConnectedPlayers)
                         * {
                         *      //if (PlayerMap.Instance.GetPlayerIdsFromSteamId(connectedPlayer).Count < 1)
                         *              //continue;
                         *
                         *      //long playerId = PlayerMap.Instance.GetPlayerIdsFromSteamId(connectedPlayer).First();
                         *      long playerId = PlayerMap.Instance.GetFastPlayerIdFromSteamId(connectedPlayer);
                         *      //if (medical.Owner == playerId || (medical.ShareMode == MyOwnershipShareModeEnum.Faction && Player.CheckPlayerSameFaction(medical.Owner, playerId)))
                         *      if(medical.HasPlayerAccess(playerId))
                         *      {
                         *              return true;
                         *      }
                         * }
                         */
                    }
                    else
                    {
                        return(true);
                    }
                }

                if (cubeBlock.BlockDefinition.TypeId == typeof(MyObjectBuilder_Refinery) || cubeBlock.BlockDefinition.TypeId == typeof(MyObjectBuilder_Assembler))
                {
                    //MyObjectBuilder_ProductionBlock production = (MyObjectBuilder_ProductionBlock)cubeBlock.GetObjectBuilderCubeBlock();
                    IMyProductionBlock production = (IMyProductionBlock)cubeBlock;
                    if (!production.Enabled)
                    {
                        continue;
                    }

                    if (production.IsProducing)
                    {
                        return(true);
                    }
                }

                foreach (string subType in PluginSettings.Instance.DynamicConcealIgnoreSubTypeList)
                {
                    if (cubeBlock.BlockDefinition.SubtypeName.Contains(subType))
                    {
//						Console.WriteLine("Not concealed due subtype");
                        //found = true;
                        return(true);
                    }
                }
            }

            return(false);
        }
 public int AlignTo(Vector3D position)
 {
     for (int i = 0; i < alignCount && GyrosWork(); i++)
     {
         double realDistance = (position - Ship.GetPosition()).Length();
         DegreesToVector(position);
         PointToVector(0);
     }
     previousAlign = position;
     Util.GetInstance().Log("[DroneNavigation.AlignTo] returning pitch:" + Math.Abs(_degreesToVectorPitch) + " yaw:" + Math.Abs(_degreesToVectorYaw));
     return((int)(Math.Abs(_degreesToVectorPitch) + Math.Abs(_degreesToVectorYaw)));
 }
Пример #7
0
        //this method will look for active ship grids/drones/players and keep killing them untill it cant find any within
        //its local known nearby objects
        public bool FindNearbyAttackTarget()
        {
            //return false;
            FindWeapons();
            ClearTarget();

            Dictionary<IMyEntity, IMyEntity> nearbyDrones = new Dictionary<IMyEntity, IMyEntity>();
            Dictionary<IMyEntity, IMyEntity> nearbyOnlineShips = new Dictionary<IMyEntity, IMyEntity>();
            List<IMyPlayer> nearbyPlayers = new List<IMyPlayer>();

            MyAPIGateway.Players.GetPlayers(nearbyPlayers);
            nearbyPlayers =
                nearbyPlayers.Where(
                    x => x.PlayerID != _ownerId && (x.GetPosition() - Ship.GetPosition()).Length() < 2000)
                    .ToList();

            bool playersNearby = nearbyPlayers.Any();

            Util.GetInstance().Log("[Drone.FindNearbyAttacktarget] enemy players nearby? " + playersNearby);
            for (int i = 0; i < _nearbyFloatingObjects.Count; i++)
            {
                if ((_nearbyFloatingObjects.ToList()[i].GetPosition() - Ship.GetPosition()).Length() > 10)
                {
                    var entity = _nearbyFloatingObjects.ToList()[i];

                    var grid = entity as IMyCubeGrid;
                    if (grid != null)
                    {
                        var gridTerminal = MyAPIGateway.TerminalActionsHelper.GetTerminalSystemForGrid(grid);

                        List<IMyTerminalBlock> val = new List<IMyTerminalBlock>();
                        gridTerminal.GetBlocks(val);
                        var isFriendly = GridFriendly(val);

                        List<IMyTerminalBlock> T = new List<IMyTerminalBlock>();
                        gridTerminal.GetBlocksOfType<IMyRemoteControl>(T);

                        List<IMyTerminalBlock> reactorBlocks = new List<IMyTerminalBlock>();
                        gridTerminal.GetBlocksOfType<IMyPowerProducer>(reactorBlocks);

                        bool isOnline =
                            reactorBlocks.Exists(x => (((IMyPowerProducer)x).CurrentPowerOutput > 0 && x.IsWorking) && !isFriendly);

                        bool isDrone =
                            T.Exists(
                                x =>
                                    (((IMyRemoteControl)x).CustomName.Contains("Drone#") && x.IsWorking &&
                                        !isFriendly));

                        bool isMothership =
                            T.Exists(x => x.CustomName.Contains("#ConquestMothership"));

                        var droneControl =
                            (IMyEntity)
                                T.FirstOrDefault(
                                    x => ((IMyRemoteControl)x).CustomName.Contains("Drone#") && x.IsWorking &&
                                            !isFriendly);

                        var shipPower =
                            (IMyEntity)
                                reactorBlocks.FirstOrDefault(
                                    x => (((IMyPowerProducer)x).CurrentPowerOutput > 0 && x.IsWorking) && !isFriendly);

                        if (isDrone && isOnline)
                        {
                            nearbyDrones.Add(grid, droneControl);
                        }
                        else if (isOnline)
                        {
                            nearbyOnlineShips.Add(grid, shipPower ?? droneControl);
                        }
                    }
                }
            }

            if (nearbyDrones.Count > 0)
            {
                Util.GetInstance().Log("[Drone.FindNearbyAttacktarget] nearby drone count " + nearbyDrones.Count);
                var myTarget =
                    nearbyDrones
                        .OrderBy(x => (x.Key.GetPosition() - Ship.GetPosition()).Length())
                        .ToList();

                if (myTarget.Count > 0)
                {
                    var target = myTarget[0];

                    IMyGridTerminalSystem gridTerminal = MyAPIGateway.TerminalActionsHelper.GetTerminalSystemForGrid((IMyCubeGrid)target.Key);
                    List<IMyTerminalBlock> T = new List<IMyTerminalBlock>();
                    gridTerminal.GetBlocks(T);

                    if (T.Count >= _minTargetSize)
                    {
                        _target = (IMyCubeGrid)target.Key;
                        _targetPlayer = null;
                        try
                        {
                            if (!FindTargetKeyPoint(_target, _target.Physics.LinearVelocity))
                                OrbitAttackTarget(_target.GetPosition(), _target.Physics.LinearVelocity);
                            return true;
                        }
                        catch
                        {
                        }
                    }
                }
            }

            if (nearbyOnlineShips.Count > 0)
            {
                Util.GetInstance().Log("[Drone.FindNearbyAttacktarget] nearby ship count " + nearbyOnlineShips.Count);
                var myTargets =
                    nearbyOnlineShips
                        .OrderBy(x => (x.Key.GetPosition() - Ship.GetPosition()).Length())
                        .ToList();

                foreach (var target in myTargets)
                {

                    IMyGridTerminalSystem gridTerminal = MyAPIGateway.TerminalActionsHelper.GetTerminalSystemForGrid((IMyCubeGrid)target.Key);
                    List<IMyTerminalBlock> T = new List<IMyTerminalBlock>();
                    gridTerminal.GetBlocks(T);

                    if (T.Count >= _minTargetSize)
                    {
                        _target = (IMyCubeGrid)target.Key;
                        _targetPlayer = null;
                        try
                        {
                            FindTargetKeyPoint(_target, _target.Physics.LinearVelocity);

                            return true;
                        }
                        catch { OrbitAttackTarget(_target.GetPosition(), _target.Physics.LinearVelocity); }
                    }
                }
            }

            //if (playersNearby && nearbyPlayers.Count > 0)
            //{
            //    Util.GetInstance().Log("[Drone.FindNearbyAttacktarget] nearby player count " + nearbyPlayers.Count);
            //    var myTarget = nearbyPlayers.OrderBy(x => ((x).GetPosition() - Ship.GetPosition()).Length()).ToList();

            //    if (myTarget.Count > 0)
            //    {
            //        _target = null;
            //        _targetPlayer = myTarget[0];
            //        OrbitAttackTarget(_targetPlayer.GetPosition(), new Vector3D(0, 0, 0));
            //        return true;
            //    }
            //}
            return false;
        }
		private static bool CheckRevealBlockRules( IMyCubeGrid grid, List<IMyPlayer> players, out string reason )
		{
			reason = "";
			// This is actually faster, but doesn't include power checks

			// Live dangerously
			List<IMySlimBlock> blocks = new List<IMySlimBlock>( );
			grid.GetBlocks( blocks, x => x.FatBlock != null );
			//CubeGrids.GetAllConnectedBlocks(_processedGrids, grid, blocks, x => x.FatBlock != null);
			//bool found = false;
			//bool powered = false;
			foreach ( IMySlimBlock block in blocks )
			{
				IMyCubeBlock cubeBlock = block.FatBlock;

				if ( cubeBlock.BlockDefinition.TypeId == typeof( MyObjectBuilder_Beacon ) )
				{
					//MyObjectBuilder_Beacon beacon = (MyObjectBuilder_Beacon)cubeBlock.GetObjectBuilderCubeBlock();
					IMyBeacon beacon = (IMyBeacon)cubeBlock;
					if ( !beacon.Enabled )
						continue;

					//Sandbox.ModAPI.Ingame.IMyFunctionalBlock functionalBlock = (Sandbox.ModAPI.Ingame.IMyFunctionalBlock)cubeBlock;
					//if (!functionalBlock.Enabled)
					//	continue;

					//Console.WriteLine("Beacon: {0} {1} {2}", beacon.BroadcastRadius, terminalBlock.IsWorking, terminalBlock.IsFunctional);
					//if (!terminalBlock.IsWorking)
					//	continue;


					foreach ( IMyPlayer player in players )
					{
						double distance;
						if ( Entity.GetDistanceBetweenPointAndPlayer( grid.GetPosition( ), player, out distance ) )
						{
							if ( distance < beacon.Radius )
							{
								//found = true;
								//break;
								reason = string.Format( "{0} distance to beacon broadcast: {1}", player.DisplayName, distance );
								return true;
							}
						}
					}
				}

				if ( cubeBlock.BlockDefinition.TypeId == typeof( MyObjectBuilder_RadioAntenna ) )
				{
					//MyObjectBuilder_RadioAntenna antenna = (MyObjectBuilder_RadioAntenna)cubeBlock.GetObjectBuilderCubeBlock();
					IMyRadioAntenna antenna = (IMyRadioAntenna)cubeBlock;

					if ( !antenna.Enabled )
						continue;

					//Sandbox.ModAPI.Ingame.IMyFunctionalBlock functionalBlock = (Sandbox.ModAPI.Ingame.IMyFunctionalBlock)cubeBlock;
					//if (!functionalBlock.Enabled)
					//	continue;

					foreach ( IMyPlayer player in players )
					{
						double distance = 0d;
						if ( Entity.GetDistanceBetweenPointAndPlayer( grid.GetPosition( ), player, out distance ) )
						{
							if ( distance < antenna.Radius )
							{
								//found = true;
								//break;
								reason = string.Format( "{0} distance to antenna broadcast: {1}", player.DisplayName, distance );
								return true;
							}
						}
					}
				}

				if ( cubeBlock.BlockDefinition.TypeId == typeof( MyObjectBuilder_MedicalRoom ) )
				{
					//MyObjectBuilder_MedicalRoom medical = (MyObjectBuilder_MedicalRoom)cubeBlock.GetObjectBuilderCubeBlock();
					IMyMedicalRoom medical = (IMyMedicalRoom)cubeBlock;
					if ( !medical.Enabled )
						continue;

					IMyFunctionalBlock functionalBlock = (IMyFunctionalBlock)cubeBlock;
					if ( !functionalBlock.IsFunctional )
						continue;

					//if (!functionalBlock.Enabled)
					//	continue;

					if ( PluginSettings.Instance.DynamicConcealIncludeMedBays )
					{
						lock ( Online )
						{
							foreach ( ulong connectedPlayer in Online )
							{
								long playerId = PlayerMap.Instance.GetFastPlayerIdFromSteamId( connectedPlayer );
								//if (medical.Owner == playerId || (medical.ShareMode == MyOwnershipShareModeEnum.Faction && Player.CheckPlayerSameFaction(medical.Owner, playerId)))
								if ( functionalBlock.OwnerId == playerId )
								{
									reason = string.Format( "Grid has medbay and player is logged in - playerid: {0}", playerId );
                                    //return true;

                                    //medbay is up for reveal, put it into the medbay queue to be revealed before other grids
                                    RevealMedbays( (IMyEntity)grid, reason );
                                    //return false so this grid doesn't get duplicated in the regular queue
                                    return false;
                                }

								if ( functionalBlock.GetUserRelationToOwner( playerId ) == MyRelationsBetweenPlayerAndBlock.FactionShare )
								{
									reason = string.Format( "Grid has medbay and player is factionshare - playerid: {0}", playerId );
                                    //return true;

                                    //medbay is up for reveal, put it into the medbay queue to be revealed before other grids
                                    RevealMedbays( (IMyEntity)grid, reason );
                                    //return false so this grid doesn't get duplicated in the regular queue
                                    return false;
                                }
							}
						}

                        /*
						foreach (ulong connectedPlayer in PlayerManager.Instance.ConnectedPlayers)
						{
							long playerId = PlayerMap.Instance.GetFastPlayerIdFromSteamId(connectedPlayer);
							//if (medical.Owner == playerId || (medical.ShareMode == MyOwnershipShareModeEnum.Faction && Player.CheckPlayerSameFaction(medical.Owner, playerId)))
							//if (functionalBlock.OwnerId == playerId || (functionalBlock.GetUserRelationToOwner(playerId) == Sandbox.Common.MyRelationsBetweenPlayerAndBlock.FactionShare))
							if(medical.HasPlayerAccess(playerId))
							{
								reason = string.Format("Grid has medbay and player is logged in - playerid: {0}", playerId);
								return true;
							}
						}
						 */
                    }
					else
					{
						reason = string.Format( "Grid has medbay and conceal can not include medbays" );
                        //return true;

                        //medbay is up for reveal, put it into the medbay queue to be revealed before other grids
                        RevealMedbays( (IMyEntity)grid, reason );
                        //return false so this grid doesn't get duplicated in the regular queue
                        return false;
                    }
                }

                if ( cubeBlock.BlockDefinition.TypeId == typeof( MyObjectBuilder_CryoChamber) )
                {
                        MyCryoChamber cryo = (MyCryoChamber)cubeBlock;
                        if ( cryo.Pilot == null )
                            continue;
                        
                    if ( !cryo.IsFunctional )
                        continue;                    

                    if ( PluginSettings.Instance.DynamicConcealIncludeMedBays )
                    {
                        lock ( Online )
                        {
                            foreach ( ulong connectedPlayer in Online )
                            {
                                long playerId = PlayerMap.Instance.GetFastPlayerIdFromSteamId( connectedPlayer );
                                IMyPlayer cryoUser = (IMyPlayer) cryo.Pilot;

                                if ( cryoUser.PlayerID == playerId )
                                {
                                    reason = string.Format( "Grid has cryopod and player is inside - playerid: {0}", playerId );
                                    //return true;

                                    //medbay is up for reveal, put it into the medbay queue to be revealed before other grids
                                    RevealMedbays( (IMyEntity)grid, reason );
                                    //return false so this grid doesn't get duplicated in the regular queue
                                    return false;
                                }

                                if ( cryo.HasPlayerAccess( playerId ) )
                                {
                                    reason = string.Format( "Grid has cryopod and player can use - playerid: {0}", playerId );
                                    //return true;

                                    //medbay is up for reveal, put it into the medbay queue to be revealed before other grids
                                    RevealMedbays( (IMyEntity)grid, reason );
                                    //return false so this grid doesn't get duplicated in the regular queue
                                    return false;
                                }
                            }
                        }
                    }
                    else
                    {
                        reason = string.Format( "Grid has cryopod and conceal can not include cryopods" );
                        //return true;

                        //medbay is up for reveal, put it into the medbay queue to be revealed before other grids
                        RevealMedbays( (IMyEntity)grid, reason );
                        //return false so this grid doesn't get duplicated in the regular queue
                        return false;
                    }
                }

                if ( cubeBlock.BlockDefinition.TypeId == typeof( MyObjectBuilder_ProductionBlock ) )
				{
					MyObjectBuilder_ProductionBlock production = (MyObjectBuilder_ProductionBlock)cubeBlock.GetObjectBuilderCubeBlock( );
					if ( !production.Enabled )
						continue;

					IMyProductionBlock productionBlock = (IMyProductionBlock)cubeBlock;
					if ( production.Queue.Length > 0 )
					{
						reason = string.Format( "Grid has production facility that has a queue" );
						return true;
					}
				}
			}

			return false;
		}
		private static bool CheckConcealBlockRules( IMyCubeGrid grid, List<IMyPlayer> players )
		{
			List<IMySlimBlock> blocks = new List<IMySlimBlock>( );            

			// Live dangerously
			grid.GetBlocks( blocks, x => x.FatBlock != null );
			//CubeGrids.GetAllConnectedBlocks(_processedGrids, grid, blocks, x => x.FatBlock != null);

			int beaconCount = 0;
			//bool found = false;
			//bool powered = false;
			foreach ( IMySlimBlock block in blocks )
			{
				IMyCubeBlock cubeBlock = block.FatBlock;

				if ( cubeBlock.BlockDefinition.TypeId == typeof( MyObjectBuilder_Beacon ) )
				{
					IMyBeacon beacon = (IMyBeacon)cubeBlock;
					//MyObjectBuilder_Beacon beacon = (MyObjectBuilder_Beacon)cubeBlock.GetObjectBuilderCubeBlock();
					beaconCount++;
					// Keep this return here, as 4 beacons always means true
					if ( beaconCount >= 4 )
					{
						return true;
					}

					if ( !beacon.Enabled )
						continue;

					IMyTerminalBlock terminalBlock = (IMyTerminalBlock)cubeBlock;
					//					Console.WriteLine("Found: {0} {1} {2}", beacon.BroadcastRadius, terminalBlock.IsWorking, terminalBlock.IsFunctional);
					//if (!terminalBlock.IsWorking)
					//{
					//						continue;
					//}

					foreach ( IMyPlayer player in players )
					{
						double distance;
						if ( Entity.GetDistanceBetweenPointAndPlayer( grid.GetPosition( ), player, out distance ) )
						{
							if ( distance < beacon.Radius )
							{
								//								Console.WriteLine("Not concealed due to broadcast radius");
								//found = true;
								//break;
								return true;
							}
						}
					}
				}

				if ( cubeBlock.BlockDefinition.TypeId == typeof( MyObjectBuilder_RadioAntenna ) )
				{
					//MyObjectBuilder_RadioAntenna antenna = (MyObjectBuilder_RadioAntenna)cubeBlock.GetObjectBuilderCubeBlock();
					IMyRadioAntenna antenna = (IMyRadioAntenna)cubeBlock;

					if ( !antenna.Enabled )
						continue;

					IMyTerminalBlock terminalBlock = (IMyTerminalBlock)cubeBlock;
					//if (!terminalBlock.IsWorking)
					//	continue;

					foreach ( IMyPlayer player in players )
					{
						double distance;
						if ( Entity.GetDistanceBetweenPointAndPlayer( grid.GetPosition( ), player, out distance ) )
						{
							if ( distance < antenna.Radius )
							{
								//								Console.WriteLine("Not concealed due to antenna broadcast radius");
								//found = true;
								//break;
								return true;
							}
						}
					}
				}

				if ( cubeBlock.BlockDefinition.TypeId == typeof( MyObjectBuilder_MedicalRoom ) )
				{
					//MyObjectBuilder_MedicalRoom medical = (MyObjectBuilder_MedicalRoom)cubeBlock.GetObjectBuilderCubeBlock();
					IMyMedicalRoom medical = (IMyMedicalRoom)cubeBlock;

					if ( !medical.Enabled )
						continue;

					IMyFunctionalBlock functionalBlock = (IMyFunctionalBlock)cubeBlock;
					//if (!terminalBlock.IsWorking)
					//	continue;

					if ( PluginSettings.Instance.DynamicConcealIncludeMedBays )
					{
						lock ( Online )
						{
							foreach ( ulong connectedPlayer in Online )
							{
								//if (PlayerMap.Instance.GetPlayerIdsFromSteamId(connectedPlayer).Count < 1)
								//continue;

								//long playerId = PlayerMap.Instance.GetPlayerIdsFromSteamId(connectedPlayer).First();
								long playerId = PlayerMap.Instance.GetFastPlayerIdFromSteamId( connectedPlayer );

								if ( functionalBlock.OwnerId == playerId || ( functionalBlock.GetUserRelationToOwner( playerId ) == MyRelationsBetweenPlayerAndBlock.FactionShare ) )
								//if (functionalBlock.Owner == playerId || (functionalBlock.ShareMode == MyOwnershipShareModeEnum.Faction && Player.CheckPlayerSameFaction(functionalBlock.Owner, playerId)))
								//if (medical.HasPlayerAccess(playerId))
								{
									return true;
								}
							}
						}

						/*
						foreach (ulong connectedPlayer in PlayerManager.Instance.ConnectedPlayers)
						{
							//if (PlayerMap.Instance.GetPlayerIdsFromSteamId(connectedPlayer).Count < 1)
								//continue;

							//long playerId = PlayerMap.Instance.GetPlayerIdsFromSteamId(connectedPlayer).First();
							long playerId = PlayerMap.Instance.GetFastPlayerIdFromSteamId(connectedPlayer);
							//if (medical.Owner == playerId || (medical.ShareMode == MyOwnershipShareModeEnum.Faction && Player.CheckPlayerSameFaction(medical.Owner, playerId)))
							if(medical.HasPlayerAccess(playerId))
							{
								return true;
							}
						}
						 */
					}
					else
					{
						return true;
					}
				}

                if ( cubeBlock.BlockDefinition.TypeId == typeof( MyObjectBuilder_CryoChamber ) )
                {
                    MyCryoChamber cryo = (MyCryoChamber)cubeBlock;
                    
                    if ( cryo.Pilot != null )
                        return true;
                }            

                if ( cubeBlock.BlockDefinition.TypeId == typeof( MyObjectBuilder_Refinery ) || cubeBlock.BlockDefinition.TypeId == typeof( MyObjectBuilder_Assembler ) )
				{
					//MyObjectBuilder_ProductionBlock production = (MyObjectBuilder_ProductionBlock)cubeBlock.GetObjectBuilderCubeBlock();
					IMyProductionBlock production = (IMyProductionBlock)cubeBlock;
					if ( !production.Enabled )
						continue;

					if ( production.IsProducing )
						return true;
				}

				foreach ( string subType in PluginSettings.Instance.DynamicConcealIgnoreSubTypeList )
				{
					if ( cubeBlock.BlockDefinition.SubtypeName.Contains( subType ) )
					{
						//						Console.WriteLine("Not concealed due subtype");
						//found = true;
						return true;
					}
				}
			}

			return false;
		}
Пример #10
0
        //this method will look for active ship grids/drones/players and keep killing them untill it cant find any within
        //its local known nearby objects
        public bool FindNearbyAttackTarget()
        {
            //return false;
            FindWeapons();
            ClearTarget();

            Dictionary <IMyEntity, IMyEntity> nearbyDrones      = new Dictionary <IMyEntity, IMyEntity>();
            Dictionary <IMyEntity, IMyEntity> nearbyOnlineShips = new Dictionary <IMyEntity, IMyEntity>();
            List <IMyPlayer> nearbyPlayers = new List <IMyPlayer>();



            MyAPIGateway.Players.GetPlayers(nearbyPlayers);
            nearbyPlayers =
                nearbyPlayers.Where(
                    x => x.PlayerID != _ownerId && (x.GetPosition() - Ship.GetPosition()).Length() < 2000)
                .ToList();

            bool playersNearby = nearbyPlayers.Any();

            Util.GetInstance().Log("[Drone.FindNearbyAttacktarget] enemy players nearby? " + playersNearby);
            for (int i = 0; i < _nearbyFloatingObjects.Count; i++)
            {
                if ((_nearbyFloatingObjects.ToList()[i].GetPosition() - Ship.GetPosition()).Length() > 10)
                {
                    var entity = _nearbyFloatingObjects.ToList()[i];

                    var grid = entity as IMyCubeGrid;
                    if (grid != null)
                    {
                        var gridTerminal = MyAPIGateway.TerminalActionsHelper.GetTerminalSystemForGrid(grid);

                        List <IMyTerminalBlock> val = new List <IMyTerminalBlock>();
                        gridTerminal.GetBlocks(val);
                        var isFriendly = GridFriendly(val);

                        List <IMyTerminalBlock> T = new List <IMyTerminalBlock>();
                        gridTerminal.GetBlocksOfType <IMyRemoteControl>(T);

                        List <IMyTerminalBlock> reactorBlocks = new List <IMyTerminalBlock>();
                        gridTerminal.GetBlocksOfType <IMyPowerProducer>(reactorBlocks);


                        bool isOnline =
                            reactorBlocks.Exists(x => (x.IsWorking) && !isFriendly);

                        bool isDrone =
                            T.Exists(
                                x =>
                                (((IMyRemoteControl)x).CustomName.Contains("Drone#") && x.IsWorking &&
                                 !isFriendly));


                        var droneControl =
                            (IMyEntity)
                            T.FirstOrDefault(
                                x => ((IMyRemoteControl)x).CustomName.Contains("Drone#") && x.IsWorking &&
                                !isFriendly);

                        var shipPower =
                            (IMyEntity)
                            reactorBlocks.FirstOrDefault(
                                x => (((IMyPowerProducer)x).CurrentPowerOutput > 0 && x.IsWorking) && !isFriendly);


                        Util.GetInstance().Log(entity.Name + "   " + isOnline + ":Online " + isDrone + ":Drone " + (shipPower != null) + ":hasPower", "friendly.txt");
                        Util.GetInstance().Log(" ", "friendly.txt");
                        if (isDrone && isOnline)
                        {
                            nearbyDrones.Add(grid, droneControl);
                        }
                        else if (isOnline)
                        {
                            nearbyOnlineShips.Add(grid, shipPower ?? droneControl);
                        }
                    }
                }
            }

            if (nearbyDrones.Count > 0)
            {
                Util.GetInstance().Log("[Drone.FindNearbyAttacktarget] nearby drone count " + nearbyDrones.Count);
                var myTarget =
                    nearbyDrones
                    .OrderBy(x => (x.Key.GetPosition() - Ship.GetPosition()).Length())
                    .ToList();

                if (myTarget.Count > 0)
                {
                    var target = myTarget[0];


                    IMyGridTerminalSystem   gridTerminal = MyAPIGateway.TerminalActionsHelper.GetTerminalSystemForGrid((IMyCubeGrid)target.Key);
                    List <IMyTerminalBlock> T            = new List <IMyTerminalBlock>();
                    gridTerminal.GetBlocks(T);

                    if (T.Count >= _minTargetSize)
                    {
                        _target       = (IMyCubeGrid)target.Key;
                        _targetPlayer = null;
                        try
                        {
                            if (!FindTargetKeyPoint(_target, _target.Physics.LinearVelocity))
                            {
                                OrbitAttackTarget(_target.GetPosition(), _target.Physics.LinearVelocity);
                            }
                            return(true);
                        }
                        catch
                        {
                        }
                    }
                }
            }

            if (nearbyOnlineShips.Count > 0)
            {
                Util.GetInstance().Log("[Drone.FindNearbyAttacktarget] nearby ship count " + nearbyOnlineShips.Count);
                var myTargets =
                    nearbyOnlineShips
                    .OrderBy(x => (x.Key.GetPosition() - Ship.GetPosition()).Length())
                    .ToList();

                foreach (var target in myTargets)
                {
                    IMyGridTerminalSystem   gridTerminal = MyAPIGateway.TerminalActionsHelper.GetTerminalSystemForGrid((IMyCubeGrid)target.Key);
                    List <IMyTerminalBlock> T            = new List <IMyTerminalBlock>();
                    gridTerminal.GetBlocks(T);

                    if (T.Count >= _minTargetSize)
                    {
                        _target       = (IMyCubeGrid)target.Key;
                        _targetPlayer = null;
                        try
                        {
                            FindTargetKeyPoint(_target, _target.Physics.LinearVelocity);

                            return(true);
                        }
                        catch { OrbitAttackTarget(_target.GetPosition(), _target.Physics.LinearVelocity); }
                    }
                }
            }

            //if (playersNearby && nearbyPlayers.Count > 0)
            //{
            //    Util.GetInstance().Log("[Drone.FindNearbyAttacktarget] nearby player count " + nearbyPlayers.Count);
            //    var myTarget = nearbyPlayers.OrderBy(x => ((x).GetPosition() - Ship.GetPosition()).Length()).ToList();

            //    if (myTarget.Count > 0)
            //    {
            //        _target = null;
            //        _targetPlayer = myTarget[0];
            //        OrbitAttackTarget(_targetPlayer.GetPosition(), new Vector3D(0, 0, 0));
            //        return true;
            //    }
            //}
            return(false);
        }
Пример #11
0
 //ship location
 public Vector3D GetPosition()
 {
     return(Ship.GetPosition());
 }