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;
}
}