Inline GetComponentOrNull

This commit is contained in:
Vera Aguilera Puerto
2021-12-03 15:32:05 +01:00
parent ee4ff9cfe8
commit 2654775bf0
30 changed files with 55 additions and 32 deletions

View File

@@ -192,7 +192,7 @@ namespace Content.Server.Weapon.Ranged.Barrels.Components
if (chamberEntity == null)
return null;
return chamberEntity.GetComponentOrNull<AmmoComponent>()?.TakeBullet(spawnAt);
return IoCManager.Resolve<IEntityManager>().GetComponentOrNull<AmmoComponent>(chamberEntity.Uid)?.TakeBullet(spawnAt);
}
protected override bool WeaponCanFire()

View File

@@ -149,6 +149,7 @@ namespace Content.Server.Weapon.Ranged.Barrels.Components
public override IEntity? TakeProjectile(EntityCoordinates spawnAt)
{
var chamberEntity = _chamberContainer.ContainedEntity;
if (!_manualCycle)
{
Cycle();
@@ -158,7 +159,10 @@ namespace Content.Server.Weapon.Ranged.Barrels.Components
Dirty();
}
return chamberEntity?.GetComponentOrNull<AmmoComponent>()?.TakeBullet(spawnAt);
if (chamberEntity == null)
return null;
return IoCManager.Resolve<IEntityManager>().GetComponentOrNull<AmmoComponent>(chamberEntity.Uid)?.TakeBullet(spawnAt);
}
private void Cycle(bool manual = false)

View File

@@ -36,7 +36,17 @@ namespace Content.Server.Weapon.Ranged.Barrels.Components
[ViewVariables] private string? _ammoPrototype;
[ViewVariables] public IEntity? PowerCellEntity => _powerCellContainer.ContainedEntity;
public BatteryComponent? PowerCell => _powerCellContainer.ContainedEntity?.GetComponentOrNull<BatteryComponent>();
public BatteryComponent? PowerCell
{
get
{
if (_powerCellContainer.ContainedEntity == null)
return null;
return _powerCellContainer.ContainedEntity.GetComponentOrNull<BatteryComponent>();
}
}
private ContainerSlot _powerCellContainer = default!;
private ContainerSlot _ammoContainer = default!;
[DataField("powerCellPrototype")]