Replace resolve dependency with attribute in components (#1995)

* Replace resolve dependency with attribute in components

* Add changes that went missing in translation
This commit is contained in:
DrSmugleaf
2020-09-02 01:30:03 +02:00
committed by GitHub
parent 4044602187
commit de9dfefd61
23 changed files with 85 additions and 66 deletions

View File

@@ -32,6 +32,8 @@ namespace Content.Server.GameObjects.Components.Atmos
public class GridAtmosphereComponent : Component, IGridAtmosphereComponent public class GridAtmosphereComponent : Component, IGridAtmosphereComponent
{ {
[Robust.Shared.IoC.Dependency] private IMapManager _mapManager = default!; [Robust.Shared.IoC.Dependency] private IMapManager _mapManager = default!;
[Robust.Shared.IoC.Dependency] private ITileDefinitionManager _tileDefinitionManager = default!;
[Robust.Shared.IoC.Dependency] private IServerEntityManager _serverEntityManager = default!;
/// <summary> /// <summary>
/// Check current execution time every n instances processed. /// Check current execution time every n instances processed.
@@ -162,14 +164,13 @@ namespace Content.Server.GameObjects.Components.Atmos
var mapGrid = mapGridComponent.Grid; var mapGrid = mapGridComponent.Grid;
var tile = mapGrid.GetTileRef(indices).Tile; var tile = mapGrid.GetTileRef(indices).Tile;
var tileDefinitionManager = IoCManager.Resolve<ITileDefinitionManager>(); 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)); 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. //Actually spawn the relevant tile item at the right position and give it some offset to the corner.
var tileItem = IoCManager.Resolve<IServerEntityManager>().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); tileItem.Transform.WorldPosition += (0.2f, 0.2f);
} }

View File

