Inline TryGetComponent completely, for real
This commit is contained in:
@@ -2,6 +2,8 @@ using Content.Server.CombatMode;
|
||||
using Content.Shared.Actions.Behaviors;
|
||||
using Content.Shared.Popups;
|
||||
using JetBrains.Annotations;
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.IoC;
|
||||
using Robust.Shared.Localization;
|
||||
using Robust.Shared.Serialization.Manager.Attributes;
|
||||
|
||||
@@ -13,7 +15,7 @@ namespace Content.Server.Actions.Actions
|
||||
{
|
||||
public bool DoToggleAction(ToggleActionEventArgs args)
|
||||
{
|
||||
if (!args.Performer.TryGetComponent(out CombatModeComponent? combatMode))
|
||||
if (!IoCManager.Resolve<IEntityManager>().TryGetComponent(args.Performer.Uid, out CombatModeComponent? combatMode))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -55,7 +55,7 @@ namespace Content.Server.Actions.Actions
|
||||
|
||||
if (disarmedActs.Length == 0)
|
||||
{
|
||||
if (args.Performer.TryGetComponent(out ActorComponent? actor))
|
||||
if (IoCManager.Resolve<IEntityManager>().TryGetComponent(args.Performer.Uid, out ActorComponent? actor))
|
||||
{
|
||||
// Fall back to a normal interaction with the entity
|
||||
var player = actor.PlayerSession;
|
||||
@@ -68,7 +68,7 @@ namespace Content.Server.Actions.Actions
|
||||
return;
|
||||
}
|
||||
|
||||
if (!args.Performer.TryGetComponent<SharedActionsComponent>(out var actions)) return;
|
||||
if (!IoCManager.Resolve<IEntityManager>().TryGetComponent<SharedActionsComponent?>(args.Performer.Uid, out var actions)) return;
|
||||
if (args.Target == args.Performer || !EntitySystem.Get<ActionBlockerSystem>().CanAttack(args.Performer.Uid)) return;
|
||||
|
||||
var random = IoCManager.Resolve<IRobustRandom>();
|
||||
|
||||
@@ -23,7 +23,7 @@ namespace Content.Server.Actions.Actions
|
||||
|
||||
public void DoInstantAction(InstantActionEventArgs args)
|
||||
{
|
||||
if (!args.Performer.TryGetComponent<SharedActionsComponent>(out var actions)) return;
|
||||
if (!IoCManager.Resolve<IEntityManager>().TryGetComponent<SharedActionsComponent?>(args.Performer.Uid, out var actions)) return;
|
||||
|
||||
// find all IGhostBooAffected nearby and do boo on them
|
||||
var ents = IoCManager.Resolve<IEntityLookup>().GetEntitiesInRange(args.Performer, _radius);
|
||||
|
||||
@@ -42,8 +42,8 @@ namespace Content.Server.Actions.Actions
|
||||
public void DoInstantAction(InstantActionEventArgs args)
|
||||
{
|
||||
if (!EntitySystem.Get<ActionBlockerSystem>().CanSpeak(args.Performer.Uid)) return;
|
||||
if (!args.Performer.TryGetComponent<HumanoidAppearanceComponent>(out var humanoid)) return;
|
||||
if (!args.Performer.TryGetComponent<SharedActionsComponent>(out var actions)) return;
|
||||
if (!IoCManager.Resolve<IEntityManager>().TryGetComponent<HumanoidAppearanceComponent?>(args.Performer.Uid, out var humanoid)) return;
|
||||
if (!IoCManager.Resolve<IEntityManager>().TryGetComponent<SharedActionsComponent?>(args.Performer.Uid, out var actions)) return;
|
||||
|
||||
if (_random.Prob(.01f))
|
||||
{
|
||||
|
||||
@@ -5,6 +5,7 @@ using Content.Shared.Actions;
|
||||
using Content.Shared.Administration;
|
||||
using Robust.Server.Player;
|
||||
using Robust.Shared.Console;
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.IoC;
|
||||
|
||||
namespace Content.Server.Actions.Commands
|
||||
@@ -27,7 +28,7 @@ namespace Content.Server.Actions.Commands
|
||||
}
|
||||
|
||||
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");
|
||||
return;
|
||||
|
||||
@@ -5,6 +5,7 @@ using Content.Shared.Actions;
|
||||
using Content.Shared.Administration;
|
||||
using Robust.Server.Player;
|
||||
using Robust.Shared.Console;
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.IoC;
|
||||
|
||||
namespace Content.Server.Actions.Commands
|
||||
@@ -27,7 +28,7 @@ namespace Content.Server.Actions.Commands
|
||||
if (!CommandUtils.TryGetAttachedEntityByUsernameOrId(shell, target, player, out attachedEntity)) 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");
|
||||
return;
|
||||
|
||||
@@ -160,7 +160,7 @@ namespace Content.Server.Actions
|
||||
return null;
|
||||
}
|
||||
|
||||
if (!item.TryGetComponent<ItemActionsComponent>(out var actionsComponent))
|
||||
if (!IoCManager.Resolve<IEntityManager>().TryGetComponent<ItemActionsComponent?>(item.Uid, out var actionsComponent))
|
||||
{
|
||||
Logger.DebugS("action", "user {0} attempted to perform" +
|
||||
" item action {1} for item {2} which has no ItemActionsComponent",
|
||||
|
||||
@@ -36,7 +36,7 @@ namespace Content.Server.Actions.Spells
|
||||
{
|
||||
var caster = args.Performer;
|
||||
|
||||
if (!caster.TryGetComponent(out HandsComponent? handsComponent))
|
||||
if (!IoCManager.Resolve<IEntityManager>().TryGetComponent(caster.Uid, out HandsComponent? handsComponent))
|
||||
{
|
||||
caster.PopupMessage(Loc.GetString("spell-fail-no-hands"));
|
||||
return;
|
||||
@@ -54,7 +54,7 @@ namespace Content.Server.Actions.Spells
|
||||
// TODO: Look this is shitty and ideally a test would do it
|
||||
var spawnedProto = IoCManager.Resolve<IEntityManager>().SpawnEntity(ItemProto, caster.Transform.MapPosition);
|
||||
|
||||
if (!spawnedProto.TryGetComponent(out ItemComponent? itemComponent))
|
||||
if (!IoCManager.Resolve<IEntityManager>().TryGetComponent(spawnedProto.Uid, out ItemComponent? itemComponent))
|
||||
{
|
||||
Logger.Error($"Tried to use {nameof(GiveItemSpell)} but prototype has no {nameof(ItemComponent)}?");
|
||||
IoCManager.Resolve<IEntityManager>().DeleteEntity(spawnedProto.Uid);
|
||||
|
||||
Reference in New Issue
Block a user