Fix errors

This commit is contained in:
DrSmugleaf
2021-12-05 21:02:04 +01:00
parent 2a3b7d809d
commit ab9d0cc6d8
94 changed files with 568 additions and 591 deletions

View File

@@ -22,6 +22,8 @@ namespace Content.Server.Weapon.Ranged.Ammunition.Components
public sealed class AmmoBoxComponent : Component, IInteractUsing, IUse, IInteractHand, IMapInit, IExamine
#pragma warning restore 618
{
[Dependency] private readonly IEntityManager _entities = default!;
public override string Name => "AmmoBox";
[DataField("caliber")]
@@ -73,7 +75,7 @@ namespace Content.Server.Weapon.Ranged.Ammunition.Components
private void UpdateAppearance()
{
if (IoCManager.Resolve<IEntityManager>().TryGetComponent(Owner, out AppearanceComponent? appearanceComponent))
if (_entities.TryGetComponent(Owner, out AppearanceComponent? appearanceComponent))
{
appearanceComponent.SetData(MagazineBarrelVisuals.MagLoaded, true);
appearanceComponent.SetData(AmmoVisuals.AmmoCount, AmmoLeft);
@@ -81,7 +83,7 @@ namespace Content.Server.Weapon.Ranged.Ammunition.Components
}
}
public EntityUid TakeAmmo()
public EntityUid? TakeAmmo()
{
if (_spawnedAmmo.TryPop(out var ammo))
{
@@ -91,10 +93,10 @@ namespace Content.Server.Weapon.Ranged.Ammunition.Components
if (_unspawnedCount > 0)
{
ammo = IoCManager.Resolve<IEntityManager>().SpawnEntity(_fillPrototype, IoCManager.Resolve<IEntityManager>().GetComponent<TransformComponent>(Owner).Coordinates);
ammo = _entities.SpawnEntity(_fillPrototype, _entities.GetComponent<TransformComponent>(Owner).Coordinates);
// when dumping from held ammo box, this detaches the spawned ammo from the player.
IoCManager.Resolve<IEntityManager>().GetComponent<TransformComponent>(ammo).AttachParentToContainerOrGrid();
_entities.GetComponent<TransformComponent>(ammo).AttachParentToContainerOrGrid();
_unspawnedCount--;
}
@@ -104,7 +106,7 @@ namespace Content.Server.Weapon.Ranged.Ammunition.Components
public bool TryInsertAmmo(EntityUid user, EntityUid entity)
{
if (!IoCManager.Resolve<IEntityManager>().TryGetComponent(entity, out AmmoComponent? ammoComponent))
if (!_entities.TryGetComponent(entity, out AmmoComponent? ammoComponent))
{
return false;
}
@@ -129,12 +131,12 @@ namespace Content.Server.Weapon.Ranged.Ammunition.Components
async Task<bool> IInteractUsing.InteractUsing(InteractUsingEventArgs eventArgs)
{
if (IoCManager.Resolve<IEntityManager>().HasComponent<AmmoComponent>(eventArgs.Using))
if (_entities.HasComponent<AmmoComponent>(eventArgs.Using))
{
return TryInsertAmmo(eventArgs.User, eventArgs.Using);
}
if (IoCManager.Resolve<IEntityManager>().TryGetComponent(eventArgs.Using, out RangedMagazineComponent? rangedMagazine))
if (_entities.TryGetComponent(eventArgs.Using, out RangedMagazineComponent? rangedMagazine))
{
for (var i = 0; i < Math.Max(10, rangedMagazine.ShotsLeft); i++)
{
@@ -158,21 +160,19 @@ namespace Content.Server.Weapon.Ranged.Ammunition.Components
return false;
}
private bool TryUse(EntityUiduser)
private bool TryUse(EntityUid user)
{
if (!IoCManager.Resolve<IEntityManager>().TryGetComponent(user, out HandsComponent? handsComponent))
if (!_entities.TryGetComponent(user, out HandsComponent? handsComponent))
{
return false;
}
var ammo = TakeAmmo();
if (ammo == null)
if (TakeAmmo() is not { } ammo)
{
return false;
}
if (IoCManager.Resolve<IEntityManager>().TryGetComponent(ammo, out ItemComponent? item))
if (_entities.TryGetComponent(ammo, out ItemComponent? item))
{
if (!handsComponent.CanPutInHand(item))
{
@@ -194,8 +194,7 @@ namespace Content.Server.Weapon.Ranged.Ammunition.Components
for (var i = 0; i < Math.Min(count, Capacity); i++)
{
var ammo = TakeAmmo();
if (ammo == null)
if (TakeAmmo() is not { } ammo)
{
break;
}

View File

@@ -319,7 +319,7 @@ namespace Content.Server.Weapon.Ranged.Barrels.Components
return true;
}
public void RemoveMagazine(EntityUiduser)
public void RemoveMagazine(EntityUid user)
{
var mag = MagazineContainer.ContainedEntity;

View File

@@ -259,24 +259,27 @@ namespace Content.Server.Weapon.Ranged.Barrels.Components
/// <param name="robustRandom"></param>
/// <param name="prototypeManager"></param>
/// <param name="ejectDirections"></param>
public void EjectCasing(
public static void EjectCasing(
EntityUid entity,
bool playSound = true,
Direction[]? ejectDirections = null,
IRobustRandom? robustRandom = null,
IPrototypeManager? prototypeManager = null,
Direction[]? ejectDirections = null)
IEntityManager? entities = null)
{
robustRandom ??= IoCManager.Resolve<IRobustRandom>();
IoCManager.Resolve(ref robustRandom, ref prototypeManager, ref entities);
ejectDirections ??= new[]
{Direction.East, Direction.North, Direction.NorthWest, Direction.South, Direction.SouthEast, Direction.West};
const float ejectOffset = 1.8f;
var ammo = _entities.GetComponent<AmmoComponent>(entity);
var ammo = entities.GetComponent<AmmoComponent>(entity);
var offsetPos = ((robustRandom.NextFloat() - 0.5f) * ejectOffset, (robustRandom.NextFloat() - 0.5f) * ejectOffset);
_entities.GetComponent<TransformComponent>(entity).Coordinates = _entities.GetComponent<TransformComponent>(entity).Coordinates.Offset(offsetPos);
_entities.GetComponent<TransformComponent>(entity).LocalRotation = robustRandom.Pick(ejectDirections).ToAngle();
entities.GetComponent<TransformComponent>(entity).Coordinates = entities.GetComponent<TransformComponent>(entity).Coordinates.Offset(offsetPos);
entities.GetComponent<TransformComponent>(entity).LocalRotation = robustRandom.Pick(ejectDirections).ToAngle();
SoundSystem.Play(Filter.Broadcast(), ammo.SoundCollectionEject.GetSound(), _entities.GetComponent<TransformComponent>(entity).Coordinates, AudioParams.Default.WithVolume(-1));
var coordinates = entities.GetComponent<TransformComponent>(entity).Coordinates;
SoundSystem.Play(Filter.Broadcast(), ammo.SoundCollectionEject.GetSound(), coordinates, AudioParams.Default.WithVolume(-1));
}
/// <summary>
@@ -284,7 +287,7 @@ namespace Content.Server.Weapon.Ranged.Barrels.Components
/// Wraps EjectCasing to make it less toxic for bulk ejections
/// </summary>
/// <param name="entities"></param>
public void EjectCasings(IEnumerable<EntityUid> entities)
public static void EjectCasings(IEnumerable<EntityUid> entities)
{
var robustRandom = IoCManager.Resolve<IRobustRandom>();
var prototypeManager = IoCManager.Resolve<IPrototypeManager>();
@@ -294,7 +297,7 @@ namespace Content.Server.Weapon.Ranged.Barrels.Components
foreach (var entity in entities)
{
EjectCasing(entity, playSound, robustRandom, prototypeManager, ejectDirections);
EjectCasing(entity, playSound, ejectDirections, robustRandom, prototypeManager);
soundPlayCount++;
if (soundPlayCount > 3)
{