@@ -23,11 +23,7 @@ using Robust.Shared.Audio;
using Robust.Shared.GameObjects; using Robust.Shared.GameObjects;
using Robust.Shared.GameObjects.Systems; using Robust.Shared.GameObjects.Systems;
using Robust.Shared.Interfaces.GameObjects; using Robust.Shared.Interfaces.GameObjects;
using Robust.Shared.Interfaces.Random;
using Robust.Shared.IoC;
using Robust.Shared.Localization; using Robust.Shared.Localization;
using Robust.Shared.Maths;
using Robust.Shared.Random;
using Robust.Shared.Serialization; using Robust.Shared.Serialization;
using Robust.Shared.ViewVariables; 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) private void TryCreatePackage(IEntity user, UiAction action, int pillAmount, int bottleAmount)
{ {
var random = IoCManager.Resolve<IRobustRandom>();
if (BufferSolution.CurrentVolume == 0) if (BufferSolution.CurrentVolume == 0)
return; return;

View File

@@ -40,6 +40,8 @@ namespace Content.Server.GameObjects.Components.Chemistry
[ComponentReference(typeof(IInteractUsing))] [ComponentReference(typeof(IInteractUsing))]
public class ReagentDispenserComponent : SharedReagentDispenserComponent, IActivate, IInteractUsing, ISolutionChange public class ReagentDispenserComponent : SharedReagentDispenserComponent, IActivate, IInteractUsing, ISolutionChange
{ {
[Dependency] private readonly IPrototypeManager _prototypeManager = default!;
[ViewVariables] private ContainerSlot _beakerContainer = default!; [ViewVariables] private ContainerSlot _beakerContainer = default!;
[ViewVariables] private string _packPrototypeId = ""; [ViewVariables] private string _packPrototypeId = "";
@@ -97,8 +99,7 @@ namespace Content.Server.GameObjects.Components.Chemistry
{ {
if (string.IsNullOrEmpty(_packPrototypeId)) return; if (string.IsNullOrEmpty(_packPrototypeId)) return;
var prototypeManager = IoCManager.Resolve<IPrototypeManager>(); if (!_prototypeManager.TryIndex(_packPrototypeId, out ReagentDispenserInventoryPrototype packPrototype))
if (!prototypeManager.TryIndex(_packPrototypeId, out ReagentDispenserInventoryPrototype packPrototype))
{ {
return; return;
} }

View File

@@ -49,6 +49,8 @@ namespace Content.Server.GameObjects.Components.Fluids
// to check for low volumes for evaporation or whatever // to check for low volumes for evaporation or whatever
[Dependency] private readonly IMapManager _mapManager = default!; [Dependency] private readonly IMapManager _mapManager = default!;
[Dependency] private readonly IRobustRandom _random = default!;
[Dependency] private readonly IEntityManager _entityManager = default!;
public override string Name => "Puddle"; 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 // Random sprite state set server-side so it's consistent across all clients
_spriteComponent = Owner.EnsureComponent<SpriteComponent>(); _spriteComponent = Owner.EnsureComponent<SpriteComponent>();
var robustRandom = IoCManager.Resolve<IRobustRandom>(); var randomVariant = _random.Next(0, _spriteVariants - 1);
var randomVariant = robustRandom.Next(0, _spriteVariants - 1);
if (_spriteComponent.BaseRSIPath != null) if (_spriteComponent.BaseRSIPath != null)
{ {
@@ -388,8 +389,7 @@ namespace Content.Server.GameObjects.Components.Fluids
if (puddle == default) if (puddle == default)
{ {
var grid = _snapGrid.DirectionToGrid(direction); var grid = _snapGrid.DirectionToGrid(direction);
var entityManager = IoCManager.Resolve<IEntityManager>(); puddle = () => _entityManager.SpawnEntity(Owner.Prototype.ID, grid).GetComponent<PuddleComponent>();
puddle = () => entityManager.SpawnEntity(Owner.Prototype.ID, grid).GetComponent<PuddleComponent>();
} }
return true; return true;

View File

@@ -4,10 +4,7 @@ using System.Threading.Tasks;
using Content.Server.GameObjects.Components.Body; using Content.Server.GameObjects.Components.Body;
using Content.Server.GameObjects.Components.GUI; using Content.Server.GameObjects.Components.GUI;
using Content.Server.GameObjects.Components.Interactable; 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.Interactable;
using Content.Shared.GameObjects.Components.Mobs;
using Content.Shared.GameObjects.Components.Storage; using Content.Shared.GameObjects.Components.Storage;
using Content.Shared.GameObjects.EntitySystems; using Content.Shared.GameObjects.EntitySystems;
using Content.Shared.GameObjects.Verbs; using Content.Shared.GameObjects.Verbs;
@@ -35,6 +32,8 @@ namespace Content.Server.GameObjects.Components.Items.Storage
[ComponentReference(typeof(IStorageComponent))] [ComponentReference(typeof(IStorageComponent))]
public class EntityStorageComponent : Component, IActivate, IStorageComponent, IInteractUsing, IDestroyAct, IActionBlocker, IExAct public class EntityStorageComponent : Component, IActivate, IStorageComponent, IInteractUsing, IDestroyAct, IActionBlocker, IExAct
{ {
[Dependency] private readonly IGameTiming _gameTiming = default!;
public override string Name => "EntityStorage"; public override string Name => "EntityStorage";
private const float MaxSize = 1.0f; // maximum width or height of an entity allowed inside the storage. 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: case RelayMovementEntityMessage msg:
if (msg.Entity.HasComponent<HandsComponent>()) if (msg.Entity.HasComponent<HandsComponent>())
{ {
var timing = IoCManager.Resolve<IGameTiming>(); if (_gameTiming.CurTime <
if (timing.CurTime <
_lastInternalOpenAttempt + InternalOpenAttemptDelay) _lastInternalOpenAttempt + InternalOpenAttemptDelay)
{ {
break; break;
} }
_lastInternalOpenAttempt = timing.CurTime; _lastInternalOpenAttempt = _gameTiming.CurTime;
TryOpenStorage(msg.Entity); TryOpenStorage(msg.Entity);
} }
break; break;

View File

@@ -13,7 +13,6 @@ namespace Content.Server.GameObjects.Components.Items.Storage.Fill
void IMapInit.MapInit() void IMapInit.MapInit()
{ {
var storage = Owner.GetComponent<IStorageComponent>(); var storage = Owner.GetComponent<IStorageComponent>();
var random = IoCManager.Resolve<IRobustRandom>();
void Spawn(string prototype) void Spawn(string prototype)
{ {

View File

@@ -9,12 +9,14 @@ namespace Content.Server.GameObjects.Components.Mobs.Speech
[RegisterComponent] [RegisterComponent]
public class OwOAccentComponent : Component, IAccentComponent public class OwOAccentComponent : Component, IAccentComponent
{ {
[Dependency] private readonly IRobustRandom _random;
public override string Name => "OwOAccent"; public override string Name => "OwOAccent";
private static readonly IReadOnlyList<string> Faces = new List<string>{ private static readonly IReadOnlyList<string> Faces = new List<string>{
" (・`ω´・)", " ;;w;;", " owo", " UwU", " >w<", " ^w^" " (・`ω´・)", " ;;w;;", " owo", " UwU", " >w<", " ^w^"
}.AsReadOnly(); }.AsReadOnly();
private string RandomFace => IoCManager.Resolve<IRobustRandom>().Pick(Faces); private string RandomFace => _random.Pick(Faces);
private static readonly Dictionary<string, string> SpecialWords = new Dictionary<string, string> private static readonly Dictionary<string, string> SpecialWords = new Dictionary<string, string>
{ {
@@ -23,7 +25,7 @@ namespace Content.Server.GameObjects.Components.Mobs.Speech
public string Accentuate(string message) public string Accentuate(string message)
{ {
foreach ((var word,var repl) in SpecialWords) foreach (var (word, repl) in SpecialWords)
{ {
message = message.Replace(word, repl); message = message.Replace(word, repl);
} }

View File

@@ -19,6 +19,9 @@ namespace Content.Server.GameObjects.Components.Movement
[RegisterComponent, ComponentReference(typeof(IMoverComponent))] [RegisterComponent, ComponentReference(typeof(IMoverComponent))]
public class AiControllerComponent : Component, IMoverComponent public class AiControllerComponent : Component, IMoverComponent
{ {
[Dependency] private readonly IPrototypeManager _prototypeManager = default!;
[Dependency] private readonly IGameTicker _gameTicker = default!;
private string? _logicName; private string? _logicName;
private float _visionRadius; private float _visionRadius;
@@ -36,7 +39,7 @@ namespace Content.Server.GameObjects.Components.Movement
} }
public AiLogicProcessor? Processor { get; set; } public AiLogicProcessor? Processor { get; set; }
[ViewVariables(VVAccess.ReadWrite)] [ViewVariables(VVAccess.ReadWrite)]
public string? StartingGearPrototype { get; set; } public string? StartingGearPrototype { get; set; }
@@ -61,13 +64,13 @@ namespace Content.Server.GameObjects.Components.Movement
protected override void Startup() protected override void Startup()
{ {
base.Startup(); base.Startup();
if (StartingGearPrototype != null) if (StartingGearPrototype != null)
{ {
var startingGear = IoCManager.Resolve<IPrototypeManager>().Index<StartingGearPrototype>(StartingGearPrototype); var startingGear = _prototypeManager.Index<StartingGearPrototype>(StartingGearPrototype);
IoCManager.Resolve<IGameTicker>().EquipStartingGear(Owner, startingGear); _gameTicker.EquipStartingGear(Owner, startingGear);
} }
} }
/// <inheritdoc /> /// <inheritdoc />
@@ -77,7 +80,7 @@ namespace Content.Server.GameObjects.Components.Movement
serializer.DataField(ref _logicName, "logic", null); serializer.DataField(ref _logicName, "logic", null);
serializer.DataReadWriteFunction( serializer.DataReadWriteFunction(
"startingGear", "startingGear",
null, null,
startingGear => StartingGearPrototype = startingGear, startingGear => StartingGearPrototype = startingGear,
() => StartingGearPrototype); () => StartingGearPrototype);

View File

@@ -6,7 +6,6 @@ using Content.Shared.GameObjects.Components.Damage;
using Content.Shared.GameObjects.Components.Mobs; using Content.Shared.GameObjects.Components.Mobs;
using Content.Shared.GameObjects.Components.Movement; using Content.Shared.GameObjects.Components.Movement;
using Content.Shared.GameObjects.Components.Nutrition; using Content.Shared.GameObjects.Components.Nutrition;
using JetBrains.Annotations;
using Robust.Shared.GameObjects; using Robust.Shared.GameObjects;
using Robust.Shared.Interfaces.Random; using Robust.Shared.Interfaces.Random;
using Robust.Shared.IoC; using Robust.Shared.IoC;
@@ -19,6 +18,8 @@ namespace Content.Server.GameObjects.Components.Nutrition
[RegisterComponent] [RegisterComponent]
public sealed class HungerComponent : SharedHungerComponent public sealed class HungerComponent : SharedHungerComponent
{ {
[Dependency] private readonly IRobustRandom _random = default!;
// Base stuff // Base stuff
[ViewVariables(VVAccess.ReadWrite)] [ViewVariables(VVAccess.ReadWrite)]
public float BaseDecayRate public float BaseDecayRate
@@ -141,7 +142,7 @@ namespace Content.Server.GameObjects.Components.Nutrition
{ {
base.Startup(); base.Startup();
// Similar functionality to SS13. Should also stagger people going to the chef. // Similar functionality to SS13. Should also stagger people going to the chef.
_currentHunger = IoCManager.Resolve<IRobustRandom>().Next( _currentHunger = _random.Next(
(int)_hungerThresholds[HungerThreshold.Peckish] + 10, (int)_hungerThresholds[HungerThreshold.Peckish] + 10,
(int)_hungerThresholds[HungerThreshold.Okay] - 1); (int)_hungerThresholds[HungerThreshold.Okay] - 1);
_currentHungerThreshold = GetHungerThreshold(_currentHunger); _currentHungerThreshold = GetHungerThreshold(_currentHunger);

View File

@@ -6,7 +6,6 @@ using Content.Shared.GameObjects.Components.Damage;
using Content.Shared.GameObjects.Components.Mobs; using Content.Shared.GameObjects.Components.Mobs;
using Content.Shared.GameObjects.Components.Movement; using Content.Shared.GameObjects.Components.Movement;
using Content.Shared.GameObjects.Components.Nutrition; using Content.Shared.GameObjects.Components.Nutrition;
using JetBrains.Annotations;
using Robust.Shared.GameObjects; using Robust.Shared.GameObjects;
using Robust.Shared.Interfaces.Random; using Robust.Shared.Interfaces.Random;
using Robust.Shared.IoC; using Robust.Shared.IoC;
@@ -19,6 +18,8 @@ namespace Content.Server.GameObjects.Components.Nutrition
[RegisterComponent] [RegisterComponent]
public sealed class ThirstComponent : SharedThirstComponent public sealed class ThirstComponent : SharedThirstComponent
{ {
[Dependency] private readonly IRobustRandom _random = default!;
// Base stuff // Base stuff
[ViewVariables(VVAccess.ReadWrite)] [ViewVariables(VVAccess.ReadWrite)]
public float BaseDecayRate public float BaseDecayRate
@@ -136,7 +137,7 @@ namespace Content.Server.GameObjects.Components.Nutrition
protected override void Startup() protected override void Startup()
{ {
base.Startup(); base.Startup();
_currentThirst = IoCManager.Resolve<IRobustRandom>().Next( _currentThirst = _random.Next(
(int)ThirstThresholds[ThirstThreshold.Thirsty] + 10, (int)ThirstThresholds[ThirstThreshold.Thirsty] + 10,
(int)ThirstThresholds[ThirstThreshold.Okay] - 1); (int)ThirstThresholds[ThirstThreshold.Okay] - 1);
_currentThirstThreshold = GetThirstThreshold(_currentThirst); _currentThirstThreshold = GetThirstThreshold(_currentThirst);

View File

@@ -24,6 +24,9 @@ namespace Content.Server.GameObjects.Components.Power.ApcNetComponents
[RegisterComponent] [RegisterComponent]
public class PowerProviderComponent : BaseApcNetComponent, IPowerProvider public class PowerProviderComponent : BaseApcNetComponent, IPowerProvider
{ {
[Dependency] private readonly IMapManager _mapManager = default!;
[Dependency] private readonly IServerEntityManager _serverEntityManager;
public override string Name => "PowerProvider"; public override string Name => "PowerProvider";
/// <summary> /// <summary>
@@ -91,14 +94,13 @@ namespace Content.Server.GameObjects.Components.Power.ApcNetComponents
private List<PowerReceiverComponent> FindAvailableReceivers() private List<PowerReceiverComponent> FindAvailableReceivers()
{ {
var mapManager = IoCManager.Resolve<IMapManager>(); var nearbyEntities = _serverEntityManager
var nearbyEntities = IoCManager.Resolve<IServerEntityManager>()
.GetEntitiesInRange(Owner, PowerTransferRange); .GetEntitiesInRange(Owner, PowerTransferRange);
return nearbyEntities.Select(entity => entity.TryGetComponent<PowerReceiverComponent>(out var receiver) ? receiver : null) return nearbyEntities.Select(entity => entity.TryGetComponent<PowerReceiverComponent>(out var receiver) ? receiver : null)
.Where(receiver => receiver != null) .Where(receiver => receiver != null)
.Where(receiver => receiver.Connectable) .Where(receiver => receiver.Connectable)
.Where(receiver => receiver.NeedsProvider) .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(); .ToList();
} }

View File

@@ -21,6 +21,9 @@ namespace Content.Server.GameObjects.Components.Power.ApcNetComponents
[RegisterComponent] [RegisterComponent]
public class PowerReceiverComponent : Component, IExamine public class PowerReceiverComponent : Component, IExamine
{ {
[Dependency] private readonly IServerEntityManager _serverEntityManager = default!;
[Dependency] private readonly IMapManager _mapManager = default!;
public override string Name => "PowerReceiver"; public override string Name => "PowerReceiver";
public event EventHandler<PowerStateEventArgs> OnPowerStateChanged; public event EventHandler<PowerStateEventArgs> OnPowerStateChanged;
@@ -116,16 +119,16 @@ namespace Content.Server.GameObjects.Components.Power.ApcNetComponents
private bool TryFindAvailableProvider(out IPowerProvider foundProvider) private bool TryFindAvailableProvider(out IPowerProvider foundProvider)
{ {
var nearbyEntities = IoCManager.Resolve<IServerEntityManager>() var nearbyEntities = _serverEntityManager
.GetEntitiesInRange(Owner, PowerReceptionRange); .GetEntitiesInRange(Owner, PowerReceptionRange);
var mapManager = IoCManager.Resolve<IMapManager>();
foreach (var entity in nearbyEntities) foreach (var entity in nearbyEntities)
{ {
if (entity.TryGetComponent<PowerProviderComponent>(out var provider)) if (entity.TryGetComponent<PowerProviderComponent>(out var provider))
{ {
if (provider.Connectable) 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)) if (distanceToProvider < Math.Min(PowerReceptionRange, provider.PowerTransferRange))
{ {
foundProvider = provider; foundProvider = provider;

View File

@@ -22,6 +22,8 @@ namespace Content.Server.GameObjects.Components.Projectiles
[RegisterComponent] [RegisterComponent]
public class HitscanComponent : Component public class HitscanComponent : Component
{ {
[Dependency] private readonly IGameTiming _gameTiming = default!;
public override string Name => "Hitscan"; public override string Name => "Hitscan";
public CollisionGroup CollisionMask => (CollisionGroup) _collisionMask; public CollisionGroup CollisionMask => (CollisionGroup) _collisionMask;
private int _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) public void FireEffects(IEntity user, float distance, Angle angle, IEntity hitEntity = null)
{ {
var effectSystem = EntitySystem.Get<EffectSystem>(); var effectSystem = EntitySystem.Get<EffectSystem>();
_startTime = IoCManager.Resolve<IGameTiming>().CurTime; _startTime = _gameTiming.CurTime;
_deathTime = _startTime + TimeSpan.FromSeconds(1); _deathTime = _startTime + TimeSpan.FromSeconds(1);
var afterEffect = AfterEffects(user.Transform.GridPosition, angle, distance, 1.0f); var afterEffect = AfterEffects(user.Transform.GridPosition, angle, distance, 1.0f);

View File

@@ -14,6 +14,7 @@ namespace Content.Server.GameObjects.Components
class RadioComponent : Component, IUse, IListen class RadioComponent : Component, IUse, IListen
{ {
[Dependency] private readonly IEntitySystemManager _entitySystemManager = default!; [Dependency] private readonly IEntitySystemManager _entitySystemManager = default!;
[Dependency] private readonly IChatManager _chatManager = default!;
public override string Name => "Radio"; public override string Name => "Radio";
@@ -51,8 +52,7 @@ namespace Content.Server.GameObjects.Components
public void Speaker(string message) public void Speaker(string message)
{ {
var chat = IoCManager.Resolve<IChatManager>(); _chatManager.EntitySay(Owner, message);
chat.EntitySay(Owner, message);
} }
public bool UseEntity(UseEntityEventArgs eventArgs) public bool UseEntity(UseEntityEventArgs eventArgs)

View File

@@ -10,6 +10,8 @@ namespace Content.Server.GameObjects.Components.Research
[ComponentReference(typeof(SharedLatheDatabaseComponent))] [ComponentReference(typeof(SharedLatheDatabaseComponent))]
public class ProtolatheDatabaseComponent : SharedProtolatheDatabaseComponent public class ProtolatheDatabaseComponent : SharedProtolatheDatabaseComponent
{ {
[Dependency] private readonly IPrototypeManager _prototypeManager = default!;
public override string Name => "ProtolatheDatabase"; public override string Name => "ProtolatheDatabase";
public override ComponentState GetComponentState() public override ComponentState GetComponentState()
@@ -24,13 +26,11 @@ namespace Content.Server.GameObjects.Components.Research
{ {
if (!Owner.TryGetComponent(out TechnologyDatabaseComponent database)) return; if (!Owner.TryGetComponent(out TechnologyDatabaseComponent database)) return;
var prototypeManager = IoCManager.Resolve<IPrototypeManager>();
foreach (var technology in database.Technologies) foreach (var technology in database.Technologies)
{ {
foreach (var id in technology.UnlockedRecipes) foreach (var id in technology.UnlockedRecipes)
{ {
var recipe = (LatheRecipePrototype)prototypeManager.Index(typeof(LatheRecipePrototype), id); var recipe = (LatheRecipePrototype) _prototypeManager.Index(typeof(LatheRecipePrototype), id);
UnlockRecipe(recipe); UnlockRecipe(recipe);
} }
} }

View File

@@ -57,8 +57,7 @@ namespace Content.Server.GameObjects.Components.Research
switch (message.Message) switch (message.Message)
{ {
case ConsoleUnlockTechnologyMessage msg: case ConsoleUnlockTechnologyMessage msg:
var protoMan = IoCManager.Resolve<IPrototypeManager>(); if (!_prototypeManager.TryIndex(msg.Id, out TechnologyPrototype tech)) break;
if (!protoMan.TryIndex(msg.Id, out TechnologyPrototype tech)) break;
if (client.Server == null) break; if (client.Server == null) break;
if (!client.Server.CanUnlockTechnology(tech)) break; if (!client.Server.CanUnlockTechnology(tech)) break;
if (client.Server.UnlockTechnology(tech)) if (client.Server.UnlockTechnology(tech))

View File

@@ -15,12 +15,15 @@ namespace Content.Server.GameObjects.Components.StationEvents
[RegisterComponent] [RegisterComponent]
public sealed class RadiationPulseComponent : SharedRadiationPulseComponent 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 MinPulseLifespan = 0.8f;
private const float MaxPulseLifespan = 2.5f; private const float MaxPulseLifespan = 2.5f;
public float DPS => _dps; public float DPS => _dps;
private float _dps; private float _dps;
private TimeSpan _endTime; private TimeSpan _endTime;
public override void ExposeData(ObjectSerializer serializer) public override void ExposeData(ObjectSerializer serializer)
@@ -33,15 +36,15 @@ namespace Content.Server.GameObjects.Components.StationEvents
{ {
base.Initialize(); base.Initialize();
var currentTime = IoCManager.Resolve<IGameTiming>().CurTime; var currentTime = _gameTiming.CurTime;
var duration = var duration =
TimeSpan.FromSeconds( TimeSpan.FromSeconds(
IoCManager.Resolve<IRobustRandom>().NextFloat() * (MaxPulseLifespan - MinPulseLifespan) + _random.NextFloat() * (MaxPulseLifespan - MinPulseLifespan) +
MinPulseLifespan); MinPulseLifespan);
_endTime = currentTime + duration; _endTime = currentTime + duration;
Timer.Spawn(duration, Timer.Spawn(duration,
() => () =>
{ {
if (!Owner.Deleted) if (!Owner.Deleted)
@@ -59,4 +62,4 @@ namespace Content.Server.GameObjects.Components.StationEvents
return new RadiationPulseMessage(_endTime); return new RadiationPulseMessage(_endTime);
} }
} }
} }

View File

@@ -32,6 +32,7 @@ namespace Content.Server.GameObjects.Components.VendingMachines
public class VendingMachineComponent : SharedVendingMachineComponent, IActivate, IExamine, IBreakAct, IWires public class VendingMachineComponent : SharedVendingMachineComponent, IActivate, IExamine, IBreakAct, IWires
{ {
[Dependency] private readonly IRobustRandom _random = default!; [Dependency] private readonly IRobustRandom _random = default!;
[Dependency] private readonly IPrototypeManager _prototypeManager = default!;
private bool _ejecting; private bool _ejecting;
private TimeSpan _animationDuration = TimeSpan.Zero; private TimeSpan _animationDuration = TimeSpan.Zero;
@@ -77,8 +78,7 @@ namespace Content.Server.GameObjects.Components.VendingMachines
private void InitializeFromPrototype() private void InitializeFromPrototype()
{ {
if (string.IsNullOrEmpty(_packPrototypeId)) { return; } if (string.IsNullOrEmpty(_packPrototypeId)) { return; }
var prototypeManger = IoCManager.Resolve<IPrototypeManager>(); if (!_prototypeManager.TryIndex(_packPrototypeId, out VendingMachineInventoryPrototype packPrototype))
if (!prototypeManger.TryIndex(_packPrototypeId, out VendingMachineInventoryPrototype packPrototype))
{ {
return; return;
} }

View File

@@ -12,13 +12,14 @@ namespace Content.Server.GameObjects.Components.Weapon
[RegisterComponent] [RegisterComponent]
public sealed class FlashableComponent : SharedFlashableComponent public sealed class FlashableComponent : SharedFlashableComponent
{ {
[Dependency] private readonly IGameTiming _gameTiming = default!;
private double _duration; private double _duration;
private TimeSpan _lastFlash; private TimeSpan _lastFlash;
public void Flash(double duration) public void Flash(double duration)
{ {
var timing = IoCManager.Resolve<IGameTiming>(); _lastFlash = _gameTiming.CurTime;
_lastFlash = timing.CurTime;
_duration = duration; _duration = duration;
Dirty(); Dirty();
} }

View File

@@ -26,6 +26,7 @@ namespace Content.Server.GameObjects.Components.Weapon.Melee
[Dependency] private readonly IMapManager _mapManager = default!; [Dependency] private readonly IMapManager _mapManager = default!;
[Dependency] private readonly IEntitySystemManager _entitySystemManager = default!; [Dependency] private readonly IEntitySystemManager _entitySystemManager = default!;
[Dependency] private readonly IPhysicsManager _physicsManager = default!; [Dependency] private readonly IPhysicsManager _physicsManager = default!;
[Dependency] private readonly IGameTiming _gameTiming = default!;
public override string Name => "MeleeWeapon"; public override string Name => "MeleeWeapon";
private TimeSpan _lastAttackTime; private TimeSpan _lastAttackTime;
@@ -85,7 +86,7 @@ namespace Content.Server.GameObjects.Components.Weapon.Melee
void IAttack.Attack(AttackEventArgs eventArgs) void IAttack.Attack(AttackEventArgs eventArgs)
{ {
var curTime = IoCManager.Resolve<IGameTiming>().CurTime; var curTime = _gameTiming.CurTime;
var span = curTime - _lastAttackTime; var span = curTime - _lastAttackTime;
if(span.TotalSeconds < _cooldownTime) { if(span.TotalSeconds < _cooldownTime) {
return; return;
@@ -127,7 +128,7 @@ namespace Content.Server.GameObjects.Components.Weapon.Melee
sys.SendAnimation(Arc, angle, eventArgs.User, hitEntities); sys.SendAnimation(Arc, angle, eventArgs.User, hitEntities);
} }
_lastAttackTime = IoCManager.Resolve<IGameTiming>().CurTime; _lastAttackTime = _gameTiming.CurTime;
if (Owner.TryGetComponent(out ItemCooldownComponent cooldown)) if (Owner.TryGetComponent(out ItemCooldownComponent cooldown))
{ {

View File

@@ -25,6 +25,8 @@ namespace Content.Server.GameObjects.Components.Weapon.Ranged.Ammunition
[RegisterComponent] [RegisterComponent]
public class AmmoComponent : Component, IExamine public class AmmoComponent : Component, IExamine
{ {
[Dependency] private readonly IGameTiming _gameTiming = default!;
public override string Name => "Ammo"; public override string Name => "Ammo";
public BallisticCaliber Caliber => _caliber; public BallisticCaliber Caliber => _caliber;
private BallisticCaliber _caliber; private BallisticCaliber _caliber;
@@ -135,7 +137,7 @@ namespace Content.Server.GameObjects.Components.Weapon.Ranged.Ammunition
return; return;
} }
var time = IoCManager.Resolve<IGameTiming>().CurTime; var time = _gameTiming.CurTime;
var deathTime = time + TimeSpan.FromMilliseconds(200); var deathTime = time + TimeSpan.FromMilliseconds(200);
// Offset the sprite so it actually looks like it's coming from the gun // Offset the sprite so it actually looks like it's coming from the gun
var offset = angle.ToVec().Normalized / 2; var offset = angle.ToVec().Normalized / 2;

View File

@@ -25,6 +25,8 @@ namespace Content.Server.GameObjects.Components.Weapon.Ranged.Barrels
[RegisterComponent] [RegisterComponent]
public sealed class RevolverBarrelComponent : ServerRangedBarrelComponent public sealed class RevolverBarrelComponent : ServerRangedBarrelComponent
{ {
[Dependency] private readonly IRobustRandom _random = default!;
public override string Name => "RevolverBarrel"; public override string Name => "RevolverBarrel";
public override uint? NetID => ContentNetIDs.REVOLVER_BARREL; public override uint? NetID => ContentNetIDs.REVOLVER_BARREL;
@@ -176,7 +178,7 @@ namespace Content.Server.GameObjects.Components.Weapon.Ranged.Barrels
/// </summary> /// </summary>
public void Spin() public void Spin()
{ {
var random = IoCManager.Resolve<IRobustRandom>().Next(_ammoSlots.Length - 1); var random = _random.Next(_ammoSlots.Length - 1);
_currentSlot = random; _currentSlot = random;
if (_soundSpin != null) if (_soundSpin != null)
{ {

View File

@@ -32,6 +32,10 @@ namespace Content.Server.GameObjects.Components.Weapon.Ranged
[RegisterComponent] [RegisterComponent]
public sealed class ServerRangedWeaponComponent : SharedRangedWeaponComponent, IHandSelected 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; private TimeSpan _lastFireTime;
[ViewVariables(VVAccess.ReadWrite)] [ViewVariables(VVAccess.ReadWrite)]
@@ -102,7 +106,7 @@ namespace Content.Server.GameObjects.Components.Weapon.Ranged
if (msg.TargetGrid != GridId.Invalid) if (msg.TargetGrid != GridId.Invalid)
{ {
// grid pos // grid pos
if (!IoCManager.Resolve<IMapManager>().TryGetGrid(msg.TargetGrid, out var grid)) if (!_mapManager.TryGetGrid(msg.TargetGrid, out var grid))
{ {
// Client sent us a message with an invalid grid. // Client sent us a message with an invalid grid.
break; break;
@@ -147,7 +151,7 @@ namespace Content.Server.GameObjects.Components.Weapon.Ranged
return; return;
} }
var curTime = IoCManager.Resolve<IGameTiming>().CurTime; var curTime = _gameTiming.CurTime;
var span = curTime - _lastFireTime; var span = curTime - _lastFireTime;
if (span.TotalSeconds < 1 / _barrel.FireRate) if (span.TotalSeconds < 1 / _barrel.FireRate)
{ {
@@ -158,7 +162,7 @@ namespace Content.Server.GameObjects.Components.Weapon.Ranged
if (ClumsyCheck && if (ClumsyCheck &&
user.HasComponent<ClumsyComponent>() && user.HasComponent<ClumsyComponent>() &&
IoCManager.Resolve<IRobustRandom>().Prob(ClumsyExplodeChance)) _random.Prob(ClumsyExplodeChance))
{ {
var soundSystem = EntitySystem.Get<AudioSystem>(); var soundSystem = EntitySystem.Get<AudioSystem>();
soundSystem.PlayAtCoords("/Audio/Items/bikehorn.ogg", soundSystem.PlayAtCoords("/Audio/Items/bikehorn.ogg",