Inline TryGetComponent completely

This commit is contained in:
Vera Aguilera Puerto
2021-12-03 14:05:23 +01:00
parent f3edecf994
commit 2ff4ec65d5
34 changed files with 98 additions and 84 deletions

View File

@@ -146,7 +146,7 @@ namespace Content.Client.Body.UI
BodyPartLabel.Text = $"{Loc.GetString(slotName)}: {Loc.GetString(part.Owner.Name)}"; BodyPartLabel.Text = $"{Loc.GetString(slotName)}: {Loc.GetString(part.Owner.Name)}";
// TODO BODY Part damage // TODO BODY Part damage
if (part.Owner.TryGetComponent(out DamageableComponent? damageable)) if (IoCManager.Resolve<IEntityManager>().TryGetComponent(part.Owner.Uid, out DamageableComponent? damageable))
{ {
BodyPartHealth.Text = Loc.GetString("body-scanner-display-body-part-damage-text",("damage", damageable.TotalDamage)); BodyPartHealth.Text = Loc.GetString("body-scanner-display-body-part-damage-text",("damage", damageable.TotalDamage));
} }

View File

@@ -25,7 +25,7 @@ namespace Content.Client.Fluids
{ {
base.InitializeEntity(entity); base.InitializeEntity(entity);
if (!entity.TryGetComponent(out SpriteComponent? spriteComponent)) if (!IoCManager.Resolve<IEntityManager>().TryGetComponent(entity.Uid, out SpriteComponent? spriteComponent))
{ {
Logger.Warning($"Missing SpriteComponent for PuddleVisualizer on entityUid = {entity.Uid}"); Logger.Warning($"Missing SpriteComponent for PuddleVisualizer on entityUid = {entity.Uid}");
return; return;
@@ -69,5 +69,5 @@ namespace Content.Client.Fluids
spriteComponent.Color = newColor; spriteComponent.Color = newColor;
} }
} }
} }

View File

