Files
tbd-station-14/Content.Server/GameObjects/Components/Markers/ConditionalSpawnerComponent.cs
ShadowCommander 7a842f7c22 Fix tests (#3707)
* First pass

* Fix access and rename banananium to bananium

* Fix captialization of CookTimeInfoLabel

* Fix InteractUsing calls

* Remove unused [Dependency]

* Replace obsolete references to Anchored with BodyType

* Assign default value to shoving someone in disposals

* Fix naming

* Replace Initialize TryGetComponents with EnsureComponent

* Rework AnchorableComponent

* Fix singularity component

* Replace obsolete usages of Angle.South

* Fix efcore warning

* Fix container tests

* Fix DebugPressurePump invalid PressurePump yaml

* Fix getting pathfinding region of grid 0

* Fix atmos plaque missing layer and add info message when it happens

* Fix AiSteeringSystem steering in an invalid grid in entity test

* Make content able to choose which log level leads to test failures

* Revert container test fix for Acruid

* Fix sprite, pipe and saving errors
Make EntityTest print all errors instead of stopping on the first

* Reorder singularity visualizer

* Disable pvs for container occlusion adn simple predict reconcile, they use entities other than map ones

Co-authored-by: Metal Gear Sloth <metalgearsloth@gmail.com>
Co-authored-by: DrSmugleaf <DrSmugleaf@users.noreply.github.com>
Co-authored-by: metalgearsloth <comedian_vs_clown@hotmail.com>
2021-03-31 21:41:23 +02:00

79 lines
2.2 KiB
C#

using System.Collections.Generic;
using Content.Server.GameTicking;
using Content.Server.Interfaces.GameTicking;
using Robust.Shared.GameObjects;
using Robust.Shared.IoC;
using Robust.Shared.Log;
using Robust.Shared.Random;
using Robust.Shared.Reflection;
using Robust.Shared.Serialization.Manager.Attributes;
using Robust.Shared.ViewVariables;
namespace Content.Server.GameObjects.Components.Markers
{
[RegisterComponent]
public class ConditionalSpawnerComponent : Component, IMapInit
{
[Dependency] private readonly IGameTicker _gameTicker = default!;
[Dependency] private readonly IRobustRandom _robustRandom = default!;
public override string Name => "ConditionalSpawner";
[ViewVariables(VVAccess.ReadWrite)]
[DataField("prototypes")]
public List<string> Prototypes { get; set; } = new();
[ViewVariables(VVAccess.ReadWrite)]
[DataField("gameRules")]
private readonly List<string> _gameRules = new();
[ViewVariables(VVAccess.ReadWrite)]
[DataField("chance")]
public float Chance { get; set; } = 1.0f;
private void RuleAdded(GameRuleAddedEventArgs obj)
{
if(_gameRules.Contains(obj.GameRule.GetType().Name))
Spawn();
}
private void TrySpawn()
{
if (_gameRules.Count == 0)
{
Spawn();
return;
}
foreach (var rule in _gameRules)
{
if (!_gameTicker.HasGameRule(rule)) continue;
Spawn();
return;
}
}
public virtual void Spawn()
{
if (Chance != 1.0f && !_robustRandom.Prob(Chance))
return;
if (Prototypes.Count == 0)
{
Logger.Warning($"Prototype list in ConditionalSpawnComponent is empty! Entity: {Owner}");
return;
}
if(!Owner.Deleted)
Owner.EntityManager.SpawnEntity(_robustRandom.Pick(Prototypes), Owner.Transform.Coordinates);
}
public virtual void MapInit()
{
_gameTicker.OnRuleAdded += RuleAdded;
TrySpawn();
}
}
}