Some manual TryGetComponent inlines

This commit is contained in:
Vera Aguilera Puerto
2021-12-03 12:51:44 +01:00
parent 0feebbff00
commit f3edecf994
10 changed files with 22 additions and 15 deletions

View File

@@ -12,7 +12,7 @@ namespace Content.Server.AI.Utility.Considerations.Combat
{
var target = context.GetState<TargetEntityState>().GetValue();
if (target == null || (!IoCManager.Resolve<IEntityManager>().EntityExists(target.Uid) ? EntityLifeStage.Deleted : IoCManager.Resolve<IEntityManager>().GetComponent<MetaDataComponent>(target.Uid).EntityLifeStage) >= EntityLifeStage.Deleted || !target.TryGetComponent(out DamageableComponent? damageableComponent))
if (target == null || !IoCManager.Resolve<IEntityManager>().EntityExists(target.Uid) || !target.TryGetComponent(out DamageableComponent? damageableComponent))
{
return 0.0f;
}

View File

@@ -13,8 +13,9 @@ namespace Content.Server.AI.Utility.Considerations.Nutrition.Food
{
var target = context.GetState<TargetEntityState>().GetValue();
if (target == null || (!IoCManager.Resolve<IEntityManager>().EntityExists(target.Uid) ? EntityLifeStage.Deleted : IoCManager.Resolve<IEntityManager>().GetComponent<MetaDataComponent>(target.Uid).EntityLifeStage) >= EntityLifeStage.Deleted || !target.TryGetComponent<FoodComponent>(out var foodComp) ||
!EntitySystem.Get<SolutionContainerSystem>().TryGetSolution(target.Uid, foodComp.SolutionName, out var food))
if (target == null || !IoCManager.Resolve<IEntityManager>().EntityExists(target.Uid)
|| !target.TryGetComponent<FoodComponent>(out var foodComp)
|| !EntitySystem.Get<SolutionContainerSystem>().TryGetSolution(target.Uid, foodComp.SolutionName, out var food))
{
return 0.0f;
}

View File

@@ -51,7 +51,7 @@ namespace Content.Server.DeviceNetwork.Systems
/// <param name="uid">The Entity containing a DeviceNetworkComponent</param>
public void Connect(EntityUid uid)
{
if (EntityManager.GetEntity(uid).TryGetComponent<DeviceNetworkComponent>(out var component))
if (EntityManager.TryGetComponent<DeviceNetworkComponent>(uid, out var component))
{
AddConnection(component);
}
@@ -90,7 +90,7 @@ namespace Content.Server.DeviceNetwork.Systems
/// <param name="uid">The Entity containing a DeviceNetworkComponent</param>
public void Disconnect(EntityUid uid)
{
if (EntityManager.GetEntity(uid).TryGetComponent<DeviceNetworkComponent>(out var component))
if (EntityManager.TryGetComponent<DeviceNetworkComponent>(uid, out var component))
{
RemoveConnection(component);
}

View File

@@ -80,7 +80,7 @@ namespace Content.Server.Light.Components
public void OnUpdate(float frameTime)
{
if ((!IoCManager.Resolve<IEntityManager>().EntityExists(Owner.Uid) ? EntityLifeStage.Deleted : IoCManager.Resolve<IEntityManager>().GetComponent<MetaDataComponent>(Owner.Uid).EntityLifeStage) >= EntityLifeStage.Deleted || !Owner.TryGetComponent(out BatteryComponent? battery) || ((!IoCManager.Resolve<IEntityManager>().EntityExists(Owner.Uid) ? EntityLifeStage.Deleted : IoCManager.Resolve<IEntityManager>().GetComponent<MetaDataComponent>(Owner.Uid).EntityLifeStage) >= EntityLifeStage.Deleted || IoCManager.Resolve<IEntityManager>().GetComponent<MetaDataComponent>(Owner.Uid).EntityPaused))
if ((!IoCManager.Resolve<IEntityManager>().EntityExists(Owner.Uid) || !Owner.TryGetComponent(out BatteryComponent? battery) || IoCManager.Resolve<IEntityManager>().GetComponent<MetaDataComponent>(Owner.Uid).EntityPaused))
{
return;
}

View File

@@ -134,11 +134,12 @@ namespace Content.Server.Medical.Components
if (Powered)
{
var body = _bodyContainer.ContainedEntity;
var state = body?.GetComponentOrNull<MobStateComponent>();
if (body == null)
return MedicalScannerStatus.Open;
return state == null
? MedicalScannerStatus.Open
: GetStatusFromDamageState(state);
var state = body.GetComponentOrNull<MobStateComponent>();
return state == null ? MedicalScannerStatus.Open : GetStatusFromDamageState(state);
}
return MedicalScannerStatus.Off;

View File

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

View File

@@ -430,7 +430,8 @@ namespace Content.Server.WireHacking
var activeHandEntity = handsComponent.GetActiveHand?.Owner;
ToolComponent? tool = null;
activeHandEntity?.TryGetComponent(out tool);
if(activeHandEntity != null)
activeHandEntity.TryGetComponent(out tool);
var toolSystem = EntitySystem.Get<ToolSystem>();
switch (msg.Action)