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

@@ -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<IGameTiming>();
_lastFlash = timing.CurTime;
_lastFlash = _gameTiming.CurTime;
_duration = duration;
Dirty();
}

View File

@@ -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<IGameTiming>().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<IGameTiming>().CurTime;
_lastAttackTime = _gameTiming.CurTime;
if (Owner.TryGetComponent(out ItemCooldownComponent cooldown))
{

View File

@@ -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<IGameTiming>().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;

View File

@@ -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
/// </summary>
public void Spin()
{
var random = IoCManager.Resolve<IRobustRandom>().Next(_ammoSlots.Length - 1);
var random = _random.Next(_ammoSlots.Length - 1);
_currentSlot = random;
if (_soundSpin != null)
{

View File

@@ -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<IMapManager>().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<IGameTiming>().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<ClumsyComponent>() &&
IoCManager.Resolve<IRobustRandom>().Prob(ClumsyExplodeChance))
_random.Prob(ClumsyExplodeChance))
{
var soundSystem = EntitySystem.Get<AudioSystem>();
soundSystem.PlayAtCoords("/Audio/Items/bikehorn.ogg",