From de9dfefd6126b394618976d22734619775ad8012 Mon Sep 17 00:00:00 2001 From: DrSmugleaf Date: Wed, 2 Sep 2020 01:30:03 +0200 Subject: [PATCH] Replace resolve dependency with attribute in components (#1995) * Replace resolve dependency with attribute in components * Add changes that went missing in translation --- .../Components/Atmos/GridAtmosphereComponent.cs | 9 +++++---- .../Components/Chemistry/ChemMasterComponent.cs | 6 ------ .../Chemistry/ReagentDispenserComponent.cs | 5 +++-- .../Components/Fluids/PuddleComponent.cs | 8 ++++---- .../Items/Storage/EntityStorageComponent.cs | 10 ++++------ .../Items/Storage/Fill/CustodialClosetFill.cs | 1 - .../Components/Mobs/Speech/OwOAccentComponent.cs | 6 ++++-- .../Components/Movement/AiControllerComponent.cs | 15 +++++++++------ .../Components/Nutrition/HungerComponent.cs | 5 +++-- .../Components/Nutrition/ThirstComponent.cs | 5 +++-- .../ApcNetComponents/PowerProviderComponent.cs | 8 +++++--- .../ApcNetComponents/PowerReceiverComponent.cs | 9 ++++++--- .../Components/Projectiles/HitscanComponent.cs | 4 +++- .../GameObjects/Components/RadioComponent.cs | 4 ++-- .../Research/ProtolatheDatabaseComponent.cs | 6 +++--- .../Research/ResearchConsoleComponent.cs | 3 +-- .../StationEvents/RadiationPulseComponent.cs | 15 +++++++++------ .../VendingMachines/VendingMachineComponent.cs | 4 ++-- .../Components/Weapon/FlashableComponent.cs | 5 +++-- .../Weapon/Melee/MeleeWeaponComponent.cs | 5 +++-- .../Weapon/Ranged/Ammunition/AmmoComponent.cs | 4 +++- .../Ranged/Barrels/RevolverBarrelComponent.cs | 4 +++- .../Weapon/Ranged/ServerRangedWeaponComponent.cs | 10 +++++++--- 23 files changed, 85 insertions(+), 66 deletions(-) diff --git a/Content.Server/GameObjects/Components/Atmos/GridAtmosphereComponent.cs b/Content.Server/GameObjects/Components/Atmos/GridAtmosphereComponent.cs index 215243a877..4bca5b202e 100644 --- a/Content.Server/GameObjects/Components/Atmos/GridAtmosphereComponent.cs +++ b/Content.Server/GameObjects/Components/Atmos/GridAtmosphereComponent.cs @@ -32,6 +32,8 @@ namespace Content.Server.GameObjects.Components.Atmos public class GridAtmosphereComponent : Component, IGridAtmosphereComponent { [Robust.Shared.IoC.Dependency] private IMapManager _mapManager = default!; + [Robust.Shared.IoC.Dependency] private ITileDefinitionManager _tileDefinitionManager = default!; + [Robust.Shared.IoC.Dependency] private IServerEntityManager _serverEntityManager = default!; /// /// Check current execution time every n instances processed. @@ -162,14 +164,13 @@ namespace Content.Server.GameObjects.Components.Atmos var mapGrid = mapGridComponent.Grid; var tile = mapGrid.GetTileRef(indices).Tile; - var tileDefinitionManager = IoCManager.Resolve(); - var tileDef = (ContentTileDefinition)tileDefinitionManager[tile.TypeId]; + var tileDef = (ContentTileDefinition) _tileDefinitionManager[tile.TypeId]; - var underplating = tileDefinitionManager["underplating"]; + var underplating = _tileDefinitionManager["underplating"]; mapGrid.SetTile(indices, new Tile(underplating.TileId)); //Actually spawn the relevant tile item at the right position and give it some offset to the corner. - var tileItem = IoCManager.Resolve().SpawnEntity(tileDef.ItemDropPrototypeName, new GridCoordinates(indices.X, indices.Y, mapGrid)); + var tileItem = _serverEntityManager.SpawnEntity(tileDef.ItemDropPrototypeName, new GridCoordinates(indices.X, indices.Y, mapGrid)); tileItem.Transform.WorldPosition += (0.2f, 0.2f); } diff --git a/Content.Server/GameObjects/Components/Chemistry/ChemMasterComponent.cs b/Content.Server/GameObjects/Components/Chemistry/ChemMasterComponent.cs index dc6bb8ae68..e862d74b58 100644 --- a/Content.Server/GameObjects/Components/Chemistry/ChemMasterComponent.cs +++ b/Content.Server/GameObjects/Components/Chemistry/ChemMasterComponent.cs @@ -23,11 +23,7 @@ using Robust.Shared.Audio; using Robust.Shared.GameObjects; using Robust.Shared.GameObjects.Systems; using Robust.Shared.Interfaces.GameObjects; -using Robust.Shared.Interfaces.Random; -using Robust.Shared.IoC; using Robust.Shared.Localization; -using Robust.Shared.Maths; -using Robust.Shared.Random; using Robust.Shared.Serialization; using Robust.Shared.ViewVariables; @@ -271,8 +267,6 @@ namespace Content.Server.GameObjects.Components.Chemistry private void TryCreatePackage(IEntity user, UiAction action, int pillAmount, int bottleAmount) { - var random = IoCManager.Resolve(); - if (BufferSolution.CurrentVolume == 0) return; diff --git a/Content.Server/GameObjects/Components/Chemistry/ReagentDispenserComponent.cs b/Content.Server/GameObjects/Components/Chemistry/ReagentDispenserComponent.cs index 24c29dfac2..86580bb399 100644 --- a/Content.Server/GameObjects/Components/Chemistry/ReagentDispenserComponent.cs +++ b/Content.Server/GameObjects/Components/Chemistry/ReagentDispenserComponent.cs @@ -40,6 +40,8 @@ namespace Content.Server.GameObjects.Components.Chemistry [ComponentReference(typeof(IInteractUsing))] public class ReagentDispenserComponent : SharedReagentDispenserComponent, IActivate, IInteractUsing, ISolutionChange { + [Dependency] private readonly IPrototypeManager _prototypeManager = default!; + [ViewVariables] private ContainerSlot _beakerContainer = default!; [ViewVariables] private string _packPrototypeId = ""; @@ -97,8 +99,7 @@ namespace Content.Server.GameObjects.Components.Chemistry { if (string.IsNullOrEmpty(_packPrototypeId)) return; - var prototypeManager = IoCManager.Resolve(); - if (!prototypeManager.TryIndex(_packPrototypeId, out ReagentDispenserInventoryPrototype packPrototype)) + if (!_prototypeManager.TryIndex(_packPrototypeId, out ReagentDispenserInventoryPrototype packPrototype)) { return; } diff --git a/Content.Server/GameObjects/Components/Fluids/PuddleComponent.cs b/Content.Server/GameObjects/Components/Fluids/PuddleComponent.cs index e2015f739c..7cc38996ec 100644 --- a/Content.Server/GameObjects/Components/Fluids/PuddleComponent.cs +++ b/Content.Server/GameObjects/Components/Fluids/PuddleComponent.cs @@ -49,6 +49,8 @@ namespace Content.Server.GameObjects.Components.Fluids // to check for low volumes for evaporation or whatever [Dependency] private readonly IMapManager _mapManager = default!; + [Dependency] private readonly IRobustRandom _random = default!; + [Dependency] private readonly IEntityManager _entityManager = default!; public override string Name => "Puddle"; @@ -134,8 +136,7 @@ namespace Content.Server.GameObjects.Components.Fluids // Random sprite state set server-side so it's consistent across all clients _spriteComponent = Owner.EnsureComponent(); - var robustRandom = IoCManager.Resolve(); - var randomVariant = robustRandom.Next(0, _spriteVariants - 1); + var randomVariant = _random.Next(0, _spriteVariants - 1); if (_spriteComponent.BaseRSIPath != null) { @@ -388,8 +389,7 @@ namespace Content.Server.GameObjects.Components.Fluids if (puddle == default) { var grid = _snapGrid.DirectionToGrid(direction); - var entityManager = IoCManager.Resolve(); - puddle = () => entityManager.SpawnEntity(Owner.Prototype.ID, grid).GetComponent(); + puddle = () => _entityManager.SpawnEntity(Owner.Prototype.ID, grid).GetComponent(); } return true; diff --git a/Content.Server/GameObjects/Components/Items/Storage/EntityStorageComponent.cs b/Content.Server/GameObjects/Components/Items/Storage/EntityStorageComponent.cs index 6bbdacca5e..2e319fa31b 100644 --- a/Content.Server/GameObjects/Components/Items/Storage/EntityStorageComponent.cs +++ b/Content.Server/GameObjects/Components/Items/Storage/EntityStorageComponent.cs @@ -4,10 +4,7 @@ using System.Threading.Tasks; using Content.Server.GameObjects.Components.Body; using Content.Server.GameObjects.Components.GUI; using Content.Server.GameObjects.Components.Interactable; -using Content.Server.GameObjects.Components.Mobs; -using Content.Server.GameObjects.EntitySystems; using Content.Shared.GameObjects.Components.Interactable; -using Content.Shared.GameObjects.Components.Mobs; using Content.Shared.GameObjects.Components.Storage; using Content.Shared.GameObjects.EntitySystems; using Content.Shared.GameObjects.Verbs; @@ -35,6 +32,8 @@ namespace Content.Server.GameObjects.Components.Items.Storage [ComponentReference(typeof(IStorageComponent))] public class EntityStorageComponent : Component, IActivate, IStorageComponent, IInteractUsing, IDestroyAct, IActionBlocker, IExAct { + [Dependency] private readonly IGameTiming _gameTiming = default!; + public override string Name => "EntityStorage"; private const float MaxSize = 1.0f; // maximum width or height of an entity allowed inside the storage. @@ -301,14 +300,13 @@ namespace Content.Server.GameObjects.Components.Items.Storage case RelayMovementEntityMessage msg: if (msg.Entity.HasComponent()) { - var timing = IoCManager.Resolve(); - if (timing.CurTime < + if (_gameTiming.CurTime < _lastInternalOpenAttempt + InternalOpenAttemptDelay) { break; } - _lastInternalOpenAttempt = timing.CurTime; + _lastInternalOpenAttempt = _gameTiming.CurTime; TryOpenStorage(msg.Entity); } break; diff --git a/Content.Server/GameObjects/Components/Items/Storage/Fill/CustodialClosetFill.cs b/Content.Server/GameObjects/Components/Items/Storage/Fill/CustodialClosetFill.cs index db89fb1798..2138b1a780 100644 --- a/Content.Server/GameObjects/Components/Items/Storage/Fill/CustodialClosetFill.cs +++ b/Content.Server/GameObjects/Components/Items/Storage/Fill/CustodialClosetFill.cs @@ -13,7 +13,6 @@ namespace Content.Server.GameObjects.Components.Items.Storage.Fill void IMapInit.MapInit() { var storage = Owner.GetComponent(); - var random = IoCManager.Resolve(); void Spawn(string prototype) { diff --git a/Content.Server/GameObjects/Components/Mobs/Speech/OwOAccentComponent.cs b/Content.Server/GameObjects/Components/Mobs/Speech/OwOAccentComponent.cs index 819e7c81cd..5b0aa232f0 100644 --- a/Content.Server/GameObjects/Components/Mobs/Speech/OwOAccentComponent.cs +++ b/Content.Server/GameObjects/Components/Mobs/Speech/OwOAccentComponent.cs @@ -9,12 +9,14 @@ namespace Content.Server.GameObjects.Components.Mobs.Speech [RegisterComponent] public class OwOAccentComponent : Component, IAccentComponent { + [Dependency] private readonly IRobustRandom _random; + public override string Name => "OwOAccent"; private static readonly IReadOnlyList Faces = new List{ " (・`ω´・)", " ;;w;;", " owo", " UwU", " >w<", " ^w^" }.AsReadOnly(); - private string RandomFace => IoCManager.Resolve().Pick(Faces); + private string RandomFace => _random.Pick(Faces); private static readonly Dictionary SpecialWords = new Dictionary { @@ -23,7 +25,7 @@ namespace Content.Server.GameObjects.Components.Mobs.Speech public string Accentuate(string message) { - foreach ((var word,var repl) in SpecialWords) + foreach (var (word, repl) in SpecialWords) { message = message.Replace(word, repl); } diff --git a/Content.Server/GameObjects/Components/Movement/AiControllerComponent.cs b/Content.Server/GameObjects/Components/Movement/AiControllerComponent.cs index a1d595062d..dc651ef36c 100644 --- a/Content.Server/GameObjects/Components/Movement/AiControllerComponent.cs +++ b/Content.Server/GameObjects/Components/Movement/AiControllerComponent.cs @@ -19,6 +19,9 @@ namespace Content.Server.GameObjects.Components.Movement [RegisterComponent, ComponentReference(typeof(IMoverComponent))] public class AiControllerComponent : Component, IMoverComponent { + [Dependency] private readonly IPrototypeManager _prototypeManager = default!; + [Dependency] private readonly IGameTicker _gameTicker = default!; + private string? _logicName; private float _visionRadius; @@ -36,7 +39,7 @@ namespace Content.Server.GameObjects.Components.Movement } public AiLogicProcessor? Processor { get; set; } - + [ViewVariables(VVAccess.ReadWrite)] public string? StartingGearPrototype { get; set; } @@ -61,13 +64,13 @@ namespace Content.Server.GameObjects.Components.Movement protected override void Startup() { base.Startup(); - + if (StartingGearPrototype != null) { - var startingGear = IoCManager.Resolve().Index(StartingGearPrototype); - IoCManager.Resolve().EquipStartingGear(Owner, startingGear); + var startingGear = _prototypeManager.Index(StartingGearPrototype); + _gameTicker.EquipStartingGear(Owner, startingGear); } - + } /// @@ -77,7 +80,7 @@ namespace Content.Server.GameObjects.Components.Movement serializer.DataField(ref _logicName, "logic", null); serializer.DataReadWriteFunction( - "startingGear", + "startingGear", null, startingGear => StartingGearPrototype = startingGear, () => StartingGearPrototype); diff --git a/Content.Server/GameObjects/Components/Nutrition/HungerComponent.cs b/Content.Server/GameObjects/Components/Nutrition/HungerComponent.cs index 00d1a8c27b..5e35835cc4 100644 --- a/Content.Server/GameObjects/Components/Nutrition/HungerComponent.cs +++ b/Content.Server/GameObjects/Components/Nutrition/HungerComponent.cs @@ -6,7 +6,6 @@ using Content.Shared.GameObjects.Components.Damage; using Content.Shared.GameObjects.Components.Mobs; using Content.Shared.GameObjects.Components.Movement; using Content.Shared.GameObjects.Components.Nutrition; -using JetBrains.Annotations; using Robust.Shared.GameObjects; using Robust.Shared.Interfaces.Random; using Robust.Shared.IoC; @@ -19,6 +18,8 @@ namespace Content.Server.GameObjects.Components.Nutrition [RegisterComponent] public sealed class HungerComponent : SharedHungerComponent { + [Dependency] private readonly IRobustRandom _random = default!; + // Base stuff [ViewVariables(VVAccess.ReadWrite)] public float BaseDecayRate @@ -141,7 +142,7 @@ namespace Content.Server.GameObjects.Components.Nutrition { base.Startup(); // Similar functionality to SS13. Should also stagger people going to the chef. - _currentHunger = IoCManager.Resolve().Next( + _currentHunger = _random.Next( (int)_hungerThresholds[HungerThreshold.Peckish] + 10, (int)_hungerThresholds[HungerThreshold.Okay] - 1); _currentHungerThreshold = GetHungerThreshold(_currentHunger); diff --git a/Content.Server/GameObjects/Components/Nutrition/ThirstComponent.cs b/Content.Server/GameObjects/Components/Nutrition/ThirstComponent.cs index e8cee505fc..6dec3efe75 100644 --- a/Content.Server/GameObjects/Components/Nutrition/ThirstComponent.cs +++ b/Content.Server/GameObjects/Components/Nutrition/ThirstComponent.cs @@ -6,7 +6,6 @@ using Content.Shared.GameObjects.Components.Damage; using Content.Shared.GameObjects.Components.Mobs; using Content.Shared.GameObjects.Components.Movement; using Content.Shared.GameObjects.Components.Nutrition; -using JetBrains.Annotations; using Robust.Shared.GameObjects; using Robust.Shared.Interfaces.Random; using Robust.Shared.IoC; @@ -19,6 +18,8 @@ namespace Content.Server.GameObjects.Components.Nutrition [RegisterComponent] public sealed class ThirstComponent : SharedThirstComponent { + [Dependency] private readonly IRobustRandom _random = default!; + // Base stuff [ViewVariables(VVAccess.ReadWrite)] public float BaseDecayRate @@ -136,7 +137,7 @@ namespace Content.Server.GameObjects.Components.Nutrition protected override void Startup() { base.Startup(); - _currentThirst = IoCManager.Resolve().Next( + _currentThirst = _random.Next( (int)ThirstThresholds[ThirstThreshold.Thirsty] + 10, (int)ThirstThresholds[ThirstThreshold.Okay] - 1); _currentThirstThreshold = GetThirstThreshold(_currentThirst); diff --git a/Content.Server/GameObjects/Components/Power/ApcNetComponents/PowerProviderComponent.cs b/Content.Server/GameObjects/Components/Power/ApcNetComponents/PowerProviderComponent.cs index 5541a2a875..b0fcd57588 100644 --- a/Content.Server/GameObjects/Components/Power/ApcNetComponents/PowerProviderComponent.cs +++ b/Content.Server/GameObjects/Components/Power/ApcNetComponents/PowerProviderComponent.cs @@ -24,6 +24,9 @@ namespace Content.Server.GameObjects.Components.Power.ApcNetComponents [RegisterComponent] public class PowerProviderComponent : BaseApcNetComponent, IPowerProvider { + [Dependency] private readonly IMapManager _mapManager = default!; + [Dependency] private readonly IServerEntityManager _serverEntityManager; + public override string Name => "PowerProvider"; /// @@ -91,14 +94,13 @@ namespace Content.Server.GameObjects.Components.Power.ApcNetComponents private List FindAvailableReceivers() { - var mapManager = IoCManager.Resolve(); - var nearbyEntities = IoCManager.Resolve() + var nearbyEntities = _serverEntityManager .GetEntitiesInRange(Owner, PowerTransferRange); return nearbyEntities.Select(entity => entity.TryGetComponent(out var receiver) ? receiver : null) .Where(receiver => receiver != null) .Where(receiver => receiver.Connectable) .Where(receiver => receiver.NeedsProvider) - .Where(receiver => receiver.Owner.Transform.GridPosition.Distance(mapManager, Owner.Transform.GridPosition) < Math.Min(PowerTransferRange, receiver.PowerReceptionRange)) + .Where(receiver => receiver.Owner.Transform.GridPosition.Distance(_mapManager, Owner.Transform.GridPosition) < Math.Min(PowerTransferRange, receiver.PowerReceptionRange)) .ToList(); } diff --git a/Content.Server/GameObjects/Components/Power/ApcNetComponents/PowerReceiverComponent.cs b/Content.Server/GameObjects/Components/Power/ApcNetComponents/PowerReceiverComponent.cs index 01f6dbd787..2402c6ea51 100644 --- a/Content.Server/GameObjects/Components/Power/ApcNetComponents/PowerReceiverComponent.cs +++ b/Content.Server/GameObjects/Components/Power/ApcNetComponents/PowerReceiverComponent.cs @@ -21,6 +21,9 @@ namespace Content.Server.GameObjects.Components.Power.ApcNetComponents [RegisterComponent] public class PowerReceiverComponent : Component, IExamine { + [Dependency] private readonly IServerEntityManager _serverEntityManager = default!; + [Dependency] private readonly IMapManager _mapManager = default!; + public override string Name => "PowerReceiver"; public event EventHandler OnPowerStateChanged; @@ -116,16 +119,16 @@ namespace Content.Server.GameObjects.Components.Power.ApcNetComponents private bool TryFindAvailableProvider(out IPowerProvider foundProvider) { - var nearbyEntities = IoCManager.Resolve() + var nearbyEntities = _serverEntityManager .GetEntitiesInRange(Owner, PowerReceptionRange); - var mapManager = IoCManager.Resolve(); + foreach (var entity in nearbyEntities) { if (entity.TryGetComponent(out var provider)) { if (provider.Connectable) { - var distanceToProvider = provider.Owner.Transform.GridPosition.Distance(mapManager, Owner.Transform.GridPosition); + var distanceToProvider = provider.Owner.Transform.GridPosition.Distance(_mapManager, Owner.Transform.GridPosition); if (distanceToProvider < Math.Min(PowerReceptionRange, provider.PowerTransferRange)) { foundProvider = provider; diff --git a/Content.Server/GameObjects/Components/Projectiles/HitscanComponent.cs b/Content.Server/GameObjects/Components/Projectiles/HitscanComponent.cs index 509de63d73..d3b56dde1b 100644 --- a/Content.Server/GameObjects/Components/Projectiles/HitscanComponent.cs +++ b/Content.Server/GameObjects/Components/Projectiles/HitscanComponent.cs @@ -22,6 +22,8 @@ namespace Content.Server.GameObjects.Components.Projectiles [RegisterComponent] public class HitscanComponent : Component { + [Dependency] private readonly IGameTiming _gameTiming = default!; + public override string Name => "Hitscan"; public CollisionGroup CollisionMask => (CollisionGroup) _collisionMask; private int _collisionMask; @@ -60,7 +62,7 @@ namespace Content.Server.GameObjects.Components.Projectiles public void FireEffects(IEntity user, float distance, Angle angle, IEntity hitEntity = null) { var effectSystem = EntitySystem.Get(); - _startTime = IoCManager.Resolve().CurTime; + _startTime = _gameTiming.CurTime; _deathTime = _startTime + TimeSpan.FromSeconds(1); var afterEffect = AfterEffects(user.Transform.GridPosition, angle, distance, 1.0f); diff --git a/Content.Server/GameObjects/Components/RadioComponent.cs b/Content.Server/GameObjects/Components/RadioComponent.cs index df927c9c28..2163ed3012 100644 --- a/Content.Server/GameObjects/Components/RadioComponent.cs +++ b/Content.Server/GameObjects/Components/RadioComponent.cs @@ -14,6 +14,7 @@ namespace Content.Server.GameObjects.Components class RadioComponent : Component, IUse, IListen { [Dependency] private readonly IEntitySystemManager _entitySystemManager = default!; + [Dependency] private readonly IChatManager _chatManager = default!; public override string Name => "Radio"; @@ -51,8 +52,7 @@ namespace Content.Server.GameObjects.Components public void Speaker(string message) { - var chat = IoCManager.Resolve(); - chat.EntitySay(Owner, message); + _chatManager.EntitySay(Owner, message); } public bool UseEntity(UseEntityEventArgs eventArgs) diff --git a/Content.Server/GameObjects/Components/Research/ProtolatheDatabaseComponent.cs b/Content.Server/GameObjects/Components/Research/ProtolatheDatabaseComponent.cs index 3067f03d5f..2179def87c 100644 --- a/Content.Server/GameObjects/Components/Research/ProtolatheDatabaseComponent.cs +++ b/Content.Server/GameObjects/Components/Research/ProtolatheDatabaseComponent.cs @@ -10,6 +10,8 @@ namespace Content.Server.GameObjects.Components.Research [ComponentReference(typeof(SharedLatheDatabaseComponent))] public class ProtolatheDatabaseComponent : SharedProtolatheDatabaseComponent { + [Dependency] private readonly IPrototypeManager _prototypeManager = default!; + public override string Name => "ProtolatheDatabase"; public override ComponentState GetComponentState() @@ -24,13 +26,11 @@ namespace Content.Server.GameObjects.Components.Research { if (!Owner.TryGetComponent(out TechnologyDatabaseComponent database)) return; - var prototypeManager = IoCManager.Resolve(); - foreach (var technology in database.Technologies) { foreach (var id in technology.UnlockedRecipes) { - var recipe = (LatheRecipePrototype)prototypeManager.Index(typeof(LatheRecipePrototype), id); + var recipe = (LatheRecipePrototype) _prototypeManager.Index(typeof(LatheRecipePrototype), id); UnlockRecipe(recipe); } } diff --git a/Content.Server/GameObjects/Components/Research/ResearchConsoleComponent.cs b/Content.Server/GameObjects/Components/Research/ResearchConsoleComponent.cs index 4a1adc57c1..e2136c29eb 100644 --- a/Content.Server/GameObjects/Components/Research/ResearchConsoleComponent.cs +++ b/Content.Server/GameObjects/Components/Research/ResearchConsoleComponent.cs @@ -57,8 +57,7 @@ namespace Content.Server.GameObjects.Components.Research switch (message.Message) { case ConsoleUnlockTechnologyMessage msg: - var protoMan = IoCManager.Resolve(); - if (!protoMan.TryIndex(msg.Id, out TechnologyPrototype tech)) break; + if (!_prototypeManager.TryIndex(msg.Id, out TechnologyPrototype tech)) break; if (client.Server == null) break; if (!client.Server.CanUnlockTechnology(tech)) break; if (client.Server.UnlockTechnology(tech)) diff --git a/Content.Server/GameObjects/Components/StationEvents/RadiationPulseComponent.cs b/Content.Server/GameObjects/Components/StationEvents/RadiationPulseComponent.cs index c0fd604f92..da755bf91d 100644 --- a/Content.Server/GameObjects/Components/StationEvents/RadiationPulseComponent.cs +++ b/Content.Server/GameObjects/Components/StationEvents/RadiationPulseComponent.cs @@ -15,12 +15,15 @@ namespace Content.Server.GameObjects.Components.StationEvents [RegisterComponent] public sealed class RadiationPulseComponent : SharedRadiationPulseComponent { + [Dependency] private readonly IGameTiming _gameTiming = default!; + [Dependency] private readonly IRobustRandom _random = default!; + private const float MinPulseLifespan = 0.8f; private const float MaxPulseLifespan = 2.5f; public float DPS => _dps; private float _dps; - + private TimeSpan _endTime; public override void ExposeData(ObjectSerializer serializer) @@ -33,15 +36,15 @@ namespace Content.Server.GameObjects.Components.StationEvents { base.Initialize(); - var currentTime = IoCManager.Resolve().CurTime; + var currentTime = _gameTiming.CurTime; var duration = TimeSpan.FromSeconds( - IoCManager.Resolve().NextFloat() * (MaxPulseLifespan - MinPulseLifespan) + + _random.NextFloat() * (MaxPulseLifespan - MinPulseLifespan) + MinPulseLifespan); _endTime = currentTime + duration; - - Timer.Spawn(duration, + + Timer.Spawn(duration, () => { if (!Owner.Deleted) @@ -59,4 +62,4 @@ namespace Content.Server.GameObjects.Components.StationEvents return new RadiationPulseMessage(_endTime); } } -} \ No newline at end of file +} diff --git a/Content.Server/GameObjects/Components/VendingMachines/VendingMachineComponent.cs b/Content.Server/GameObjects/Components/VendingMachines/VendingMachineComponent.cs index 3fd2c7177a..363dbf98ac 100644 --- a/Content.Server/GameObjects/Components/VendingMachines/VendingMachineComponent.cs +++ b/Content.Server/GameObjects/Components/VendingMachines/VendingMachineComponent.cs @@ -32,6 +32,7 @@ namespace Content.Server.GameObjects.Components.VendingMachines public class VendingMachineComponent : SharedVendingMachineComponent, IActivate, IExamine, IBreakAct, IWires { [Dependency] private readonly IRobustRandom _random = default!; + [Dependency] private readonly IPrototypeManager _prototypeManager = default!; private bool _ejecting; private TimeSpan _animationDuration = TimeSpan.Zero; @@ -77,8 +78,7 @@ namespace Content.Server.GameObjects.Components.VendingMachines private void InitializeFromPrototype() { if (string.IsNullOrEmpty(_packPrototypeId)) { return; } - var prototypeManger = IoCManager.Resolve(); - if (!prototypeManger.TryIndex(_packPrototypeId, out VendingMachineInventoryPrototype packPrototype)) + if (!_prototypeManager.TryIndex(_packPrototypeId, out VendingMachineInventoryPrototype packPrototype)) { return; } diff --git a/Content.Server/GameObjects/Components/Weapon/FlashableComponent.cs b/Content.Server/GameObjects/Components/Weapon/FlashableComponent.cs index b09d95aa19..4646c136c1 100644 --- a/Content.Server/GameObjects/Components/Weapon/FlashableComponent.cs +++ b/Content.Server/GameObjects/Components/Weapon/FlashableComponent.cs @@ -12,13 +12,14 @@ namespace Content.Server.GameObjects.Components.Weapon [RegisterComponent] public sealed class FlashableComponent : SharedFlashableComponent { + [Dependency] private readonly IGameTiming _gameTiming = default!; + private double _duration; private TimeSpan _lastFlash; public void Flash(double duration) { - var timing = IoCManager.Resolve(); - _lastFlash = timing.CurTime; + _lastFlash = _gameTiming.CurTime; _duration = duration; Dirty(); } diff --git a/Content.Server/GameObjects/Components/Weapon/Melee/MeleeWeaponComponent.cs b/Content.Server/GameObjects/Components/Weapon/Melee/MeleeWeaponComponent.cs index ce4a5bf376..b4f89bca67 100644 --- a/Content.Server/GameObjects/Components/Weapon/Melee/MeleeWeaponComponent.cs +++ b/Content.Server/GameObjects/Components/Weapon/Melee/MeleeWeaponComponent.cs @@ -26,6 +26,7 @@ namespace Content.Server.GameObjects.Components.Weapon.Melee [Dependency] private readonly IMapManager _mapManager = default!; [Dependency] private readonly IEntitySystemManager _entitySystemManager = default!; [Dependency] private readonly IPhysicsManager _physicsManager = default!; + [Dependency] private readonly IGameTiming _gameTiming = default!; public override string Name => "MeleeWeapon"; private TimeSpan _lastAttackTime; @@ -85,7 +86,7 @@ namespace Content.Server.GameObjects.Components.Weapon.Melee void IAttack.Attack(AttackEventArgs eventArgs) { - var curTime = IoCManager.Resolve().CurTime; + var curTime = _gameTiming.CurTime; var span = curTime - _lastAttackTime; if(span.TotalSeconds < _cooldownTime) { return; @@ -127,7 +128,7 @@ namespace Content.Server.GameObjects.Components.Weapon.Melee sys.SendAnimation(Arc, angle, eventArgs.User, hitEntities); } - _lastAttackTime = IoCManager.Resolve().CurTime; + _lastAttackTime = _gameTiming.CurTime; if (Owner.TryGetComponent(out ItemCooldownComponent cooldown)) { diff --git a/Content.Server/GameObjects/Components/Weapon/Ranged/Ammunition/AmmoComponent.cs b/Content.Server/GameObjects/Components/Weapon/Ranged/Ammunition/AmmoComponent.cs index 8e3df42259..1cb559aeaa 100644 --- a/Content.Server/GameObjects/Components/Weapon/Ranged/Ammunition/AmmoComponent.cs +++ b/Content.Server/GameObjects/Components/Weapon/Ranged/Ammunition/AmmoComponent.cs @@ -25,6 +25,8 @@ namespace Content.Server.GameObjects.Components.Weapon.Ranged.Ammunition [RegisterComponent] public class AmmoComponent : Component, IExamine { + [Dependency] private readonly IGameTiming _gameTiming = default!; + public override string Name => "Ammo"; public BallisticCaliber Caliber => _caliber; private BallisticCaliber _caliber; @@ -135,7 +137,7 @@ namespace Content.Server.GameObjects.Components.Weapon.Ranged.Ammunition return; } - var time = IoCManager.Resolve().CurTime; + var time = _gameTiming.CurTime; var deathTime = time + TimeSpan.FromMilliseconds(200); // Offset the sprite so it actually looks like it's coming from the gun var offset = angle.ToVec().Normalized / 2; diff --git a/Content.Server/GameObjects/Components/Weapon/Ranged/Barrels/RevolverBarrelComponent.cs b/Content.Server/GameObjects/Components/Weapon/Ranged/Barrels/RevolverBarrelComponent.cs index 4f16ffc90a..0430263cd0 100644 --- a/Content.Server/GameObjects/Components/Weapon/Ranged/Barrels/RevolverBarrelComponent.cs +++ b/Content.Server/GameObjects/Components/Weapon/Ranged/Barrels/RevolverBarrelComponent.cs @@ -25,6 +25,8 @@ namespace Content.Server.GameObjects.Components.Weapon.Ranged.Barrels [RegisterComponent] public sealed class RevolverBarrelComponent : ServerRangedBarrelComponent { + [Dependency] private readonly IRobustRandom _random = default!; + public override string Name => "RevolverBarrel"; public override uint? NetID => ContentNetIDs.REVOLVER_BARREL; @@ -176,7 +178,7 @@ namespace Content.Server.GameObjects.Components.Weapon.Ranged.Barrels /// public void Spin() { - var random = IoCManager.Resolve().Next(_ammoSlots.Length - 1); + var random = _random.Next(_ammoSlots.Length - 1); _currentSlot = random; if (_soundSpin != null) { diff --git a/Content.Server/GameObjects/Components/Weapon/Ranged/ServerRangedWeaponComponent.cs b/Content.Server/GameObjects/Components/Weapon/Ranged/ServerRangedWeaponComponent.cs index d852fe0b7b..f490be0c1a 100644 --- a/Content.Server/GameObjects/Components/Weapon/Ranged/ServerRangedWeaponComponent.cs +++ b/Content.Server/GameObjects/Components/Weapon/Ranged/ServerRangedWeaponComponent.cs @@ -32,6 +32,10 @@ namespace Content.Server.GameObjects.Components.Weapon.Ranged [RegisterComponent] public sealed class ServerRangedWeaponComponent : SharedRangedWeaponComponent, IHandSelected { + [Dependency] private readonly IMapManager _mapManager = default!; + [Dependency] private readonly IGameTiming _gameTiming = default!; + [Dependency] private readonly IRobustRandom _random = default!; + private TimeSpan _lastFireTime; [ViewVariables(VVAccess.ReadWrite)] @@ -102,7 +106,7 @@ namespace Content.Server.GameObjects.Components.Weapon.Ranged if (msg.TargetGrid != GridId.Invalid) { // grid pos - if (!IoCManager.Resolve().TryGetGrid(msg.TargetGrid, out var grid)) + if (!_mapManager.TryGetGrid(msg.TargetGrid, out var grid)) { // Client sent us a message with an invalid grid. break; @@ -147,7 +151,7 @@ namespace Content.Server.GameObjects.Components.Weapon.Ranged return; } - var curTime = IoCManager.Resolve().CurTime; + var curTime = _gameTiming.CurTime; var span = curTime - _lastFireTime; if (span.TotalSeconds < 1 / _barrel.FireRate) { @@ -158,7 +162,7 @@ namespace Content.Server.GameObjects.Components.Weapon.Ranged if (ClumsyCheck && user.HasComponent() && - IoCManager.Resolve().Prob(ClumsyExplodeChance)) + _random.Prob(ClumsyExplodeChance)) { var soundSystem = EntitySystem.Get(); soundSystem.PlayAtCoords("/Audio/Items/bikehorn.ogg",