From 4dcbf28714f994c749d4e931afb1e3e99058bc31 Mon Sep 17 00:00:00 2001 From: DamianX Date: Sat, 17 Aug 2019 21:09:09 +0200 Subject: [PATCH] IoC'd random (#302) * Implemented RobustRandom * update submodule * update submodule * Fix benchmark --- Content.Benchmarks/ColorInterpolateBenchmark.cs | 3 +++ .../GameObjects/Components/Sound/SoundComponent.cs | 8 +++++--- Content.Client/Parallax/ParallaxGenerator.cs | 1 + .../Construction/ConstructionComponent.cs | 10 ++++++---- .../Components/Damage/BreakableComponent.cs | 4 +++- .../Components/Damage/DestructibleComponent.cs | 6 ++++-- .../Components/Explosion/ExplosiveComponent.cs | 7 +++++-- .../GameObjects/Components/Items/DiceComponent.cs | 10 +++------- .../Items/Storage/Fill/ToolLockerFillComponent.cs | 4 +++- .../Storage/Fill/ToolboxElectricalFillComponent.cs | 4 +++- .../Components/Items/Storage/ItemComponent.cs | 9 ++++++++- .../Movement/ServerTeleporterComponent.cs | 5 ++--- .../Components/Sound/FootstepModifierComponent.cs | 10 +++------- .../Projectile/BallisticMagazineWeaponComponent.cs | 9 ++++++--- .../Weapon/Ranged/Projectile/ProjectileWeapon.cs | 8 +++++--- .../GameObjects/EntitySystems/MoverSystem.cs | 13 +++++++------ Content.Server/GameTicking/GameTicker.cs | 7 ++++--- 17 files changed, 71 insertions(+), 47 deletions(-) diff --git a/Content.Benchmarks/ColorInterpolateBenchmark.cs b/Content.Benchmarks/ColorInterpolateBenchmark.cs index aaa172f0aa..f45b91363d 100644 --- a/Content.Benchmarks/ColorInterpolateBenchmark.cs +++ b/Content.Benchmarks/ColorInterpolateBenchmark.cs @@ -5,7 +5,10 @@ using System.Runtime.Intrinsics; using System.Runtime.Intrinsics.X86; #endif using BenchmarkDotNet.Attributes; +using Robust.Shared.Interfaces.Random; +using Robust.Shared.IoC; using Robust.Shared.Maths; +using Robust.Shared.Random; using SysVector4 = System.Numerics.Vector4; namespace Content.Benchmarks diff --git a/Content.Client/GameObjects/Components/Sound/SoundComponent.cs b/Content.Client/GameObjects/Components/Sound/SoundComponent.cs index cfed2998ee..9b46924eb0 100644 --- a/Content.Client/GameObjects/Components/Sound/SoundComponent.cs +++ b/Content.Client/GameObjects/Components/Sound/SoundComponent.cs @@ -5,6 +5,7 @@ using Robust.Client.GameObjects.EntitySystems; using Robust.Shared.GameObjects; using Robust.Shared.Interfaces.GameObjects; using Robust.Shared.Interfaces.Network; +using Robust.Shared.Interfaces.Random; using Robust.Shared.IoC; using Robust.Shared.Serialization; using Robust.Shared.Timers; @@ -16,7 +17,9 @@ namespace Content.Client.GameObjects.Components.Sound { private readonly List _schedules = new List(); private AudioSystem _audioSystem; - private Random Random; + #pragma warning disable 649 + [Dependency] private readonly IRobustRandom _random; + #pragma warning restore 649 public override void StopAllSounds() { @@ -46,9 +49,8 @@ namespace Content.Client.GameObjects.Components.Sound public void Play(ScheduledSound schedule) { if (!schedule.Play) return; - if (Random == null) Random = new Random(Owner.Uid.GetHashCode() ^ DateTime.Now.GetHashCode()); - Timer.Spawn((int) schedule.Delay + (Random.Next((int) schedule.RandomDelay)),() => + Timer.Spawn((int) schedule.Delay + (_random.Next((int) schedule.RandomDelay)),() => { if (!schedule.Play) return; // We make sure this hasn't changed. if (_audioSystem == null) _audioSystem = IoCManager.Resolve().GetEntitySystem(); diff --git a/Content.Client/Parallax/ParallaxGenerator.cs b/Content.Client/Parallax/ParallaxGenerator.cs index a42cf44a04..98823fc160 100644 --- a/Content.Client/Parallax/ParallaxGenerator.cs +++ b/Content.Client/Parallax/ParallaxGenerator.cs @@ -10,6 +10,7 @@ using Robust.Client.Utility; using Robust.Shared.Interfaces.Log; using Robust.Shared.Maths; using Robust.Shared.Noise; +using Robust.Shared.Random; using SixLabors.ImageSharp.Advanced; using BlendFactor = Robust.Shared.Maths.Color.BlendFactor; diff --git a/Content.Server/GameObjects/Components/Construction/ConstructionComponent.cs b/Content.Server/GameObjects/Components/Construction/ConstructionComponent.cs index 86e64d2b5c..c7783a2c29 100644 --- a/Content.Server/GameObjects/Components/Construction/ConstructionComponent.cs +++ b/Content.Server/GameObjects/Components/Construction/ConstructionComponent.cs @@ -10,6 +10,7 @@ using Robust.Server.Interfaces.GameObjects; using Robust.Shared.GameObjects; using Robust.Shared.Interfaces.GameObjects; using Robust.Shared.Interfaces.GameObjects.Components; +using Robust.Shared.Interfaces.Random; using Robust.Shared.IoC; using Robust.Shared.ViewVariables; using static Content.Shared.Construction.ConstructionStepMaterial; @@ -29,7 +30,9 @@ namespace Content.Server.GameObjects.Components.Construction SpriteComponent Sprite; ITransformComponent Transform; - Random random; + #pragma warning disable 649 + [Dependency] private IRobustRandom _random; + #pragma warning restore 649 public override void Initialize() { @@ -38,7 +41,6 @@ namespace Content.Server.GameObjects.Components.Construction Sprite = Owner.GetComponent(); Transform = Owner.GetComponent(); var systemman = IoCManager.Resolve(); - random = new Random(); } public bool AttackBy(AttackByEventArgs eventArgs) @@ -127,7 +129,7 @@ namespace Content.Server.GameObjects.Components.Construction case ToolType.Welder: if (slapped.TryGetComponent(out WelderComponent welder) && welder.TryUse(toolStep.Amount)) { - if (random.NextDouble() > 0.5) + if (_random.NextDouble() > 0.5) sound.Play("/Audio/items/welder.ogg", Transform.GridPosition); else sound.Play("/Audio/items/welder2.ogg", Transform.GridPosition); @@ -144,7 +146,7 @@ namespace Content.Server.GameObjects.Components.Construction case ToolType.Screwdriver: if (slapped.HasComponent()) { - if (random.NextDouble() > 0.5) + if (_random.NextDouble() > 0.5) sound.Play("/Audio/items/screwdriver.ogg", Transform.GridPosition); else sound.Play("/Audio/items/screwdriver2.ogg", Transform.GridPosition); diff --git a/Content.Server/GameObjects/Components/Damage/BreakableComponent.cs b/Content.Server/GameObjects/Components/Damage/BreakableComponent.cs index 1f1a87d427..56c44178b8 100644 --- a/Content.Server/GameObjects/Components/Damage/BreakableComponent.cs +++ b/Content.Server/GameObjects/Components/Damage/BreakableComponent.cs @@ -5,8 +5,10 @@ using Content.Server.Interfaces; using Content.Shared.GameObjects; using Robust.Shared.GameObjects; using Robust.Shared.Interfaces.GameObjects; +using Robust.Shared.Interfaces.Random; using Robust.Shared.IoC; using Robust.Shared.Maths; +using Robust.Shared.Random; using Robust.Shared.Serialization; namespace Content.Server.GameObjects.Components.Damage @@ -59,7 +61,7 @@ namespace Content.Server.GameObjects.Components.Damage public void OnExplosion(ExplosionEventArgs eventArgs) { - var prob = new Random(); + var prob = IoCManager.Resolve(); switch (eventArgs.Severity) { case ExplosionSeverity.Destruction: diff --git a/Content.Server/GameObjects/Components/Damage/DestructibleComponent.cs b/Content.Server/GameObjects/Components/Damage/DestructibleComponent.cs index d5efd91802..492d4deeb0 100644 --- a/Content.Server/GameObjects/Components/Damage/DestructibleComponent.cs +++ b/Content.Server/GameObjects/Components/Damage/DestructibleComponent.cs @@ -5,8 +5,10 @@ using Content.Server.Interfaces; using Content.Shared.GameObjects; using Robust.Shared.GameObjects; using Robust.Shared.Interfaces.GameObjects; +using Robust.Shared.Interfaces.Random; using Robust.Shared.IoC; using Robust.Shared.Maths; +using Robust.Shared.Random; using Robust.Shared.Serialization; using Robust.Shared.ViewVariables; @@ -74,7 +76,7 @@ namespace Content.Server.GameObjects.Components.Destructible void IExAct.OnExplosion(ExplosionEventArgs eventArgs) { - var prob = new Random(); + var prob = IoCManager.Resolve(); switch (eventArgs.Severity) { case ExplosionSeverity.Destruction: @@ -84,7 +86,7 @@ namespace Content.Server.GameObjects.Components.Destructible _actSystem.HandleDestruction(Owner, true); break; case ExplosionSeverity.Light: - if (RandomExtensions.Prob(prob, 40)) + if (prob.Prob(40)) _actSystem.HandleDestruction(Owner, true); break; } diff --git a/Content.Server/GameObjects/Components/Explosion/ExplosiveComponent.cs b/Content.Server/GameObjects/Components/Explosion/ExplosiveComponent.cs index 656ccd4c5a..d1f6f0e1f3 100644 --- a/Content.Server/GameObjects/Components/Explosion/ExplosiveComponent.cs +++ b/Content.Server/GameObjects/Components/Explosion/ExplosiveComponent.cs @@ -10,10 +10,12 @@ using Robust.Shared.GameObjects; using Robust.Shared.GameObjects.EntitySystemMessages; using Robust.Shared.Interfaces.GameObjects; using Robust.Shared.Interfaces.Map; +using Robust.Shared.Interfaces.Random; using Robust.Shared.Interfaces.Timing; using Robust.Shared.IoC; using Robust.Shared.Map; using Robust.Shared.Maths; +using Robust.Shared.Random; using Robust.Shared.Serialization; namespace Content.Server.GameObjects.Components.Explosive @@ -26,6 +28,7 @@ namespace Content.Server.GameObjects.Components.Explosive [Dependency] private readonly IMapManager _mapManager; [Dependency] private readonly IServerEntityManager _serverEntityManager; [Dependency] private readonly IEntitySystemManager _entitySystemManager; + [Dependency] private readonly IRobustRandom _robustRandom; #pragma warning restore 649 public override string Name => "Explosive"; @@ -96,7 +99,7 @@ namespace Content.Server.GameObjects.Components.Explosive mapGrid.SetTile(tileLoc, new Tile(_tileDefinitionManager["space"].TileId)); if (distanceFromTile < HeavyImpactRange) { - if (new Random().Prob(80)) + if (_robustRandom.Prob(80)) { mapGrid.SetTile(tileLoc, new Tile(_tileDefinitionManager[tileDef.SubFloor].TileId)); } @@ -107,7 +110,7 @@ namespace Content.Server.GameObjects.Components.Explosive } if (distanceFromTile < LightImpactRange) { - if (new Random().Prob(50)) + if (_robustRandom.Prob(50)) { mapGrid.SetTile(tileLoc, new Tile(_tileDefinitionManager[tileDef.SubFloor].TileId)); } diff --git a/Content.Server/GameObjects/Components/Items/DiceComponent.cs b/Content.Server/GameObjects/Components/Items/DiceComponent.cs index ef9b10afb2..1dc5939f00 100644 --- a/Content.Server/GameObjects/Components/Items/DiceComponent.cs +++ b/Content.Server/GameObjects/Components/Items/DiceComponent.cs @@ -5,9 +5,11 @@ using Content.Shared.Audio; using Robust.Server.GameObjects; using Robust.Shared.Audio; using Robust.Shared.GameObjects; +using Robust.Shared.Interfaces.Random; using Robust.Shared.IoC; using Robust.Shared.Maths; using Robust.Shared.Prototypes; +using Robust.Shared.Random; using Robust.Shared.Serialization; using Robust.Shared.Utility; using Robust.Shared.ViewVariables; @@ -19,11 +21,11 @@ namespace Content.Server.GameObjects.Components.Items { #pragma warning disable 649 [Dependency] private readonly IPrototypeManager _prototypeManager; + [Dependency] private readonly IRobustRandom _random; #pragma warning restore 649 public override string Name => "Dice"; - private Random _random; private int _step = 1; private int _sides = 20; private int _currentSide = 20; @@ -45,12 +47,6 @@ namespace Content.Server.GameObjects.Components.Items _currentSide = _sides; } - public override void OnAdd() - { - base.OnAdd(); - _random = new Random(Owner.Uid.GetHashCode() ^ DateTime.Now.GetHashCode()); - } - public void Roll() { _currentSide = _random.Next(1, (_sides/_step)+1) * _step; diff --git a/Content.Server/GameObjects/Components/Items/Storage/Fill/ToolLockerFillComponent.cs b/Content.Server/GameObjects/Components/Items/Storage/Fill/ToolLockerFillComponent.cs index d84e55d2f8..5fa5e0fa9c 100644 --- a/Content.Server/GameObjects/Components/Items/Storage/Fill/ToolLockerFillComponent.cs +++ b/Content.Server/GameObjects/Components/Items/Storage/Fill/ToolLockerFillComponent.cs @@ -2,8 +2,10 @@ using System; using Robust.Server.Interfaces.GameObjects; using Robust.Shared.GameObjects; using Robust.Shared.Interfaces.GameObjects; +using Robust.Shared.Interfaces.Random; using Robust.Shared.IoC; using Robust.Shared.Maths; +using Robust.Shared.Random; namespace Content.Server.GameObjects.Components.Items.Storage.Fill { @@ -19,7 +21,7 @@ namespace Content.Server.GameObjects.Components.Items.Storage.Fill void IMapInit.MapInit() { var storage = Owner.GetComponent(); - var random = new Random(DateTime.Now.GetHashCode() ^ Owner.Uid.GetHashCode()); + var random = IoCManager.Resolve(); void Spawn(string prototype) { diff --git a/Content.Server/GameObjects/Components/Items/Storage/Fill/ToolboxElectricalFillComponent.cs b/Content.Server/GameObjects/Components/Items/Storage/Fill/ToolboxElectricalFillComponent.cs index 95227b7141..3d42912ea0 100644 --- a/Content.Server/GameObjects/Components/Items/Storage/Fill/ToolboxElectricalFillComponent.cs +++ b/Content.Server/GameObjects/Components/Items/Storage/Fill/ToolboxElectricalFillComponent.cs @@ -2,8 +2,10 @@ using System; using Robust.Server.Interfaces.GameObjects; using Robust.Shared.GameObjects; using Robust.Shared.Interfaces.GameObjects; +using Robust.Shared.Interfaces.Random; using Robust.Shared.IoC; using Robust.Shared.Maths; +using Robust.Shared.Random; namespace Content.Server.GameObjects.Components.Items.Storage.Fill { @@ -19,7 +21,7 @@ namespace Content.Server.GameObjects.Components.Items.Storage.Fill void IMapInit.MapInit() { var storage = Owner.GetComponent(); - var random = new Random(DateTime.Now.GetHashCode() ^ Owner.Uid.GetHashCode()); + var random = IoCManager.Resolve(); void Spawn(string prototype) { diff --git a/Content.Server/GameObjects/Components/Items/Storage/ItemComponent.cs b/Content.Server/GameObjects/Components/Items/Storage/ItemComponent.cs index 5cf06c5508..695d2fff6c 100644 --- a/Content.Server/GameObjects/Components/Items/Storage/ItemComponent.cs +++ b/Content.Server/GameObjects/Components/Items/Storage/ItemComponent.cs @@ -7,7 +7,10 @@ using Robust.Server.GameObjects; using Robust.Server.Interfaces.GameObjects; using Robust.Shared.GameObjects; using Robust.Shared.Interfaces.GameObjects; +using Robust.Shared.Interfaces.Random; +using Robust.Shared.IoC; using Robust.Shared.Maths; +using Robust.Shared.Random; using Robust.Shared.Serialization; namespace Content.Server.GameObjects @@ -20,6 +23,10 @@ namespace Content.Server.GameObjects public override uint? NetID => ContentNetIDs.ITEM; public override Type StateType => typeof(ItemComponentState); + #pragma warning disable 649 + [Dependency] private readonly IRobustRandom _robustRandom; + #pragma warning restore 649 + private string _equippedPrefix; public string EquippedPrefix @@ -115,7 +122,7 @@ namespace Content.Server.GameObjects float RandomOffset() { var size = 15.0F; - return (new Random().NextFloat() * size) - size / 2; + return (_robustRandom.NextFloat() * size) - size / 2; } } } diff --git a/Content.Server/GameObjects/Components/Movement/ServerTeleporterComponent.cs b/Content.Server/GameObjects/Components/Movement/ServerTeleporterComponent.cs index fca5b45b79..7771bdf05c 100644 --- a/Content.Server/GameObjects/Components/Movement/ServerTeleporterComponent.cs +++ b/Content.Server/GameObjects/Components/Movement/ServerTeleporterComponent.cs @@ -8,6 +8,7 @@ using Robust.Server.Interfaces.GameObjects; using Robust.Shared.GameObjects; using Robust.Shared.Interfaces.GameObjects; using Robust.Shared.Interfaces.Map; +using Robust.Shared.Interfaces.Random; using Robust.Shared.IoC; using Robust.Shared.Map; using Robust.Shared.Maths; @@ -24,6 +25,7 @@ namespace Content.Server.GameObjects.Components.Movement #pragma warning disable 649 [Dependency] private readonly IMapManager _mapManager; [Dependency] private readonly IServerEntityManager _serverEntityManager; + [Dependency] private readonly IRobustRandom _spreadRandom; #pragma warning restore 649 // TODO: Look at MapManager.Map for Beacons to get all entities on grid public ItemTeleporterState State => _state; @@ -44,8 +46,6 @@ namespace Content.Server.GameObjects.Components.Movement private AppearanceComponent _appearanceComponent; - private Random _spreadRandom; - public override void ExposeData(ObjectSerializer serializer) { base.ExposeData(serializer); @@ -149,7 +149,6 @@ namespace Content.Server.GameObjects.Components.Movement public override void Initialize() { _appearanceComponent = Owner.GetComponent(); - _spreadRandom = new Random(Owner.Uid.GetHashCode() ^ DateTime.Now.GetHashCode()); _state = ItemTeleporterState.Off; base.Initialize(); } diff --git a/Content.Server/GameObjects/Components/Sound/FootstepModifierComponent.cs b/Content.Server/GameObjects/Components/Sound/FootstepModifierComponent.cs index 1cf60c0bc5..eb68beb188 100644 --- a/Content.Server/GameObjects/Components/Sound/FootstepModifierComponent.cs +++ b/Content.Server/GameObjects/Components/Sound/FootstepModifierComponent.cs @@ -2,9 +2,11 @@ using Content.Shared.Audio; using Robust.Shared.Audio; using Robust.Shared.GameObjects; +using Robust.Shared.Interfaces.Random; using Robust.Shared.IoC; using Robust.Shared.Maths; using Robust.Shared.Prototypes; +using Robust.Shared.Random; using Robust.Shared.Serialization; namespace Content.Server.GameObjects.Components.Sound @@ -17,10 +19,10 @@ namespace Content.Server.GameObjects.Components.Sound { #pragma warning disable 649 [Dependency] private readonly IPrototypeManager _prototypeManager; + [Dependency] private readonly IRobustRandom _footstepRandom; #pragma warning restore 649 /// /// - private Random _footstepRandom; public override string Name => "FootstepModifier"; @@ -32,12 +34,6 @@ namespace Content.Server.GameObjects.Components.Sound serializer.DataField(ref _soundCollectionName, "footstepSoundCollection", ""); } - public override void Initialize() - { - base.Initialize(); - _footstepRandom = new Random(Owner.Uid.GetHashCode() ^ DateTime.Now.GetHashCode()); - } - public void PlayFootstep() { if (!string.IsNullOrWhiteSpace(_soundCollectionName)) diff --git a/Content.Server/GameObjects/Components/Weapon/Ranged/Projectile/BallisticMagazineWeaponComponent.cs b/Content.Server/GameObjects/Components/Weapon/Ranged/Projectile/BallisticMagazineWeaponComponent.cs index 7b6dccfe06..4d6053a42b 100644 --- a/Content.Server/GameObjects/Components/Weapon/Ranged/Projectile/BallisticMagazineWeaponComponent.cs +++ b/Content.Server/GameObjects/Components/Weapon/Ranged/Projectile/BallisticMagazineWeaponComponent.cs @@ -10,7 +10,10 @@ using Robust.Server.Interfaces.GameObjects; using Robust.Shared.Audio; using Robust.Shared.GameObjects; using Robust.Shared.Interfaces.GameObjects; +using Robust.Shared.Interfaces.Random; +using Robust.Shared.IoC; using Robust.Shared.Maths; +using Robust.Shared.Random; using Robust.Shared.Serialization; using Robust.Shared.Utility; using Robust.Shared.ViewVariables; @@ -34,8 +37,9 @@ namespace Content.Server.GameObjects.Components.Weapon.Ranged.Projectile [ViewVariables] private IEntity Magazine => _magazineSlot.ContainedEntity; - [ViewVariables] - private Random _bulletDropRandom; +#pragma warning disable 649 + [Dependency] private readonly IRobustRandom _bulletDropRandom; +#pragma warning restore 649 [ViewVariables] private string _magInSound; [ViewVariables] @@ -74,7 +78,6 @@ namespace Content.Server.GameObjects.Components.Weapon.Ranged.Projectile base.Initialize(); _appearance = Owner.GetComponent(); - _bulletDropRandom = new Random(Owner.Uid.GetHashCode() ^ DateTime.Now.GetHashCode()); } public override void Startup() diff --git a/Content.Server/GameObjects/Components/Weapon/Ranged/Projectile/ProjectileWeapon.cs b/Content.Server/GameObjects/Components/Weapon/Ranged/Projectile/ProjectileWeapon.cs index 9d86c27a94..7481342ead 100644 --- a/Content.Server/GameObjects/Components/Weapon/Ranged/Projectile/ProjectileWeapon.cs +++ b/Content.Server/GameObjects/Components/Weapon/Ranged/Projectile/ProjectileWeapon.cs @@ -8,10 +8,12 @@ using Robust.Server.Interfaces.GameObjects; using Robust.Shared.GameObjects; using Robust.Shared.Interfaces.GameObjects; using Robust.Shared.Interfaces.GameObjects.Components; +using Robust.Shared.Interfaces.Random; using Robust.Shared.IoC; using Robust.Shared.Log; using Robust.Shared.Map; using Robust.Shared.Maths; +using Robust.Shared.Random; using Robust.Shared.Serialization; using Robust.Shared.ViewVariables; @@ -23,7 +25,9 @@ namespace Content.Server.GameObjects.Components.Weapon.Ranged.Projectile private float _spreadStdDev = 3; private bool _spread = true; - private Random _spreadRandom; +#pragma warning disable 649 + [Dependency] private IRobustRandom _spreadRandom; +#pragma warning restore 649 [ViewVariables(VVAccess.ReadWrite)] public bool Spread @@ -45,8 +49,6 @@ namespace Content.Server.GameObjects.Components.Weapon.Ranged.Projectile var rangedWeapon = Owner.GetComponent(); rangedWeapon.FireHandler = Fire; - - _spreadRandom = new Random(Owner.Uid.GetHashCode() ^ DateTime.Now.GetHashCode()); } public override void ExposeData(ObjectSerializer serializer) diff --git a/Content.Server/GameObjects/EntitySystems/MoverSystem.cs b/Content.Server/GameObjects/EntitySystems/MoverSystem.cs index ef0faabec0..7febdefc70 100644 --- a/Content.Server/GameObjects/EntitySystems/MoverSystem.cs +++ b/Content.Server/GameObjects/EntitySystems/MoverSystem.cs @@ -23,7 +23,9 @@ using Robust.Shared.Players; using Robust.Shared.Prototypes; using Content.Server.GameObjects.Components.Sound; using Content.Shared.GameObjects.Components.Inventory; +using Robust.Shared.Interfaces.Random; using Robust.Shared.Log; +using Robust.Shared.Random; namespace Content.Server.GameObjects.EntitySystems { @@ -35,10 +37,10 @@ namespace Content.Server.GameObjects.EntitySystems [Dependency] private readonly IPrototypeManager _prototypeManager; [Dependency] private readonly ITileDefinitionManager _tileDefinitionManager; [Dependency] private readonly IMapManager _mapManager; + [Dependency] private readonly IRobustRandom _robustRandom; #pragma warning restore 649 private AudioSystem _audioSystem; - private Random _footstepRandom; private const float StepSoundMoveDistanceRunning = 2; private const float StepSoundMoveDistanceWalking = 1.5f; @@ -47,7 +49,7 @@ namespace Content.Server.GameObjects.EntitySystems public override void Initialize() { EntityQuery = new TypeEntityQuery(typeof(IMoverComponent)); - + var moveUpCmdHandler = InputCmdHandler.FromDelegate( session => HandleDirChange(session, Direction.North, true), session => HandleDirChange(session, Direction.North, false)); @@ -75,7 +77,6 @@ namespace Content.Server.GameObjects.EntitySystems SubscribeEvent(PlayerAttached); SubscribeEvent(PlayerDetached); - _footstepRandom = new Random(); _audioSystem = EntitySystemManager.GetEntitySystem(); } @@ -153,7 +154,7 @@ namespace Content.Server.GameObjects.EntitySystems { mover.StepSoundDistance = 0; if (mover.Owner.TryGetComponent(out var inventory) - && inventory.TryGetSlotItem(EquipmentSlotDefines.Slots.SHOES, out var item) + && inventory.TryGetSlotItem(EquipmentSlotDefines.Slots.SHOES, out var item) && item.Owner.TryGetComponent(out var modifier)) { modifier.PlayFootstep(); @@ -186,7 +187,7 @@ namespace Content.Server.GameObjects.EntitySystems where T: Component { component = default; - + var ent = session.AttachedEntity; if (ent == null || !ent.IsValid()) @@ -238,7 +239,7 @@ namespace Content.Server.GameObjects.EntitySystems try { var soundCollection = _prototypeManager.Index(soundCollectionName); - var file = _footstepRandom.Pick(soundCollection.PickFiles); + var file = _robustRandom.Pick(soundCollection.PickFiles); _audioSystem.Play(file, coordinates); } catch (UnknownPrototypeException) diff --git a/Content.Server/GameTicking/GameTicker.cs b/Content.Server/GameTicking/GameTicker.cs index d9b019129d..76726b6ceb 100644 --- a/Content.Server/GameTicking/GameTicker.cs +++ b/Content.Server/GameTicking/GameTicker.cs @@ -21,12 +21,14 @@ using Robust.Shared.Interfaces.Configuration; using Robust.Shared.Interfaces.GameObjects; using Robust.Shared.Interfaces.Map; using Robust.Shared.Interfaces.Network; +using Robust.Shared.Interfaces.Random; using Robust.Shared.Interfaces.Timing; using Robust.Shared.IoC; using Robust.Shared.Log; using Robust.Shared.Map; using Robust.Shared.Maths; using Robust.Shared.Network; +using Robust.Shared.Random; using Robust.Shared.Timers; using Robust.Shared.Timing; using Robust.Shared.Utility; @@ -76,8 +78,6 @@ namespace Content.Server.GameTicking [ViewVariables] private bool _roundStartCountdownHasNotStartedYetDueToNoPlayers; private DateTime _roundStartTimeUtc; - private readonly Random _spawnRandom = new Random(); - [ViewVariables] private readonly List _gameRules = new List(); [ViewVariables] private Type _presetType; @@ -92,6 +92,7 @@ namespace Content.Server.GameTicking [Dependency] private IChatManager _chatManager; [Dependency] private IServerNetManager _netManager; [Dependency] private IDynamicTypeFactory _dynamicTypeFactory; + [Dependency] private readonly IRobustRandom _robustRandom; #pragma warning restore 649 public void Initialize() @@ -293,7 +294,7 @@ namespace Content.Server.GameTicking if (possiblePoints.Count != 0) { - location = _spawnRandom.Pick(possiblePoints); + location = _robustRandom.Pick(possiblePoints); } return location;