Fix more errors

This commit is contained in:
DrSmugleaf
2021-12-06 00:52:58 +01:00
parent 2b1fecbe02
commit 215cae5655
55 changed files with 262 additions and 297 deletions

View File

@@ -104,7 +104,7 @@ namespace Content.Server.Weapon.Ranged.Ammunition.Components
}
}
public EntityUid TakeBullet(EntityCoordinates spawnAt)
public EntityUid? TakeBullet(EntityCoordinates spawnAt)
{
if (_ammoIsProjectile)
{

View File

@@ -76,7 +76,7 @@ namespace Content.Server.Weapon.Ranged.Barrels
Verb verb = new()
{
Text = IoCManager.Resolve<IEntityManager>().GetComponent<MetaDataComponent>(component.PowerCell.Owner).EntityName,
Text = EntityManager.GetComponent<MetaDataComponent>(component.PowerCell.Owner).EntityName,
Category = VerbCategory.Eject,
Act = () => component.TryEjectCell(args.User)
};
@@ -85,18 +85,18 @@ namespace Content.Server.Weapon.Ranged.Barrels
private void AddInsertCellVerb(EntityUid uid, ServerBatteryBarrelComponent component, GetInteractionVerbsEvent args)
{
if (args.Using == null ||
if (args.Using is not {Valid: true} @using ||
!args.CanAccess ||
!args.CanInteract ||
component.PowerCell != null ||
!IoCManager.Resolve<IEntityManager>().HasComponent<BatteryComponent>(args.Using) ||
!EntityManager.HasComponent<BatteryComponent>(@using) ||
!_actionBlockerSystem.CanDrop(args.User))
return;
Verb verb = new();
verb.Text = IoCManager.Resolve<IEntityManager>().GetComponent<MetaDataComponent>(args.Using).EntityName;
verb.Text = EntityManager.GetComponent<MetaDataComponent>(@using).EntityName;
verb.Category = VerbCategory.Insert;
verb.Act = () => component.TryInsertPowerCell(args.Using);
verb.Act = () => component.TryInsertPowerCell(@using);
args.Verbs.Add(verb);
}
@@ -113,7 +113,7 @@ namespace Content.Server.Weapon.Ranged.Barrels
return;
Verb verb = new();
verb.Text = IoCManager.Resolve<IEntityManager>().GetComponent<MetaDataComponent>(component.MagazineContainer.ContainedEntity!).EntityName;
verb.Text = EntityManager.GetComponent<MetaDataComponent>(component.MagazineContainer.ContainedEntity!.Value).EntityName;
verb.Category = VerbCategory.Eject;
verb.Act = () => component.RemoveMagazine(args.User);
args.Verbs.Add(verb);
@@ -135,16 +135,16 @@ namespace Content.Server.Weapon.Ranged.Barrels
args.Verbs.Add(toggleBolt);
// Are we holding a mag that we can insert?
if (args.Using == null ||
!component.CanInsertMagazine(args.User, args.Using) ||
if (args.Using is not {Valid: true} @using ||
!component.CanInsertMagazine(args.User, @using) ||
!_actionBlockerSystem.CanDrop(args.User))
return;
// Insert mag verb
Verb insert = new();
insert.Text = IoCManager.Resolve<IEntityManager>().GetComponent<MetaDataComponent>(args.Using).EntityName;
insert.Text = EntityManager.GetComponent<MetaDataComponent>(@using).EntityName;
insert.Category = VerbCategory.Insert;
insert.Act = () => component.InsertMagazine(args.User, args.Using);
insert.Act = () => component.InsertMagazine(args.User, @using);
args.Verbs.Add(insert);
}
}

View File

@@ -31,6 +31,7 @@ namespace Content.Server.Weapon.Ranged.Barrels.Components
{
// Originally I had this logic shared with PumpBarrel and used a couple of variables to control things
// but it felt a lot messier to play around with, especially when adding verbs
[Dependency] private readonly IEntityManager _entities = default!;
public override string Name => "BoltActionBarrel";
@@ -110,7 +111,7 @@ namespace Content.Server.Weapon.Ranged.Barrels.Components
if (_unspawnedCount > 0)
{
_unspawnedCount--;
var chamberEntity = IoCManager.Resolve<IEntityManager>().SpawnEntity(_fillPrototype, IoCManager.Resolve<IEntityManager>().GetComponent<TransformComponent>(Owner).Coordinates);
var chamberEntity = _entities.SpawnEntity(_fillPrototype, _entities.GetComponent<TransformComponent>(Owner).Coordinates);
_chamberContainer.Insert(chamberEntity);
}
}
@@ -124,7 +125,7 @@ namespace Content.Server.Weapon.Ranged.Barrels.Components
// (Is one chambered?, is the bullet spend)
var chamber = (chamberedExists, false);
if (chamberedExists && IoCManager.Resolve<IEntityManager>().TryGetComponent<AmmoComponent?>(_chamberContainer.ContainedEntity!, out var ammo))
if (chamberedExists && _entities.TryGetComponent<AmmoComponent?>(_chamberContainer.ContainedEntity!.Value, out var ammo))
{
chamber.Item2 = ammo.Spent;
}
@@ -154,7 +155,7 @@ namespace Content.Server.Weapon.Ranged.Barrels.Components
_chamberContainer = ContainerHelpers.EnsureContainer<ContainerSlot>(Owner, $"{Name}-chamber-container");
if (IoCManager.Resolve<IEntityManager>().TryGetComponent(Owner, out AppearanceComponent? appearanceComponent))
if (_entities.TryGetComponent(Owner, out AppearanceComponent? appearanceComponent))
{
_appearanceComponent = appearanceComponent;
}
@@ -171,14 +172,13 @@ namespace Content.Server.Weapon.Ranged.Barrels.Components
_appearanceComponent?.SetData(AmmoVisuals.AmmoMax, Capacity);
}
public override EntityUid PeekAmmo()
public override EntityUid? PeekAmmo()
{
return _chamberContainer.ContainedEntity;
}
public override EntityUid TakeProjectile(EntityCoordinates spawnAt)
public override EntityUid? TakeProjectile(EntityCoordinates spawnAt)
{
var chamberEntity = _chamberContainer.ContainedEntity;
if (_autoCycle)
{
Cycle();
@@ -188,10 +188,10 @@ namespace Content.Server.Weapon.Ranged.Barrels.Components
Dirty();
}
if (chamberEntity == null)
if (_chamberContainer.ContainedEntity is not {Valid: true} chamberEntity)
return null;
return IoCManager.Resolve<IEntityManager>().GetComponentOrNull<AmmoComponent>(chamberEntity)?.TakeBullet(spawnAt);
return _entities.GetComponentOrNull<AmmoComponent>(chamberEntity)?.TakeBullet(spawnAt);
}
protected override bool WeaponCanFire()
@@ -229,7 +229,7 @@ namespace Content.Server.Weapon.Ranged.Barrels.Components
public bool TryInsertBullet(EntityUid user, EntityUid ammo)
{
if (!IoCManager.Resolve<IEntityManager>().TryGetComponent(ammo, out AmmoComponent? ammoComponent))
if (!_entities.TryGetComponent(ammo, out AmmoComponent? ammoComponent))
{
return false;
}
@@ -291,16 +291,15 @@ namespace Content.Server.Weapon.Ranged.Barrels.Components
private bool TryEjectChamber()
{
var chamberedEntity = _chamberContainer.ContainedEntity;
if (chamberedEntity != null)
if (_chamberContainer.ContainedEntity is {Valid: true} chambered)
{
if (!_chamberContainer.Remove(chamberedEntity))
if (!_chamberContainer.Remove(chambered))
{
return false;
}
if (!IoCManager.Resolve<IEntityManager>().GetComponent<AmmoComponent>(chamberedEntity).Caseless)
if (!_entities.GetComponent<AmmoComponent>(chambered).Caseless)
{
EjectCasing(chamberedEntity);
EjectCasing(chambered);
}
return true;
}
@@ -322,7 +321,7 @@ namespace Content.Server.Weapon.Ranged.Barrels.Components
else if (_unspawnedCount > 0)
{
_unspawnedCount--;
var ammoEntity = IoCManager.Resolve<IEntityManager>().SpawnEntity(_fillPrototype, IoCManager.Resolve<IEntityManager>().GetComponent<TransformComponent>(Owner).Coordinates);
var ammoEntity = _entities.SpawnEntity(_fillPrototype, _entities.GetComponent<TransformComponent>(Owner).Coordinates);
_chamberContainer.Insert(ammoEntity);
return true;
}

View File

@@ -85,7 +85,7 @@ namespace Content.Server.Weapon.Ranged.Barrels.Components
// (Is one chambered?, is the bullet spend)
var chamber = (chamberedExists, false);
if (chamberedExists && IoCManager.Resolve<IEntityManager>().TryGetComponent<AmmoComponent?>(_chamberContainer.ContainedEntity!, out var ammo))
if (chamberedExists && IoCManager.Resolve<IEntityManager>().TryGetComponent<AmmoComponent?>(_chamberContainer.ContainedEntity!.Value, out var ammo))
{
chamber.Item2 = ammo.Spent;
}
@@ -140,15 +140,13 @@ namespace Content.Server.Weapon.Ranged.Barrels.Components
_appearanceComponent?.SetData(AmmoVisuals.AmmoMax, Capacity);
}
public override EntityUid PeekAmmo()
public override EntityUid? PeekAmmo()
{
return _chamberContainer.ContainedEntity;
}
public override EntityUid TakeProjectile(EntityCoordinates spawnAt)
public override EntityUid? TakeProjectile(EntityCoordinates spawnAt)
{
var chamberEntity = _chamberContainer.ContainedEntity;
if (!_manualCycle)
{
Cycle();
@@ -158,7 +156,7 @@ namespace Content.Server.Weapon.Ranged.Barrels.Components
Dirty();
}
if (chamberEntity == null)
if (_chamberContainer.ContainedEntity is not {Valid: true} chamberEntity)
return null;
return IoCManager.Resolve<IEntityManager>().GetComponentOrNull<AmmoComponent>(chamberEntity)?.TakeBullet(spawnAt);
@@ -166,8 +164,7 @@ namespace Content.Server.Weapon.Ranged.Barrels.Components
private void Cycle(bool manual = false)
{
var chamberedEntity = _chamberContainer.ContainedEntity;
if (chamberedEntity != null)
if (_chamberContainer.ContainedEntity is {Valid: true} chamberedEntity)
{
_chamberContainer.Remove(chamberedEntity);
var ammoComponent = IoCManager.Resolve<IEntityManager>().GetComponent<AmmoComponent>(chamberedEntity);

View File

@@ -71,7 +71,7 @@ namespace Content.Server.Weapon.Ranged.Barrels.Components
void ISerializationHooks.AfterDeserialization()
{
_ammoSlots = new IEntity[_serializedCapacity];
_ammoSlots = new EntityUid[_serializedCapacity];
}
public override ComponentState GetComponentState()
@@ -81,7 +81,7 @@ namespace Content.Server.Weapon.Ranged.Barrels.Components
{
slotsSpent[i] = null;
var ammoEntity = _ammoSlots[i];
if (ammoEntity != null && IoCManager.Resolve<IEntityManager>().TryGetComponent(ammoEntity, out AmmoComponent? ammo))
if (ammoEntity != default && IoCManager.Resolve<IEntityManager>().TryGetComponent(ammoEntity, out AmmoComponent? ammo))
{
slotsSpent[i] = ammo.Spent;
}
@@ -155,7 +155,7 @@ namespace Content.Server.Weapon.Ranged.Barrels.Components
for (var i = _ammoSlots.Length - 1; i >= 0; i--)
{
var slot = _ammoSlots[i];
if (slot == null)
if (slot == default)
{
_currentSlot = i;
_ammoSlots[i] = entity;
@@ -191,7 +191,7 @@ namespace Content.Server.Weapon.Ranged.Barrels.Components
Dirty();
}
public override EntityUid PeekAmmo()
public override EntityUid? PeekAmmo()
{
return _ammoSlots[_currentSlot];
}
@@ -202,17 +202,17 @@ namespace Content.Server.Weapon.Ranged.Barrels.Components
/// </summary>
/// <returns></returns>
/// <exception cref="NotImplementedException"></exception>
public override EntityUid TakeProjectile(EntityCoordinates spawnAt)
public override EntityUid? TakeProjectile(EntityCoordinates spawnAt)
{
var ammo = _ammoSlots[_currentSlot];
EntityUid bullet = null;
if (ammo != null)
EntityUid? bullet = null;
if (ammo != default)
{
var ammoComponent = IoCManager.Resolve<IEntityManager>().GetComponent<AmmoComponent>(ammo);
bullet = ammoComponent.TakeBullet(spawnAt);
if (ammoComponent.Caseless)
{
_ammoSlots[_currentSlot] = null;
_ammoSlots[_currentSlot] = default;
_ammoContainer.Remove(ammo);
}
}
@@ -226,14 +226,14 @@ namespace Content.Server.Weapon.Ranged.Barrels.Components
for (var i = 0; i < _ammoSlots.Length; i++)
{
var entity = _ammoSlots[i];
if (entity == null)
if (entity == default)
{
continue;
}
_ammoContainer.Remove(entity);
EjectCasing(entity);
_ammoSlots[i] = null;
_ammoSlots[i] = default;
}
if (_ammoContainer.ContainedEntities.Count > 0)
@@ -243,7 +243,6 @@ namespace Content.Server.Weapon.Ranged.Barrels.Components
// May as well point back at the end?
_currentSlot = _ammoSlots.Length - 1;
return;
}
/// <summary>

View File

@@ -127,7 +127,7 @@ namespace Content.Server.Weapon.Ranged.Barrels.Components
Dirty();
}
public override EntityUid PeekAmmo()
public override EntityUid? PeekAmmo()
{
// Spawn a dummy entity because it's easier to work with I guess
// This will get re-used for the projectile
@@ -141,7 +141,7 @@ namespace Content.Server.Weapon.Ranged.Barrels.Components
return ammo.Value;
}
public override EntityUid TakeProjectile(EntityCoordinates spawnAt)
public override EntityUid? TakeProjectile(EntityCoordinates spawnAt)
{
var powerCellEntity = _powerCellContainer.ContainedEntity;

View File

@@ -191,12 +191,12 @@ namespace Content.Server.Weapon.Ranged.Barrels.Components
UpdateAppearance();
}
public override EntityUid PeekAmmo()
public override EntityUid? PeekAmmo()
{
return BoltOpen ? default : _chamberContainer.ContainedEntity;
}
public override EntityUid TakeProjectile(EntityCoordinates spawnAt)
public override EntityUid? TakeProjectile(EntityCoordinates spawnAt)
{
if (BoltOpen)
{

View File

@@ -57,8 +57,8 @@ namespace Content.Server.Weapon.Ranged.Barrels.Components
// _lastFire is when we actually fired (so if we hold the button then recoil doesn't build up if we're not firing)
private TimeSpan _lastFire;
public abstract EntityUid PeekAmmo();
public abstract EntityUid TakeProjectile(EntityCoordinates spawnAt);
public abstract EntityUid? PeekAmmo();
public abstract EntityUid? TakeProjectile(EntityCoordinates spawnAt);
// Recoil / spray control
[DataField("minAngle")]
@@ -202,8 +202,7 @@ namespace Content.Server.Weapon.Ranged.Barrels.Components
}
var ammo = PeekAmmo();
var projectile = TakeProjectile(_entities.GetComponent<TransformComponent>(shooter).Coordinates);
if (projectile == default)
if (TakeProjectile(_entities.GetComponent<TransformComponent>(shooter).Coordinates) is not {Valid: true} projectile)
{
SoundSystem.Play(Filter.Broadcast(), SoundEmpty.GetSound(), Owner);
return;
@@ -225,9 +224,9 @@ namespace Content.Server.Weapon.Ranged.Barrels.Components
}
else if (_entities.HasComponent<ProjectileComponent>(projectile) &&
ammo != default &&
_entities.TryGetComponent(ammo, out AmmoComponent? ammoComponent))
_entities.TryGetComponent(ammo.Value, out AmmoComponent? ammoComponent))
{
FireProjectiles(shooter, projectile, ammoComponent.ProjectilesFired, ammoComponent.EvenSpreadAngle, angle, ammoComponent.Velocity, ammo);
FireProjectiles(shooter, projectile, ammoComponent.ProjectilesFired, ammoComponent.EvenSpreadAngle, angle, ammoComponent.Velocity, ammo.Value);
if (CanMuzzleFlash)
{
@@ -236,7 +235,7 @@ namespace Content.Server.Weapon.Ranged.Barrels.Components
if (ammoComponent.Caseless)
{
_entities.DeleteEntity(ammo);
_entities.DeleteEntity(ammo.Value);
}
}
else

View File

@@ -104,8 +104,7 @@ namespace Content.Server.Weapon.Ranged
switch (message)
{
case FirePosComponentMessage msg:
var user = session.AttachedEntity;
if (user == null)
if (session.AttachedEntity is not {Valid: true} user)
{
return;
}