@@ -181,8 +181,8 @@ namespace Content.Client.Storage
if (!IoCManager.Resolve<IEntityManager>().TryGetEntity(entityUid, out var entity)) if (!IoCManager.Resolve<IEntityManager>().TryGetEntity(entityUid, out var entity))
return; return;
entity.TryGetComponent(out ISpriteComponent? sprite); IoCManager.Resolve<IEntityManager>().TryGetComponent(entity.Uid, out ISpriteComponent? sprite);
entity.TryGetComponent(out ItemComponent? item); IoCManager.Resolve<IEntityManager>().TryGetComponent(entity.Uid, out ItemComponent? item);
button.AddChild(new BoxContainer button.AddChild(new BoxContainer
{ {
@@ -252,7 +252,7 @@ namespace Content.Client.Storage
{ {
var controlledEntity = IoCManager.Resolve<IPlayerManager>().LocalPlayer?.ControlledEntity; var controlledEntity = IoCManager.Resolve<IPlayerManager>().LocalPlayer?.ControlledEntity;
if (controlledEntity != null && controlledEntity.TryGetComponent(out HandsComponent? hands)) if (controlledEntity != null && IoCManager.Resolve<IEntityManager>().TryGetComponent(controlledEntity.Uid, out HandsComponent? hands))
{ {
#pragma warning disable 618 #pragma warning disable 618
StorageEntity.SendNetworkMessage(new InsertEntityMessage()); StorageEntity.SendNetworkMessage(new InsertEntityMessage());

View File

@@ -4,6 +4,7 @@ using Content.Shared.Storage.Components;
using JetBrains.Annotations; using JetBrains.Annotations;
using Robust.Client.GameObjects; using Robust.Client.GameObjects;
using Robust.Shared.GameObjects; using Robust.Shared.GameObjects;
using Robust.Shared.IoC;
using Robust.Shared.Serialization.Manager.Attributes; using Robust.Shared.Serialization.Manager.Attributes;
using Robust.Shared.Utility; using Robust.Shared.Utility;
@@ -19,7 +20,7 @@ namespace Content.Client.Storage.Visualizers
{ {
base.InitializeEntity(entity); base.InitializeEntity(entity);
if (entity.TryGetComponent<ISpriteComponent>(out var spriteComponent)) if (IoCManager.Resolve<IEntityManager>().TryGetComponent<ISpriteComponent?>(entity.Uid, out var spriteComponent))
{ {
_rsiPath ??= spriteComponent.BaseRSI!.Path!; _rsiPath ??= spriteComponent.BaseRSI!.Path!;
} }

View File

@@ -2,6 +2,7 @@ using Content.Shared.Storage;
using JetBrains.Annotations; using JetBrains.Annotations;
using Robust.Client.GameObjects; using Robust.Client.GameObjects;
using Robust.Shared.GameObjects; using Robust.Shared.GameObjects;
using Robust.Shared.IoC;
using Robust.Shared.Serialization.Manager.Attributes; using Robust.Shared.Serialization.Manager.Attributes;
namespace Content.Client.Storage.Visualizers namespace Content.Client.Storage.Visualizers
@@ -18,7 +19,7 @@ namespace Content.Client.Storage.Visualizers
public override void InitializeEntity(IEntity entity) public override void InitializeEntity(IEntity entity)
{ {
if (!entity.TryGetComponent(out ISpriteComponent? sprite)) if (!IoCManager.Resolve<IEntityManager>().TryGetComponent(entity.Uid, out ISpriteComponent? sprite))
{ {
return; return;
} }

View File

@@ -78,7 +78,7 @@ namespace Content.IntegrationTests.Tests.Buckle
chair = entityManager.SpawnEntity(StrapDummyId, coordinates); chair = entityManager.SpawnEntity(StrapDummyId, coordinates);
// Default state, unbuckled // Default state, unbuckled
Assert.True(human.TryGetComponent(out buckle)); Assert.True(IoCManager.Resolve<IEntityManager>().TryGetComponent(human.Uid, out buckle));
Assert.NotNull(buckle); Assert.NotNull(buckle);
Assert.Null(buckle.BuckledTo); Assert.Null(buckle.BuckledTo);
Assert.False(buckle.Buckled); Assert.False(buckle.Buckled);
@@ -88,7 +88,7 @@ namespace Content.IntegrationTests.Tests.Buckle
Assert.True(standingState.Stand(human.Uid)); Assert.True(standingState.Stand(human.Uid));
// Default state, no buckled entities, strap // Default state, no buckled entities, strap
Assert.True(chair.TryGetComponent(out strap)); Assert.True(IoCManager.Resolve<IEntityManager>().TryGetComponent(chair.Uid, out strap));
Assert.NotNull(strap); Assert.NotNull(strap);
Assert.IsEmpty(strap.BuckledEntities); Assert.IsEmpty(strap.BuckledEntities);
Assert.Zero(strap.OccupiedSize); Assert.Zero(strap.OccupiedSize);
@@ -239,10 +239,10 @@ namespace Content.IntegrationTests.Tests.Buckle
IEntity chair = entityManager.SpawnEntity(StrapDummyId, coordinates); IEntity chair = entityManager.SpawnEntity(StrapDummyId, coordinates);
// Component sanity check // Component sanity check
Assert.True(human.TryGetComponent(out buckle)); Assert.True(IoCManager.Resolve<IEntityManager>().TryGetComponent(human.Uid, out buckle));
Assert.True(IoCManager.Resolve<IEntityManager>().HasComponent<StrapComponent>(chair.Uid)); Assert.True(IoCManager.Resolve<IEntityManager>().HasComponent<StrapComponent>(chair.Uid));
Assert.True(human.TryGetComponent(out hands)); Assert.True(IoCManager.Resolve<IEntityManager>().TryGetComponent(human.Uid, out hands));
Assert.True(human.TryGetComponent(out body)); Assert.True(IoCManager.Resolve<IEntityManager>().TryGetComponent(human.Uid, out body));
// Buckle // Buckle
Assert.True(buckle.TryBuckle(human, chair)); Assert.True(buckle.TryBuckle(human, chair));
@@ -255,7 +255,7 @@ namespace Content.IntegrationTests.Tests.Buckle
var akms = entityManager.SpawnEntity(ItemDummyId, coordinates); var akms = entityManager.SpawnEntity(ItemDummyId, coordinates);
// Equip items // Equip items
Assert.True(akms.TryGetComponent(out ItemComponent item)); Assert.True(IoCManager.Resolve<IEntityManager>().TryGetComponent(akms.Uid, out ItemComponent item));
Assert.True(hands.PutInHand(item)); Assert.True(hands.PutInHand(item));
} }
}); });
@@ -324,7 +324,7 @@ namespace Content.IntegrationTests.Tests.Buckle
chair = entityManager.SpawnEntity(StrapDummyId, coordinates); chair = entityManager.SpawnEntity(StrapDummyId, coordinates);
// Component sanity check // Component sanity check
Assert.True(human.TryGetComponent(out buckle)); Assert.True(IoCManager.Resolve<IEntityManager>().TryGetComponent(human.Uid, out buckle));
Assert.True(IoCManager.Resolve<IEntityManager>().HasComponent<StrapComponent>(chair.Uid)); Assert.True(IoCManager.Resolve<IEntityManager>().HasComponent<StrapComponent>(chair.Uid));
// Buckle // Buckle

View File

@@ -48,8 +48,8 @@ namespace Content.IntegrationTests.Tests.Commands
var human = entityManager.SpawnEntity("DamageableDummy", MapCoordinates.Nullspace); var human = entityManager.SpawnEntity("DamageableDummy", MapCoordinates.Nullspace);
// Sanity check // Sanity check
Assert.True(human.TryGetComponent(out DamageableComponent damageable)); Assert.True(IoCManager.Resolve<IEntityManager>().TryGetComponent(human.Uid, out DamageableComponent damageable));
Assert.True(human.TryGetComponent(out MobStateComponent mobState)); Assert.True(IoCManager.Resolve<IEntityManager>().TryGetComponent(human.Uid, out MobStateComponent mobState));
mobState.UpdateState(0); mobState.UpdateState(0);
Assert.That(mobState.IsAlive, Is.True); Assert.That(mobState.IsAlive, Is.True);
Assert.That(mobState.IsCritical, Is.False); Assert.That(mobState.IsCritical, Is.False);

View File

@@ -2,6 +2,7 @@ using Content.Server.AI.Components;
using Content.Server.AI.Utility.AiLogic; using Content.Server.AI.Utility.AiLogic;
using Content.Server.AI.WorldState; using Content.Server.AI.WorldState;
using Robust.Shared.GameObjects; using Robust.Shared.GameObjects;
using Robust.Shared.IoC;
namespace Content.Server.AI.Utility namespace Content.Server.AI.Utility
{ {
@@ -9,7 +10,7 @@ namespace Content.Server.AI.Utility
{ {
public static Blackboard? GetBlackboard(IEntity entity) public static Blackboard? GetBlackboard(IEntity entity)
{ {
if (!entity.TryGetComponent(out AiControllerComponent? aiControllerComponent)) if (!IoCManager.Resolve<IEntityManager>().TryGetComponent(entity.Uid, out AiControllerComponent? aiControllerComponent))
{ {
return null; return null;
} }

View File

@@ -23,8 +23,8 @@ namespace Content.Server.Actions.Actions
public void DoInstantAction(InstantActionEventArgs args) public void DoInstantAction(InstantActionEventArgs args)
{ {
if (!args.Performer.TryGetComponent<ServerUserInterfaceComponent>(out var serverUi)) return; if (!IoCManager.Resolve<IEntityManager>().TryGetComponent<ServerUserInterfaceComponent?>(args.Performer.Uid, out var serverUi)) return;
if (!args.Performer.TryGetComponent<ActorComponent>(out var actor)) return; if (!IoCManager.Resolve<IEntityManager>().TryGetComponent<ActorComponent?>(args.Performer.Uid, out var actor)) return;
if (!serverUi.TryGetBoundUserInterface(InstrumentUiKey.Key,out var bui)) return; if (!serverUi.TryGetBoundUserInterface(InstrumentUiKey.Key,out var bui)) return;
bui.Toggle(actor.PlayerSession); bui.Toggle(actor.PlayerSession);

View File

@@ -5,6 +5,7 @@ using Content.Shared.Actions;
using Content.Shared.Administration; using Content.Shared.Administration;
using Robust.Server.Player; using Robust.Server.Player;
using Robust.Shared.Console; using Robust.Shared.Console;
using Robust.Shared.GameObjects;
using Robust.Shared.IoC; using Robust.Shared.IoC;
using Robust.Shared.Timing; using Robust.Shared.Timing;
@@ -29,7 +30,7 @@ namespace Content.Server.Actions.Commands
} }
if (attachedEntity == null) return; if (attachedEntity == null) return;
if (!attachedEntity.TryGetComponent(out ServerActionsComponent? actionsComponent)) if (!IoCManager.Resolve<IEntityManager>().TryGetComponent(attachedEntity.Uid, out ServerActionsComponent? actionsComponent))
{ {
shell.WriteLine("user has no actions component"); shell.WriteLine("user has no actions component");
return; return;

View File

@@ -1,6 +1,8 @@
using Content.Server.Cuffs.Components; using Content.Server.Cuffs.Components;
using Content.Shared.Alert; using Content.Shared.Alert;
using JetBrains.Annotations; using JetBrains.Annotations;
using Robust.Shared.GameObjects;
using Robust.Shared.IoC;
using Robust.Shared.Serialization.Manager.Attributes; using Robust.Shared.Serialization.Manager.Attributes;
namespace Content.Server.Alert.Click namespace Content.Server.Alert.Click
@@ -14,7 +16,7 @@ namespace Content.Server.Alert.Click
{ {
public void AlertClicked(ClickAlertEventArgs args) public void AlertClicked(ClickAlertEventArgs args)
{ {
if (args.Player.TryGetComponent(out CuffableComponent? cuffableComponent)) if (IoCManager.Resolve<IEntityManager>().TryGetComponent(args.Player.Uid, out CuffableComponent? cuffableComponent))
{ {
cuffableComponent.TryUncuff(args.Player); cuffableComponent.TryUncuff(args.Player);
} }

View File

@@ -74,7 +74,7 @@ namespace Content.Server.Arcade.Components
void IActivate.Activate(ActivateEventArgs eventArgs) void IActivate.Activate(ActivateEventArgs eventArgs)
{ {
if (!Powered || !eventArgs.User.TryGetComponent(out ActorComponent? actor)) if (!Powered || !IoCManager.Resolve<IEntityManager>().TryGetComponent(eventArgs.User.Uid, out ActorComponent? actor))
return; return;
if (!EntitySystem.Get<ActionBlockerSystem>().CanInteract(eventArgs.User.Uid)) if (!EntitySystem.Get<ActionBlockerSystem>().CanInteract(eventArgs.User.Uid))

View File

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

View File

@@ -3,6 +3,7 @@ using Content.Shared.Body.Components;
using Content.Shared.Interaction; using Content.Shared.Interaction;
using Robust.Server.GameObjects; using Robust.Server.GameObjects;
using Robust.Shared.GameObjects; using Robust.Shared.GameObjects;
using Robust.Shared.IoC;
using Robust.Shared.ViewVariables; using Robust.Shared.ViewVariables;
namespace Content.Server.Body.Components namespace Content.Server.Body.Components
@@ -16,7 +17,7 @@ namespace Content.Server.Body.Components
void IActivate.Activate(ActivateEventArgs eventArgs) void IActivate.Activate(ActivateEventArgs eventArgs)
{ {
if (!eventArgs.User.TryGetComponent(out ActorComponent? actor)) if (!IoCManager.Resolve<IEntityManager>().TryGetComponent(eventArgs.User.Uid, out ActorComponent? actor))
{ {
return; return;
} }
@@ -28,7 +29,7 @@ namespace Content.Server.Body.Components
return; return;
} }
if (session.AttachedEntity.TryGetComponent(out SharedBodyComponent? body)) if (IoCManager.Resolve<IEntityManager>().TryGetComponent(session.AttachedEntity.Uid, out SharedBodyComponent? body))
{ {
var state = InterfaceState(body); var state = InterfaceState(body);
UserInterface?.SetState(state); UserInterface?.SetState(state);

View File

@@ -7,6 +7,7 @@ using JetBrains.Annotations;
using Robust.Server.GameObjects; using Robust.Server.GameObjects;
using Robust.Shared.Containers; using Robust.Shared.Containers;
using Robust.Shared.GameObjects; using Robust.Shared.GameObjects;
using Robust.Shared.IoC;
using Robust.Shared.Localization; using Robust.Shared.Localization;
namespace Content.Server.Buckle.Systems namespace Content.Server.Buckle.Systems
@@ -40,7 +41,7 @@ namespace Content.Server.Buckle.Systems
{ {
if (!args.CanAccess || !args.CanInteract || !component.Buckled) if (!args.CanAccess || !args.CanInteract || !component.Buckled)
return; return;
Verb verb = new(); Verb verb = new();
verb.Act = () => component.TryUnbuckle(args.User); verb.Act = () => component.TryUnbuckle(args.User);
verb.Text = Loc.GetString("verb-categories-unbuckle"); verb.Text = Loc.GetString("verb-categories-unbuckle");
@@ -94,7 +95,7 @@ namespace Content.Server.Buckle.Systems
// This fixes buckle offsets and draw depths. // This fixes buckle offsets and draw depths.
foreach (var buckledEntity in strap.BuckledEntities) foreach (var buckledEntity in strap.BuckledEntities)
{ {
if (!buckledEntity.TryGetComponent(out BuckleComponent? buckled)) if (!IoCManager.Resolve<IEntityManager>().TryGetComponent(buckledEntity.Uid, out BuckleComponent? buckled))
{ {
continue; continue;
} }
@@ -111,7 +112,7 @@ namespace Content.Server.Buckle.Systems
{ {
foreach (var buckledEntity in strap.BuckledEntities) foreach (var buckledEntity in strap.BuckledEntities)
{ {
if (!buckledEntity.TryGetComponent(out BuckleComponent? buckled)) if (!IoCManager.Resolve<IEntityManager>().TryGetComponent(buckledEntity.Uid, out BuckleComponent? buckled))
{ {
continue; continue;
} }

View File

@@ -8,6 +8,7 @@ using System.Collections.Generic;
using Content.Shared.Chemistry.Reagent; using Content.Shared.Chemistry.Reagent;
using Content.Shared.FixedPoint; using Content.Shared.FixedPoint;
using Content.Shared.Popups; using Content.Shared.Popups;
using Robust.Shared.IoC;
namespace Content.Server.Chemistry.EntitySystems namespace Content.Server.Chemistry.EntitySystems
{ {
@@ -31,9 +32,9 @@ namespace Content.Server.Chemistry.EntitySystems
if (!args.CanAccess || !args.CanInteract || !component.CanChangeTransferAmount) if (!args.CanAccess || !args.CanInteract || !component.CanChangeTransferAmount)
return; return;
if (!args.User.TryGetComponent<ActorComponent>(out var actor)) if (!IoCManager.Resolve<IEntityManager>().TryGetComponent<ActorComponent?>(args.User.Uid, out var actor))
return; return;
// Custom transfer verb // Custom transfer verb
Verb custom = new(); Verb custom = new();
custom.Text = Loc.GetString("comp-solution-transfer-verb-custom-amount"); custom.Text = Loc.GetString("comp-solution-transfer-verb-custom-amount");
@@ -61,7 +62,7 @@ namespace Content.Server.Chemistry.EntitySystems
// we want to sort by size, not alphabetically by the verb text. // we want to sort by size, not alphabetically by the verb text.
verb.Priority = priority; verb.Priority = priority;
priority--; priority--;
args.Verbs.Add(verb); args.Verbs.Add(verb);
} }
} }

View File

@@ -36,7 +36,7 @@ namespace Content.Server.Cloning
{ {
if (!ClonesWaitingForMind.TryGetValue(mind, out var entityUid) || if (!ClonesWaitingForMind.TryGetValue(mind, out var entityUid) ||
!EntityManager.TryGetEntity(entityUid, out var entity) || !EntityManager.TryGetEntity(entityUid, out var entity) ||
!entity.TryGetComponent(out MindComponent? mindComp) || !IoCManager.Resolve<IEntityManager>().TryGetComponent(entity.Uid, out MindComponent? mindComp) ||
mindComp.Mind != null) mindComp.Mind != null)
return; return;
@@ -48,7 +48,7 @@ namespace Content.Server.Cloning
private void HandleActivate(EntityUid uid, CloningPodComponent component, ActivateInWorldEvent args) private void HandleActivate(EntityUid uid, CloningPodComponent component, ActivateInWorldEvent args)
{ {
if (!component.Powered || if (!component.Powered ||
!args.User.TryGetComponent(out ActorComponent? actor)) !IoCManager.Resolve<IEntityManager>().TryGetComponent(args.User.Uid, out ActorComponent? actor))
{ {
return; return;
} }
@@ -60,7 +60,7 @@ namespace Content.Server.Cloning
{ {
if (component.Parent == EntityUid.Invalid || if (component.Parent == EntityUid.Invalid ||
!EntityManager.TryGetEntity(component.Parent, out var parent) || !EntityManager.TryGetEntity(component.Parent, out var parent) ||
!parent.TryGetComponent<CloningPodComponent>(out var cloningPodComponent) || !IoCManager.Resolve<IEntityManager>().TryGetComponent<CloningPodComponent?>(parent.Uid, out var cloningPodComponent) ||
component.Owner != cloningPodComponent.BodyContainer?.ContainedEntity) component.Owner != cloningPodComponent.BodyContainer?.ContainedEntity)
{ {
IoCManager.Resolve<IEntityManager>().RemoveComponent<BeingClonedComponent>(component.Owner.Uid); IoCManager.Resolve<IEntityManager>().RemoveComponent<BeingClonedComponent>(component.Owner.Uid);

View File

@@ -66,7 +66,7 @@ namespace Content.Server.Cuffs
if (args.User == args.Target) if (args.User == args.Target)
{ {
// This UncuffAttemptEvent check should probably be In MobStateSystem, not here? // This UncuffAttemptEvent check should probably be In MobStateSystem, not here?
if (userEntity.TryGetComponent<MobStateComponent>(out var state)) if (IoCManager.Resolve<IEntityManager>().TryGetComponent<MobStateComponent?>(userEntity.Uid, out var state))
{ {
// Manually check this. // Manually check this.
if (state.IsIncapacitated()) if (state.IsIncapacitated())
@@ -101,7 +101,7 @@ namespace Content.Server.Cuffs
{ {
var owner = message.Sender; var owner = message.Sender;
if (!owner.TryGetComponent(out CuffableComponent? cuffable) || if (!IoCManager.Resolve<IEntityManager>().TryGetComponent(owner.Uid, out CuffableComponent? cuffable) ||
!cuffable.Initialized) return; !cuffable.Initialized) return;
var dirty = false; var dirty = false;

View File

@@ -28,13 +28,13 @@ namespace Content.Server.Disposal.Tube
SubscribeLocalEvent<DisposalTaggerComponent, GetInteractionVerbsEvent>(AddOpenUIVerbs); SubscribeLocalEvent<DisposalTaggerComponent, GetInteractionVerbsEvent>(AddOpenUIVerbs);
SubscribeLocalEvent<DisposalRouterComponent, GetInteractionVerbsEvent>(AddOpenUIVerbs); SubscribeLocalEvent<DisposalRouterComponent, GetInteractionVerbsEvent>(AddOpenUIVerbs);
} }
private void AddOpenUIVerbs(EntityUid uid, DisposalTaggerComponent component, GetInteractionVerbsEvent args) private void AddOpenUIVerbs(EntityUid uid, DisposalTaggerComponent component, GetInteractionVerbsEvent args)
{ {
if (!args.CanAccess || !args.CanInteract) if (!args.CanAccess || !args.CanInteract)
return; return;
if (!args.User.TryGetComponent<ActorComponent>(out var actor)) if (!IoCManager.Resolve<IEntityManager>().TryGetComponent<ActorComponent?>(args.User.Uid, out var actor))
return; return;
var player = actor.PlayerSession; var player = actor.PlayerSession;
@@ -42,7 +42,7 @@ namespace Content.Server.Disposal.Tube
verb.Text = Loc.GetString("configure-verb-get-data-text"); verb.Text = Loc.GetString("configure-verb-get-data-text");
verb.IconTexture = "/Textures/Interface/VerbIcons/settings.svg.192dpi.png"; verb.IconTexture = "/Textures/Interface/VerbIcons/settings.svg.192dpi.png";
verb.Act = () => component.OpenUserInterface(actor); verb.Act = () => component.OpenUserInterface(actor);
args.Verbs.Add(verb); args.Verbs.Add(verb);
} }
private void AddOpenUIVerbs(EntityUid uid, DisposalRouterComponent component, GetInteractionVerbsEvent args) private void AddOpenUIVerbs(EntityUid uid, DisposalRouterComponent component, GetInteractionVerbsEvent args)
@@ -50,7 +50,7 @@ namespace Content.Server.Disposal.Tube
if (!args.CanAccess || !args.CanInteract) if (!args.CanAccess || !args.CanInteract)
return; return;
if (!args.User.TryGetComponent<ActorComponent>(out var actor)) if (!IoCManager.Resolve<IEntityManager>().TryGetComponent<ActorComponent?>(args.User.Uid, out var actor))
return; return;
var player = actor.PlayerSession; var player = actor.PlayerSession;

View File

@@ -1,5 +1,5 @@
using System.Linq; using System.Linq;
using Content.Server.Atmos; using Content.Server.Atmos;
using Content.Server.Atmos.EntitySystems; using Content.Server.Atmos.EntitySystems;
using Content.Server.Disposal.Tube.Components; using Content.Server.Disposal.Tube.Components;
using Content.Server.Disposal.Tube; using Content.Server.Disposal.Tube;

View File

@@ -111,7 +111,7 @@ namespace Content.Server.Fluids.Components
return true; return true;
} }
if (!eventArgs.Target.TryGetComponent(out PuddleComponent? puddleComponent) || if (!IoCManager.Resolve<IEntityManager>().TryGetComponent(eventArgs.Target.Uid, out PuddleComponent? puddleComponent) ||
!solutionSystem.TryGetSolution(puddleComponent.OwnerUid, puddleComponent.SolutionName, out var puddleSolution)) !solutionSystem.TryGetSolution(puddleComponent.OwnerUid, puddleComponent.SolutionName, out var puddleSolution))
return false; return false;
@@ -141,7 +141,7 @@ namespace Content.Server.Fluids.Components
transferAmount = FixedPoint2.Min(PickupAmount, puddleSolution.TotalVolume, CurrentVolume); transferAmount = FixedPoint2.Min(PickupAmount, puddleSolution.TotalVolume, CurrentVolume);
// is the puddle cleaned? // is the puddle cleaned?
if (puddleSolution.TotalVolume - transferAmount <= 0) if (puddleSolution.TotalVolume - transferAmount <= 0)
{ {
IoCManager.Resolve<IEntityManager>().DeleteEntity(puddleComponent.Owner.Uid); IoCManager.Resolve<IEntityManager>().DeleteEntity(puddleComponent.Owner.Uid);

View File

@@ -230,7 +230,7 @@ namespace Content.Server.GameTicking
#region Equip Helpers #region Equip Helpers
public void EquipStartingGear(IEntity entity, StartingGearPrototype startingGear, HumanoidCharacterProfile? profile) public void EquipStartingGear(IEntity entity, StartingGearPrototype startingGear, HumanoidCharacterProfile? profile)
{ {
if (entity.TryGetComponent(out InventoryComponent? inventory)) if (IoCManager.Resolve<IEntityManager>().TryGetComponent(entity.Uid, out InventoryComponent? inventory))
{ {
foreach (var slot in EquipmentSlotDefines.AllSlots) foreach (var slot in EquipmentSlotDefines.AllSlots)
{ {
@@ -243,7 +243,7 @@ namespace Content.Server.GameTicking
} }
} }
if (entity.TryGetComponent(out HandsComponent? handsComponent)) if (IoCManager.Resolve<IEntityManager>().TryGetComponent(entity.Uid, out HandsComponent? handsComponent))
{ {
var inhand = startingGear.Inhand; var inhand = startingGear.Inhand;
foreach (var (hand, prototype) in inhand) foreach (var (hand, prototype) in inhand)
@@ -256,7 +256,7 @@ namespace Content.Server.GameTicking
public void EquipIdCard(IEntity entity, string characterName, JobPrototype jobPrototype) public void EquipIdCard(IEntity entity, string characterName, JobPrototype jobPrototype)
{ {
if (!entity.TryGetComponent(out InventoryComponent? inventory)) if (!IoCManager.Resolve<IEntityManager>().TryGetComponent(entity.Uid, out InventoryComponent? inventory))
return; return;
if (!inventory.TryGetSlotItem(EquipmentSlotDefines.Slots.IDCARD, out ItemComponent? item)) if (!inventory.TryGetSlotItem(EquipmentSlotDefines.Slots.IDCARD, out ItemComponent? item))
@@ -266,7 +266,7 @@ namespace Content.Server.GameTicking
var itemEntity = item.Owner; var itemEntity = item.Owner;
if (!itemEntity.TryGetComponent(out PDAComponent? pdaComponent) || pdaComponent.ContainedID == null) if (!IoCManager.Resolve<IEntityManager>().TryGetComponent(itemEntity.Uid, out PDAComponent? pdaComponent) || pdaComponent.ContainedID == null)
return; return;
var card = pdaComponent.ContainedID; var card = pdaComponent.ContainedID;

View File

@@ -30,7 +30,7 @@ namespace Content.Server.Interaction.Components
/// <returns>True if a "bad action" happened, false if the normal action should happen.</returns> /// <returns>True if a "bad action" happened, false if the normal action should happen.</returns>
public static bool TryRollClumsy(IEntity entity, float chance) public static bool TryRollClumsy(IEntity entity, float chance)
{ {
return entity.TryGetComponent(out ClumsyComponent? clumsy) return IoCManager.Resolve<IEntityManager>().TryGetComponent(entity.Uid, out ClumsyComponent? clumsy)
&& clumsy.RollClumsy(chance); && clumsy.RollClumsy(chance);
} }
} }

View File

@@ -8,6 +8,7 @@ using Robust.Shared.GameObjects;
using Robust.Shared.Localization; using Robust.Shared.Localization;
using Robust.Shared.Player; using Robust.Shared.Player;
using System; using System;
using Robust.Shared.IoC;
namespace Content.Server.Light.EntitySystems namespace Content.Server.Light.EntitySystems
{ {
@@ -36,13 +37,13 @@ namespace Content.Server.Light.EntitySystems
public void ToggleLight(UnpoweredFlashlightComponent flashlight) public void ToggleLight(UnpoweredFlashlightComponent flashlight)
{ {
if (!flashlight.Owner.TryGetComponent(out PointLightComponent? light)) if (!IoCManager.Resolve<IEntityManager>().TryGetComponent(flashlight.Owner.Uid, out PointLightComponent? light))
return; return;
flashlight.LightOn = !flashlight.LightOn; flashlight.LightOn = !flashlight.LightOn;
light.Enabled = flashlight.LightOn; light.Enabled = flashlight.LightOn;
if (flashlight.Owner.TryGetComponent(out AppearanceComponent? appearance)) if (IoCManager.Resolve<IEntityManager>().TryGetComponent(flashlight.Owner.Uid, out AppearanceComponent? appearance))
appearance.SetData(UnpoweredFlashlightVisuals.LightOn, flashlight.LightOn); appearance.SetData(UnpoweredFlashlightVisuals.LightOn, flashlight.LightOn);
SoundSystem.Play(Filter.Pvs(light.Owner), flashlight.ToggleSound.GetSound(), flashlight.Owner); SoundSystem.Play(Filter.Pvs(light.Owner), flashlight.ToggleSound.GetSound(), flashlight.Owner);

View File

@@ -35,7 +35,7 @@ namespace Content.Server.Lock
private void OnStartup(EntityUid uid, LockComponent lockComp, ComponentStartup args) private void OnStartup(EntityUid uid, LockComponent lockComp, ComponentStartup args)
{ {
if (lockComp.Owner.TryGetComponent(out AppearanceComponent? appearance)) if (IoCManager.Resolve<IEntityManager>().TryGetComponent(lockComp.Owner.Uid, out AppearanceComponent? appearance))
{ {
appearance.SetData(StorageVisuals.CanLock, true); appearance.SetData(StorageVisuals.CanLock, true);
} }
@@ -71,22 +71,22 @@ namespace Content.Server.Lock
{ {
if (!Resolve(uid, ref lockComp)) if (!Resolve(uid, ref lockComp))
return false; return false;
if (!CanToggleLock(uid, user, quiet: false)) if (!CanToggleLock(uid, user, quiet: false))
return false; return false;
if (!HasUserAccess(uid, user, quiet: false)) if (!HasUserAccess(uid, user, quiet: false))
return false; return false;
lockComp.Owner.PopupMessage(user, Loc.GetString("lock-comp-do-lock-success", ("entityName",lockComp.Owner.Name))); lockComp.Owner.PopupMessage(user, Loc.GetString("lock-comp-do-lock-success", ("entityName",lockComp.Owner.Name)));
lockComp.Locked = true; lockComp.Locked = true;
if(lockComp.LockSound != null) if(lockComp.LockSound != null)
{ {
SoundSystem.Play(Filter.Pvs(lockComp.Owner), lockComp.LockSound.GetSound(), lockComp.Owner, AudioParams.Default.WithVolume(-5)); SoundSystem.Play(Filter.Pvs(lockComp.Owner), lockComp.LockSound.GetSound(), lockComp.Owner, AudioParams.Default.WithVolume(-5));
} }
if (lockComp.Owner.TryGetComponent(out AppearanceComponent? appearanceComp)) if (IoCManager.Resolve<IEntityManager>().TryGetComponent(lockComp.Owner.Uid, out AppearanceComponent? appearanceComp))
{ {
appearanceComp.SetData(StorageVisuals.Locked, true); appearanceComp.SetData(StorageVisuals.Locked, true);
} }
@@ -100,22 +100,22 @@ namespace Content.Server.Lock
{ {
if (!Resolve(uid, ref lockComp)) if (!Resolve(uid, ref lockComp))
return false; return false;
if (!CanToggleLock(uid, user, quiet: false)) if (!CanToggleLock(uid, user, quiet: false))
return false; return false;
if (!HasUserAccess(uid, user, quiet: false)) if (!HasUserAccess(uid, user, quiet: false))
return false; return false;
lockComp.Owner.PopupMessage(user, Loc.GetString("lock-comp-do-unlock-success", ("entityName", lockComp.Owner.Name))); lockComp.Owner.PopupMessage(user, Loc.GetString("lock-comp-do-unlock-success", ("entityName", lockComp.Owner.Name)));
lockComp.Locked = false; lockComp.Locked = false;
if(lockComp.UnlockSound != null) if(lockComp.UnlockSound != null)
{ {
SoundSystem.Play(Filter.Pvs(lockComp.Owner), lockComp.UnlockSound.GetSound(), lockComp.Owner, AudioParams.Default.WithVolume(-5)); SoundSystem.Play(Filter.Pvs(lockComp.Owner), lockComp.UnlockSound.GetSound(), lockComp.Owner, AudioParams.Default.WithVolume(-5));
} }
if (lockComp.Owner.TryGetComponent(out AppearanceComponent? appearanceComp)) if (IoCManager.Resolve<IEntityManager>().TryGetComponent(lockComp.Owner.Uid, out AppearanceComponent? appearanceComp))
{ {
appearanceComp.SetData(StorageVisuals.Locked, false); appearanceComp.SetData(StorageVisuals.Locked, false);
} }

View File

@@ -16,7 +16,7 @@ namespace Content.Server.Morgue.Components
void IActivate.Activate(ActivateEventArgs eventArgs) void IActivate.Activate(ActivateEventArgs eventArgs)
{ {
if (Morgue != null && !((!IoCManager.Resolve<IEntityManager>().EntityExists(Morgue.Uid) ? EntityLifeStage.Deleted : IoCManager.Resolve<IEntityManager>().GetComponent<MetaDataComponent>(Morgue.Uid).EntityLifeStage) >= EntityLifeStage.Deleted) && Morgue.TryGetComponent<MorgueEntityStorageComponent>(out var comp)) if (Morgue != null && !((!IoCManager.Resolve<IEntityManager>().EntityExists(Morgue.Uid) ? EntityLifeStage.Deleted : IoCManager.Resolve<IEntityManager>().GetComponent<MetaDataComponent>(Morgue.Uid).EntityLifeStage) >= EntityLifeStage.Deleted) && IoCManager.Resolve<IEntityManager>().TryGetComponent<MorgueEntityStorageComponent?>(Morgue.Uid, out var comp))
{ {
comp.Activate(new ActivateEventArgs(eventArgs.User, Morgue)); comp.Activate(new ActivateEventArgs(eventArgs.User, Morgue));
} }

View File

@@ -57,7 +57,7 @@ namespace Content.Server.Research.Components
void IActivate.Activate(ActivateEventArgs eventArgs) void IActivate.Activate(ActivateEventArgs eventArgs)
{ {
if (!eventArgs.User.TryGetComponent(out ActorComponent? actor)) if (!IoCManager.Resolve<IEntityManager>().TryGetComponent(eventArgs.User.Uid, out ActorComponent? actor))
return; return;
OpenUserInterface(actor.PlayerSession); OpenUserInterface(actor.PlayerSession);

View File

@@ -4,6 +4,7 @@ using Content.Shared.Tabletop.Events;
using Robust.Server.Player; using Robust.Server.Player;
using Robust.Shared.GameObjects; using Robust.Shared.GameObjects;
using Robust.Shared.GameStates; using Robust.Shared.GameStates;
using Robust.Shared.IoC;
using Robust.Shared.Map; using Robust.Shared.Map;
using Robust.Shared.Maths; using Robust.Shared.Maths;
using DrawDepth = Content.Shared.DrawDepth.DrawDepth; using DrawDepth = Content.Shared.DrawDepth.DrawDepth;
@@ -60,11 +61,11 @@ namespace Content.Server.Tabletop
{ {
var draggedEntity = EntityManager.GetEntity(msg.DraggedEntityUid); var draggedEntity = EntityManager.GetEntity(msg.DraggedEntityUid);
if (!draggedEntity.TryGetComponent<TabletopDraggableComponent>(out var draggableComponent)) return; if (!IoCManager.Resolve<IEntityManager>().TryGetComponent<TabletopDraggableComponent?>(draggedEntity.Uid, out var draggableComponent)) return;
draggableComponent.DraggingPlayer = msg.DraggingPlayer; draggableComponent.DraggingPlayer = msg.DraggingPlayer;
if (!draggedEntity.TryGetComponent<AppearanceComponent>(out var appearance)) return; if (!IoCManager.Resolve<IEntityManager>().TryGetComponent<AppearanceComponent?>(draggedEntity.Uid, out var appearance)) return;
if (draggableComponent.DraggingPlayer != null) if (draggableComponent.DraggingPlayer != null)
{ {

View File

@@ -17,6 +17,7 @@ using Robust.Server.GameObjects;
using Robust.Shared.Audio; using Robust.Shared.Audio;
using Robust.Shared.GameObjects; using Robust.Shared.GameObjects;
using Robust.Shared.GameStates; using Robust.Shared.GameStates;
using Robust.Shared.IoC;
using Robust.Shared.Localization; using Robust.Shared.Localization;
using Robust.Shared.Player; using Robust.Shared.Player;
@@ -209,7 +210,7 @@ namespace Content.Server.Tools
// TODO: Clean up this inherited oldcode. // TODO: Clean up this inherited oldcode.
if (args.Target.TryGetComponent(out ReagentTankComponent? tank) if (IoCManager.Resolve<IEntityManager>().TryGetComponent(args.Target.Uid, out ReagentTankComponent? tank)
&& tank.TankType == ReagentTankType.Fuel && tank.TankType == ReagentTankType.Fuel
&& _solutionContainerSystem.TryGetDrainableSolution(args.Target.Uid, out var targetSolution) && _solutionContainerSystem.TryGetDrainableSolution(args.Target.Uid, out var targetSolution)
&& _solutionContainerSystem.TryGetSolution(uid, welder.FuelSolution, out var welderSolution)) && _solutionContainerSystem.TryGetSolution(uid, welder.FuelSolution, out var welderSolution))

View File

@@ -67,7 +67,7 @@ namespace Content.Server.UserInterface
private bool InteractUI(IEntity user, ActivatableUIComponent aui) private bool InteractUI(IEntity user, ActivatableUIComponent aui)
{ {
if (!user.TryGetComponent(out ActorComponent? actor)) return false; if (!IoCManager.Resolve<IEntityManager>().TryGetComponent(user.Uid, out ActorComponent? actor)) return false;
if (aui.AdminOnly && !_adminManager.IsAdmin(actor.PlayerSession)) return false; if (aui.AdminOnly && !_adminManager.IsAdmin(actor.PlayerSession)) return false;

View File

@@ -18,8 +18,8 @@ namespace Content.Shared.Lathe
public bool CanProduce(LatheRecipePrototype recipe, int quantity = 1) public bool CanProduce(LatheRecipePrototype recipe, int quantity = 1)
{ {
if (!Owner.TryGetComponent(out SharedMaterialStorageComponent? storage) if (!IoCManager.Resolve<IEntityManager>().TryGetComponent(Owner.Uid, out SharedMaterialStorageComponent? storage)
|| !Owner.TryGetComponent(out SharedLatheDatabaseComponent? database)) return false; || !IoCManager.Resolve<IEntityManager>().TryGetComponent(Owner.Uid, out SharedLatheDatabaseComponent? database)) return false;
if (!database.Contains(recipe)) return false; if (!database.Contains(recipe)) return false;

View File

@@ -54,7 +54,7 @@ namespace Content.Shared.Movement.EntitySystems
// For stuff like "Moving out of locker" or the likes // For stuff like "Moving out of locker" or the likes
if (owner.IsInContainer() && if (owner.IsInContainer() &&
(!owner.TryGetComponent(out MobStateComponent? mobState) || (!IoCManager.Resolve<IEntityManager>().TryGetComponent(owner.Uid, out MobStateComponent? mobState) ||
mobState.IsAlive())) mobState.IsAlive()))
{ {
var relayMoveEvent = new RelayMovementEntityEvent(owner); var relayMoveEvent = new RelayMovementEntityEvent(owner);
@@ -85,7 +85,7 @@ namespace Content.Shared.Movement.EntitySystems
if (ent == null || !IoCManager.Resolve<IEntityManager>().EntityExists(ent.Uid)) if (ent == null || !IoCManager.Resolve<IEntityManager>().EntityExists(ent.Uid))
return false; return false;
if (!ent.TryGetComponent(out T? comp)) if (!IoCManager.Resolve<IEntityManager>().TryGetComponent(ent.Uid, out T? comp))
return false; return false;
component = comp; component = comp;

View File

@@ -3,6 +3,7 @@ using Content.Shared.Storage.Components;
using JetBrains.Annotations; using JetBrains.Annotations;
using Robust.Shared.Containers; using Robust.Shared.Containers;
using Robust.Shared.GameObjects; using Robust.Shared.GameObjects;
using Robust.Shared.IoC;
namespace Content.Shared.Storage.EntitySystems namespace Content.Shared.Storage.EntitySystems
{ {
@@ -20,32 +21,32 @@ namespace Content.Shared.Storage.EntitySystems
private void CounterEntityInserted(EntityUid uid, ItemCounterComponent itemCounter, private void CounterEntityInserted(EntityUid uid, ItemCounterComponent itemCounter,
EntInsertedIntoContainerMessage args) EntInsertedIntoContainerMessage args)
{ {
if (!itemCounter.Owner.TryGetComponent(out AppearanceComponent? appearanceComponent)) return; if (!IoCManager.Resolve<IEntityManager>().TryGetComponent(itemCounter.Owner.Uid, out AppearanceComponent? appearanceComponent)) return;
var count = GetCount(args, itemCounter); var count = GetCount(args, itemCounter);
if (count == null) if (count == null)
return; return;
appearanceComponent.SetData(StackVisuals.Actual, count); appearanceComponent.SetData(StackVisuals.Actual, count);
if (itemCounter.MaxAmount != null) if (itemCounter.MaxAmount != null)
appearanceComponent.SetData(StackVisuals.MaxCount, itemCounter.MaxAmount); appearanceComponent.SetData(StackVisuals.MaxCount, itemCounter.MaxAmount);
} }
private void CounterEntityRemoved(EntityUid uid, ItemCounterComponent itemCounter, private void CounterEntityRemoved(EntityUid uid, ItemCounterComponent itemCounter,
EntRemovedFromContainerMessage args) EntRemovedFromContainerMessage args)
{ {
if (!itemCounter.Owner.TryGetComponent(out AppearanceComponent? appearanceComponent)) return; if (!IoCManager.Resolve<IEntityManager>().TryGetComponent(itemCounter.Owner.Uid, out AppearanceComponent? appearanceComponent)) return;
var count = GetCount(args, itemCounter); var count = GetCount(args, itemCounter);
if (count == null) if (count == null)
return; return;
appearanceComponent.SetData(StackVisuals.Actual, count); appearanceComponent.SetData(StackVisuals.Actual, count);
if (itemCounter.MaxAmount != null) if (itemCounter.MaxAmount != null)
appearanceComponent.SetData(StackVisuals.MaxCount, itemCounter.MaxAmount); appearanceComponent.SetData(StackVisuals.MaxCount, itemCounter.MaxAmount);
} }
protected abstract int? GetCount(ContainerModifiedMessage msg, ItemCounterComponent itemCounter); protected abstract int? GetCount(ContainerModifiedMessage msg, ItemCounterComponent itemCounter);
} }
} }

View File

@@ -3,6 +3,7 @@ using Content.Shared.Storage.Components;
using JetBrains.Annotations; using JetBrains.Annotations;
using Robust.Shared.Containers; using Robust.Shared.Containers;
using Robust.Shared.GameObjects; using Robust.Shared.GameObjects;
using Robust.Shared.IoC;
namespace Content.Shared.Storage.EntitySystems namespace Content.Shared.Storage.EntitySystems
{ {
@@ -20,7 +21,7 @@ namespace Content.Shared.Storage.EntitySystems
private void InitLayers(EntityUid uid, ItemMapperComponent component, ComponentInit args) private void InitLayers(EntityUid uid, ItemMapperComponent component, ComponentInit args)
{ {
if (component.Owner.TryGetComponent(out AppearanceComponent? appearanceComponent)) if (IoCManager.Resolve<IEntityManager>().TryGetComponent(component.Owner.Uid, out AppearanceComponent? appearanceComponent))
{ {
var list = new List<string>(component.MapLayers.Keys); var list = new List<string>(component.MapLayers.Keys);
appearanceComponent.SetData(StorageMapVisuals.InitLayers, new ShowLayerData(list)); appearanceComponent.SetData(StorageMapVisuals.InitLayers, new ShowLayerData(list));
@@ -30,7 +31,7 @@ namespace Content.Shared.Storage.EntitySystems
private void MapperEntityRemoved(EntityUid uid, ItemMapperComponent itemMapper, private void MapperEntityRemoved(EntityUid uid, ItemMapperComponent itemMapper,
EntRemovedFromContainerMessage args) EntRemovedFromContainerMessage args)
{ {
if (itemMapper.Owner.TryGetComponent(out AppearanceComponent? appearanceComponent) if (IoCManager.Resolve<IEntityManager>().TryGetComponent(itemMapper.Owner.Uid, out AppearanceComponent? appearanceComponent)
&& TryGetLayers(args, itemMapper, out var containedLayers)) && TryGetLayers(args, itemMapper, out var containedLayers))
{ {
appearanceComponent.SetData(StorageMapVisuals.LayerChanged, new ShowLayerData(containedLayers)); appearanceComponent.SetData(StorageMapVisuals.LayerChanged, new ShowLayerData(containedLayers));
@@ -40,7 +41,7 @@ namespace Content.Shared.Storage.EntitySystems
private void MapperEntityInserted(EntityUid uid, ItemMapperComponent itemMapper, private void MapperEntityInserted(EntityUid uid, ItemMapperComponent itemMapper,
EntInsertedIntoContainerMessage args) EntInsertedIntoContainerMessage args)
{ {
if (itemMapper.Owner.TryGetComponent(out AppearanceComponent? appearanceComponent) if (IoCManager.Resolve<IEntityManager>().TryGetComponent(itemMapper.Owner.Uid, out AppearanceComponent? appearanceComponent)
&& TryGetLayers(args, itemMapper, out var containedLayers)) && TryGetLayers(args, itemMapper, out var containedLayers))
{ {
appearanceComponent.SetData(StorageMapVisuals.LayerChanged, new ShowLayerData(containedLayers)); appearanceComponent.SetData(StorageMapVisuals.LayerChanged, new ShowLayerData(containedLayers));
@@ -51,4 +52,4 @@ namespace Content.Shared.Storage.EntitySystems
ItemMapperComponent itemMapper, ItemMapperComponent itemMapper,
out IReadOnlyList<string> containedLayers); out IReadOnlyList<string> containedLayers);
} }
} }