private static bool CheckRevealMedbay(IMyCubeGrid grid, ulong steamId) { // Live dangerously List <IMySlimBlock> blocks = new List <IMySlimBlock>(); grid.GetBlocks(blocks, x => x.FatBlock != null); foreach (IMySlimBlock block in blocks) { IMyCubeBlock cubeBlock = block.FatBlock; if (cubeBlock.BlockDefinition.TypeId == typeof(MyObjectBuilder_MedicalRoom)) { Sandbox.ModAPI.Ingame.IMyMedicalRoom medical = (Sandbox.ModAPI.Ingame.IMyMedicalRoom)cubeBlock; if (!medical.Enabled) { continue; } long playerId = PlayerMap.Instance.GetFastPlayerIdFromSteamId(steamId); //if (medical.Owner == playerId || (medical.ShareMode == MyOwnershipShareModeEnum.Faction && Player.CheckPlayerSameFaction(medical.Owner, playerId))) if (medical.HasPlayerAccess(playerId)) { 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(m_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(); Sandbox.ModAPI.Ingame.IMyBeacon beacon = (Sandbox.ModAPI.Ingame.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(); Sandbox.ModAPI.Ingame.IMyRadioAntenna antenna = (Sandbox.ModAPI.Ingame.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(); Sandbox.ModAPI.Ingame.IMyMedicalRoom medical = (Sandbox.ModAPI.Ingame.IMyMedicalRoom)cubeBlock; if (!medical.Enabled) { continue; } Sandbox.ModAPI.Ingame.IMyFunctionalBlock functionalBlock = (Sandbox.ModAPI.Ingame.IMyFunctionalBlock)cubeBlock; if (!functionalBlock.IsFunctional) { continue; } //if (!functionalBlock.Enabled) // continue; if (PluginSettings.Instance.DynamicConcealIncludeMedBays) { lock (m_online) { foreach (ulong connectedPlayer in m_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) == Sandbox.Common.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; } Sandbox.ModAPI.Ingame.IMyProductionBlock productionBlock = (Sandbox.ModAPI.Ingame.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(m_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)) { Sandbox.ModAPI.Ingame.IMyBeacon beacon = (Sandbox.ModAPI.Ingame.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; } Sandbox.ModAPI.Ingame.IMyTerminalBlock terminalBlock = (Sandbox.ModAPI.Ingame.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(); Sandbox.ModAPI.Ingame.IMyRadioAntenna antenna = (Sandbox.ModAPI.Ingame.IMyRadioAntenna)cubeBlock; if (!antenna.Enabled) { continue; } Sandbox.ModAPI.Ingame.IMyTerminalBlock terminalBlock = (Sandbox.ModAPI.Ingame.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(); Sandbox.ModAPI.Ingame.IMyMedicalRoom medical = (Sandbox.ModAPI.Ingame.IMyMedicalRoom)cubeBlock; if (!medical.Enabled) { continue; } Sandbox.ModAPI.Ingame.IMyFunctionalBlock functionalBlock = (Sandbox.ModAPI.Ingame.IMyFunctionalBlock)cubeBlock; //if (!terminalBlock.IsWorking) // continue; if (PluginSettings.Instance.DynamicConcealIncludeMedBays) { lock (m_online) { foreach (ulong connectedPlayer in m_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) == Sandbox.Common.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(); Sandbox.ModAPI.Ingame.IMyProductionBlock production = (Sandbox.ModAPI.Ingame.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); }