Inline TryGetComponent completely, for real

This commit is contained in:
Vera Aguilera Puerto
2021-12-03 14:17:01 +01:00
parent 2ff4ec65d5
commit 69b270017b
425 changed files with 1143 additions and 995 deletions

View File

@@ -84,7 +84,7 @@ namespace Content.Server.Atmos.Components
_ => "Uhm",
};
if (Owner.TryGetComponent(out AppearanceComponent? appearance))
if (IoCManager.Resolve<IEntityManager>().TryGetComponent(Owner.Uid, out AppearanceComponent? appearance))
{
var state = _type == PlaqueType.Zumos ? "zumosplaque" : "atmosplaque";

View File

@@ -1,6 +1,7 @@
using Content.Server.Body.Components;
using Content.Shared.Inventory;
using Robust.Shared.GameObjects;
using Robust.Shared.IoC;
using Robust.Shared.Serialization.Manager.Attributes;
namespace Content.Server.Atmos.Components
@@ -32,7 +33,7 @@ namespace Content.Server.Atmos.Components
if ((EquipmentSlotDefines.SlotMasks[eventArgs.Slot] & _allowedSlots) != _allowedSlots) return;
IsFunctional = true;
if (eventArgs.User.TryGetComponent(out InternalsComponent? internals))
if (IoCManager.Resolve<IEntityManager>().TryGetComponent(eventArgs.User.Uid, out InternalsComponent? internals))
{
ConnectedInternalsEntity = eventArgs.User;
internals.ConnectBreathTool(Owner);
@@ -49,7 +50,7 @@ namespace Content.Server.Atmos.Components
var old = ConnectedInternalsEntity;
ConnectedInternalsEntity = null;
if (old != null && old.TryGetComponent<InternalsComponent>(out var internalsComponent))
if (old != null && IoCManager.Resolve<IEntityManager>().TryGetComponent<InternalsComponent?>(old.Uid, out var internalsComponent))
{
internalsComponent.DisconnectBreathTool();
}

View File

@@ -40,7 +40,7 @@ namespace Content.Server.Atmos.Components
UserInterface.OnClosed += UserInterfaceOnClose;
}
Owner.TryGetComponent(out _appearance);
IoCManager.Resolve<IEntityManager>().TryGetComponent(Owner.Uid, out _appearance);
}
public override ComponentState GetComponentState()
@@ -161,11 +161,11 @@ namespace Content.Server.Atmos.Components
if (session.AttachedEntity == null)
return;
if (!session.AttachedEntity.TryGetComponent(out HandsComponent? handsComponent))
if (!IoCManager.Resolve<IEntityManager>().TryGetComponent(session.AttachedEntity.Uid, out HandsComponent? handsComponent))
return;
var activeHandEntity = handsComponent?.GetActiveHand?.Owner;
if (activeHandEntity == null || !activeHandEntity.TryGetComponent(out GasAnalyzerComponent? gasAnalyzer))
if (activeHandEntity == null || !IoCManager.Resolve<IEntityManager>().TryGetComponent(activeHandEntity.Uid, out GasAnalyzerComponent? gasAnalyzer))
{
return;
}
@@ -226,14 +226,14 @@ namespace Content.Server.Atmos.Components
return;
}
if (!player.TryGetComponent(out HandsComponent? handsComponent))
if (!IoCManager.Resolve<IEntityManager>().TryGetComponent(player.Uid, out HandsComponent? handsComponent))
{
Owner.PopupMessage(player, Loc.GetString("gas-analyzer-component-player-has-no-hands-message"));
return;
}
var activeHandEntity = handsComponent.GetActiveHand?.Owner;
if (activeHandEntity == null || !activeHandEntity.TryGetComponent(out GasAnalyzerComponent? gasAnalyzer))
if (activeHandEntity == null || !IoCManager.Resolve<IEntityManager>().TryGetComponent(activeHandEntity.Uid, out GasAnalyzerComponent? gasAnalyzer))
{
serverMsg.Session.AttachedEntity?.PopupMessage(Loc.GetString("gas-analyzer-component-need-gas-analyzer-in-hand-message"));
return;
@@ -253,7 +253,7 @@ namespace Content.Server.Atmos.Components
return true;
}
if (eventArgs.User.TryGetComponent(out ActorComponent? actor))
if (IoCManager.Resolve<IEntityManager>().TryGetComponent(eventArgs.User.Uid, out ActorComponent? actor))
{
OpenInterface(actor.PlayerSession, eventArgs.ClickLocation);
}
@@ -265,7 +265,7 @@ namespace Content.Server.Atmos.Components
void IDropped.Dropped(DroppedEventArgs eventArgs)
{
if (eventArgs.User.TryGetComponent(out ActorComponent? actor))
if (IoCManager.Resolve<IEntityManager>().TryGetComponent(eventArgs.User.Uid, out ActorComponent? actor))
{
CloseInterface(actor.PlayerSession);
}
@@ -273,7 +273,7 @@ namespace Content.Server.Atmos.Components
bool IUse.UseEntity(UseEntityEventArgs eventArgs)
{
if (eventArgs.User.TryGetComponent(out ActorComponent? actor))
if (IoCManager.Resolve<IEntityManager>().TryGetComponent(eventArgs.User.Uid, out ActorComponent? actor))
{
ToggleInterface(actor.PlayerSession);
return true;

View File

@@ -155,14 +155,14 @@ namespace Content.Server.Atmos.Components
bool IUse.UseEntity(UseEntityEventArgs eventArgs)
{
if (!eventArgs.User.TryGetComponent(out ActorComponent? actor)) return false;
if (!IoCManager.Resolve<IEntityManager>().TryGetComponent(eventArgs.User.Uid, out ActorComponent? actor)) return false;
OpenInterface(actor.PlayerSession);
return true;
}
void IActivate.Activate(ActivateEventArgs eventArgs)
{
if (!eventArgs.User.TryGetComponent(out ActorComponent? actor)) return;
if (!IoCManager.Resolve<IEntityManager>().TryGetComponent(eventArgs.User.Uid, out ActorComponent? actor)) return;
OpenInterface(actor.PlayerSession);
}
@@ -328,7 +328,7 @@ namespace Content.Server.Atmos.Components
{
public bool DoToggleAction(ToggleItemActionEventArgs args)
{
if (!args.Item.TryGetComponent<GasTankComponent>(out var gasTankComponent)) return false;
if (!IoCManager.Resolve<IEntityManager>().TryGetComponent<GasTankComponent?>(args.Item.Uid, out var gasTankComponent)) return false;
// no change
if (gasTankComponent.IsConnected == args.ToggledOn) return false;
gasTankComponent.ToggleInternals();

View File

@@ -42,7 +42,7 @@ namespace Content.Server.Atmos.Components
public void ExperiencePressureDifference(int cycle, float pressureDifference, AtmosDirection direction,
float pressureResistanceProbDelta, EntityCoordinates throwTarget)
{
if (!Owner.TryGetComponent(out PhysicsComponent? physics))
if (!IoCManager.Resolve<IEntityManager>().TryGetComponent(Owner.Uid, out PhysicsComponent? physics))
return;
// TODO ATMOS stuns?
@@ -72,7 +72,7 @@ namespace Content.Server.Atmos.Components
Owner.SpawnTimer(2000, () =>
{
if (Deleted || !Owner.TryGetComponent(out PhysicsComponent? physicsComponent)) return;
if (Deleted || !IoCManager.Resolve<IEntityManager>().TryGetComponent(Owner.Uid, out PhysicsComponent? physicsComponent)) return;
// Uhh if you get race conditions good luck buddy.
if (IoCManager.Resolve<IEntityManager>().HasComponent<MobStateComponent>(physicsComponent.Owner.Uid))
@@ -118,7 +118,7 @@ namespace Content.Server.Atmos.Components
public static bool IsMovedByPressure(this IEntity entity, [NotNullWhen(true)] out MovedByPressureComponent? moved)
{
return entity.TryGetComponent(out moved) &&
return IoCManager.Resolve<IEntityManager>().TryGetComponent(entity.Uid, out moved) &&
moved.Enabled;
}
}

View File

@@ -7,6 +7,7 @@ using JetBrains.Annotations;
using Robust.Server.Player;
using Robust.Shared.Configuration;
using Robust.Shared.Enums;
using Robust.Shared.GameObjects;
using Robust.Shared.IoC;
using Robust.Shared.Map;
using Robust.Shared.Maths;
@@ -142,7 +143,7 @@ namespace Content.Server.Atmos.EntitySystems
{
if (!EntityManager.TryGetEntity(grid.GridEntityId, out var gridEnt)) continue;
if (!gridEnt.TryGetComponent<GridAtmosphereComponent>(out var gam)) continue;
if (!IoCManager.Resolve<IEntityManager>().TryGetComponent<GridAtmosphereComponent?>(gridEnt.Uid, out var gam)) continue;
var entityTile = grid.GetTileRef(entity.Transform.Coordinates).GridIndices;
var baseTile = new Vector2i(entityTile.X - (LocalViewRange / 2), entityTile.Y - (LocalViewRange / 2));

View File

@@ -1526,7 +1526,7 @@ namespace Content.Server.Atmos.EntitySystems
public bool TryGetMapGrid(GridAtmosphereComponent gridAtmosphere, [NotNullWhen(true)] out IMapGrid? mapGrid)
{
if (gridAtmosphere.Owner.TryGetComponent(out IMapGridComponent? mapGridComponent))
if (IoCManager.Resolve<IEntityManager>().TryGetComponent(gridAtmosphere.Owner.Uid, out IMapGridComponent? mapGridComponent))
{
mapGrid = mapGridComponent.Grid;
return true;

View File

@@ -5,6 +5,7 @@ using Robust.Server.GameObjects;
using Robust.Shared.Audio;
using Robust.Shared.Containers;
using Robust.Shared.GameObjects;
using Robust.Shared.IoC;
using Robust.Shared.Map;
using Robust.Shared.Maths;
using Robust.Shared.Physics;
@@ -33,7 +34,7 @@ namespace Content.Server.Atmos.EntitySystems
foreach (var entity in _gridtileLookupSystem.GetEntitiesIntersecting(tile.GridIndex, tile.GridIndices))
{
if (!entity.TryGetComponent(out IPhysBody? physics)
if (!IoCManager.Resolve<IEntityManager>().TryGetComponent(entity.Uid, out IPhysBody? physics)
|| !entity.IsMovedByPressure(out var pressure)
|| entity.IsInContainer())
continue;

View File

@@ -225,7 +225,7 @@ namespace Content.Server.Atmos.EntitySystems
flammable.FireStacks = MathF.Min(0, flammable.FireStacks + 1);
}
flammable.Owner.TryGetComponent(out ServerAlertsComponent? status);
IoCManager.Resolve<IEntityManager>().TryGetComponent(flammable.Owner.Uid, out ServerAlertsComponent? status);
if (!flammable.OnFire)
{

View File

@@ -24,7 +24,7 @@ namespace Content.Server.Atmos.EntitySystems
private void AddOpenUIVerb(EntityUid uid, GasTankComponent component, GetActivationVerbsEvent args)
{
if (!args.CanAccess || !args.User.TryGetComponent<ActorComponent>(out var actor))
if (!args.CanAccess || !IoCManager.Resolve<IEntityManager>().TryGetComponent<ActorComponent?>(args.User.Uid, out var actor))
return;
Verb verb = new();

View File

@@ -92,7 +92,7 @@ namespace Content.Server.Atmos.Piping.Binary.EntitySystems
private void OnPumpInteractHand(EntityUid uid, GasPressurePumpComponent component, InteractHandEvent args)
{
if (!args.User.TryGetComponent(out ActorComponent? actor))
if (!IoCManager.Resolve<IEntityManager>().TryGetComponent(args.User.Uid, out ActorComponent? actor))
return;
if (component.Owner.Transform.Anchored)

View File

@@ -81,7 +81,7 @@ namespace Content.Server.Atmos.Piping.Trinary.EntitySystems
private void OnFilterInteractHand(EntityUid uid, GasFilterComponent component, InteractHandEvent args)
{
if (!args.User.TryGetComponent(out ActorComponent? actor))
if (!IoCManager.Resolve<IEntityManager>().TryGetComponent(args.User.Uid, out ActorComponent? actor))
return;
if (component.Owner.Transform.Anchored)

View File

@@ -106,7 +106,7 @@ namespace Content.Server.Atmos.Piping.Trinary.EntitySystems
private void OnMixerInteractHand(EntityUid uid, GasMixerComponent component, InteractHandEvent args)
{
if (!args.User.TryGetComponent(out ActorComponent? actor))
if (!IoCManager.Resolve<IEntityManager>().TryGetComponent(args.User.Uid, out ActorComponent? actor))
return;
if (component.Owner.Transform.Anchored)

View File

@@ -244,7 +244,7 @@ namespace Content.Server.Atmos.Piping.Unary.EntitySystems
private void OnCanisterActivate(EntityUid uid, GasCanisterComponent component, ActivateInWorldEvent args)
{
if (!args.User.TryGetComponent(out ActorComponent? actor))
if (!IoCManager.Resolve<IEntityManager>().TryGetComponent(args.User.Uid, out ActorComponent? actor))
return;
_userInterfaceSystem.GetUiOrNull(uid, GasCanisterUiKey.Key)?.Open(actor.PlayerSession);
@@ -254,7 +254,7 @@ namespace Content.Server.Atmos.Piping.Unary.EntitySystems
private void OnCanisterInteractHand(EntityUid uid, GasCanisterComponent component, InteractHandEvent args)
{
if (!args.User.TryGetComponent(out ActorComponent? actor))
if (!IoCManager.Resolve<IEntityManager>().TryGetComponent(args.User.Uid, out ActorComponent? actor))
return;
_userInterfaceSystem.GetUiOrNull(uid, GasCanisterUiKey.Key)?.Open(actor.PlayerSession);
@@ -271,11 +271,11 @@ namespace Content.Server.Atmos.Piping.Unary.EntitySystems
return;
// Check the used item is valid...
if (!args.Used.TryGetComponent(out GasTankComponent? _))
if (!IoCManager.Resolve<IEntityManager>().TryGetComponent(args.Used.Uid, out GasTankComponent? _))
return;
// Check the user has hands.
if (!args.User.TryGetComponent(out HandsComponent? hands))
if (!IoCManager.Resolve<IEntityManager>().TryGetComponent(args.User.Uid, out HandsComponent? hands))
return;
if (!args.User.InRangeUnobstructed(canister, SharedInteractionSystem.InteractionRange, popup: true))