public override MyObjectBuilder_CubeBlock GetObjectBuilderCubeBlock(bool copy = false) { MyObjectBuilder_Beacon objectBuilder = (MyObjectBuilder_Beacon)base.GetObjectBuilderCubeBlock(copy); objectBuilder.BroadcastRadius = m_radioBroadcaster.BroadcastRadius; return(objectBuilder); }
public static void SendClientMessage(ulong steamId, string message) { if (PlayerMap.Instance.GetPlayerIdsFromSteamId(steamId).Count < 1) { Log.Info(string.Format("Unable to locate playerId for user with steamId: {0}", steamId)); return; } CubeGridEntity entity = new CubeGridEntity(new FileInfo(Essentials.PluginPath + "CommRelay.sbc")); long entityId = BaseEntity.GenerateEntityId( ); entity.EntityId = entityId; entity.DisplayName = string.Format("CommRelayOutput{0}", PlayerMap.Instance.GetPlayerIdsFromSteamId(steamId).First( )); entity.PositionAndOrientation = new MyPositionAndOrientation(MathUtility.GenerateRandomEdgeVector(getPos(steamId)), Vector3.Forward, Vector3.Up); foreach (MyObjectBuilder_CubeBlock block in entity.BaseCubeBlocks) { MyObjectBuilder_Beacon beacon = block as MyObjectBuilder_Beacon; if (beacon != null) { beacon.CustomName = message; } } SectorObjectManager.Instance.AddEntity(entity); TimedEntityCleanup.Instance.Add(entityId); }
public BeaconEntity(CubeGridEntity parent, MyObjectBuilder_Beacon definition, Object backingObject) : base(parent, definition, backingObject) { Object internalRadioManager = InternalGetRadioManager( ); m_radioManager = new RadioManager(internalRadioManager); }
public override MyObjectBuilder_CubeBlock GetObjectBuilderCubeBlock(bool copy = false) { MyObjectBuilder_Beacon objectBuilderCubeBlock = (MyObjectBuilder_Beacon)base.GetObjectBuilderCubeBlock(copy); objectBuilderCubeBlock.HudText = this.HudText.ToString(); objectBuilderCubeBlock.BroadcastRadius = this.RadioBroadcaster.BroadcastRadius; return(objectBuilderCubeBlock); }
public override void Init(MyObjectBuilder_CubeBlock objectBuilder, MyCubeGrid cubeGrid) { MyBeaconDefinition blockDefinition = base.BlockDefinition as MyBeaconDefinition; if (blockDefinition.EmissiveColorPreset == MyStringHash.NullOrEmpty) { blockDefinition.EmissiveColorPreset = MyStringHash.GetOrCompute("Beacon"); } MyResourceSinkComponent component = new MyResourceSinkComponent(1); component.Init(MyStringHash.GetOrCompute(blockDefinition.ResourceSinkGroup), 0.02f, new Func <float>(this.UpdatePowerInput)); base.ResourceSink = component; this.RadioBroadcaster = new MyRadioBroadcaster(blockDefinition.MaxBroadcastRadius / 10f); MyObjectBuilder_Beacon beacon = (MyObjectBuilder_Beacon)objectBuilder; if (beacon.BroadcastRadius > 0f) { this.RadioBroadcaster.BroadcastRadius = beacon.BroadcastRadius; } this.RadioBroadcaster.BroadcastRadius = MathHelper.Clamp(this.RadioBroadcaster.BroadcastRadius, 1f, blockDefinition.MaxBroadcastRadius); this.HudText.Clear(); if (beacon.HudText != null) { this.HudText.Append(beacon.HudText); } base.Init(objectBuilder, cubeGrid); component.IsPoweredChanged += new Action(this.Receiver_IsPoweredChanged); component.Update(); MyRadioBroadcaster radioBroadcaster = this.RadioBroadcaster; radioBroadcaster.OnBroadcastRadiusChanged = (Action)Delegate.Combine(radioBroadcaster.OnBroadcastRadiusChanged, new Action(this.OnBroadcastRadiusChanged)); this.m_largeLight = cubeGrid.GridSizeEnum == MyCubeSize.Large; this.m_light = MyLights.AddLight(); if (this.m_light != null) { this.m_light.Start(this.DisplayNameText); this.m_light.Range = this.m_largeLight ? 2f : 0.3f; this.m_light.GlareOn = false; this.m_light.GlareQuerySize = this.m_largeLight ? 1.5f : 0.3f; this.m_light.GlareQueryShift = this.m_largeLight ? 1f : 0.2f; this.m_light.GlareType = MyGlareTypeEnum.Normal; this.m_light.GlareMaxDistance = GLARE_MAX_DISTANCE; MyDefinitionId id = new MyDefinitionId(typeof(MyObjectBuilder_FlareDefinition), blockDefinition.Flare); MyFlareDefinition definition = MyDefinitionManager.Static.GetDefinition(id) as MyFlareDefinition; this.m_flare = definition ?? new MyFlareDefinition(); this.m_light.GlareIntensity = this.m_flare.Intensity; this.m_light.GlareSize = this.m_flare.Size; this.m_light.SubGlares = this.m_flare.SubGlares; } this.m_lightPositionOffset = this.m_largeLight ? new Vector3(0f, base.CubeGrid.GridSize * 0.3f, 0f) : Vector3.Zero; this.UpdateLightPosition(); this.m_restartTimeMeasure = false; this.AnimationRunning = true; base.SlimBlock.ComponentStack.IsFunctionalChanged += new Action(this.ComponentStack_IsFunctionalChanged); base.IsWorkingChanged += new Action <MyCubeBlock>(this.MyBeacon_IsWorkingChanged); base.ShowOnHUD = false; this.UpdateText(); }
private static long BeaconValue(IMyCubeBlock block) //Returns the points value of specified beacon. { MyObjectBuilder_CubeBlock cube = block.GetObjectBuilderCubeBlock(); if (cube is MyObjectBuilder_Beacon) { MyObjectBuilder_Beacon beaconval = (MyObjectBuilder_Beacon)cube; float radius = beaconval.BroadcastRadius; return(Convert.ToInt64(Math.Floor(Convert.ToDouble(radius / 5000)))); } return(0); }
private void ExtractCommandFromEntity(IMyEntity entity) { IMyCubeGrid grid = (IMyCubeGrid)entity; MyObjectBuilder_CubeGrid gridBuilder = CubeGrids.SafeGetObjectBuilder(grid); if (gridBuilder == null) { return; } string command = string.Empty; foreach (MyObjectBuilder_CubeBlock block in gridBuilder.CubeBlocks) { MyObjectBuilder_Beacon beacon = block as MyObjectBuilder_Beacon; if (beacon != null) { command = beacon.CustomName; break; } } string player = entity.DisplayName.Replace("CommRelay", string.Empty); long playerId = long.Parse(player); ulong steamId = PlayerMap.Instance.GetSteamIdFromPlayerId(playerId); Wrapper.GameAction(() => { entity.DisplayName = string.Empty; BaseEntityNetworkManager.BroadcastRemoveEntity(entity, false); }); Essentials.Log.Info("COMMAND {1} - {2}: {0}", command, playerId, entity.EntityId); if (!m_processedRelays.Contains(entity.EntityId)) { m_processedRelays.Add(entity.EntityId); Essentials.Instance.HandleChatMessage(steamId, command); } else { Essentials.Log.Info("Ignoring repeat beacon: {0}"); } }
private static Boolean TestBeacon(IMyCubeBlock block) { MyObjectBuilder_CubeBlock cube = block.GetObjectBuilderCubeBlock(); if (cube is MyObjectBuilder_Beacon) { MyObjectBuilder_Beacon beacontest = (MyObjectBuilder_Beacon)cube; bool enabled = block.IsWorking; float radius = beacontest.BroadcastRadius; if (radius > 4999 && enabled) { return(true); } else { return(false); } } return(false); }
public static void SendBroadcastMessage(string message) { CubeGridEntity entity = new CubeGridEntity(new FileInfo(Essentials.PluginPath + "CommRelay.sbc")); long entityId = BaseEntity.GenerateEntityId( ); entity.EntityId = entityId; entity.DisplayName = string.Format("CommRelayBroadcast{0}", m_random.Next(1, 10000)); entity.PositionAndOrientation = new MyPositionAndOrientation(MathUtility.GenerateRandomEdgeVector(), Vector3.Forward, Vector3.Up); foreach (MyObjectBuilder_CubeBlock block in entity.BaseCubeBlocks) { MyObjectBuilder_Beacon beacon = block as MyObjectBuilder_Beacon; if (beacon != null) { beacon.CustomName = message; } } SectorObjectManager.Instance.AddEntity(entity); TimedEntityCleanup.Instance.Add(entityId); }
private void AddGlobalRelay() { CubeGridEntity entity = new CubeGridEntity(new FileInfo(Essentials.PluginPath + "CommRelay.sbc")); entity.EntityId = BaseEntity.GenerateEntityId(); entity.DisplayName = "CommRelayGlobal"; ApplicationLog.BaseLog.Debug("Attempting to place global relay"); entity.PositionAndOrientation = new MyPositionAndOrientation(MathUtility.GenerateRandomEdgeVector(), Vector3.Forward, Vector3.Up); List <string> commands = new List <string>(); // Give a list of commands foreach (ChatHandlerBase chatBase in Essentials.ChatHandlers) { if (chatBase.GetMultipleCommandText().Length > 0) { foreach (string cmd in chatBase.GetMultipleCommandText()) { string[] command = cmd.Split(new char[] { ' ' }, 2); if (!commands.Contains(command[0])) { commands.Add(command[0]); } } } else { string[] command = chatBase.GetCommandText().Split(new char[] { ' ' }, 2); if (!commands.Contains(command[0])) { commands.Add(command[0]); } } } string finalText = ""; foreach (string command in commands) { if (finalText != "") { finalText += "\n"; } finalText += command; } finalText += "\n/help"; if (PluginSettings.Instance.ServerName != "") { finalText += "\n" + "servername:" + PluginSettings.Instance.ServerName; } foreach (MyObjectBuilder_CubeBlock block in entity.BaseCubeBlocks) { MyObjectBuilder_Beacon beacon = block as MyObjectBuilder_Beacon; if (beacon != null) { beacon.CustomName = finalText; } } SectorObjectManager.Instance.AddEntity(entity); }
public void SpawnCargoShipGroup(Vector3 startPosition, Vector3 stopPosition, ulong remoteUserId = 0) { try { //Calculate lowest and highest frequencies double lowestFrequency = double.MaxValue; double highestFrequency = 0d; foreach (MySpawnGroupDefinition entry in MyDefinitionManager.Static.GetSpawnGroupDefinitions( )) { if (entry.Frequency < lowestFrequency) { lowestFrequency = entry.Frequency; } if (entry.Frequency > highestFrequency) { highestFrequency = entry.Frequency; } } if (lowestFrequency <= 0d) { lowestFrequency = 1d; } //Get a list of which groups *could* spawn Random random = new Random( ); double randomChance = random.NextDouble( ); randomChance = randomChance * (highestFrequency / lowestFrequency); List <MySpawnGroupDefinition> possibleGroups = MyDefinitionManager.Static.GetSpawnGroupDefinitions( ).Where(entry => entry.Frequency >= randomChance).ToList( ); //Determine which group *will* spawn randomChance = random.NextDouble( ); int randomShipIndex = Math.Max(0, Math.Min((int)Math.Round(randomChance * possibleGroups.Count, 0), possibleGroups.Count - 1)); MySpawnGroupDefinition randomSpawnGroup = possibleGroups[randomShipIndex]; ChatManager.Instance.SendPrivateChatMessage(remoteUserId, string.Format("Spawning cargo group '{0}' ...", randomSpawnGroup.DisplayNameText)); //Spawn the ships in the group Matrix orientation = Matrix.CreateLookAt(startPosition, stopPosition, new Vector3(0, 1, 0)); foreach (MySpawnGroupDefinition.SpawnGroupPrefab entry in randomSpawnGroup.Prefabs) { MyPrefabDefinition matchedPrefab = MyDefinitionManager.Static.GetPrefabDefinitions( ).Select(prefabEntry => prefabEntry.Value).FirstOrDefault(prefabDefinition => prefabDefinition.Id.SubtypeId.ToString( ) == entry.SubtypeId); if (matchedPrefab == null) { continue; } foreach (MyObjectBuilder_CubeGrid objectBuilder in matchedPrefab.CubeGrids) { //Create the ship CubeGridEntity cubeGrid = new CubeGridEntity(objectBuilder); //Set the ship position and orientation Vector3 shipPosition = Vector3.Transform(entry.Position, orientation) + startPosition; orientation.Translation = shipPosition; MyPositionAndOrientation newPositionOrientation = new MyPositionAndOrientation(orientation); cubeGrid.PositionAndOrientation = newPositionOrientation; //Set the ship velocity //Speed is clamped between 1.0f and the max cube grid speed Vector3 travelVector = stopPosition - startPosition; travelVector.Normalize( ); Vector3 shipVelocity = travelVector * Math.Min(cubeGrid.MaxLinearVelocity, Math.Max(1.0f, entry.Speed)); cubeGrid.LinearVelocity = shipVelocity; //cubeGrid.IsDampenersEnabled = false; foreach (MyObjectBuilder_CubeBlock cubeBlock in cubeGrid.BaseCubeBlocks) { //Set the beacon names MyObjectBuilder_Beacon beacon = cubeBlock as MyObjectBuilder_Beacon; if (beacon != null) { beacon.CustomName = entry.BeaconText; } //Set the owner of every block //TODO - Find out if setting to an arbitrary non-zero works for this //cubeBlock.Owner = PlayerMap.Instance.GetServerVirtualPlayerId(); cubeBlock.Owner = 0; cubeBlock.ShareMode = MyOwnershipShareModeEnum.Faction; } //And add the ship to the world SectorObjectManager.Instance.AddEntity(cubeGrid); } } ChatManager.Instance.SendPrivateChatMessage(remoteUserId, string.Format("Cargo group '{0}' spawned with {1} ships at {2}", randomSpawnGroup.DisplayNameText, randomSpawnGroup.Prefabs.Count, startPosition)); } catch (ArgumentOutOfRangeException ex) { ApplicationLog.BaseLog.Error(ex); } catch (ArgumentNullException ex) { ApplicationLog.BaseLog.Error(ex); } catch (FormatException ex) { ApplicationLog.BaseLog.Error(ex); } catch (Exception ex) { ApplicationLog.BaseLog.Error(ex); } }
public void SpawnCargoShipGroup(Vector3 startPosition, Vector3 stopPosition, ulong remoteUserId = 0) { try { //Load the spawn groups SpawnGroupsDefinitionsManager spawnGroupsDefinitionsManager = new SpawnGroupsDefinitionsManager(); FileInfo contentDataFile = new FileInfo(Path.Combine(MyFileSystem.ContentPath, "Data", "SpawnGroups.sbc")); spawnGroupsDefinitionsManager.Load(contentDataFile); //Calculate lowest and highest frequencies float lowestFrequency = 999999; float highestFrequency = 0; foreach (SpawnGroupDefinition entry in spawnGroupsDefinitionsManager.Definitions) { if (entry.Frequency < lowestFrequency) { lowestFrequency = entry.Frequency; } if (entry.Frequency > highestFrequency) { highestFrequency = entry.Frequency; } } if (lowestFrequency <= 0) { lowestFrequency = 1; } //Get a list of which groups *could* spawn Random random = new Random((int)DateTime.Now.ToBinary()); double randomChance = random.NextDouble(); randomChance = randomChance * (highestFrequency / lowestFrequency); List <SpawnGroupDefinition> possibleGroups = new List <SpawnGroupDefinition>(); foreach (SpawnGroupDefinition entry in spawnGroupsDefinitionsManager.Definitions) { if (entry.Frequency >= randomChance) { possibleGroups.Add(entry); } } //Determine which group *will* spawn randomChance = random.NextDouble(); int randomShipIndex = Math.Max(0, Math.Min((int)Math.Round(randomChance * possibleGroups.Count, 0), possibleGroups.Count - 1)); SpawnGroupDefinition randomSpawnGroup = possibleGroups[randomShipIndex]; ChatManager.Instance.SendPrivateChatMessage(remoteUserId, "Spawning cargo group '" + randomSpawnGroup.Name + "' ..."); //Spawn the ships in the group Matrix orientation = Matrix.CreateLookAt(startPosition, stopPosition, new Vector3(0, 1, 0)); foreach (SpawnGroupPrefab entry in randomSpawnGroup.Prefabs) { FileInfo prefabFile = new FileInfo(Path.Combine(MyFileSystem.ContentPath, "Data", "Prefabs", entry.File + ".sbc")); if (!prefabFile.Exists) { continue; } //Create the ship CubeGridEntity cubeGrid = new CubeGridEntity(prefabFile); //Set the ship position and orientation Vector3 shipPosition = Vector3.Transform(entry.Position, orientation) + startPosition; orientation.Translation = shipPosition; MyPositionAndOrientation newPositionOrientation = new MyPositionAndOrientation(orientation); cubeGrid.PositionAndOrientation = newPositionOrientation; //Set the ship velocity //Speed is clamped between 1.0f and the max cube grid speed Vector3 travelVector = stopPosition - startPosition; travelVector.Normalize(); Vector3 shipVelocity = travelVector * (float)Math.Min(cubeGrid.MaxLinearVelocity, Math.Max(1.0f, entry.Speed)); cubeGrid.LinearVelocity = shipVelocity; cubeGrid.IsDampenersEnabled = false; foreach (MyObjectBuilder_CubeBlock cubeBlock in cubeGrid.BaseCubeBlocks) { //Set the beacon names if (cubeBlock.TypeId == typeof(MyObjectBuilder_Beacon)) { MyObjectBuilder_Beacon beacon = (MyObjectBuilder_Beacon)cubeBlock; beacon.CustomName = entry.BeaconText; } //Set the owner of every block //TODO - Find out if setting to an arbitrary non-zero works for this cubeBlock.Owner = PlayerMap.Instance.GetServerVirtualPlayerId(); cubeBlock.ShareMode = MyOwnershipShareModeEnum.Faction; } //And add the ship to the world SectorObjectManager.Instance.AddEntity(cubeGrid); //Force a refresh of the cube grid List <CubeBlockEntity> cubeBlocks = cubeGrid.CubeBlocks; } ChatManager.Instance.SendPrivateChatMessage(remoteUserId, "Cargo group '" + randomSpawnGroup.DisplayName + "' spawned with " + randomSpawnGroup.Prefabs.Length.ToString() + " ships at " + startPosition.ToString()); } catch (Exception ex) { LogManager.ErrorLog.WriteLine(ex); } }
public BeaconEntity(CubeGridEntity parent, MyObjectBuilder_Beacon definition) : base(parent, definition) { }
public void SpawnCargoShipGroup(Vector3 startPosition, Vector3 stopPosition, ulong remoteUserId = 0) { try { //Calculate lowest and highest frequencies float lowestFrequency = 999999; float highestFrequency = 0; foreach (MySpawnGroupDefinition entry in MyDefinitionManager.Static.GetSpawnGroupDefinitions()) { if (entry.Frequency < lowestFrequency) { lowestFrequency = entry.Frequency; } if (entry.Frequency > highestFrequency) { highestFrequency = entry.Frequency; } } if (lowestFrequency <= 0) { lowestFrequency = 1; } //Get a list of which groups *could* spawn Random random = new Random((int)DateTime.Now.ToBinary()); double randomChance = random.NextDouble(); randomChance = randomChance * (highestFrequency / lowestFrequency); List <MySpawnGroupDefinition> possibleGroups = new List <MySpawnGroupDefinition>(); foreach (MySpawnGroupDefinition entry in MyDefinitionManager.Static.GetSpawnGroupDefinitions()) { if (entry.Frequency >= randomChance) { possibleGroups.Add(entry); } } //Determine which group *will* spawn randomChance = random.NextDouble(); int randomShipIndex = Math.Max(0, Math.Min((int)Math.Round(randomChance * possibleGroups.Count, 0), possibleGroups.Count - 1)); MySpawnGroupDefinition randomSpawnGroup = possibleGroups[randomShipIndex]; ChatManager.Instance.SendPrivateChatMessage(remoteUserId, "Spawning cargo group '" + randomSpawnGroup.DisplayNameText.ToString() + "' ..."); //Spawn the ships in the group Matrix orientation = Matrix.CreateLookAt(startPosition, stopPosition, new Vector3(0, 1, 0)); foreach (MySpawnGroupDefinition.SpawnGroupPrefab entry in randomSpawnGroup.Prefabs) { MyPrefabDefinition matchedPrefab = null; foreach (var prefabEntry in MyDefinitionManager.Static.GetPrefabDefinitions()) { MyPrefabDefinition prefabDefinition = prefabEntry.Value; if (prefabDefinition.Id.SubtypeId.ToString() == entry.SubtypeId) { matchedPrefab = prefabDefinition; break; } } if (matchedPrefab == null) { continue; } //TODO - Build this to iterate through all cube grids in the prefab MyObjectBuilder_CubeGrid objectBuilder = matchedPrefab.CubeGrids[0]; //Create the ship CubeGridEntity cubeGrid = new CubeGridEntity(objectBuilder); //Set the ship position and orientation Vector3 shipPosition = Vector3.Transform(entry.Position, orientation) + startPosition; orientation.Translation = shipPosition; MyPositionAndOrientation newPositionOrientation = new MyPositionAndOrientation(orientation); cubeGrid.PositionAndOrientation = newPositionOrientation; //Set the ship velocity //Speed is clamped between 1.0f and the max cube grid speed Vector3 travelVector = stopPosition - startPosition; travelVector.Normalize(); Vector3 shipVelocity = travelVector * (float)Math.Min(cubeGrid.MaxLinearVelocity, Math.Max(1.0f, entry.Speed)); cubeGrid.LinearVelocity = shipVelocity; cubeGrid.IsDampenersEnabled = false; foreach (MyObjectBuilder_CubeBlock cubeBlock in cubeGrid.BaseCubeBlocks) { //Set the beacon names if (cubeBlock.TypeId == typeof(MyObjectBuilder_Beacon)) { MyObjectBuilder_Beacon beacon = (MyObjectBuilder_Beacon)cubeBlock; beacon.CustomName = entry.BeaconText; } //Set the owner of every block //TODO - Find out if setting to an arbitrary non-zero works for this //cubeBlock.Owner = PlayerMap.Instance.GetServerVirtualPlayerId(); cubeBlock.Owner = 0; cubeBlock.ShareMode = MyOwnershipShareModeEnum.Faction; } //And add the ship to the world SectorObjectManager.Instance.AddEntity(cubeGrid); } ChatManager.Instance.SendPrivateChatMessage(remoteUserId, "Cargo group '" + randomSpawnGroup.DisplayNameText.ToString() + "' spawned with " + randomSpawnGroup.Prefabs.Count.ToString() + " ships at " + startPosition.ToString()); } catch (Exception ex) { LogManager.ErrorLog.WriteLine(ex); } }