Fix errors

This commit is contained in:
DrSmugleaf
2021-12-05 21:02:04 +01:00
parent 2a3b7d809d
commit ab9d0cc6d8
94 changed files with 568 additions and 591 deletions

View File

@@ -31,7 +31,7 @@ namespace Content.Client.DoAfter
/// </summary>
public const float ExcessTime = 0.5f;
private EntityUid _attachedEntity;
private EntityUid? _attachedEntity;
public override void Initialize()
{
@@ -51,7 +51,8 @@ namespace Content.Client.DoAfter
var currentTime = _gameTiming.CurTime;
// Can't see any I guess?
if (_attachedEntity == default || (!EntityManager.EntityExists(_attachedEntity) ? EntityLifeStage.Deleted : EntityManager.GetComponent<MetaDataComponent>(_attachedEntity).EntityLifeStage) >= EntityLifeStage.Deleted)
if (_attachedEntity is not {Valid: true} entity ||
(!EntityManager.EntityExists(_attachedEntity.Value) ? EntityLifeStage.Deleted : EntityManager.GetComponent<MetaDataComponent>(entity).EntityLifeStage) >= EntityLifeStage.Deleted)
return;
var viewbox = _eyeManager.GetWorldViewport().Enlarged(2.0f);
@@ -62,19 +63,19 @@ namespace Content.Client.DoAfter
var compPos = EntityManager.GetComponent<TransformComponent>(comp.Owner).WorldPosition;
if (doAfters.Count == 0 ||
EntityManager.GetComponent<TransformComponent>(comp.Owner).MapID != EntityManager.GetComponent<TransformComponent>(_attachedEntity).MapID ||
EntityManager.GetComponent<TransformComponent>(comp.Owner).MapID != EntityManager.GetComponent<TransformComponent>(entity).MapID ||
!viewbox.Contains(compPos))
{
comp.Disable();
continue;
}
var range = (compPos - EntityManager.GetComponent<TransformComponent>(_attachedEntity).WorldPosition).Length +
var range = (compPos - EntityManager.GetComponent<TransformComponent>(entity).WorldPosition).Length +
0.01f;
if (comp.Owner != _attachedEntity &&
!ExamineSystemShared.InRangeUnOccluded(
EntityManager.GetComponent<TransformComponent>(_attachedEntity).MapPosition,
EntityManager.GetComponent<TransformComponent>(entity).MapPosition,
EntityManager.GetComponent<TransformComponent>(comp.Owner).MapPosition, range,
entity => entity == comp.Owner || entity == _attachedEntity))
{

View File

@@ -15,9 +15,10 @@ namespace Content.Client.HealthOverlay
public class HealthOverlaySystem : EntitySystem
{
[Dependency] private readonly IEyeManager _eyeManager = default!;
[Dependency] private readonly IEntityManager _entities = default!;
private readonly Dictionary<EntityUid, HealthOverlayGui> _guis = new();
private EntityUid _attachedEntity;
private EntityUid? _attachedEntity;
private bool _enabled;
public bool Enabled
@@ -72,7 +73,7 @@ namespace Content.Client.HealthOverlay
return;
}
if (_attachedEntity == null || (!IoCManager.Resolve<IEntityManager>().EntityExists(_attachedEntity) ? EntityLifeStage.Deleted : IoCManager.Resolve<IEntityManager>().GetComponent<MetaDataComponent>(_attachedEntity).EntityLifeStage) >= EntityLifeStage.Deleted)
if (_attachedEntity == null || (!_entities.EntityExists(_attachedEntity.Value) ? EntityLifeStage.Deleted : _entities.GetComponent<MetaDataComponent>(_attachedEntity.Value).EntityLifeStage) >= EntityLifeStage.Deleted)
{
return;
}
@@ -83,8 +84,8 @@ namespace Content.Client.HealthOverlay
{
var entity = mobState.Owner;
if (IoCManager.Resolve<IEntityManager>().GetComponent<TransformComponent>(_attachedEntity).MapID != IoCManager.Resolve<IEntityManager>().GetComponent<TransformComponent>(entity).MapID ||
!viewBox.Contains(IoCManager.Resolve<IEntityManager>().GetComponent<TransformComponent>(entity).WorldPosition))
if (_entities.GetComponent<TransformComponent>(_attachedEntity.Value).MapID != _entities.GetComponent<TransformComponent>(entity).MapID ||
!viewBox.Contains(_entities.GetComponent<TransformComponent>(entity).WorldPosition))
{
if (_guis.TryGetValue(entity, out var oldGui))
{

View File

@@ -44,8 +44,7 @@ namespace Content.Client.Physics.Controllers
// If we're being pulled then we won't predict anything and will receive server lerps so it looks way smoother.
if (EntityManager.TryGetComponent(player, out SharedPullableComponent? pullableComp))
{
var puller = pullableComp.Puller;
if (puller != default && EntityManager.TryGetComponent<PhysicsComponent?>(puller, out var pullerBody))
if (pullableComp.Puller is {Valid: true} puller && EntityManager.TryGetComponent<PhysicsComponent?>(puller, out var pullerBody))
{
pullerBody.Predict = false;
body.Predict = false;
@@ -55,9 +54,7 @@ namespace Content.Client.Physics.Controllers
// If we're pulling a mob then make sure that isn't predicted so it doesn't fuck our velocity up.
if (EntityManager.TryGetComponent(player, out SharedPullerComponent? pullerComp))
{
var pulling = pullerComp.Pulling;
if (pulling != default &&
if (pullerComp.Pulling is {Valid: true} pulling &&
EntityManager.HasComponent<MobStateComponent>(pulling) &&
EntityManager.TryGetComponent(pulling, out PhysicsComponent? pullingBody))
{

View File

@@ -91,14 +91,14 @@ namespace Content.IntegrationTests.Tests
server.Post(() =>
{
IoCManager.Resolve<IEntityManager>().DeleteEntity((EntityUid) playerEnt);
IoCManager.Resolve<IEntityManager>().DeleteEntity(playerEnt);
});
server.RunTicks(1);
server.Assert(() =>
{
Assert.That(IoCManager.Resolve<IEntityManager>().EntityExists(mind.CurrentEntity), Is.True);
Assert.That(IoCManager.Resolve<IEntityManager>().EntityExists(mind.CurrentEntity!.Value), Is.True);
});
await server.WaitIdleAsync();
@@ -149,7 +149,7 @@ namespace Content.IntegrationTests.Tests
server.Assert(() =>
{
Assert.That(IoCManager.Resolve<IEntityManager>().EntityExists(mind.CurrentEntity), Is.True);
Assert.That(IoCManager.Resolve<IEntityManager>().EntityExists(mind.CurrentEntity!.Value), Is.True);
Assert.That(mind.CurrentEntity, Is.Not.EqualTo(playerEnt));
});

View File

@@ -49,7 +49,7 @@ namespace Content.Server.Chat.Commands
return;
}
chat.EntityMe(mindComponent.OwnedEntity, action);
chat.EntityMe(mindComponent.OwnedEntity.Value, action);
}
}
}

View File

@@ -62,11 +62,11 @@ namespace Content.Server.Chat.Commands
return;
}
var emote = chatSanitizer.TrySanitizeOutSmilies(message, mindComponent.OwnedEntity, out var sanitized, out var emoteStr);
var emote = chatSanitizer.TrySanitizeOutSmilies(message, mindComponent.OwnedEntity.Value, out var sanitized, out var emoteStr);
if (sanitized.Length != 0)
chat.EntitySay(mindComponent.OwnedEntity, sanitized);
chat.EntitySay(mindComponent.OwnedEntity.Value, sanitized);
if (emote)
chat.EntityMe(mindComponent.OwnedEntity, emoteStr!);
chat.EntityMe(mindComponent.OwnedEntity.Value, emoteStr!);
}
}

View File

@@ -288,10 +288,10 @@ namespace Content.Server.Chemistry.EntitySystems
UpdateChemicals(uid, solution);
}
public FixedPoint2 GetReagentQuantity(EntityUid Owner, string reagentId)
public FixedPoint2 GetReagentQuantity(EntityUid owner, string reagentId)
{
var reagentQuantity = FixedPoint2.New(0);
if (EntityManager.EntityExists(Owner)
if (EntityManager.EntityExists(owner)
&& IoCManager.Resolve<IEntityManager>().TryGetComponent(owner, out SolutionContainerManagerComponent? managerComponent))
{
foreach (var solution in managerComponent.Solutions.Values)

View File

@@ -22,10 +22,10 @@ namespace Content.Server.Chemistry.EntitySystems
SubscribeLocalEvent<TransformableContainerComponent, SolutionChangedEvent>(OnSolutionChange);
}
private void OnSolutionChange(EntityUid uid, TransformableContainerComponent component,
private void OnSolutionChange(EntityUid owner, TransformableContainerComponent component,
SolutionChangedEvent args)
{
if (!_solutionsSystem.TryGetFitsInDispenser(uid, out var solution))
if (!_solutionsSystem.TryGetFitsInDispenser(owner, out var solution))
return;
//Transform container into initial state when emptied
if (component.CurrentReagent != null && solution.Contents.Count == 0)
@@ -50,15 +50,14 @@ namespace Content.Server.Chemistry.EntitySystems
var spriteSpec =
new SpriteSpecifier.Rsi(
new ResourcePath("Objects/Consumable/Drinks/" + proto.SpriteReplacementPath), "icon");
var Owner
if (IoCManager.Resolve<IEntityManager>().TryGetComponent(ownerEntity, out SpriteComponent? sprite))
if (IoCManager.Resolve<IEntityManager>().TryGetComponent(owner, out SpriteComponent? sprite))
{
sprite?.LayerSetSprite(0, spriteSpec);
}
string val = proto.Name + " glass";
IoCManager.Resolve<IEntityManager>().GetComponent<MetaDataComponent>(ownerEntity).EntityName = val;
IoCManager.Resolve<IEntityManager>().GetComponent<MetaDataComponent>(ownerEntity).EntityDescription = proto.Description;
IoCManager.Resolve<IEntityManager>().GetComponent<MetaDataComponent>(owner).EntityName = val;
IoCManager.Resolve<IEntityManager>().GetComponent<MetaDataComponent>(owner).EntityDescription = proto.Description;
component.CurrentReagent = proto;
component.Transformed = true;
}

View File

@@ -27,7 +27,7 @@ public class DoAction : ReagentEffect
if (actions.IsGranted(proto.ActionType))
{
var attempt = new ActionAttempt(proto);
attempt.DoInstantAction(args.args.SolutionEntity)
attempt.DoInstantAction(args.SolutionEntity);
}
}
}

View File

@@ -22,6 +22,8 @@ namespace Content.Server.Climbing.Components
[ComponentReference(typeof(IClimbable))]
public class ClimbableComponent : SharedClimbableComponent
{
[Dependency] private readonly IEntityManager _entities = default!;
/// <summary>
/// The time it takes to climb onto the entity.
/// </summary>
@@ -35,7 +37,7 @@ namespace Content.Server.Climbing.Components
if (!Owner.EnsureComponent(out PhysicsComponent _))
{
Logger.Warning($"Entity {IoCManager.Resolve<IEntityManager>().GetComponent<MetaDataComponent>(Owner).EntityName} at {IoCManager.Resolve<IEntityManager>().GetComponent<TransformComponent>(Owner).MapPosition} didn't have a {nameof(PhysicsComponent)}");
Logger.Warning($"Entity {_entities.GetComponent<MetaDataComponent>(Owner).EntityName} at {_entities.GetComponent<TransformComponent>(Owner).MapPosition} didn't have a {nameof(PhysicsComponent)}");
}
}
@@ -73,8 +75,8 @@ namespace Content.Server.Climbing.Components
return false;
}
if (!IoCManager.Resolve<IEntityManager>().HasComponent<ClimbingComponent>(user) ||
!IoCManager.Resolve<IEntityManager>().TryGetComponent(user, out SharedBodyComponent? body))
if (!_entities.HasComponent<ClimbingComponent>(user) ||
!_entities.TryGetComponent(user, out SharedBodyComponent? body))
{
reason = Loc.GetString("comp-climbable-cant-climb");
return false;
@@ -113,7 +115,7 @@ namespace Content.Server.Climbing.Components
return false;
}
if (target == null || !IoCManager.Resolve<IEntityManager>().HasComponent<ClimbingComponent>(dragged))
if (target == null || !_entities.HasComponent<ClimbingComponent>(dragged))
{
reason = Loc.GetString("comp-climbable-cant-climb");
return false;
@@ -158,14 +160,14 @@ namespace Content.Server.Climbing.Components
var result = await EntitySystem.Get<DoAfterSystem>().WaitDoAfter(doAfterEventArgs);
if (result != DoAfterStatus.Cancelled && IoCManager.Resolve<IEntityManager>().TryGetComponent(entityToMove, out PhysicsComponent? body) && body.Fixtures.Count >= 1)
if (result != DoAfterStatus.Cancelled && _entities.TryGetComponent(entityToMove, out PhysicsComponent? body) && body.Fixtures.Count >= 1)
{
var entityPos = IoCManager.Resolve<IEntityManager>().GetComponent<TransformComponent>(entityToMove).WorldPosition;
var entityPos = _entities.GetComponent<TransformComponent>(entityToMove).WorldPosition;
var direction = (IoCManager.Resolve<IEntityManager>().GetComponent<TransformComponent>(Owner).WorldPosition - entityPos).Normalized;
var endPoint = IoCManager.Resolve<IEntityManager>().GetComponent<TransformComponent>(Owner).WorldPosition;
var direction = (_entities.GetComponent<TransformComponent>(Owner).WorldPosition - entityPos).Normalized;
var endPoint = _entities.GetComponent<TransformComponent>(Owner).WorldPosition;
var climbMode = IoCManager.Resolve<IEntityManager>().GetComponent<ClimbingComponent>(entityToMove);
var climbMode = _entities.GetComponent<ClimbingComponent>(entityToMove);
climbMode.IsClimbing = true;
if (MathF.Abs(direction.X) < 0.6f) // user climbed mostly vertically so lets make it a clean straight line
@@ -192,7 +194,7 @@ namespace Content.Server.Climbing.Components
public async void TryClimb(EntityUid user)
{
if (!IoCManager.Resolve<IEntityManager>().TryGetComponent(user, out ClimbingComponent? climbingComponent) || climbingComponent.IsClimbing)
if (!_entities.TryGetComponent(user, out ClimbingComponent? climbingComponent) || climbingComponent.IsClimbing)
return;
var doAfterEventArgs = new DoAfterEventArgs(user, _climbDelay, default, Owner)
@@ -205,24 +207,24 @@ namespace Content.Server.Climbing.Components
var result = await EntitySystem.Get<DoAfterSystem>().WaitDoAfter(doAfterEventArgs);
if (result != DoAfterStatus.Cancelled && IoCManager.Resolve<IEntityManager>().TryGetComponent(user, out PhysicsComponent? body) && body.Fixtures.Count >= 1)
if (result != DoAfterStatus.Cancelled && _entities.TryGetComponent(user, out PhysicsComponent? body) && body.Fixtures.Count >= 1)
{
// TODO: Remove the copy-paste code
var userPos = IoCManager.Resolve<IEntityManager>().GetComponent<TransformComponent>(user).WorldPosition;
var userPos = _entities.GetComponent<TransformComponent>(user).WorldPosition;
var direction = (IoCManager.Resolve<IEntityManager>().GetComponent<TransformComponent>(Owner).WorldPosition - userPos).Normalized;
var endPoint = IoCManager.Resolve<IEntityManager>().GetComponent<TransformComponent>(Owner).WorldPosition;
var direction = (_entities.GetComponent<TransformComponent>(Owner).WorldPosition - userPos).Normalized;
var endPoint = _entities.GetComponent<TransformComponent>(Owner).WorldPosition;
var climbMode = IoCManager.Resolve<IEntityManager>().GetComponent<ClimbingComponent>(user);
var climbMode = _entities.GetComponent<ClimbingComponent>(user);
climbMode.IsClimbing = true;
if (MathF.Abs(direction.X) < 0.6f) // user climbed mostly vertically so lets make it a clean straight line
{
endPoint = new Vector2(IoCManager.Resolve<IEntityManager>().GetComponent<TransformComponent>(user).WorldPosition.X, endPoint.Y);
endPoint = new Vector2(_entities.GetComponent<TransformComponent>(user).WorldPosition.X, endPoint.Y);
}
else if (MathF.Abs(direction.Y) < 0.6f) // user climbed mostly horizontally so lets make it a clean straight line
{
endPoint = new Vector2(endPoint.X, IoCManager.Resolve<IEntityManager>().GetComponent<TransformComponent>(user).WorldPosition.Y);
endPoint = new Vector2(endPoint.X, _entities.GetComponent<TransformComponent>(user).WorldPosition.Y);
}
climbMode.TryMoveTo(userPos, endPoint);

View File

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

View File

@@ -23,10 +23,12 @@ namespace Content.Server.Cloning.Components
public class CloningPodComponent : SharedCloningPodComponent
{
[Dependency] private readonly IPlayerManager _playerManager = null!;
[Dependency] private readonly IEntityManager _entities = default!;
[Dependency] private readonly EuiManager _euiManager = null!;
[ViewVariables]
public bool Powered => !IoCManager.Resolve<IEntityManager>().TryGetComponent(Owner, out ApcPowerReceiverComponent? receiver) || receiver.Powered;
public bool Powered => !_entities.TryGetComponent(Owner, out ApcPowerReceiverComponent? receiver) || receiver.Powered;
[ViewVariables]
public BoundUserInterface? UserInterface =>
@@ -70,7 +72,7 @@ namespace Content.Server.Cloning.Components
private void UpdateAppearance()
{
if (IoCManager.Resolve<IEntityManager>().TryGetComponent(Owner, out AppearanceComponent? appearance))
if (_entities.TryGetComponent(Owner, out AppearanceComponent? appearance))
{
appearance.SetData(CloningPodVisuals.Status, Status);
}
@@ -105,12 +107,12 @@ namespace Content.Server.Cloning.Components
var mind = dna.Mind;
if (cloningSystem.ClonesWaitingForMind.TryGetValue(mind, out var cloneUid))
if (cloningSystem.ClonesWaitingForMind.TryGetValue(mind, out var clone))
{
if (IoCManager.Resolve<IEntityManager>().EntityExists(cloneUid) &&
IoCManager.Resolve<IEntityManager>().TryGetComponent<MobStateComponent?>(clone, out var cloneState) &&
if (_entities.EntityExists(clone) &&
_entities.TryGetComponent<MobStateComponent?>(clone, out var cloneState) &&
!cloneState.IsDead() &&
IoCManager.Resolve<IEntityManager>().TryGetComponent(clone, out MindComponent? cloneMindComp) &&
_entities.TryGetComponent(clone, out MindComponent? cloneMindComp) &&
(cloneMindComp.Mind == null || cloneMindComp.Mind == mind))
{
obj.Session.AttachedEntity?.PopupMessageCursor(Loc.GetString("cloning-pod-component-msg-already-cloning"));
@@ -121,7 +123,7 @@ namespace Content.Server.Cloning.Components
}
if (mind.OwnedEntity != null &&
IoCManager.Resolve<IEntityManager>().TryGetComponent<MobStateComponent?>(mind.OwnedEntity, out var state) &&
_entities.TryGetComponent<MobStateComponent?>(mind.OwnedEntity.Value, out var state) &&
!state.IsDead())
{
obj.Session.AttachedEntity?.PopupMessageCursor(Loc.GetString("cloning-pod-component-msg-already-alive"));
@@ -135,13 +137,13 @@ namespace Content.Server.Cloning.Components
return; // If we can't track down the client, we can't offer transfer. That'd be quite bad.
}
var mob = IoCManager.Resolve<IEntityManager>().SpawnEntity("MobHuman", IoCManager.Resolve<IEntityManager>().GetComponent<TransformComponent>(Owner).MapPosition);
var mob = _entities.SpawnEntity("MobHuman", _entities.GetComponent<TransformComponent>(Owner).MapPosition);
EntitySystem.Get<SharedHumanoidAppearanceSystem>().UpdateFromProfile(mob, dna.Profile);
IoCManager.Resolve<IEntityManager>().GetComponent<MetaDataComponent>(mob).EntityName = dna.Profile.Name;
_entities.GetComponent<MetaDataComponent>(mob).EntityName = dna.Profile.Name;
var cloneMindReturn = IoCManager.Resolve<IEntityManager>().AddComponent<BeingClonedComponent>(mob);
var cloneMindReturn = _entities.AddComponent<BeingClonedComponent>(mob);
cloneMindReturn.Mind = mind;
cloneMindReturn.Parent = Owner;
@@ -167,12 +169,11 @@ namespace Content.Server.Cloning.Components
public void Eject()
{
var entity = BodyContainer.ContainedEntity;
if (entity == null || CloningProgress < CloningTime)
if (BodyContainer.ContainedEntity is not {Valid: true} entity || CloningProgress < CloningTime)
return;
IoCManager.Resolve<IEntityManager>().RemoveComponent<BeingClonedComponent>(entity);
BodyContainer.Remove(entity!);
_entities.RemoveComponent<BeingClonedComponent>(entity);
BodyContainer.Remove(entity);
CapturedMind = null;
CloningProgress = 0f;
UpdateStatus(CloningPodStatus.Idle);

View File

@@ -21,6 +21,8 @@ namespace Content.Server.Clothing.Components
[NetworkedComponent()]
public class ClothingComponent : ItemComponent, IUse
{
[Dependency] private readonly IEntityManager _entities = default!;
public override string Name => "Clothing";
[ViewVariables]
@@ -60,8 +62,8 @@ namespace Content.Server.Clothing.Components
bool IUse.UseEntity(UseEntityEventArgs eventArgs)
{
if (!_quickEquipEnabled) return false;
if (!IoCManager.Resolve<IEntityManager>().TryGetComponent(eventArgs.User, out InventoryComponent? inv)
|| !IoCManager.Resolve<IEntityManager>().TryGetComponent(eventArgs.User, out HandsComponent? hands)) return false;
if (!_entities.TryGetComponent(eventArgs.User, out InventoryComponent? inv)
|| !_entities.TryGetComponent(eventArgs.User, out HandsComponent? hands)) return false;
foreach (var (slot, flag) in SlotMasks)
{
@@ -79,14 +81,14 @@ namespace Content.Server.Clothing.Components
{
hands.Drop(item.Owner);
inv.Equip(slot, item);
hands.PutInHand(IoCManager.Resolve<IEntityManager>().GetComponent<ItemComponent>(Owner));
hands.PutInHand(_entities.GetComponent<ItemComponent>(Owner));
}
}
else
{
hands.Drop(Owner);
if (!TryEquip(inv, slot, eventArgs.User))
hands.PutInHand(IoCManager.Resolve<IEntityManager>().GetComponent<ItemComponent>(Owner));
hands.PutInHand(_entities.GetComponent<ItemComponent>(Owner));
}
return true;

View File

@@ -1,8 +1,8 @@
using Content.Server.Construction.Components;
using Content.Shared.Containers.ItemSlots;
using JetBrains.Annotations;
using Robust.Shared.Containers;
using Robust.Shared.GameObjects;
using Content.Shared.Containers.ItemSlots;
using Robust.Shared.IoC;
namespace Content.Server.Containers
@@ -27,7 +27,7 @@ namespace Content.Server.Containers
foreach (var slot in component.Slots.Values)
{
if (slot.EjectOnDeconstruct && slot.Item != null)
slot.ContainerSlot.Remove(slot.Item);
slot.ContainerSlot.Remove(slot.Item.Value);
}
}

View File

@@ -24,6 +24,8 @@ namespace Content.Server.Cuffs.Components
[ComponentReference(typeof(SharedHandcuffComponent))]
public class HandcuffComponent : SharedHandcuffComponent, IAfterInteract
{
[Dependency] private readonly IEntityManager _entities = default!;
/// <summary>
/// The time it takes to apply a <see cref="CuffedComponent"/> to an entity.
/// </summary>
@@ -146,7 +148,9 @@ namespace Content.Server.Cuffs.Components
{
if (_cuffing) return true;
if (eventArgs.Target == null || !EntitySystem.Get<ActionBlockerSystem>().CanUse(eventArgs.User) || !IoCManager.Resolve<IEntityManager>().TryGetComponent<CuffableComponent?>(eventArgs.Target, out var cuffed))
if (eventArgs.Target is not {Valid: true} target ||
!EntitySystem.Get<ActionBlockerSystem>().CanUse(eventArgs.User) ||
!_entities.TryGetComponent<CuffableComponent?>(eventArgs.Target.Value, out var cuffed))
{
return false;
}
@@ -163,7 +167,7 @@ namespace Content.Server.Cuffs.Components
return true;
}
if (!IoCManager.Resolve<IEntityManager>().TryGetComponent<HandsComponent?>(eventArgs.Target, out var hands))
if (!_entities.TryGetComponent<HandsComponent?>(target, out var hands))
{
eventArgs.User.PopupMessage(Loc.GetString("handcuff-component-target-has-no-hands-error",("targetName", eventArgs.Target)));
return true;
@@ -182,11 +186,11 @@ namespace Content.Server.Cuffs.Components
}
eventArgs.User.PopupMessage(Loc.GetString("handcuff-component-start-cuffing-target-message",("targetName", eventArgs.Target)));
eventArgs.User.PopupMessage(eventArgs.Target, Loc.GetString("handcuff-component-start-cuffing-by-other-message",("otherName", eventArgs.User)));
eventArgs.User.PopupMessage(target, Loc.GetString("handcuff-component-start-cuffing-by-other-message",("otherName", eventArgs.User)));
SoundSystem.Play(Filter.Pvs(Owner), StartCuffSound.GetSound(), Owner);
TryUpdateCuff(eventArgs.User, eventArgs.Target, cuffed);
TryUpdateCuff(eventArgs.User, target, cuffed);
return true;
}
@@ -197,7 +201,7 @@ namespace Content.Server.Cuffs.Components
{
var cuffTime = CuffTime;
if (IoCManager.Resolve<IEntityManager>().HasComponent<StunnedComponent>(target))
if (_entities.HasComponent<StunnedComponent>(target))
{
cuffTime = MathF.Max(0.1f, cuffTime - StunBonus);
}

View File

@@ -55,7 +55,7 @@ namespace Content.Server.Cuffs
{
return;
}
if (!EntityManager.EntityExists(args.User)
if (!EntityManager.EntityExists(args.User))
{
// Should this even be possible?
args.Cancel();
@@ -66,7 +66,7 @@ namespace Content.Server.Cuffs
if (args.User == args.Target)
{
// This UncuffAttemptEvent check should probably be In MobStateSystem, not here?
if (IoCManager.Resolve<IEntityManager>().TryGetComponent<MobStateComponent?>(userEntity, out var state))
if (IoCManager.Resolve<IEntityManager>().TryGetComponent<MobStateComponent?>(args.User, out var state))
{
// Manually check this.
if (state.IsIncapacitated())
@@ -83,14 +83,14 @@ namespace Content.Server.Cuffs
else
{
// Check if the user can interact.
if (!_actionBlockerSystem.CanInteract(userEntity))
if (!_actionBlockerSystem.CanInteract(args.User))
{
args.Cancel();
}
}
if (args.Cancelled)
{
_popupSystem.PopupEntity(Loc.GetString("cuffable-component-cannot-interact-message"), args.Target, Filter.Entities(userEntity));
_popupSystem.PopupEntity(Loc.GetString("cuffable-component-cannot-interact-message"), args.Target, Filter.Entities(args.User));
}
}

View File

@@ -43,16 +43,13 @@ namespace Content.Server.Damage.Commands
private delegate void Damage(EntityUid entity, bool ignoreResistances);
private bool TryParseEntity(IConsoleShell shell, IPlayerSession? player, string arg,
[NotNullWhen(true)] out EntityUid entity)
private bool TryParseEntity(IConsoleShell shell, IPlayerSession? player, string arg, out EntityUid entity)
{
entity = null;
entity = default;
if (arg == "_")
{
var playerEntity = player?.AttachedEntity;
if (playerEntity == null)
if (player?.AttachedEntity is not {Valid: true} playerEntity)
{
shell.WriteLine($"You must have a player entity to use this command without specifying an entity.\n{Help}");
return false;
@@ -62,23 +59,20 @@ namespace Content.Server.Damage.Commands
return true;
}
if (!EntityUid.TryParse(arg, out var entityUid))
if (!EntityUid.TryParse(arg, out entity))
{
shell.WriteLine($"{arg} is not a valid entity uid.\n{Help}");
return false;
}
var entityManager = IoCManager.Resolve<IEntityManager>();
if (!entityManager.EntityExists(entityUid)
if (!entityManager.EntityExists(entity))
{
shell.WriteLine($"No entity found with uid {entityUid}");
shell.WriteLine($"No entity found with uid {entity}");
return false;
}
entity = parsedEntity;
return true;
}

View File

@@ -1,7 +1,6 @@
using Content.Server.DeviceNetwork.Components;
using JetBrains.Annotations;
using Robust.Shared.GameObjects;
using Robust.Shared.IoC;
namespace Content.Server.DeviceNetwork.Systems
{
@@ -19,10 +18,7 @@ namespace Content.Server.DeviceNetwork.Systems
/// </summary>
private void OnBeforePacketSent(EntityUid uid, WiredNetworkComponent component, BeforePacketSentEvent args)
{
args.Sender
uid
if (IoCManager.Resolve<IEntityManager>().GetComponent<TransformComponent>(receiver).GridID != IoCManager.Resolve<IEntityManager>().GetComponent<TransformComponent>(sender).GridID)
if (EntityManager.GetComponent<TransformComponent>(uid).GridID != EntityManager.GetComponent<TransformComponent>(args.Sender).GridID)
{
args.Cancel();
}

View File

@@ -1,7 +1,6 @@
using Content.Server.DeviceNetwork.Components;
using JetBrains.Annotations;
using Robust.Shared.GameObjects;
using Robust.Shared.IoC;
namespace Content.Server.DeviceNetwork.Systems
{
@@ -19,13 +18,11 @@ namespace Content.Server.DeviceNetwork.Systems
/// </summary>
private void OnBeforePacketSent(EntityUid uid, WirelessNetworkComponent component, BeforePacketSentEvent args)
{
var sender = args.Sender
var ownPosition = IoCManager.Resolve<IEntityManager>().GetComponent<TransformComponent>(component.Owner).WorldPosition;
var position = IoCManager.Resolve<IEntityManager>().GetComponent<TransformComponent>(sender).WorldPosition;
var ownPosition = EntityManager.GetComponent<TransformComponent>(component.Owner).WorldPosition;
var position = EntityManager.GetComponent<TransformComponent>(args.Sender).WorldPosition;
var distance = (ownPosition - position).Length;
if(IoCManager.Resolve<IEntityManager>().TryGetComponent<WirelessNetworkComponent?>(sender, out var sendingComponent) && distance > sendingComponent.Range)
if (EntityManager.TryGetComponent<WirelessNetworkComponent?>(args.Sender, out var sendingComponent) && distance > sendingComponent.Range)
{
args.Cancel();
}

View File

@@ -68,9 +68,8 @@ namespace Content.Server.Disposal.Tube
return;
}
var uid
component.LastClang = _gameTiming.CurTime;
SoundSystem.Play(Filter.Pvs(entity), component.ClangSound.GetSound(), entity);
SoundSystem.Play(Filter.Pvs(uid), component.ClangSound.GetSound(), uid);
}
private static void BodyTypeChanged(

View File

@@ -38,13 +38,13 @@ namespace Content.Server.Disposal
}
var entityManager = IoCManager.Resolve<IEntityManager>();
if (!entityManager.EntityExists(id)
if (!entityManager.EntityExists(id))
{
shell.WriteLine(Loc.GetString("shell-could-not-find-entity-with-uid",("uid", id)));
return;
}
if (!IoCManager.Resolve<IEntityManager>().TryGetComponent(entity, out IDisposalTubeComponent? tube))
if (!entityManager.TryGetComponent(id, out IDisposalTubeComponent? tube))
{
shell.WriteLine(Loc.GetString("shell-entity-with-uid-lacks-component",
("uid", id),
@@ -52,7 +52,7 @@ namespace Content.Server.Disposal
return;
}
tube.PopupDirections(player.AttachedEntity);
tube.PopupDirections(player.AttachedEntity.Value);
}
}
}

View File

@@ -108,12 +108,12 @@ namespace Content.Server.Disposal.Unit.Components
public void OnUiReceiveMessage(ServerBoundUserInterfaceMessage obj)
{
if (obj.Session.AttachedEntity == null)
if (obj.Session.AttachedEntity is not {Valid: true} player)
{
return;
}
if (!PlayerCanUse(obj.Session.AttachedEntity))
if (!PlayerCanUse(player))
{
return;
}

View File

@@ -116,7 +116,7 @@ namespace Content.Server.Disposal.Unit.EntitySystems
private void DoInsertDisposalUnit(DoInsertDisposalUnitEvent ev)
{
var toInsert = ev.ToInsert
var toInsert = ev.ToInsert;
if (!EntityManager.TryGetComponent(ev.Unit, out DisposalUnitComponent? unit))
{

View File

@@ -392,17 +392,17 @@ namespace Content.Server.Electrocution
visited.Add(entity);
if (EntityManager.TryGetComponent(entity, out SharedPullableComponent? pullable)
&& pullable.Puller != default
&& !visited.Contains(pullable.Puller))
&& pullable.Puller is {Valid: true} pullerId
&& !visited.Contains(pullerId))
{
GetChainedElectrocutionTargetsRecurse(pullable.Puller, depth + 1, visited, all);
GetChainedElectrocutionTargetsRecurse(pullerId, depth + 1, visited, all);
}
if (EntityManager.TryGetComponent(entity, out SharedPullerComponent? puller)
&& puller.Pulling != default
&& !visited.Contains(puller.Pulling))
&& puller.Pulling is {Valid: true} pullingId
&& !visited.Contains(pullingId))
{
GetChainedElectrocutionTargetsRecurse(puller.Pulling, depth + 1, visited, all);
GetChainedElectrocutionTargetsRecurse(pullingId, depth + 1, visited, all);
}
}

View File

@@ -49,7 +49,7 @@ namespace Content.Server.EntityList
foreach (var entity in prototype.Entities(prototypeManager))
{
entityManager.SpawnEntity(entity.ID, IoCManager.Resolve<IEntityManager>().GetComponent<TransformComponent>(player.AttachedEntity).Coordinates);
entityManager.SpawnEntity(entity.ID, entityManager.GetComponent<TransformComponent>(player.AttachedEntity.Value).Coordinates);
i++;
}

View File

@@ -32,10 +32,9 @@ namespace Content.Server.Examine
{
var player = (IPlayerSession) eventArgs.SenderSession;
var session = eventArgs.SenderSession;
var playerEnt = session.AttachedEntity;
var channel = player.ConnectedClient;
if (playerEnt == default
if (session.AttachedEntity is not {Valid: true} playerEnt
|| !EntityManager.EntityExists(request.EntityUid)
|| !CanExamine(playerEnt, request.EntityUid))
{

View File

@@ -81,12 +81,13 @@ namespace Content.Server.Explosion.EntitySystems
foreach (var player in players)
{
if (!player.AttachedEntity.Valid || !EntityManager.TryGetComponent(player.AttachedEntity, out CameraRecoilComponent? recoil))
if (player.AttachedEntity is not {Valid: true} playerEntity ||
!EntityManager.TryGetComponent(playerEntity, out CameraRecoilComponent? recoil))
{
continue;
}
var playerPos = EntityManager.GetComponent<TransformComponent>(player.AttachedEntity).WorldPosition;
var playerPos = EntityManager.GetComponent<TransformComponent>(playerEntity).WorldPosition;
var delta = epicenter.ToMapPos(EntityManager) - playerPos;
//Change if zero. Will result in a NaN later breaking camera shake if not changed

View File

@@ -48,7 +48,7 @@ namespace Content.Server.Flash
}
args.Handled = true;
foreach (EntityUide in args.HitEntities)
foreach (var e in args.HitEntities)
{
Flash(e, args.User, uid, comp.FlashDuration, comp.SlowTo);
}
@@ -135,15 +135,11 @@ namespace Content.Server.Flash
if (displayPopup && user != null && target != user)
{
// TODO Resolving the EntityUidhere bad.
if(EntityManager.EntityExists(user.Value)
&& EntityManager.EntityExists(target)
userEntity.PopupMessage(targetEntity,
Loc.GetString(
"flash-component-user-blinds-you",
("user", userEntity)
)
);
if (EntityManager.EntityExists(user.Value) && EntityManager.EntityExists(target))
{
user.Value.PopupMessage(target, Loc.GetString("flash-component-user-blinds-you",
("user", user.Value)));
}
}
}

View File

@@ -23,6 +23,8 @@ namespace Content.Server.Fluids.Components
[RegisterComponent]
public class MopComponent : Component, IAfterInteract
{
[Dependency] private readonly IEntityManager _entities = default!;
public override string Name => "Mop";
public const string SolutionName = "mop";
@@ -101,7 +103,7 @@ namespace Content.Server.Fluids.Components
return false;
}
if (eventArgs.Target == null)
if (eventArgs.Target is not {Valid: true} target)
{
// Drop the liquid on the mop on to the ground
solutionSystem.SplitSolution(Owner, contents, FixedPoint2.Min(ResidueAmount, CurrentVolume))
@@ -109,13 +111,13 @@ namespace Content.Server.Fluids.Components
return true;
}
if (!IoCManager.Resolve<IEntityManager>().TryGetComponent(eventArgs.Target, out PuddleComponent? puddleComponent) ||
if (!_entities.TryGetComponent(target, out PuddleComponent? puddleComponent) ||
!solutionSystem.TryGetSolution(((IComponent) puddleComponent).Owner, puddleComponent.SolutionName, out var puddleSolution))
return false;
// So if the puddle has 20 units we mop in 2 seconds. Don't just store CurrentVolume given it can change so need to re-calc it anyway.
var doAfterArgs = new DoAfterEventArgs(eventArgs.User, _mopSpeed * puddleSolution.CurrentVolume.Float() / 10.0f,
target: eventArgs.Target)
target: target)
{
BreakOnUserMove = true,
BreakOnStun = true,
@@ -152,7 +154,7 @@ namespace Content.Server.Fluids.Components
else
{
// remove solution from the puddle
solutionSystem.SplitSolution(eventArgs.Target, puddleSolution, transferAmount);
solutionSystem.SplitSolution(target, puddleSolution, transferAmount);
// and from the mop
solutionSystem.SplitSolution(Owner, contents, transferAmount);

View File

@@ -18,6 +18,8 @@ namespace Content.Server.GameTicking.Commands
[AdminCommand(AdminFlags.Server | AdminFlags.Mapping)]
class MappingCommand : IConsoleCommand
{
[Dependency] private readonly IEntityManager _entities = default!;
public string Command => "mapping";
public string Description => "Creates and teleports you to a new uninitialized map for mapping.";
public string Help => $"Usage: {Command} <mapname> / {Command} <id> <mapname>";
@@ -76,9 +78,11 @@ namespace Content.Server.GameTicking.Commands
shell.ExecuteCommand($"addmap {mapId} false");
shell.ExecuteCommand($"loadbp {mapId} \"{CommandParsing.Escape(mapName)}\" true");
EntityUid tempQualifier = player.AttachedEntity;
if ((tempQualifier != null ? IoCManager.Resolve<IEntityManager>().GetComponent<MetaDataComponent>(tempQualifier).EntityPrototype : null)?.ID != "AdminObserver")
if (player.AttachedEntity is {Valid: true} playerEntity &&
_entities.GetComponent<MetaDataComponent>(playerEntity).EntityPrototype?.ID != "AdminObserver")
{
shell.ExecuteCommand("aghost");
}
shell.ExecuteCommand($"tp 0 0 {mapId}");
shell.RemoteExecuteCommand("showmarkers");

View File

@@ -278,7 +278,7 @@ namespace Content.Server.GameTicking
if (mind.CharacterName != null)
playerIcName = mind.CharacterName;
else if (mind.CurrentEntity != null)
playerIcName = IoCManager.Resolve<IEntityManager>().GetComponent<MetaDataComponent>(mind.CurrentEntity).EntityName;
playerIcName = IoCManager.Resolve<IEntityManager>().GetComponent<MetaDataComponent>(mind.CurrentEntity.Value).EntityName;
var playerEndRoundInfo = new RoundEndMessageEvent.RoundEndPlayerInfo()
{

View File

@@ -19,6 +19,8 @@ namespace Content.Server.GameTicking.Presets
/// </summary>
public abstract class GamePreset
{
[Dependency] private readonly IEntityManager _entities = default!;
public abstract bool Start(IReadOnlyList<IPlayerSession> readyPlayers, bool force = false);
public virtual string ModeTitle => "Sandbox";
public virtual string Description => "Secret!";
@@ -39,7 +41,7 @@ namespace Content.Server.GameTicking.Presets
{
var playerEntity = mind.OwnedEntity;
if (playerEntity != default && IoCManager.Resolve<IEntityManager>().HasComponent<GhostComponent>(playerEntity))
if (playerEntity != default && IoCManager.Resolve<IEntityManager>().HasComponent<GhostComponent>(playerEntity.Value))
return false;
if (mind.VisitingEntity != default)
@@ -47,7 +49,9 @@ namespace Content.Server.GameTicking.Presets
mind.UnVisit();
}
var position = (playerEntity != null ? IoCManager.Resolve<IEntityManager>().GetComponent<TransformComponent>(playerEntity) : null).Coordinates ?? EntitySystem.Get<GameTicker>().GetObserverSpawnPoint();
var position = playerEntity is {Valid: true}
? _entities.GetComponent<TransformComponent>(playerEntity.Value).Coordinates
: EntitySystem.Get<GameTicker>().GetObserverSpawnPoint();
// Ok, so, this is the master place for the logic for if ghosting is "too cheaty" to allow returning.
// There's no reason at this time to move it to any other place, especially given that the 'side effects required' situations would also have to be moved.
// + If CharacterDeadPhysically applies, we're physically dead. Therefore, ghosting OK, and we can return (this is critical for gibbing)
@@ -58,7 +62,7 @@ namespace Content.Server.GameTicking.Presets
// (If the mob survives, that's a bug. Ghosting is kept regardless.)
var canReturn = canReturnGlobal && mind.CharacterDeadPhysically;
if (playerEntity != null && canReturnGlobal && IoCManager.Resolve<IEntityManager>().TryGetComponent(playerEntity, out MobStateComponent? mobState))
if (playerEntity != default && canReturnGlobal && IoCManager.Resolve<IEntityManager>().TryGetComponent(playerEntity.Value, out MobStateComponent? mobState))
{
if (mobState.IsCritical())
{
@@ -67,7 +71,7 @@ namespace Content.Server.GameTicking.Presets
//todo: what if they dont breathe lol
//cry deeply
DamageSpecifier damage = new(IoCManager.Resolve<IPrototypeManager>().Index<DamageTypePrototype>("Asphyxiation"), 200);
EntitySystem.Get<DamageableSystem>().TryChangeDamage(playerEntity, damage, true);
EntitySystem.Get<DamageableSystem>().TryChangeDamage(playerEntity.Value, damage, true);
}
}

View File

@@ -1,16 +1,12 @@
using System.Collections.Generic;
using Content.Server.Chat.Managers;
using Content.Server.GameTicking.Rules;
using Content.Server.Inventory.Components;
using Content.Server.Items;
using Content.Server.Players;
using Content.Server.Suspicion;
using Content.Server.Suspicion.Roles;
using Content.Server.Traitor.Uplink;
using Content.Server.Traitor.Uplink.Account;
using Content.Server.Traitor.Uplink.Components;
using Content.Shared.CCVar;
using Content.Shared.Inventory;
using Content.Shared.Roles;
using Content.Shared.Traitor.Uplink;
using Robust.Server.Player;
@@ -121,7 +117,7 @@ namespace Content.Server.GameTicking.Presets
// try to place uplink
if (!EntityManager.EntitySysManager.GetEntitySystem<UplinkSystem>()
.AddUplink(mind.OwnedEntity, uplinkAccount))
.AddUplink(mind.OwnedEntity!.Value, uplinkAccount))
continue;
}

View File

@@ -3,19 +3,14 @@ using System.Collections.Generic;
using System.Linq;
using Content.Server.Chat.Managers;
using Content.Server.GameTicking.Rules;
using Content.Server.Inventory.Components;
using Content.Server.Items;
using Content.Server.Objectives.Interfaces;
using Content.Server.PDA;
using Content.Server.Players;
using Content.Server.Roles;
using Content.Server.Traitor;
using Content.Server.Traitor.Uplink;
using Content.Server.Traitor.Uplink.Account;
using Content.Server.Traitor.Uplink.Components;
using Content.Shared.CCVar;
using Content.Shared.Dataset;
using Content.Shared.Inventory;
using Content.Shared.Traitor.Uplink;
using Robust.Server.Player;
using Robust.Shared.Configuration;
@@ -131,7 +126,7 @@ namespace Content.Server.GameTicking.Presets
accounts.AddNewAccount(uplinkAccount);
if (!EntityManager.EntitySysManager.GetEntitySystem<UplinkSystem>()
.AddUplink(mind.OwnedEntity, uplinkAccount))
.AddUplink(mind.OwnedEntity!.Value, uplinkAccount))
continue;
var traitorRole = new TraitorRole(mind);

View File

@@ -80,50 +80,50 @@ namespace Content.Server.GameTicking.Presets
// Delete anything that may contain "dangerous" role-specific items.
// (This includes the PDA, as everybody gets the captain PDA in this mode for true-all-access reasons.)
if (mind.OwnedEntity != null && IoCManager.Resolve<IEntityManager>().TryGetComponent(mind.OwnedEntity, out InventoryComponent? inventory))
if (mind.OwnedEntity is {Valid: true} owned && _entityManager.TryGetComponent(owned, out InventoryComponent? inventory))
{
var victimSlots = new[] {EquipmentSlotDefines.Slots.IDCARD, EquipmentSlotDefines.Slots.BELT, EquipmentSlotDefines.Slots.BACKPACK};
foreach (var slot in victimSlots)
{
if (inventory.TryGetSlotItem(slot, out ItemComponent? vItem))
IoCManager.Resolve<IEntityManager>().DeleteEntity(vItem.Owner);
_entityManager.DeleteEntity(vItem.Owner);
}
// Replace their items:
// pda
var newPDA = _entityManager.SpawnEntity(PDAPrototypeName, IoCManager.Resolve<IEntityManager>().GetComponent<TransformComponent>(mind.OwnedEntity).Coordinates);
inventory.Equip(EquipmentSlotDefines.Slots.IDCARD, IoCManager.Resolve<IEntityManager>().GetComponent<ItemComponent>(newPDA));
var newPDA = _entityManager.SpawnEntity(PDAPrototypeName, _entityManager.GetComponent<TransformComponent>(owned).Coordinates);
inventory.Equip(EquipmentSlotDefines.Slots.IDCARD, _entityManager.GetComponent<ItemComponent>(newPDA));
// belt
var newTmp = _entityManager.SpawnEntity(BeltPrototypeName, IoCManager.Resolve<IEntityManager>().GetComponent<TransformComponent>(mind.OwnedEntity).Coordinates);
inventory.Equip(EquipmentSlotDefines.Slots.BELT, IoCManager.Resolve<IEntityManager>().GetComponent<ItemComponent>(newTmp));
var newTmp = _entityManager.SpawnEntity(BeltPrototypeName, _entityManager.GetComponent<TransformComponent>(owned).Coordinates);
inventory.Equip(EquipmentSlotDefines.Slots.BELT, _entityManager.GetComponent<ItemComponent>(newTmp));
// backpack
newTmp = _entityManager.SpawnEntity(BackpackPrototypeName, IoCManager.Resolve<IEntityManager>().GetComponent<TransformComponent>(mind.OwnedEntity).Coordinates);
inventory.Equip(EquipmentSlotDefines.Slots.BACKPACK, IoCManager.Resolve<IEntityManager>().GetComponent<ItemComponent>(newTmp));
newTmp = _entityManager.SpawnEntity(BackpackPrototypeName, _entityManager.GetComponent<TransformComponent>(owned).Coordinates);
inventory.Equip(EquipmentSlotDefines.Slots.BACKPACK, _entityManager.GetComponent<ItemComponent>(newTmp));
// Like normal traitors, they need access to a traitor account.
var uplinkAccount = new UplinkAccount(startingBalance, mind.OwnedEntity);
var uplinkAccount = new UplinkAccount(startingBalance, owned);
var accounts = _entityManager.EntitySysManager.GetEntitySystem<UplinkAccountsSystem>();
accounts.AddNewAccount(uplinkAccount);
_entityManager.EntitySysManager.GetEntitySystem<UplinkSystem>()
.AddUplink(mind.OwnedEntity, uplinkAccount, newPDA);
.AddUplink(owned, uplinkAccount, newPDA);
_allOriginalNames[uplinkAccount] = IoCManager.Resolve<IEntityManager>().GetComponent<MetaDataComponent>(mind.OwnedEntity).EntityName;
_allOriginalNames[uplinkAccount] = _entityManager.GetComponent<MetaDataComponent>(owned).EntityName;
// The PDA needs to be marked with the correct owner.
var pda = IoCManager.Resolve<IEntityManager>().GetComponent<PDAComponent>(newPDA);
var pda = _entityManager.GetComponent<PDAComponent>(newPDA);
_entityManager.EntitySysManager.GetEntitySystem<PDASystem>()
.SetOwner(pda, IoCManager.Resolve<IEntityManager>().GetComponent<MetaDataComponent>(mind.OwnedEntity).EntityName);
IoCManager.Resolve<IEntityManager>().AddComponent<TraitorDeathMatchReliableOwnerTagComponent>(newPDA).UserId = mind.UserId;
.SetOwner(pda, _entityManager.GetComponent<MetaDataComponent>(owned).EntityName);
_entityManager.AddComponent<TraitorDeathMatchReliableOwnerTagComponent>(newPDA).UserId = mind.UserId;
}
// Finally, it would be preferrable if they spawned as far away from other players as reasonably possible.
if (mind.OwnedEntity != null && FindAnyIsolatedSpawnLocation(mind, out var bestTarget))
if (mind.OwnedEntity != default && FindAnyIsolatedSpawnLocation(mind, out var bestTarget))
{
IoCManager.Resolve<IEntityManager>().GetComponent<TransformComponent>(mind.OwnedEntity).Coordinates = bestTarget;
_entityManager.GetComponent<TransformComponent>(mind.OwnedEntity.Value).Coordinates = bestTarget;
}
else
{
@@ -151,7 +151,7 @@ namespace Content.Server.GameTicking.Presets
var avoidMeEntity = avoidMeMind.OwnedEntity;
if (avoidMeEntity == null)
continue;
if (IoCManager.Resolve<IEntityManager>().TryGetComponent(avoidMeEntity, out MobStateComponent? mobState))
if (_entityManager.TryGetComponent(avoidMeEntity.Value, out MobStateComponent? mobState))
{
// Does have mob state component; if critical or dead, they don't really matter for spawn checks
if (mobState.IsCritical() || mobState.IsDead())
@@ -162,7 +162,7 @@ namespace Content.Server.GameTicking.Presets
// Doesn't have mob state component. Assume something interesting is going on and don't count this as someone to avoid.
continue;
}
existingPlayerPoints.Add(IoCManager.Resolve<IEntityManager>().GetComponent<TransformComponent>(avoidMeEntity).Coordinates);
existingPlayerPoints.Add(_entityManager.GetComponent<TransformComponent>(avoidMeEntity.Value).Coordinates);
}
// Iterate over each possible spawn point, comparing to the existing player points.
@@ -176,18 +176,18 @@ namespace Content.Server.GameTicking.Presets
var atmosphereSystem = EntitySystem.Get<AtmosphereSystem>();
foreach (var entity in ents)
{
if (!atmosphereSystem.IsTileMixtureProbablySafe(IoCManager.Resolve<IEntityManager>().GetComponent<TransformComponent>(entity).Coordinates))
if (!atmosphereSystem.IsTileMixtureProbablySafe(_entityManager.GetComponent<TransformComponent>(entity).Coordinates))
continue;
var distanceFromNearest = float.PositiveInfinity;
foreach (var existing in existingPlayerPoints)
{
if (IoCManager.Resolve<IEntityManager>().GetComponent<TransformComponent>(entity).Coordinates.TryDistance(_entityManager, existing, out var dist))
if (_entityManager.GetComponent<TransformComponent>(entity).Coordinates.TryDistance(_entityManager, existing, out var dist))
distanceFromNearest = Math.Min(distanceFromNearest, dist);
}
if (bestTargetDistanceFromNearest < distanceFromNearest)
{
bestTarget = IoCManager.Resolve<IEntityManager>().GetComponent<TransformComponent>(entity).Coordinates;
bestTarget = _entityManager.GetComponent<TransformComponent>(entity).Coordinates;
bestTargetDistanceFromNearest = distanceFromNearest;
foundATarget = true;
}
@@ -197,8 +197,7 @@ namespace Content.Server.GameTicking.Presets
public override bool OnGhostAttempt(Mind.Mind mind, bool canReturnGlobal)
{
var entity = mind.OwnedEntity;
if ((entity != null) && IoCManager.Resolve<IEntityManager>().TryGetComponent(entity, out MobStateComponent? mobState))
if (mind.OwnedEntity is {Valid: true} entity && _entityManager.TryGetComponent(entity, out MobStateComponent? mobState))
{
if (mobState.IsCritical())
{
@@ -208,7 +207,7 @@ namespace Content.Server.GameTicking.Presets
}
else if (!mobState.IsDead())
{
if (IoCManager.Resolve<IEntityManager>().HasComponent<HandsComponent>(entity))
if (_entityManager.HasComponent<HandsComponent>(entity))
{
return false;
}

View File

@@ -1,6 +1,4 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading;
using Content.Server.Chat.Managers;
using Content.Shared.CCVar;
@@ -62,9 +60,8 @@ namespace Content.Server.GameTicking.Rules
IPlayerSession? winner = null;
foreach (var playerSession in _playerManager.ServerSessions)
{
var playerEntity = playerSession.AttachedEntity;
if (playerEntity == null
|| !IoCManager.Resolve<IEntityManager>().TryGetComponent(playerEntity, out MobStateComponent? state))
if (playerSession.AttachedEntity is not {Valid: true} playerEntity
|| !_entityManager.TryGetComponent(playerEntity, out MobStateComponent? state))
{
continue;
}

View File

@@ -1,6 +1,4 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading;
using Content.Server.Chat.Managers;
using Content.Server.Doors;
@@ -35,6 +33,7 @@ namespace Content.Server.GameTicking.Rules
[Dependency] private readonly IChatManager _chatManager = default!;
[Dependency] private readonly IConfigurationManager _cfg = default!;
[Dependency] private readonly IGameTiming _timing = default!;
[Dependency] private readonly IEntityManager _entities = default!;
[DataField("addedSound")] private SoundSpecifier _addedSound = new SoundPathSpecifier("/Audio/Misc/tatoralert.ogg");
@@ -90,9 +89,9 @@ namespace Content.Server.GameTicking.Rules
foreach (var playerSession in _playerManager.ServerSessions)
{
if (playerSession.AttachedEntity == null
|| !IoCManager.Resolve<IEntityManager>().TryGetComponent(playerSession.AttachedEntity, out MobStateComponent? mobState)
|| !IoCManager.Resolve<IEntityManager>().HasComponent<SuspicionRoleComponent>(playerSession.AttachedEntity))
if (playerSession.AttachedEntity is not {Valid: true} playerEntity
|| !_entities.TryGetComponent(playerEntity, out MobStateComponent? mobState)
|| !_entities.HasComponent<SuspicionRoleComponent>(playerEntity))
{
continue;
}

View File

@@ -64,7 +64,7 @@ namespace Content.Server.Ghost
visibility.Layer |= (int) VisibilityFlags.Ghost;
visibility.Layer &= ~(int) VisibilityFlags.Normal;
if (IoCManager.Resolve<IEntityManager>().TryGetComponent(component.Owner, out EyeComponent? eye))
if (EntityManager.TryGetComponent(component.Owner, out EyeComponent? eye))
{
eye.VisibilityMask |= (uint) VisibilityFlags.Ghost;
}
@@ -75,17 +75,17 @@ namespace Content.Server.Ghost
private void OnGhostShutdown(EntityUid uid, GhostComponent component, ComponentShutdown args)
{
// Perf: If the entity is deleting itself, no reason to change these back.
if ((!IoCManager.Resolve<IEntityManager>().EntityExists(component.Owner) ? EntityLifeStage.Deleted : IoCManager.Resolve<IEntityManager>().GetComponent<MetaDataComponent>(component.Owner).EntityLifeStage) < EntityLifeStage.Terminating)
if ((!EntityManager.EntityExists(component.Owner) ? EntityLifeStage.Deleted : EntityManager.GetComponent<MetaDataComponent>(component.Owner).EntityLifeStage) < EntityLifeStage.Terminating)
{
// Entity can't be seen by ghosts anymore.
if (IoCManager.Resolve<IEntityManager>().TryGetComponent(component.Owner, out VisibilityComponent? visibility))
if (EntityManager.TryGetComponent(component.Owner, out VisibilityComponent? visibility))
{
visibility.Layer &= ~(int) VisibilityFlags.Ghost;
visibility.Layer |= (int) VisibilityFlags.Normal;
}
// Entity can't see ghosts anymore.
if (IoCManager.Resolve<IEntityManager>().TryGetComponent(component.Owner, out EyeComponent? eye))
if (EntityManager.TryGetComponent(component.Owner, out EyeComponent? eye))
{
eye.VisibilityMask &= ~(uint) VisibilityFlags.Ghost;
}
@@ -114,10 +114,8 @@ namespace Content.Server.Ghost
private void OnGhostWarpsRequest(GhostWarpsRequestEvent msg, EntitySessionEventArgs args)
{
var entity = args.SenderSession.AttachedEntity;
if (entity == null ||
!IoCManager.Resolve<IEntityManager>().HasComponent<GhostComponent>(entity))
if (args.SenderSession.AttachedEntity is not {Valid: true} entity ||
!EntityManager.HasComponent<GhostComponent>(entity))
{
Logger.Warning($"User {args.SenderSession.Name} sent a {nameof(GhostWarpsRequestEvent)} without being a ghost.");
return;
@@ -129,12 +127,10 @@ namespace Content.Server.Ghost
private void OnGhostReturnToBodyRequest(GhostReturnToBodyRequest msg, EntitySessionEventArgs args)
{
var entity = args.SenderSession.AttachedEntity;
if (entity == null ||
!IoCManager.Resolve<IEntityManager>().TryGetComponent(entity, out GhostComponent? ghost) ||
if (args.SenderSession.AttachedEntity is not {Valid: true} attached ||
!EntityManager.TryGetComponent(attached, out GhostComponent? ghost) ||
!ghost.CanReturnToBody ||
!IoCManager.Resolve<IEntityManager>().TryGetComponent(entity, out ActorComponent? actor))
!EntityManager.TryGetComponent(attached, out ActorComponent? actor))
{
Logger.Warning($"User {args.SenderSession.Name} sent an invalid {nameof(GhostReturnToBodyRequest)}");
return;
@@ -145,8 +141,8 @@ namespace Content.Server.Ghost
private void OnGhostWarpToLocationRequest(GhostWarpToLocationRequestEvent msg, EntitySessionEventArgs args)
{
if (args.SenderSession.AttachedEntity == null ||
!IoCManager.Resolve<IEntityManager>().TryGetComponent(args.SenderSession.AttachedEntity, out GhostComponent? ghost))
if (args.SenderSession.AttachedEntity is not {Valid: true} attached ||
!EntityManager.TryGetComponent(attached, out GhostComponent? ghost))
{
Logger.Warning($"User {args.SenderSession.Name} tried to warp to {msg.Name} without being a ghost.");
return;
@@ -154,7 +150,7 @@ namespace Content.Server.Ghost
if (FindLocation(msg.Name) is { } warp)
{
IoCManager.Resolve<IEntityManager>().GetComponent<TransformComponent>(ghost.Owner).Coordinates = IoCManager.Resolve<IEntityManager>().GetComponent<TransformComponent>(warp.Owner).Coordinates;
EntityManager.GetComponent<TransformComponent>(ghost.Owner).Coordinates = EntityManager.GetComponent<TransformComponent>(warp.Owner).Coordinates;
}
Logger.Warning($"User {args.SenderSession.Name} tried to warp to an invalid warp: {msg.Name}");
@@ -162,32 +158,32 @@ namespace Content.Server.Ghost
private void OnGhostWarpToTargetRequest(GhostWarpToTargetRequestEvent msg, EntitySessionEventArgs args)
{
if (args.SenderSession.AttachedEntity == null ||
!IoCManager.Resolve<IEntityManager>().TryGetComponent(args.SenderSession.AttachedEntity, out GhostComponent? ghost))
if (args.SenderSession.AttachedEntity is not {Valid: true} attached ||
!EntityManager.TryGetComponent(attached, out GhostComponent? ghost))
{
Logger.Warning($"User {args.SenderSession.Name} tried to warp to {msg.Target} without being a ghost.");
return;
}
if (!EntityManager.EntityExists(msg.Target)
if (!EntityManager.EntityExists(msg.Target))
{
Logger.Warning($"User {args.SenderSession.Name} tried to warp to an invalid entity id: {msg.Target}");
return;
}
IoCManager.Resolve<IEntityManager>().GetComponent<TransformComponent>(ghost.Owner).Coordinates = IoCManager.Resolve<IEntityManager>().GetComponent<TransformComponent>(entity).Coordinates;
EntityManager.GetComponent<TransformComponent>(ghost.Owner).Coordinates = EntityManager.GetComponent<TransformComponent>(msg.Target).Coordinates;
}
private void DeleteEntity(EntityUid uid)
{
if (!EntityManager.EntityExists(uid)
|| (!IoCManager.Resolve<IEntityManager>().EntityExists(entity) ? EntityLifeStage.Deleted : IoCManager.Resolve<IEntityManager>().GetComponent<MetaDataComponent>(entity).EntityLifeStage) >= EntityLifeStage.Deleted
|| (!IoCManager.Resolve<IEntityManager>().EntityExists(entity) ? EntityLifeStage.Deleted : IoCManager.Resolve<IEntityManager>().GetComponent<MetaDataComponent>(entity).EntityLifeStage) == EntityLifeStage.Terminating)
|| (!EntityManager.EntityExists(uid) ? EntityLifeStage.Deleted : EntityManager.GetComponent<MetaDataComponent>(uid).EntityLifeStage) >= EntityLifeStage.Deleted
|| (!EntityManager.EntityExists(uid) ? EntityLifeStage.Deleted : EntityManager.GetComponent<MetaDataComponent>(uid).EntityLifeStage) == EntityLifeStage.Terminating)
return;
if (IoCManager.Resolve<IEntityManager>().TryGetComponent<MindComponent?>(entity, out var mind))
if (EntityManager.TryGetComponent<MindComponent?>(uid, out var mind))
mind.GhostOnShutdown = false;
IoCManager.Resolve<IEntityManager>().DeleteEntity((EntityUid) entity);
EntityManager.DeleteEntity(uid);
}
private IEnumerable<string> GetLocationNames()
@@ -220,9 +216,9 @@ namespace Content.Server.Ghost
foreach (var player in _playerManager.Sessions)
{
if (player.AttachedEntity != null)
if (player.AttachedEntity is {Valid: true} attached)
{
players.Add(player.AttachedEntity, IoCManager.Resolve<IEntityManager>().GetComponent<MetaDataComponent>(player.AttachedEntity).EntityName);
players.Add(attached, EntityManager.GetComponent<MetaDataComponent>(attached).EntityName);
}
}

View File

@@ -6,17 +6,17 @@ using Content.Server.Ghost.Roles.Components;
using Content.Server.Ghost.Roles.UI;
using Content.Server.Players;
using Content.Shared.GameTicking;
using Content.Shared.Ghost.Roles;
using Content.Shared.Ghost;
using Content.Shared.Ghost.Roles;
using JetBrains.Annotations;
using Robust.Server.GameObjects;
using Robust.Server.Player;
using Robust.Shared.Console;
using Robust.Shared.Enums;
using Robust.Shared.GameObjects;
using Robust.Shared.IoC;
using Robust.Shared.ViewVariables;
using Robust.Shared.Utility;
using Robust.Shared.Enums;
using Robust.Shared.ViewVariables;
namespace Content.Server.Ghost.Roles
{
@@ -59,7 +59,8 @@ namespace Content.Server.Ghost.Roles
public void OpenEui(IPlayerSession session)
{
if (session.AttachedEntity == null || !IoCManager.Resolve<IEntityManager>().HasComponent<GhostComponent>(session.AttachedEntity))
if (session.AttachedEntity is not {Valid: true} attached ||
!EntityManager.HasComponent<GhostComponent>(attached))
return;
if(_openUis.ContainsKey(session))
@@ -194,7 +195,7 @@ namespace Content.Server.Ghost.Roles
{
// Close the session of any player that has a ghost roles window open and isn't a ghost anymore.
if (!_openUis.ContainsKey(message.Player)) return;
if (IoCManager.Resolve<IEntityManager>().HasComponent<GhostComponent>(message.Entity)) return;
if (EntityManager.HasComponent<GhostComponent>(message.Entity)) return;
CloseEui(message.Player);
}

View File

@@ -79,9 +79,9 @@ namespace Content.Server.Gravity.EntitySystems
{
foreach (var player in _playerManager.Sessions)
{
if (player.AttachedEntity == null
|| IoCManager.Resolve<IEntityManager>().GetComponent<TransformComponent>(player.AttachedEntity).GridID != gridId
|| !IoCManager.Resolve<IEntityManager>().TryGetComponent(player.AttachedEntity, out CameraRecoilComponent? recoil))
if (player.AttachedEntity is not {Valid: true} attached
|| EntityManager.GetComponent<TransformComponent>(attached).GridID != gridId
|| !EntityManager.TryGetComponent(attached, out CameraRecoilComponent? recoil))
{
continue;
}

View File

@@ -34,15 +34,14 @@ namespace Content.Server.Gravity.EntitySystems
public void AddAlert(ServerAlertsComponent status)
{
var gridId = IoCManager.Resolve<IEntityManager>().GetComponent<TransformComponent>(status.Owner).GridID;
var gridId = EntityManager.GetComponent<TransformComponent>(status.Owner).GridID;
var alerts = _alerts.GetOrNew(gridId);
alerts.Add(status);
if (_mapManager.TryGetGrid(IoCManager.Resolve<IEntityManager>().GetComponent<TransformComponent>(status.Owner).GridID, out var grid))
if (_mapManager.TryGetGrid(EntityManager.GetComponent<TransformComponent>(status.Owner).GridID, out var grid))
{
var gridgrid.GridEntityId
if (IoCManager.Resolve<IEntityManager>().GetComponent<GravityComponent>(gridEntity).Enabled)
if (EntityManager.GetComponent<GravityComponent>(grid.GridEntityId).Enabled)
{
RemoveWeightless(status);
}
@@ -55,7 +54,7 @@ namespace Content.Server.Gravity.EntitySystems
public void RemoveAlert(ServerAlertsComponent status)
{
var grid = IoCManager.Resolve<IEntityManager>().GetComponent<TransformComponent>(status.Owner).GridID;
var grid = EntityManager.GetComponent<TransformComponent>(status.Owner).GridID;
if (!_alerts.TryGetValue(grid, out var statuses))
{
return;
@@ -99,13 +98,13 @@ namespace Content.Server.Gravity.EntitySystems
private void EntParentChanged(ref EntParentChangedMessage ev)
{
if (!IoCManager.Resolve<IEntityManager>().TryGetComponent(ev.Entity, out ServerAlertsComponent? status))
if (!EntityManager.TryGetComponent(ev.Entity, out ServerAlertsComponent? status))
{
return;
}
if (ev.OldParent != null &&
IoCManager.Resolve<IEntityManager>().TryGetComponent(ev.OldParent, out IMapGridComponent? mapGrid))
if (ev.OldParent is {Valid: true} old &&
EntityManager.TryGetComponent(old, out IMapGridComponent? mapGrid))
{
var oldGrid = mapGrid.GridIndex;
@@ -115,7 +114,7 @@ namespace Content.Server.Gravity.EntitySystems
}
}
var newGrid = IoCManager.Resolve<IEntityManager>().GetComponent<TransformComponent>(ev.Entity).GridID;
var newGrid = EntityManager.GetComponent<TransformComponent>(ev.Entity).GridID;
var newStatuses = _alerts.GetOrNew(newGrid);
newStatuses.Add(status);

View File

@@ -31,6 +31,7 @@ namespace Content.Server.Hands.Components
#pragma warning restore 618
{
[Dependency] private readonly IEntitySystemManager _entitySystemManager = default!;
[Dependency] private readonly IEntityManager _entities = default!;
[DataField("disarmedSound")] SoundSpecifier _disarmedSound = new SoundPathSpecifier("/Audio/Effects/thudswoosh.ogg");
@@ -38,27 +39,27 @@ namespace Content.Server.Hands.Components
protected override void OnHeldEntityRemovedFromHand(EntityUid heldEntity, HandState handState)
{
if (IoCManager.Resolve<IEntityManager>().TryGetComponent(heldEntity, out ItemComponent? item))
if (_entities.TryGetComponent(heldEntity, out ItemComponent? item))
{
item.RemovedFromSlot();
_entitySystemManager.GetEntitySystem<InteractionSystem>().UnequippedHandInteraction(Owner, heldEntity, handState);
}
if (IoCManager.Resolve<IEntityManager>().TryGetComponent(heldEntity, out SpriteComponent? sprite))
if (_entities.TryGetComponent(heldEntity, out SpriteComponent? sprite))
{
sprite.RenderOrder = IoCManager.Resolve<IEntityManager>().CurrentTick.Value;
sprite.RenderOrder = _entities.CurrentTick.Value;
}
}
protected override void HandlePickupAnimation(EntityUid entity)
{
var initialPosition = EntityCoordinates.FromMap(IoCManager.Resolve<IEntityManager>().GetComponent<TransformComponent>(Owner).Parent?.Owner ?? Owner, IoCManager.Resolve<IEntityManager>().GetComponent<TransformComponent>(entity).MapPosition);
var initialPosition = EntityCoordinates.FromMap(_entities.GetComponent<TransformComponent>(Owner).Parent?.Owner ?? Owner, _entities.GetComponent<TransformComponent>(entity).MapPosition);
var finalPosition = IoCManager.Resolve<IEntityManager>().GetComponent<TransformComponent>(Owner).LocalPosition;
var finalPosition = _entities.GetComponent<TransformComponent>(Owner).LocalPosition;
if (finalPosition.EqualsApprox(initialPosition.Position))
return;
IoCManager.Resolve<IEntityManager>().EntityNetManager!.SendSystemNetworkMessage(
_entities.EntityNetManager!.SendSystemNetworkMessage(
new PickupAnimationMessage(entity, finalPosition, initialPosition));
}
@@ -106,13 +107,13 @@ namespace Content.Server.Hands.Components
{
if (ActiveHand != null && Drop(ActiveHand, false))
{
source.PopupMessageOtherClients(Loc.GetString("hands-component-disarm-success-others-message", ("disarmer", Name: IoCManager.Resolve<IEntityManager>().GetComponent<MetaDataComponent>(source).EntityName), ("disarmed", Name: IoCManager.Resolve<IEntityManager>().GetComponent<MetaDataComponent>(target).EntityName)));
source.PopupMessageCursor(Loc.GetString("hands-component-disarm-success-message", ("disarmed", Name: IoCManager.Resolve<IEntityManager>().GetComponent<MetaDataComponent>(target).EntityName)));
source.PopupMessageOtherClients(Loc.GetString("hands-component-disarm-success-others-message", ("disarmer", Name: _entities.GetComponent<MetaDataComponent>(source).EntityName), ("disarmed", Name: _entities.GetComponent<MetaDataComponent>(target).EntityName)));
source.PopupMessageCursor(Loc.GetString("hands-component-disarm-success-message", ("disarmed", Name: _entities.GetComponent<MetaDataComponent>(target).EntityName)));
}
else
{
source.PopupMessageOtherClients(Loc.GetString("hands-component-shove-success-others-message", ("shover", Name: IoCManager.Resolve<IEntityManager>().GetComponent<MetaDataComponent>(source).EntityName), ("shoved", Name: IoCManager.Resolve<IEntityManager>().GetComponent<MetaDataComponent>(target).EntityName)));
source.PopupMessageCursor(Loc.GetString("hands-component-shove-success-message", ("shoved", Name: IoCManager.Resolve<IEntityManager>().GetComponent<MetaDataComponent>(target).EntityName)));
source.PopupMessageOtherClients(Loc.GetString("hands-component-shove-success-others-message", ("shover", Name: _entities.GetComponent<MetaDataComponent>(source).EntityName), ("shoved", Name: _entities.GetComponent<MetaDataComponent>(target).EntityName)));
source.PopupMessageCursor(Loc.GetString("hands-component-shove-success-message", ("shoved", Name: _entities.GetComponent<MetaDataComponent>(target).EntityName)));
}
}
}
@@ -123,8 +124,8 @@ namespace Content.Server.Hands.Components
private bool BreakPulls()
{
// What is this API??
if (!IoCManager.Resolve<IEntityManager>().TryGetComponent(Owner, out SharedPullerComponent? puller)
|| puller.Pulling == null || !IoCManager.Resolve<IEntityManager>().TryGetComponent(puller.Pulling, out SharedPullableComponent? pullable))
if (!_entities.TryGetComponent(Owner, out SharedPullerComponent? puller)
|| puller.Pulling is not {Valid: true} pulling || !_entities.TryGetComponent(puller.Pulling.Value, out SharedPullableComponent? pullable))
return false;
return _entitySystemManager.GetEntitySystem<PullingSystem>().TryStopPull(pullable);
@@ -163,7 +164,7 @@ namespace Content.Server.Hands.Components
if (!TryGetHeldEntity(handName, out var heldEntity))
return null;
IoCManager.Resolve<IEntityManager>().TryGetComponent(heldEntity, out ItemComponent? item);
_entities.TryGetComponent(heldEntity, out ItemComponent? item);
return item;
}
@@ -177,7 +178,7 @@ namespace Content.Server.Hands.Components
if (!TryGetHeldEntity(handName, out var heldEntity))
return false;
return IoCManager.Resolve<IEntityManager>().TryGetComponent(heldEntity, out item);
return _entities.TryGetComponent(heldEntity, out item);
}
/// <summary>
@@ -190,7 +191,7 @@ namespace Content.Server.Hands.Components
if (!TryGetActiveHeldEntity(out var heldEntity))
return null;
IoCManager.Resolve<IEntityManager>().TryGetComponent(heldEntity, out ItemComponent? item);
_entities.TryGetComponent(heldEntity, out ItemComponent? item);
return item;
}
}
@@ -199,7 +200,7 @@ namespace Content.Server.Hands.Components
{
foreach (var entity in GetAllHeldEntities())
{
if (IoCManager.Resolve<IEntityManager>().TryGetComponent(entity, out ItemComponent? item))
if (_entities.TryGetComponent(entity, out ItemComponent? item))
yield return item;
}
}

View File

@@ -14,8 +14,10 @@ using Content.Shared.Hands;
using Content.Shared.Hands.Components;
using Content.Shared.Input;
using Content.Shared.Physics.Pull;
using Content.Shared.Popups;
using JetBrains.Annotations;
using Robust.Server.Player;
using Robust.Shared.Containers;
using Robust.Shared.GameObjects;
using Robust.Shared.Input.Binding;
using Robust.Shared.IoC;
@@ -187,9 +189,7 @@ namespace Content.Server.Hands.Systems
if (session is not IPlayerSession playerSession)
return false;
var playerEnt = playerSession.AttachedEntity;
if (playerEnt == default || !EntityManager.EntityExists(playerEnt))
if (playerSession.AttachedEntity is not {Valid: true} playerEnt || !EntityManager.EntityExists(playerEnt))
return false;
return EntityManager.TryGetComponent(playerEnt, out hands);
@@ -216,9 +216,7 @@ namespace Content.Server.Hands.Systems
if (session is not IPlayerSession playerSession)
return false;
var playerEnt = playerSession.AttachedEntity;
if (playerEnt == default ||
if (playerSession.AttachedEntity is not {Valid: true} playerEnt ||
!EntityManager.EntityExists(playerEnt) ||
playerEnt.IsInContainer() ||
!EntityManager.TryGetComponent(playerEnt, out SharedHandsComponent? hands) ||
@@ -230,10 +228,10 @@ namespace Content.Server.Hands.Systems
{
var splitStack = _stackSystem.Split(throwEnt, 1, EntityManager.GetComponent<TransformComponent>(playerEnt).Coordinates, stack);
if (!splitStack.Valid)
if (splitStack is not {Valid: true})
return false;
throwEnt = splitStack;
throwEnt = splitStack.Value;
}
else if (!hands.Drop(throwEnt))
return false;
@@ -265,9 +263,7 @@ namespace Content.Server.Hands.Systems
if (session is not IPlayerSession playerSession)
return;
var plyEnt = playerSession.AttachedEntity;
if (plyEnt == default || !EntityManager.EntityExists(plyEnt))
if (playerSession.AttachedEntity is not {Valid: true} plyEnt || !EntityManager.EntityExists(plyEnt))
return;
if (!EntityManager.TryGetComponent(plyEnt, out SharedHandsComponent? hands) ||

View File

@@ -150,13 +150,11 @@ public sealed partial class InstrumentSystem : SharedInstrumentSystem
|| instrument.LaggedBatches >= MaxMidiLaggedBatches)
&& instrument.InstrumentPlayer != null && instrument.RespectMidiLimits)
{
var mob = instrument.InstrumentPlayer.AttachedEntity;
// Just in case
Clean(((IComponent) instrument).Owner);
instrument.UserInterface?.CloseAll();
if (mob != null)
if (instrument.InstrumentPlayer.AttachedEntity is {Valid: true} mob)
{
_stunSystem.TryParalyze(mob, TimeSpan.FromSeconds(1));

View File

@@ -5,7 +5,6 @@ using System.Threading.Tasks;
using Content.Server.Administration.Logs;
using Content.Server.CombatMode;
using Content.Server.Hands.Components;
using Content.Server.Items;
using Content.Server.Pulling;
using Content.Server.Storage.Components;
using Content.Shared.ActionBlocker;
@@ -70,7 +69,7 @@ namespace Content.Server.Interaction
}
#region Client Input Validation
private bool ValidateClientInput(ICommonSession? session, EntityCoordinates coords, EntityUid uid, [NotNullWhen(true)] out EntityUid userEntity)
private bool ValidateClientInput(ICommonSession? session, EntityCoordinates coords, EntityUid uid, [NotNullWhen(true)] out EntityUid? userEntity)
{
userEntity = null;
@@ -89,7 +88,7 @@ namespace Content.Server.Interaction
userEntity = ((IPlayerSession?) session)?.AttachedEntity;
if (userEntity == null || !IoCManager.Resolve<IEntityManager>().EntityExists(userEntity))
if (userEntity == null || !EntityManager.EntityExists(userEntity.Value))
{
Logger.WarningS("system.interaction",
$"Client sent interaction with no attached entity. Session={session}");
@@ -101,10 +100,10 @@ namespace Content.Server.Interaction
public override bool CanAccessViaStorage(EntityUid user, EntityUid target)
{
if (!EntityManager.EntityExists(target)
if (!EntityManager.EntityExists(target))
return false;
if (!entity.TryGetContainer(out var container))
if (!target.TryGetContainer(out var container))
return false;
if (!EntityManager.TryGetComponent(container.Owner, out ServerStorageComponent storage))
@@ -127,7 +126,7 @@ namespace Content.Server.Interaction
/// </summary>
private void HandleInteractInventorySlotEvent(InteractInventorySlotEvent msg, EntitySessionEventArgs args)
{
if (!EntityManager.EntityExists(msg.ItemUid)
if (!EntityManager.EntityExists(msg.ItemUid))
{
Logger.WarningS("system.interaction",
$"Client sent inventory interaction with an invalid target item. Session={args.SenderSession}");
@@ -135,7 +134,7 @@ namespace Content.Server.Interaction
}
// client sanitization
if (!ValidateClientInput(args.SenderSession, IoCManager.Resolve<IEntityManager>().GetComponent<TransformComponent>(item).Coordinates, msg.ItemUid, out var userEntity))
if (!ValidateClientInput(args.SenderSession, EntityManager.GetComponent<TransformComponent>(msg.ItemUid).Coordinates, msg.ItemUid, out var userEntity))
{
Logger.InfoS("system.interaction", $"Inventory interaction validation failed. Session={args.SenderSession}");
return;
@@ -143,10 +142,10 @@ namespace Content.Server.Interaction
if (msg.AltInteract)
// Use 'UserInteraction' function - behaves as if the user alt-clicked the item in the world.
UserInteraction(userEntity, IoCManager.Resolve<IEntityManager>().GetComponent<TransformComponent>(item).Coordinates, msg.ItemUid, msg.AltInteract);
UserInteraction(userEntity.Value, EntityManager.GetComponent<TransformComponent>(msg.ItemUid).Coordinates, msg.ItemUid, msg.AltInteract);
else
// User used 'E'. We want to activate it, not simulate clicking on the item
InteractionActivate(userEntity, item);
InteractionActivate(userEntity.Value, msg.ItemUid);
}
#region Drag drop
@@ -158,15 +157,15 @@ namespace Content.Server.Interaction
return;
}
if (!_actionBlockerSystem.CanInteract(userEntity))
if (!_actionBlockerSystem.CanInteract(userEntity.Value))
return;
if (!EntityManager.EntityExists(msg.Dropped)
if (!EntityManager.EntityExists(msg.Dropped))
return;
if (!EntityManager.EntityExists(msg.Target)
if (!EntityManager.EntityExists(msg.Target))
return;
var interactionArgs = new DragDropEvent(userEntity, msg.DropLocation, dropped, target);
var interactionArgs = new DragDropEvent(userEntity.Value, msg.DropLocation, msg.Dropped, msg.Target);
// must be in range of both the target and the object they are drag / dropping
// Client also does this check but ya know we gotta validate it.
@@ -174,8 +173,8 @@ namespace Content.Server.Interaction
return;
// trigger dragdrops on the dropped entity
RaiseLocalEvent(dropped, interactionArgs);
foreach (var dragDrop in IoCManager.Resolve<IEntityManager>().GetComponents<IDraggable>(dropped))
RaiseLocalEvent(msg.Dropped, interactionArgs);
foreach (var dragDrop in EntityManager.GetComponents<IDraggable>(msg.Dropped))
{
if (dragDrop.CanDrop(interactionArgs) &&
dragDrop.Drop(interactionArgs))
@@ -185,8 +184,8 @@ namespace Content.Server.Interaction
}
// trigger dragdropons on the targeted entity
RaiseLocalEvent(target, interactionArgs, false);
foreach (var dragDropOn in IoCManager.Resolve<IEntityManager>().GetComponents<IDragDropOn>(target))
RaiseLocalEvent(msg.Target, interactionArgs, false);
foreach (var dragDropOn in EntityManager.GetComponents<IDragDropOn>(msg.Target))
{
if (dragDropOn.CanDragDropOn(interactionArgs) &&
dragDropOn.DragDropOn(interactionArgs))
@@ -206,10 +205,10 @@ namespace Content.Server.Interaction
return false;
}
if (!EntityManager.EntityExists(uid)
if (!EntityManager.EntityExists(uid))
return false;
InteractionActivate(user, used);
InteractionActivate(user.Value, uid);
return true;
}
#endregion
@@ -223,8 +222,8 @@ namespace Content.Server.Interaction
return true;
}
if (IoCManager.Resolve<IEntityManager>().TryGetComponent(userEntity, out CombatModeComponent? combatMode) && combatMode.IsInCombatMode)
DoAttack(userEntity, coords, true);
if (EntityManager.TryGetComponent(userEntity.Value, out CombatModeComponent? combatMode) && combatMode.IsInCombatMode)
DoAttack(userEntity.Value, coords, true);
return true;
}
@@ -238,7 +237,7 @@ namespace Content.Server.Interaction
/// <param name="uid"></param>
internal void AiUseInteraction(EntityUid entity, EntityCoordinates coords, EntityUid uid)
{
if (IoCManager.Resolve<IEntityManager>().HasComponent<ActorComponent>(entity))
if (EntityManager.HasComponent<ActorComponent>(entity))
throw new InvalidOperationException();
UserInteraction(entity, coords, uid);
@@ -253,7 +252,7 @@ namespace Content.Server.Interaction
return true;
}
UserInteraction(userEntity, coords, uid);
UserInteraction(userEntity.Value, coords, uid);
return true;
}
@@ -267,7 +266,7 @@ namespace Content.Server.Interaction
return true;
}
UserInteraction(userEntity, coords, uid, altInteract : true );
UserInteraction(userEntity.Value, coords, uid, altInteract : true );
return true;
}
@@ -283,16 +282,16 @@ namespace Content.Server.Interaction
if (userEntity == uid)
return false;
if (!EntityManager.EntityExists(uid)
if (!EntityManager.EntityExists(uid))
return false;
if (!InRangeUnobstructed(userEntity, pulledObject, popup: true))
if (!InRangeUnobstructed(userEntity.Value, uid, popup: true))
return false;
if (!IoCManager.Resolve<IEntityManager>().TryGetComponent(pulledObject, out SharedPullableComponent? pull))
if (!EntityManager.TryGetComponent(uid, out SharedPullableComponent? pull))
return false;
return _pullSystem.TogglePull(userEntity, pull);
return _pullSystem.TogglePull(userEntity.Value, pull);
}
/// <summary>
@@ -304,12 +303,12 @@ namespace Content.Server.Interaction
/// <param name="altInteract">Whether to use default or alternative interactions (usually as a result of
/// alt+clicking). If combat mode is enabled, the alternative action is to perform the default non-combat
/// interaction. Having an item in the active hand also disables alternative interactions.</param>
public async void UserInteraction(EntityUid user, EntityCoordinates coordinates, EntityUid clickedUid, bool altInteract = false)
public async void UserInteraction(EntityUid user, EntityCoordinates coordinates, EntityUid target, bool altInteract = false)
{
// TODO COMBAT Consider using alt-interact for advanced combat? maybe alt-interact disarms?
if (!altInteract && IoCManager.Resolve<IEntityManager>().TryGetComponent(user, out CombatModeComponent? combatMode) && combatMode.IsInCombatMode)
if (!altInteract && EntityManager.TryGetComponent(user, out CombatModeComponent? combatMode) && combatMode.IsInCombatMode)
{
DoAttack(user, coordinates, false, clickedUid);
DoAttack(user, coordinates, false, target);
return;
}
@@ -319,32 +318,29 @@ namespace Content.Server.Interaction
if (!_actionBlockerSystem.CanInteract(user))
return;
// Get entity clicked upon from UID if valid UID, if not assume no entity clicked upon and null
EntityManager.EntityExists(clickedUid);
// Check if interacted entity is in the same container, the direct child, or direct parent of the user.
// This is bypassed IF the interaction happened through an item slot (e.g., backpack UI)
if (target != null && !user.IsInSameOrParentContainer(target) && !CanAccessViaStorage(user, target))
if (target != default && !user.IsInSameOrParentContainer(target) && !CanAccessViaStorage(user, target))
{
Logger.WarningS("system.interaction",
$"User entity named {IoCManager.Resolve<IEntityManager>().GetComponent<MetaDataComponent>(user).EntityName} clicked on object {IoCManager.Resolve<IEntityManager>().GetComponent<MetaDataComponent>(target).EntityName} that isn't the parent, child, or in the same container");
$"User entity named {EntityManager.GetComponent<MetaDataComponent>(user).EntityName} clicked on object {EntityManager.GetComponent<MetaDataComponent>(target).EntityName} that isn't the parent, child, or in the same container");
return;
}
// Verify user has a hand, and find what object they are currently holding in their active hand
if (!IoCManager.Resolve<IEntityManager>().TryGetComponent<HandsComponent?>(user, out var hands))
if (!EntityManager.TryGetComponent<HandsComponent?>(user, out var hands))
return;
var item = hands.GetActiveHand?.Owner;
// TODO: Replace with body interaction range when we get something like arm length or telekinesis or something.
var inRangeUnobstructed = user.InRangeUnobstructed(coordinates, ignoreInsideBlocker: true);
if (target == null || !inRangeUnobstructed)
if (target == default || !inRangeUnobstructed)
{
if (item == null)
return;
if (!await InteractUsingRanged(user, item, target, coordinates, inRangeUnobstructed) &&
if (!await InteractUsingRanged(user, item.Value, target, coordinates, inRangeUnobstructed) &&
!inRangeUnobstructed)
{
var message = Loc.GetString("interaction-system-user-interaction-cannot-reach");
@@ -362,7 +358,7 @@ namespace Content.Server.Interaction
else if (item != null && item != target)
// We are performing a standard interaction with an item, and the target isn't the same as the item
// currently in our hand. We will use the item in our hand on the nearby object via InteractUsing
await InteractUsing(user, item, target, coordinates);
await InteractUsing(user, item.Value, target, coordinates);
else if (item == null)
// Since our hand is empty we will use InteractHand/Activate
InteractHand(user, target);
@@ -372,10 +368,10 @@ namespace Content.Server.Interaction
private bool ValidateInteractAndFace(EntityUid user, EntityCoordinates coordinates)
{
// Verify user is on the same map as the entity they clicked on
if (coordinates.GetMapId(_entityManager) != IoCManager.Resolve<IEntityManager>().GetComponent<TransformComponent>(user).MapID)
if (coordinates.GetMapId(_entityManager) != EntityManager.GetComponent<TransformComponent>(user).MapID)
{
Logger.WarningS("system.interaction",
$"User entity named {IoCManager.Resolve<IEntityManager>().GetComponent<MetaDataComponent>(user).EntityName} clicked on a map they aren't located on");
$"User entity named {EntityManager.GetComponent<MetaDataComponent>(user).EntityName} clicked on a map they aren't located on");
return false;
}
@@ -403,7 +399,7 @@ namespace Content.Server.Interaction
var interactHandEventArgs = new InteractHandEventArgs(user, target);
var interactHandComps = IoCManager.Resolve<IEntityManager>().GetComponents<IInteractHand>(target).ToList();
var interactHandComps = EntityManager.GetComponents<IInteractHand>(target).ToList();
foreach (var interactHandComp in interactHandComps)
{
// If an InteractHand returns a status completion we finish our interaction
@@ -433,7 +429,7 @@ namespace Content.Server.Interaction
if (rangedMsg.Handled)
return true;
var rangedInteractions = IoCManager.Resolve<IEntityManager>().GetComponents<IRangedInteract>(target).ToList();
var rangedInteractions = EntityManager.GetComponents<IRangedInteract>(target).ToList();
var rangedInteractionEventArgs = new RangedInteractEventArgs(user, used, clickLocation);
// See if we have a ranged interaction
@@ -458,18 +454,13 @@ namespace Content.Server.Interaction
if (!_actionBlockerSystem.CanAttack(user))
return;
EntityUid targetEnt = null;
if (!wideAttack)
{
// Get entity clicked upon from UID if valid UID, if not assume no entity clicked upon and null
EntityManager.EntityExists(targetUid);
// Check if interacted entity is in the same container, the direct child, or direct parent of the user.
if (targetEnt != null && !user.IsInSameOrParentContainer(targetEnt) && !CanAccessViaStorage(user, targetEnt))
if (targetUid != default && !user.IsInSameOrParentContainer(targetUid) && !CanAccessViaStorage(user, targetUid))
{
Logger.WarningS("system.interaction",
$"User entity named {IoCManager.Resolve<IEntityManager>().GetComponent<MetaDataComponent>(user).EntityName} clicked on object {IoCManager.Resolve<IEntityManager>().GetComponent<MetaDataComponent>(targetEnt).EntityName} that isn't the parent, child, or in the same container");
$"User entity named {EntityManager.GetComponent<MetaDataComponent>(user).EntityName} clicked on object {EntityManager.GetComponent<MetaDataComponent>(targetUid).EntityName} that isn't the parent, child, or in the same container");
return;
}
@@ -479,11 +470,9 @@ namespace Content.Server.Interaction
}
// Verify user has a hand, and find what object they are currently holding in their active hand
if (IoCManager.Resolve<IEntityManager>().TryGetComponent<HandsComponent?>(user, out var hands))
if (EntityManager.TryGetComponent<HandsComponent?>(user, out var hands))
{
var item = hands.GetActiveHand?.Owner;
if (item != null)
if (hands.GetActiveHand?.Owner is {Valid: true} item)
{
if (wideAttack)
{
@@ -503,10 +492,10 @@ namespace Content.Server.Interaction
if (ev.Handled)
{
if (targetEnt != null)
if (targetUid != default)
{
_adminLogSystem.Add(LogType.AttackArmedClick, LogImpact.Medium,
$"{user} attacked {targetEnt} with {item} at {coordinates}");
$"{user} attacked {targetUid} with {item} at {coordinates}");
}
else
{
@@ -518,12 +507,10 @@ namespace Content.Server.Interaction
}
}
}
else if (!wideAttack &&
(targetEnt != null || EntityManager.EntityExists(targetUid) &&
IoCManager.Resolve<IEntityManager>().HasComponent<ItemComponent>(targetEnt))
else if (!wideAttack && targetUid != default)
{
// We pick up items if our hand is empty, even if we're in combat mode.
InteractHand(user, targetEnt);
InteractHand(user, targetUid);
return;
}
}
@@ -543,10 +530,10 @@ namespace Content.Server.Interaction
RaiseLocalEvent(user, ev, false);
if (ev.Handled)
{
if (targetEnt != null)
if (targetUid != default)
{
_adminLogSystem.Add(LogType.AttackUnarmedClick, LogImpact.Medium,
$"{user} attacked {targetEnt} at {coordinates}");
$"{user} attacked {targetUid} at {coordinates}");
}
else
{

View File

@@ -16,6 +16,8 @@ namespace Content.Server.Interaction
[AdminCommand(AdminFlags.Debug)]
class TilePryCommand : IConsoleCommand
{
[Dependency] private readonly IEntityManager _entities = default!;
public string Command => "tilepry";
public string Description => "Pries up all tiles in a radius around the user.";
public string Help => $"Usage: {Command} <radius>";
@@ -47,9 +49,9 @@ namespace Content.Server.Interaction
}
var mapManager = IoCManager.Resolve<IMapManager>();
var playerGrid = IoCManager.Resolve<IEntityManager>().GetComponent<TransformComponent>(player.AttachedEntity).GridID;
var playerGrid = _entities.GetComponent<TransformComponent>(player.AttachedEntity.Value).GridID;
var mapGrid = mapManager.GetGrid(playerGrid);
var playerPosition = IoCManager.Resolve<IEntityManager>().GetComponent<TransformComponent>(player.AttachedEntity).Coordinates;
var playerPosition = _entities.GetComponent<TransformComponent>(player.AttachedEntity.Value).Coordinates;
var tileDefinitionManager = IoCManager.Resolve<ITileDefinitionManager>();
for (var i = -radius; i <= radius; i++)

View File

@@ -32,6 +32,7 @@ namespace Content.Server.Inventory.Components
public class InventoryComponent : SharedInventoryComponent, IExAct
{
[Dependency] private readonly IEntitySystemManager _entitySystemManager = default!;
[Dependency] private readonly IEntityManager _entities = default!;
[ViewVariables] private readonly Dictionary<Slots, ContainerSlot> _slotContainers = new();
@@ -62,7 +63,7 @@ namespace Content.Server.Inventory.Components
{
if (TryGetSlotItem(slot, out ItemComponent? item))
{
IoCManager.Resolve<IEntityManager>().DeleteEntity(item.Owner);
_entities.DeleteEntity(item.Owner);
}
RemoveSlot(slot);
@@ -105,7 +106,7 @@ namespace Content.Server.Inventory.Components
public IEnumerable<T?> LookupItems<T>() where T : Component
{
return _slotContainers.Values
.SelectMany(x => x.ContainedEntities.Select(e => IoCManager.Resolve<IEntityManager>().GetComponentOrNull<T>(e)))
.SelectMany(x => x.ContainedEntities.Select(e => _entities.GetComponentOrNull<T>(e)))
.Where(x => x != null);
}
@@ -117,14 +118,14 @@ namespace Content.Server.Inventory.Components
}
var containedEntity = _slotContainers[slot].ContainedEntity;
if ((containedEntity != null ? (!IoCManager.Resolve<IEntityManager>().EntityExists(containedEntity) ? EntityLifeStage.Deleted : IoCManager.Resolve<IEntityManager>().GetComponent<MetaDataComponent>(containedEntity).EntityLifeStage) >= EntityLifeStage.Deleted : null) == true)
if (containedEntity != null && _entities.GetComponent<MetaDataComponent>(containedEntity.Value).EntityDeleted)
{
_slotContainers.Remove(slot);
containedEntity = null;
Dirty();
}
return (containedEntity != null ? IoCManager.Resolve<IEntityManager>().GetComponent<T>(containedEntity) : null);
return containedEntity.HasValue ? _entities.GetComponent<T>(containedEntity.Value) : null;
}
public bool TryGetSlotItem<T>(Slots slot, [NotNullWhen(true)] out T? itemComponent) where T : ItemComponent
@@ -186,7 +187,7 @@ namespace Content.Server.Inventory.Components
Equip(slot, item, mobCheck, out var _);
public bool Equip(Slots slot, EntityUid entity, bool mobCheck = true) =>
Equip(slot, IoCManager.Resolve<IEntityManager>().GetComponent<ItemComponent>(entity), mobCheck);
Equip(slot, _entities.GetComponent<ItemComponent>(entity), mobCheck);
/// <summary>
/// Checks whether an item can be put in the specified slot.
@@ -218,7 +219,7 @@ namespace Content.Server.Inventory.Components
}
}
if (IoCManager.Resolve<IEntityManager>().TryGetComponent(Owner, out IInventoryController? controller))
if (_entities.TryGetComponent(Owner, out IInventoryController? controller))
{
pass = controller.CanEquip(slot, item.Owner, pass, out var controllerReason);
reason = controllerReason ?? reason;
@@ -244,7 +245,7 @@ namespace Content.Server.Inventory.Components
CanEquip(slot, item, mobCheck, out var _);
public bool CanEquip(Slots slot, EntityUid entity, bool mobCheck = true) =>
CanEquip(slot, IoCManager.Resolve<IEntityManager>().GetComponent<ItemComponent>(entity), mobCheck);
CanEquip(slot, _entities.GetComponent<ItemComponent>(entity), mobCheck);
/// <summary>
/// Drops the item in a slot.
@@ -260,9 +261,8 @@ namespace Content.Server.Inventory.Components
}
var inventorySlot = _slotContainers[slot];
var entity = inventorySlot.ContainedEntity;
if (entity == null)
if (inventorySlot.ContainedEntity is not {Valid: true} entity)
{
return false;
}
@@ -273,7 +273,7 @@ namespace Content.Server.Inventory.Components
}
// TODO: The item should be dropped to the container our owner is in, if any.
IoCManager.Resolve<IEntityManager>().GetComponent<TransformComponent>(entity).AttachParentToContainerOrGrid();
_entities.GetComponent<TransformComponent>(entity).AttachParentToContainerOrGrid();
_entitySystemManager.GetEntitySystem<InteractionSystem>().UnequippedInteraction(Owner, entity, slot);
@@ -294,16 +294,15 @@ namespace Content.Server.Inventory.Components
public void ForceUnequip(Slots slot)
{
var inventorySlot = _slotContainers[slot];
var entity = inventorySlot.ContainedEntity;
if (entity == null)
if (inventorySlot.ContainedEntity is not {Valid: true} entity)
{
return;
}
var item = IoCManager.Resolve<IEntityManager>().GetComponent<ItemComponent>(entity);
var item = _entities.GetComponent<ItemComponent>(entity);
inventorySlot.ForceRemove(entity);
var itemTransform = IoCManager.Resolve<IEntityManager>().GetComponent<TransformComponent>(entity);
var itemTransform = _entities.GetComponent<TransformComponent>(entity);
itemTransform.AttachParentToContainerOrGrid();
@@ -328,7 +327,7 @@ namespace Content.Server.Inventory.Components
return false;
var inventorySlot = _slotContainers[slot];
return inventorySlot.ContainedEntity != null && inventorySlot.CanRemove(inventorySlot.ContainedEntity);
return inventorySlot.ContainedEntity != null && inventorySlot.CanRemove(inventorySlot.ContainedEntity.Value);
}
/// <summary>
@@ -404,7 +403,7 @@ namespace Content.Server.Inventory.Components
if (container is not ContainerSlot slot || !_slotContainers.ContainsValue(slot))
return;
if (IoCManager.Resolve<IEntityManager>().TryGetComponent(entity, out ItemComponent? itemComp))
if (_entities.TryGetComponent(entity, out ItemComponent? itemComp))
{
itemComp.RemovedFromSlot();
}
@@ -424,10 +423,10 @@ namespace Content.Server.Inventory.Components
{
case ClientInventoryUpdate.Equip:
{
var hands = IoCManager.Resolve<IEntityManager>().GetComponent<HandsComponent>(Owner);
var hands = _entities.GetComponent<HandsComponent>(Owner);
var activeHand = hands.ActiveHand;
var activeItem = hands.GetActiveHand;
if (activeHand != null && activeItem != null && IoCManager.Resolve<IEntityManager>().TryGetComponent(activeItem.Owner, out ItemComponent? item))
if (activeHand != null && activeItem != null && _entities.TryGetComponent(activeItem.Owner, out ItemComponent? item))
{
hands.TryDropNoInteraction();
if (!Equip(msg.Inventoryslot, item, true, out var reason))
@@ -442,7 +441,7 @@ namespace Content.Server.Inventory.Components
case ClientInventoryUpdate.Use:
{
var interactionSystem = _entitySystemManager.GetEntitySystem<InteractionSystem>();
var hands = IoCManager.Resolve<IEntityManager>().GetComponent<HandsComponent>(Owner);
var hands = _entities.GetComponent<HandsComponent>(Owner);
var activeHand = hands.GetActiveHand;
var itemContainedInSlot = GetSlotItem(msg.Inventoryslot);
if (itemContainedInSlot != null)
@@ -462,7 +461,7 @@ namespace Content.Server.Inventory.Components
}
case ClientInventoryUpdate.Hover:
{
var hands = IoCManager.Resolve<IEntityManager>().GetComponent<HandsComponent>(Owner);
var hands = _entities.GetComponent<HandsComponent>(Owner);
var activeHand = hands.GetActiveHand;
if (activeHand != null && GetSlotItem(msg.Inventoryslot) == null)
{
@@ -504,7 +503,7 @@ namespace Content.Server.Inventory.Components
if (!HasSlot(msg.Slot)) // client input sanitization
return;
var item = GetSlotItem(msg.Slot);
if (item != null && IoCManager.Resolve<IEntityManager>().TryGetComponent(item.Owner, out ServerStorageComponent? storage))
if (item != null && _entities.TryGetComponent(item.Owner, out ServerStorageComponent? storage))
storage.OpenStorageUI(Owner);
break;
}
@@ -515,9 +514,9 @@ namespace Content.Server.Inventory.Components
var list = new List<KeyValuePair<Slots, EntityUid>>();
foreach (var (slot, container) in _slotContainers)
{
if (container != null && container.ContainedEntity != null)
if (container is {ContainedEntity: { }})
{
list.Add(new KeyValuePair<Slots, EntityUid>(slot, container.ContainedEntity));
list.Add(new KeyValuePair<Slots, EntityUid>(slot, container.ContainedEntity.Value));
}
}
@@ -538,7 +537,7 @@ namespace Content.Server.Inventory.Components
{
foreach (var entity in slot.ContainedEntities)
{
var exActs = IoCManager.Resolve<IEntityManager>().GetComponents<IExAct>(entity).ToList();
var exActs = _entities.GetComponents<IExAct>(entity).ToList();
foreach (var exAct in exActs)
{
exAct.OnExplosion(eventArgs);
@@ -549,7 +548,7 @@ namespace Content.Server.Inventory.Components
public override bool IsEquipped(EntityUid item)
{
if (item == null) return false;
if (item == default) return false;
foreach (var containerSlot in _slotContainers.Values)
{
// we don't want a recursive check here

View File

@@ -37,6 +37,8 @@ namespace Content.Server.Kitchen.Components
[ComponentReference(typeof(IActivate))]
public class MicrowaveComponent : SharedMicrowaveComponent, IActivate, IInteractUsing, ISuicideAct, IBreakAct
{
[Dependency] private readonly IEntityManager _entities = default!;
[Dependency] private readonly RecipeManager _recipeManager = default!;
#region YAMLSERIALIZE
@@ -66,7 +68,7 @@ namespace Content.Server.Kitchen.Components
/// </summary>
[ViewVariables] private uint _currentCookTimerTime = 1;
private bool Powered => !IoCManager.Resolve<IEntityManager>().TryGetComponent(Owner, out ApcPowerReceiverComponent? receiver) || receiver.Powered;
private bool Powered => !_entities.TryGetComponent(Owner, out ApcPowerReceiverComponent? receiver) || receiver.Powered;
private bool HasContents => EntitySystem.Get<SolutionContainerSystem>()
.TryGetSolution(Owner, SolutionName, out var solution) &&
@@ -204,7 +206,7 @@ namespace Content.Server.Kitchen.Components
finalState = MicrowaveVisualState.Broken;
}
if (IoCManager.Resolve<IEntityManager>().TryGetComponent(Owner, out AppearanceComponent? appearance))
if (_entities.TryGetComponent(Owner, out AppearanceComponent? appearance))
{
appearance.SetData(PowerDeviceVisuals.VisualState, finalState);
}
@@ -218,7 +220,7 @@ namespace Content.Server.Kitchen.Components
void IActivate.Activate(ActivateEventArgs eventArgs)
{
if (!IoCManager.Resolve<IEntityManager>().TryGetComponent(eventArgs.User, out ActorComponent? actor) || !Powered)
if (!_entities.TryGetComponent(eventArgs.User, out ActorComponent? actor) || !Powered)
{
return;
}
@@ -241,15 +243,13 @@ namespace Content.Server.Kitchen.Components
return false;
}
var itemEntity = IoCManager.Resolve<IEntityManager>().GetComponent<HandsComponent>(eventArgs.User).GetActiveHand?.Owner;
if (itemEntity == null)
if (_entities.GetComponent<HandsComponent>(eventArgs.User).GetActiveHand?.Owner is not {Valid: true} itemEntity)
{
eventArgs.User.PopupMessage(Loc.GetString("microwave-component-interact-using-no-active-hand"));
return false;
}
if (IoCManager.Resolve<IEntityManager>().TryGetComponent<SolutionTransferComponent?>(itemEntity, out var attackPourable))
if (_entities.TryGetComponent<SolutionTransferComponent?>(itemEntity, out var attackPourable))
{
var solutionsSystem = EntitySystem.Get<SolutionContainerSystem>();
if (!solutionsSystem.TryGetDrainableSolution(itemEntity, out var attackSolution))
@@ -284,7 +284,7 @@ namespace Content.Server.Kitchen.Components
return true;
}
if (!IoCManager.Resolve<IEntityManager>().TryGetComponent(itemEntity, typeof(ItemComponent), out var food))
if (!_entities.TryGetComponent(itemEntity, typeof(ItemComponent), out var food))
{
Owner.PopupMessage(eventArgs.User, "microwave-component-interact-using-transfer-fail");
return false;
@@ -310,18 +310,19 @@ namespace Content.Server.Kitchen.Components
var solidsDict = new Dictionary<string, int>();
foreach (var item in _storage.ContainedEntities)
{
if (IoCManager.Resolve<IEntityManager>().GetComponent<MetaDataComponent>(item).EntityPrototype == null)
var metaData = _entities.GetComponent<MetaDataComponent>(item);
if (metaData.EntityPrototype == null)
{
continue;
}
if (solidsDict.ContainsKey(IoCManager.Resolve<IEntityManager>().GetComponent<MetaDataComponent>(item).EntityPrototype.ID))
if (solidsDict.ContainsKey(metaData.EntityPrototype.ID))
{
solidsDict[IoCManager.Resolve<IEntityManager>().GetComponent<MetaDataComponent>(item).EntityPrototype.ID]++;
solidsDict[metaData.EntityPrototype.ID]++;
}
else
{
solidsDict.Add(IoCManager.Resolve<IEntityManager>().GetComponent<MetaDataComponent>(item).EntityPrototype.ID, 1);
solidsDict.Add(metaData.EntityPrototype.ID, 1);
}
}
@@ -364,13 +365,13 @@ namespace Content.Server.Kitchen.Components
if (recipeToCook != null)
{
SubtractContents(recipeToCook);
IoCManager.Resolve<IEntityManager>().SpawnEntity(recipeToCook.Result, IoCManager.Resolve<IEntityManager>().GetComponent<TransformComponent>(Owner).Coordinates);
_entities.SpawnEntity(recipeToCook.Result, _entities.GetComponent<TransformComponent>(Owner).Coordinates);
}
else
{
VaporizeReagents();
VaporizeSolids();
IoCManager.Resolve<IEntityManager>().SpawnEntity(_badRecipeName, IoCManager.Resolve<IEntityManager>().GetComponent<TransformComponent>(Owner).Coordinates);
_entities.SpawnEntity(_badRecipeName, _entities.GetComponent<TransformComponent>(Owner).Coordinates);
}
}
@@ -409,7 +410,7 @@ namespace Content.Server.Kitchen.Components
{
var item = _storage.ContainedEntities.ElementAt(i);
_storage.Remove(item);
IoCManager.Resolve<IEntityManager>().DeleteEntity(item);
_entities.DeleteEntity(item);
}
}
@@ -423,9 +424,9 @@ namespace Content.Server.Kitchen.Components
private void EjectSolid(EntityUid entityId)
{
if (IoCManager.Resolve<IEntityManager>().EntityExists(entityId))
if (_entities.EntityExists(entityId))
{
_storage.Remove(IoCManager.Resolve<IEntityManager>().GetEntity(entityId));
_storage.Remove(entityId);
}
}
@@ -449,15 +450,16 @@ namespace Content.Server.Kitchen.Components
{
foreach (var item in _storage.ContainedEntities)
{
if (IoCManager.Resolve<IEntityManager>().GetComponent<MetaDataComponent>(item).EntityPrototype == null)
var metaData = _entities.GetComponent<MetaDataComponent>(item);
if (metaData.EntityPrototype == null)
{
continue;
}
if (IoCManager.Resolve<IEntityManager>().GetComponent<MetaDataComponent>(item).EntityPrototype.ID == recipeSolid.Key)
if (metaData.EntityPrototype.ID == recipeSolid.Key)
{
_storage.Remove(item);
IoCManager.Resolve<IEntityManager>().DeleteEntity(item);
_entities.DeleteEntity(item);
break;
}
}
@@ -515,7 +517,7 @@ namespace Content.Server.Kitchen.Components
{
var headCount = 0;
if (IoCManager.Resolve<IEntityManager>().TryGetComponent<SharedBodyComponent?>(victim, out var body))
if (_entities.TryGetComponent<SharedBodyComponent?>(victim, out var body))
{
var headSlots = body.GetSlotsOfType(BodyPartType.Head);

View File

@@ -21,6 +21,7 @@ using Robust.Shared.IoC;
using Robust.Shared.Localization;
using Robust.Shared.Log;
using Robust.Shared.Player;
using Robust.Shared.Utility;
namespace Content.Server.Kitchen.EntitySystems
{
@@ -52,7 +53,7 @@ namespace Content.Server.Kitchen.EntitySystems
{
if (args.Handled) return;
if (!IoCManager.Resolve<IEntityManager>().HasComponent<HandsComponent>(args.User))
if (!EntityManager.HasComponent<HandsComponent>(args.User))
{
component.Owner.PopupMessage(args.User,
Loc.GetString("reagent-grinder-component-interact-using-no-hands"));
@@ -60,7 +61,7 @@ namespace Content.Server.Kitchen.EntitySystems
return;
}
EntityUidheldEnt = args.Used;
var heldEnt = args.Used;
// First, check if user is trying to insert a beaker.
// No promise it will be a beaker right now, but whatever.
@@ -71,7 +72,7 @@ namespace Content.Server.Kitchen.EntitySystems
component.HeldBeaker = beaker;
EnqueueUiUpdate(component);
//We are done, return. Insert the beaker and exit!
if (IoCManager.Resolve<IEntityManager>().TryGetComponent(component.Owner, out AppearanceComponent? appearance))
if (EntityManager.TryGetComponent(component.Owner, out AppearanceComponent? appearance))
{
appearance.SetData(SharedReagentGrinderComponent.ReagentGrinderVisualState.BeakerAttached,
component.BeakerContainer.ContainedEntity != null);
@@ -83,7 +84,7 @@ namespace Content.Server.Kitchen.EntitySystems
}
//Next, see if the user is trying to insert something they want to be ground/juiced.
if (!IoCManager.Resolve<IEntityManager>().TryGetComponent(heldEnt, out ExtractableComponent? juice))
if (!EntityManager.TryGetComponent(heldEnt, out ExtractableComponent? juice))
{
//Entity did NOT pass the whitelist for grind/juice.
//Wouldn't want the clown grinding up the Captain's ID card now would you?
@@ -111,7 +112,7 @@ namespace Content.Server.Kitchen.EntitySystems
{
if (args.Handled) return;
if (!IoCManager.Resolve<IEntityManager>().TryGetComponent(args.User, out ActorComponent? actor))
if (!EntityManager.TryGetComponent(args.User, out ActorComponent? actor))
{
return;
}
@@ -159,18 +160,18 @@ namespace Content.Server.Kitchen.EntitySystems
switch (message.Message)
{
case SharedReagentGrinderComponent.ReagentGrinderGrindStartMessage msg:
if (!IoCManager.Resolve<IEntityManager>().TryGetComponent(component.Owner, out ApcPowerReceiverComponent? receiver) ||
if (!EntityManager.TryGetComponent(component.Owner, out ApcPowerReceiverComponent? receiver) ||
!receiver.Powered) break;
ClickSound(component);
DoWork(component, message.Session.AttachedEntity!,
DoWork(component, message.Session.AttachedEntity!.Value,
SharedReagentGrinderComponent.GrinderProgram.Grind);
break;
case SharedReagentGrinderComponent.ReagentGrinderJuiceStartMessage msg:
if (!IoCManager.Resolve<IEntityManager>().TryGetComponent(component.Owner, out ApcPowerReceiverComponent? receiver2) ||
if (!EntityManager.TryGetComponent(component.Owner, out ApcPowerReceiverComponent? receiver2) ||
!receiver2.Powered) break;
ClickSound(component);
DoWork(component, message.Session.AttachedEntity!,
DoWork(component, message.Session.AttachedEntity!.Value,
SharedReagentGrinderComponent.GrinderProgram.Juice);
break;
@@ -191,10 +192,10 @@ namespace Content.Server.Kitchen.EntitySystems
break;
case SharedReagentGrinderComponent.ReagentGrinderEjectChamberContentMessage msg:
if (component.Chamber.ContainedEntities.TryFirstOrDefault(x => x == msg.EntityID, out var ent))
if (component.Chamber.ContainedEntities.TryFirstOrNull(x => x == msg.EntityID, out var ent))
{
component.Chamber.Remove(ent);
SharedEntityExtensions.RandomOffset(ent, 0.4f);
component.Chamber.Remove(ent.Value);
SharedEntityExtensions.RandomOffset(ent.Value, 0.4f);
EnqueueUiUpdate(component);
ClickSound(component);
}
@@ -224,7 +225,7 @@ namespace Content.Server.Kitchen.EntitySystems
{
foreach (var entity in comp.Chamber.ContainedEntities)
{
if (canJuice || !IoCManager.Resolve<IEntityManager>().TryGetComponent(entity, out ExtractableComponent? component)) continue;
if (canJuice || !EntityManager.TryGetComponent(entity, out ExtractableComponent? component)) continue;
canJuice = component.JuiceSolution != null;
canGrind = component.GrindableSolution != null
@@ -237,7 +238,7 @@ namespace Content.Server.Kitchen.EntitySystems
(
comp.Busy,
comp.BeakerContainer.ContainedEntity != null,
IoCManager.Resolve<IEntityManager>().TryGetComponent(comp.Owner, out ApcPowerReceiverComponent? receiver) && receiver.Powered,
EntityManager.TryGetComponent(comp.Owner, out ApcPowerReceiverComponent? receiver) && receiver.Powered,
canJuice,
canGrind,
comp.Chamber.ContainedEntities.Select(item => item).ToArray(),
@@ -251,25 +252,26 @@ namespace Content.Server.Kitchen.EntitySystems
/// Tries to eject whatever is in the beaker slot. Puts the item in the user's hands or failing that on top
/// of the grinder.
/// </summary>
private void EjectBeaker(ReagentGrinderComponent component, EntityUid user)
private void EjectBeaker(ReagentGrinderComponent component, EntityUid? user)
{
if (component.BeakerContainer.ContainedEntity == null || component.HeldBeaker == null || component.Busy)
return;
var beaker = component.BeakerContainer.ContainedEntity;
if (beaker is null)
if (component.BeakerContainer.ContainedEntity is not {Valid: true} beaker)
return;
component.BeakerContainer.Remove(beaker);
if (user == null || !IoCManager.Resolve<IEntityManager>().TryGetComponent<HandsComponent?>(user, out var hands) ||
!IoCManager.Resolve<IEntityManager>().TryGetComponent<ItemComponent?>(beaker, out var item))
if (user == null ||
!EntityManager.TryGetComponent<HandsComponent?>(user.Value, out var hands) ||
!EntityManager.TryGetComponent<ItemComponent?>(beaker, out var item))
return;
hands.PutInHandOrDrop(item);
component.HeldBeaker = null;
EnqueueUiUpdate(component);
if (IoCManager.Resolve<IEntityManager>().TryGetComponent(component.Owner, out AppearanceComponent? appearance))
if (EntityManager.TryGetComponent(component.Owner, out AppearanceComponent? appearance))
{
appearance.SetData(SharedReagentGrinderComponent.ReagentGrinderVisualState.BeakerAttached,
component.BeakerContainer.ContainedEntity != null);
@@ -284,7 +286,7 @@ namespace Content.Server.Kitchen.EntitySystems
SharedReagentGrinderComponent.GrinderProgram program)
{
//Have power, are we busy, chamber has anything to grind, a beaker for the grounds to go?
if (!IoCManager.Resolve<IEntityManager>().TryGetComponent(component.Owner, out ApcPowerReceiverComponent? receiver) || !receiver.Powered ||
if (!EntityManager.TryGetComponent(component.Owner, out ApcPowerReceiverComponent? receiver) || !receiver.Powered ||
component.Busy || component.Chamber.ContainedEntities.Count <= 0 ||
component.BeakerContainer.ContainedEntity == null || component.HeldBeaker == null)
{
@@ -306,7 +308,7 @@ namespace Content.Server.Kitchen.EntitySystems
{
foreach (var item in component.Chamber.ContainedEntities.ToList())
{
if (!IoCManager.Resolve<IEntityManager>().TryGetComponent(item, out ExtractableComponent? extract)
if (!EntityManager.TryGetComponent(item, out ExtractableComponent? extract)
|| extract.GrindableSolution == null
|| !_solutionsSystem.TryGetSolution(item, extract.GrindableSolution, out var solution)) continue;
@@ -315,9 +317,9 @@ namespace Content.Server.Kitchen.EntitySystems
if (component.HeldBeaker.CurrentVolume + solution.CurrentVolume * juiceEvent.Scalar >
component.HeldBeaker.MaxVolume) continue;
solution.ScaleSolution(juiceEvent.Scalar);
_solutionsSystem.TryAddSolution(beakerEntity, component.HeldBeaker, solution);
_solutionsSystem.RemoveAllSolution(beakerEntity, solution);
IoCManager.Resolve<IEntityManager>().DeleteEntity(item);
_solutionsSystem.TryAddSolution(beakerEntity.Value, component.HeldBeaker, solution);
_solutionsSystem.RemoveAllSolution(beakerEntity.Value, solution);
EntityManager.DeleteEntity(item);
}
component.Busy = false;
@@ -332,14 +334,14 @@ namespace Content.Server.Kitchen.EntitySystems
{
foreach (var item in component.Chamber.ContainedEntities.ToList())
{
if (!IoCManager.Resolve<IEntityManager>().TryGetComponent<ExtractableComponent?>(item, out var juiceMe)
if (!EntityManager.TryGetComponent<ExtractableComponent?>(item, out var juiceMe)
|| juiceMe.JuiceSolution == null)
{
Logger.Warning("Couldn't find a juice solution on entityUid:{0}", item);
continue;
}
var juiceEvent = new ExtractableScalingEvent(); // default of scalar is always 1.0
if (IoCManager.Resolve<IEntityManager>().HasComponent<StackComponent>(item))
if (EntityManager.HasComponent<StackComponent>(item))
{
RaiseLocalEvent(item, juiceEvent);
}
@@ -348,8 +350,8 @@ namespace Content.Server.Kitchen.EntitySystems
juiceMe.JuiceSolution.TotalVolume * juiceEvent.Scalar >
component.HeldBeaker.MaxVolume) continue;
juiceMe.JuiceSolution.ScaleSolution(juiceEvent.Scalar);
_solutionsSystem.TryAddSolution(beakerEntity, component.HeldBeaker, juiceMe.JuiceSolution);
IoCManager.Resolve<IEntityManager>().DeleteEntity(item);
_solutionsSystem.TryAddSolution(beakerEntity.Value, component.HeldBeaker, juiceMe.JuiceSolution);
EntityManager.DeleteEntity(item);
}
bui?.SendMessage(new SharedReagentGrinderComponent.ReagentGrinderWorkCompleteMessage());

View File

@@ -34,10 +34,10 @@ namespace Content.Server.Labels
private void AfterInteractOn(EntityUid uid, HandLabelerComponent handLabeler, AfterInteractEvent args)
{
if (args.Target == null || !handLabeler.Whitelist.IsValid(args.Target))
if (args.Target is not {Valid: true} target || !handLabeler.Whitelist.IsValid(target))
return;
AddLabelTo(uid, handLabeler, args.Target, out string? result);
AddLabelTo(uid, handLabeler, target, out string? result);
if (result != null)
handLabeler.Owner.PopupMessage(args.User, result);
}

View File

@@ -62,7 +62,7 @@ namespace Content.Server.Labels
private void OnExamined(EntityUid uid, PaperLabelComponent comp, ExaminedEvent args)
{
if (comp.LabelSlot.Item == null)
if (comp.LabelSlot.Item is not {Valid: true} item)
return;
if (!args.IsInDetailsRange)
@@ -71,7 +71,7 @@ namespace Content.Server.Labels
return;
}
if (!EntityManager.TryGetComponent(comp.LabelSlot.Item, out PaperComponent paper))
if (!EntityManager.TryGetComponent(item, out PaperComponent paper))
// Assuming yaml has the correct entity whitelist, this should not happen.
return;

View File

@@ -154,7 +154,7 @@ namespace Content.Server.Light.EntitySystems
return false;
// try to insert bulb in container
if (!light.LightBulbContainer.Insert(EntityManager.GetEntity(bulbUid)))
if (!light.LightBulbContainer.Insert(bulbUid))
return false;
UpdateLight(uid, light);
@@ -172,24 +172,22 @@ namespace Content.Server.Light.EntitySystems
return null;
// check if light has bulb
var bulbUid = GetBulb(uid, light);
if (bulbUid == null)
if (GetBulb(uid, light) is not {Valid: true} bulb)
return null;
// try to remove bulb from container
var bulbbulbUid.Value
if (!light.LightBulbContainer.Remove(bulbEnt))
if (!light.LightBulbContainer.Remove(bulb))
return null;
// try to place bulb in hands
if (userUid != null)
{
if (EntityManager.TryGetComponent(userUid.Value, out SharedHandsComponent? hands))
hands.TryPutInActiveHandOrAny(bulbEnt);
hands.TryPutInActiveHandOrAny(bulb);
}
UpdateLight(uid, light);
return bulbUid;
return bulb;
}
/// <summary>

View File

@@ -5,7 +5,7 @@ namespace Content.Server.MachineLinking.Events
{
public class LinkAttemptEvent : CancellableEntityEventArgs
{
public readonly EntityUid Attemptee,
public readonly EntityUid Attemptee;
public readonly SignalTransmitterComponent TransmitterComponent;
public readonly string TransmitterPort;
public readonly SignalReceiverComponent ReceiverComponent;

View File

@@ -13,7 +13,6 @@ using Content.Shared.MachineLinking;
using Content.Shared.Popups;
using Robust.Server.GameObjects;
using Robust.Shared.GameObjects;
using Robust.Shared.IoC;
using Robust.Shared.Localization;
using Robust.Shared.Utility;
@@ -81,8 +80,8 @@ namespace Content.Server.MachineLinking.System
{
if (args.Handled) return;
if (!IoCManager.Resolve<IEntityManager>().TryGetComponent<SignalLinkerComponent?>(args.Used, out var linker) || !linker.Port.HasValue ||
!IoCManager.Resolve<IEntityManager>().TryGetComponent(args.User, out ActorComponent? actor) ||
if (!EntityManager.TryGetComponent<SignalLinkerComponent?>(args.Used, out var linker) || !linker.Port.HasValue ||
!EntityManager.TryGetComponent(args.User, out ActorComponent? actor) ||
!linker.Port.Value.transmitter.Outputs.TryGetPort(linker.Port.Value.port, out var port))
{
return;
@@ -121,15 +120,15 @@ namespace Content.Server.MachineLinking.System
{
case SignalPortSelected portSelected:
if (msg.Session.AttachedEntity == null ||
!IoCManager.Resolve<IEntityManager>().TryGetComponent(msg.Session.AttachedEntity, out HandsComponent? hands) ||
!EntityManager.TryGetComponent(msg.Session.AttachedEntity.Value, out HandsComponent? hands) ||
!hands.TryGetActiveHeldEntity(out var heldEntity) ||
!IoCManager.Resolve<IEntityManager>().TryGetComponent(heldEntity, out SignalLinkerComponent? signalLinkerComponent) ||
!_interaction.InRangeUnobstructed(msg.Session.AttachedEntity, component.Owner, ignoreInsideBlocker: true) ||
!EntityManager.TryGetComponent(heldEntity, out SignalLinkerComponent? signalLinkerComponent) ||
!_interaction.InRangeUnobstructed(msg.Session.AttachedEntity.Value, component.Owner, ignoreInsideBlocker: true) ||
!signalLinkerComponent.Port.HasValue ||
!signalLinkerComponent.Port.Value.transmitter.Outputs.ContainsPort(signalLinkerComponent.Port
.Value.port) || !component.Inputs.ContainsPort(portSelected.Port))
return;
LinkerInteraction(msg.Session.AttachedEntity, signalLinkerComponent.Port.Value.transmitter,
LinkerInteraction(msg.Session.AttachedEntity.Value, signalLinkerComponent.Port.Value.transmitter,
signalLinkerComponent.Port.Value.port, component, portSelected.Port);
break;
}
@@ -161,12 +160,12 @@ namespace Content.Server.MachineLinking.System
{
case SignalPortSelected portSelected:
if (msg.Session.AttachedEntity == null ||
!IoCManager.Resolve<IEntityManager>().TryGetComponent(msg.Session.AttachedEntity, out HandsComponent? hands) ||
!EntityManager.TryGetComponent(msg.Session.AttachedEntity.Value, out HandsComponent? hands) ||
!hands.TryGetActiveHeldEntity(out var heldEntity) ||
!IoCManager.Resolve<IEntityManager>().TryGetComponent(heldEntity, out SignalLinkerComponent? signalLinkerComponent) ||
!_interaction.InRangeUnobstructed(msg.Session.AttachedEntity, component.Owner, ignoreInsideBlocker: true))
!EntityManager.TryGetComponent(heldEntity, out SignalLinkerComponent? signalLinkerComponent) ||
!_interaction.InRangeUnobstructed(msg.Session.AttachedEntity.Value, component.Owner, ignoreInsideBlocker: true))
return;
LinkerSaveInteraction(msg.Session.AttachedEntity, signalLinkerComponent, component,
LinkerSaveInteraction(msg.Session.AttachedEntity.Value, signalLinkerComponent, component,
portSelected.Port);
break;
}
@@ -177,8 +176,8 @@ namespace Content.Server.MachineLinking.System
{
if (args.Handled) return;
if (!IoCManager.Resolve<IEntityManager>().TryGetComponent<SignalLinkerComponent?>(args.Used, out var linker) ||
!IoCManager.Resolve<IEntityManager>().TryGetComponent(args.User, out ActorComponent? actor))
if (!EntityManager.TryGetComponent<SignalLinkerComponent?>(args.Used, out var linker) ||
!EntityManager.TryGetComponent(args.User, out ActorComponent? actor))
{
return;
}
@@ -277,15 +276,15 @@ namespace Content.Server.MachineLinking.System
private bool IsInRange(SignalTransmitterComponent transmitterComponent,
SignalReceiverComponent receiverComponent)
{
if (IoCManager.Resolve<IEntityManager>().TryGetComponent<ApcPowerReceiverComponent?>(transmitterComponent.Owner, out var transmitterPowerReceiverComponent) &&
IoCManager.Resolve<IEntityManager>().TryGetComponent<ApcPowerReceiverComponent?>(receiverComponent.Owner, out var receiverPowerReceiverComponent)
if (EntityManager.TryGetComponent<ApcPowerReceiverComponent?>(transmitterComponent.Owner, out var transmitterPowerReceiverComponent) &&
EntityManager.TryGetComponent<ApcPowerReceiverComponent?>(receiverComponent.Owner, out var receiverPowerReceiverComponent)
) //&& todo are they on the same powernet?
{
return true;
}
return IoCManager.Resolve<IEntityManager>().GetComponent<TransformComponent>(transmitterComponent.Owner).MapPosition.InRange(
IoCManager.Resolve<IEntityManager>().GetComponent<TransformComponent>(receiverComponent.Owner).MapPosition, 30f);
return EntityManager.GetComponent<TransformComponent>(transmitterComponent.Owner).MapPosition.InRange(
EntityManager.GetComponent<TransformComponent>(receiverComponent.Owner).MapPosition, 30f);
}
}
}

View File

@@ -19,7 +19,7 @@ namespace Content.Server.MachineLinking.System
private void OnSignalReceived(EntityUid uid, TriggerOnSignalReceivedComponent component, SignalReceivedEvent args)
{
_trigger.Trigger(uid)
_trigger.Trigger(uid);
}
}
}

View File

@@ -2,7 +2,6 @@ using System.Threading.Tasks;
using Content.Server.Administration.Logs;
using Content.Server.Stack;
using Content.Shared.ActionBlocker;
using Content.Shared.Administration.Logs;
using Content.Shared.Damage;
using Content.Shared.Damage.Prototypes;
using Content.Shared.Database;
@@ -41,7 +40,7 @@ namespace Content.Server.Medical.Components
return false;
}
if (!IoCManager.Resolve<IEntityManager>().TryGetComponent(eventArgs.Target, out DamageableComponent? targetDamage))
if (!IoCManager.Resolve<IEntityManager>().TryGetComponent(eventArgs.Target.Value, out DamageableComponent? targetDamage))
{
return true;
}
@@ -66,7 +65,7 @@ namespace Content.Server.Medical.Components
return true;
}
var healed = EntitySystem.Get<DamageableSystem>().TryChangeDamage(eventArgs.Target, Damage, true);
var healed = EntitySystem.Get<DamageableSystem>().TryChangeDamage(eventArgs.Target.Value, Damage, true);
if (healed == null)
return true;

View File

@@ -79,7 +79,7 @@ namespace Content.Server.Medical.Components
return EmptyUIState;
}
if (!IoCManager.Resolve<IEntityManager>().TryGetComponent(body, out DamageableComponent? damageable))
if (!IoCManager.Resolve<IEntityManager>().TryGetComponent(body.Value, out DamageableComponent? damageable))
{
return EmptyUIState;
}
@@ -90,7 +90,7 @@ namespace Content.Server.Medical.Components
}
var cloningSystem = EntitySystem.Get<CloningSystem>();
var scanned = IoCManager.Resolve<IEntityManager>().TryGetComponent(_bodyContainer.ContainedEntity, out MindComponent? mindComponent) &&
var scanned = IoCManager.Resolve<IEntityManager>().TryGetComponent(_bodyContainer.ContainedEntity.Value, out MindComponent? mindComponent) &&
mindComponent.Mind != null &&
cloningSystem.HasDnaScan(mindComponent.Mind);
@@ -136,7 +136,7 @@ namespace Content.Server.Medical.Components
if (body == null)
return MedicalScannerStatus.Open;
var state = IoCManager.Resolve<IEntityManager>().GetComponentOrNull<MobStateComponent>(body);
var state = IoCManager.Resolve<IEntityManager>().GetComponentOrNull<MobStateComponent>(body.Value);
return state == null ? MedicalScannerStatus.Open : GetStatusFromDamageState(state);
}
@@ -174,12 +174,11 @@ namespace Content.Server.Medical.Components
public void EjectBody()
{
var containedEntity = _bodyContainer.ContainedEntity;
if (containedEntity == null) return;
_bodyContainer.Remove(containedEntity);
if (_bodyContainer.ContainedEntity is not {Valid: true} contained) return;
_bodyContainer.Remove(contained);
UpdateUserInterface();
UpdateAppearance();
EntitySystem.Get<ClimbSystem>().ForciblySetClimbing(containedEntity);
EntitySystem.Get<ClimbSystem>().ForciblySetClimbing(contained);
}
public void Update(float frameTime)
@@ -199,7 +198,7 @@ namespace Content.Server.Medical.Components
{
var cloningSystem = EntitySystem.Get<CloningSystem>();
if (!IoCManager.Resolve<IEntityManager>().TryGetComponent(_bodyContainer.ContainedEntity, out MindComponent? mindComp) || mindComp.Mind == null)
if (!IoCManager.Resolve<IEntityManager>().TryGetComponent(_bodyContainer.ContainedEntity.Value, out MindComponent? mindComp) || mindComp.Mind == null)
{
obj.Session.AttachedEntity?.PopupMessageCursor(Loc.GetString("medical-scanner-component-msg-no-soul"));
break;

View File

@@ -67,7 +67,7 @@ namespace Content.Server.Mind
[ViewVariables]
public EntityUid VisitingEntity { get; private set; }
[ViewVariables] public EntityUid CurrentEntity => VisitingEntity.IsValid() ? VisitingEntity : OwnedEntity;
[ViewVariables] public EntityUid? CurrentEntity => VisitingEntity.IsValid() ? VisitingEntity : OwnedEntity;
[ViewVariables(VVAccess.ReadWrite)]
public string? CharacterName { get; set; }
@@ -90,7 +90,7 @@ namespace Content.Server.Mind
/// Can be null.
/// </summary>
[ViewVariables]
public EntityUid OwnedEntity => OwnedComponent?.Owner ?? default;
public EntityUid? OwnedEntity => OwnedComponent?.Owner;
/// <summary>
/// An enumerable over all the roles this mind has.
@@ -155,7 +155,7 @@ namespace Content.Server.Mind
// This can be null if they're deleted (spike / brain nom)
if (OwnedEntity == default)
return true;
var targetMobState = IoCManager.Resolve<IEntityManager>().GetComponentOrNull<MobStateComponent>(OwnedEntity);
var targetMobState = IoCManager.Resolve<IEntityManager>().GetComponentOrNull<MobStateComponent>(OwnedEntity.Value);
// This can be null if it's a brain (this happens very often)
// Brains are the result of gibbing so should definitely count as dead
if (targetMobState == null)
@@ -184,7 +184,10 @@ namespace Content.Server.Mind
role.Greet();
var message = new RoleAddedEvent(role);
IoCManager.Resolve<IEntityManager>().EventBus.RaiseLocalEvent(OwnedEntity, message);
if (OwnedEntity != default)
{
IoCManager.Resolve<IEntityManager>().EventBus.RaiseLocalEvent(OwnedEntity.Value, message);
}
return role;
}
@@ -206,7 +209,11 @@ namespace Content.Server.Mind
_roles.Remove(role);
var message = new RoleRemovedEvent(role);
IoCManager.Resolve<IEntityManager>().EventBus.RaiseLocalEvent(OwnedEntity, message);
if (OwnedEntity != default)
{
IoCManager.Resolve<IEntityManager>().EventBus.RaiseLocalEvent(OwnedEntity.Value, message);
}
}
public bool HasRole<T>() where T : Role

View File

@@ -32,6 +32,8 @@ namespace Content.Server.Morgue.Components
public class CrematoriumEntityStorageComponent : MorgueEntityStorageComponent, IExamine, ISuicideAct
#pragma warning restore 618
{
[Dependency] private readonly IEntityManager _entities = default!;
public override string Name => "CrematoriumEntityStorage";
[DataField("cremateStartSound")] private SoundSpecifier _cremateStartSound = new SoundPathSpecifier("/Audio/Items/lighter1.ogg");
@@ -104,7 +106,7 @@ namespace Content.Server.Morgue.Components
_cremateCancelToken = new CancellationTokenSource();
Owner.SpawnTimer(_burnMilis, () =>
{
if ((!IoCManager.Resolve<IEntityManager>().EntityExists(Owner) ? EntityLifeStage.Deleted : IoCManager.Resolve<IEntityManager>().GetComponent<MetaDataComponent>(Owner).EntityLifeStage) >= EntityLifeStage.Deleted)
if ((!_entities.EntityExists(Owner) ? EntityLifeStage.Deleted : _entities.GetComponent<MetaDataComponent>(Owner).EntityLifeStage) >= EntityLifeStage.Deleted)
return;
Appearance?.SetData(CrematoriumVisuals.Burning, false);
@@ -116,10 +118,10 @@ namespace Content.Server.Morgue.Components
{
var item = Contents.ContainedEntities[i];
Contents.Remove(item);
IoCManager.Resolve<IEntityManager>().DeleteEntity(item);
_entities.DeleteEntity(item);
}
var ash = IoCManager.Resolve<IEntityManager>().SpawnEntity("Ash", IoCManager.Resolve<IEntityManager>().GetComponent<TransformComponent>(Owner).Coordinates);
var ash = _entities.SpawnEntity("Ash", _entities.GetComponent<TransformComponent>(Owner).Coordinates);
Contents.Insert(ash);
}
@@ -132,13 +134,13 @@ namespace Content.Server.Morgue.Components
SuicideKind ISuicideAct.Suicide(EntityUid victim, IChatManager chat)
{
if (IoCManager.Resolve<IEntityManager>().TryGetComponent(victim, out ActorComponent? actor) && actor.PlayerSession.ContentData()?.Mind is {} mind)
if (_entities.TryGetComponent(victim, out ActorComponent? actor) && actor.PlayerSession.ContentData()?.Mind is {} mind)
{
EntitySystem.Get<GameTicker>().OnGhostAttempt(mind, false);
if (mind.OwnedEntity.Valid)
if (mind.OwnedEntity is {Valid: true} entity)
{
mind.OwnedEntity.PopupMessage(Loc.GetString("crematorium-entity-storage-component-suicide-message"));
entity.PopupMessage(Loc.GetString("crematorium-entity-storage-component-suicide-message"));
}
}
@@ -151,7 +153,7 @@ namespace Content.Server.Morgue.Components
}
else
{
IoCManager.Resolve<IEntityManager>().DeleteEntity(victim);
_entities.DeleteEntity(victim);
}
Cremate();

View File

@@ -12,6 +12,8 @@ namespace Content.Server.Nutrition
[AdminCommand(AdminFlags.Debug)]
public class Hungry : IConsoleCommand
{
[Dependency] private readonly IEntityManager _entities = default!;
public string Command => "hungry";
public string Description => "Makes you hungry.";
public string Help => $"{Command}";
@@ -25,13 +27,13 @@ namespace Content.Server.Nutrition
return;
}
if (player.AttachedEntity == null)
if (player.AttachedEntity is not {Valid: true} playerEntity)
{
shell.WriteLine("You cannot use this command without an entity.");
return;
}
if (!IoCManager.Resolve<IEntityManager>().TryGetComponent(player.AttachedEntity, out HungerComponent? hunger))
if (!_entities.TryGetComponent(playerEntity, out HungerComponent? hunger))
{
shell.WriteLine($"Your entity does not have a {nameof(HungerComponent)} component.");
return;

View File

@@ -22,8 +22,8 @@ namespace Content.Server.Objectives.Conditions
if (Target.CharacterName != null)
targetName = Target.CharacterName;
else if (Target.OwnedEntity != null)
targetName = IoCManager.Resolve<IEntityManager>().GetComponent<MetaDataComponent>(Target.OwnedEntity).EntityName;
else if (Target.OwnedEntity is {Valid: true} owned)
targetName = IoCManager.Resolve<IEntityManager>().GetComponent<MetaDataComponent>(owned).EntityName;
return Loc.GetString("objective-condition-kill-person-title", ("targetName", targetName));
}

View File

@@ -57,8 +57,8 @@ namespace Content.Server.Objectives.Conditions
{
get
{
if (_mind?.OwnedEntity == null) return 0f;
if (!IoCManager.Resolve<IEntityManager>().TryGetComponent<ContainerManagerComponent?>(_mind.OwnedEntity, out var containerManagerComponent)) return 0f;
if (_mind?.OwnedEntity is not {Valid: true} owned) return 0f;
if (!IoCManager.Resolve<IEntityManager>().TryGetComponent<ContainerManagerComponent?>(owned, out var containerManagerComponent)) return 0f;
float count = containerManagerComponent.CountPrototypeOccurencesRecursive(_prototypeId);
return count/_amount;

View File

@@ -145,7 +145,7 @@ namespace Content.Server.PDA
private void OnUIMessage(PDAComponent pda, ServerBoundUserInterfaceMessage msg)
{
// cast EntityUid? to EntityUid
if (msg.Session.AttachedEntity is not EntityUid playerUid)
if (msg.Session.AttachedEntity is not { } playerUid)
return;
switch (msg.Message)

View File

@@ -152,8 +152,8 @@ namespace Content.Server.ParticleAccelerator.Components
}
if (!obj.Session.AttachedEntity.Valid ||
!EntitySystem.Get<ActionBlockerSystem>().CanInteract(obj.Session.AttachedEntity))
if (obj.Session.AttachedEntity is not {Valid: true} attached ||
!EntitySystem.Get<ActionBlockerSystem>().CanInteract(attached))
{
return;
}

View File

@@ -2,11 +2,9 @@
using System.Collections.Generic;
using Content.Shared.Pulling;
using Robust.Shared.GameObjects;
using Robust.Shared.IoC;
using Robust.Shared.Maths;
using Robust.Shared.Physics;
using Robust.Shared.Physics.Controllers;
using Robust.Shared.Maths;
using Robust.Shared.Utility;
namespace Content.Server.Physics.Controllers
{
@@ -66,32 +64,31 @@ namespace Content.Server.Physics.Controllers
continue;
}
var puller = pullable.Puller;
if (puller == null)
if (pullable.Puller is not {Valid: true} puller)
{
continue;
}
// Now that's over with...
var pullerPosition = IoCManager.Resolve<IEntityManager>().GetComponent<TransformComponent>(puller).MapPosition;
var movingTo = pullable.MovingTo.Value.ToMap(IoCManager.Resolve<IEntityManager>());
var pullerPosition = EntityManager.GetComponent<TransformComponent>(puller).MapPosition;
var movingTo = pullable.MovingTo.Value.ToMap(EntityManager);
if (movingTo.MapId != pullerPosition.MapId)
{
_pullableSystem.StopMoveTo(pullable);
continue;
}
if (!IoCManager.Resolve<IEntityManager>().TryGetComponent<PhysicsComponent?>(pullable.Owner, out var physics) ||
if (!EntityManager.TryGetComponent<PhysicsComponent?>(pullable.Owner, out var physics) ||
physics.BodyType == BodyType.Static ||
movingTo.MapId != IoCManager.Resolve<IEntityManager>().GetComponent<TransformComponent>(pullable.Owner).MapID)
movingTo.MapId != EntityManager.GetComponent<TransformComponent>(pullable.Owner).MapID)
{
_pullableSystem.StopMoveTo(pullable);
continue;
}
var movingPosition = movingTo.Position;
var ownerPosition = IoCManager.Resolve<IEntityManager>().GetComponent<TransformComponent>(pullable.Owner).MapPosition.Position;
var ownerPosition = EntityManager.GetComponent<TransformComponent>(pullable.Owner).MapPosition.Position;
var diff = movingPosition - ownerPosition;
var diffLength = diff.Length;
@@ -119,7 +116,7 @@ namespace Content.Server.Physics.Controllers
var impulse = accel * physics.Mass * frameTime;
physics.ApplyLinearImpulse(impulse);
if (IoCManager.Resolve<IEntityManager>().TryGetComponent<PhysicsComponent?>(puller, out var pullerPhysics))
if (EntityManager.TryGetComponent<PhysicsComponent?>(puller, out var pullerPhysics))
{
pullerPhysics.WakeBody();
pullerPhysics.ApplyLinearImpulse(-impulse);

View File

@@ -1,4 +1,5 @@
using System.Collections.Generic;
using Robust.Shared.GameObjects;
namespace Content.Server.Radio.Components
{

View File

@@ -18,6 +18,8 @@ namespace Content.Server.Storage.Components
[RegisterComponent]
public class SecretStashComponent : Component, IDestroyAct
{
[Dependency] private readonly IEntityManager _entities = default!;
public override string Name => "SecretStash";
[ViewVariables] [DataField("maxItemSize")]
@@ -78,20 +80,20 @@ namespace Content.Server.Storage.Components
/// <returns>True if user recieved item</returns>
public bool TryGetItem(EntityUid user)
{
if (_itemContainer.ContainedEntity == null)
if (_itemContainer.ContainedEntity is not {Valid: true} contained)
return false;
Owner.PopupMessage(user, Loc.GetString("comp-secret-stash-action-get-item-found-something", ("stash", SecretPartName)));
if (IoCManager.Resolve<IEntityManager>().TryGetComponent(user, out HandsComponent? hands))
{
if (!IoCManager.Resolve<IEntityManager>().TryGetComponent(_itemContainer.ContainedEntity, out ItemComponent? item))
if (!IoCManager.Resolve<IEntityManager>().TryGetComponent(contained, out ItemComponent? item))
return false;
hands.PutInHandOrDrop(item);
}
else if (_itemContainer.Remove(_itemContainer.ContainedEntity))
else if (_itemContainer.Remove(contained))
{
IoCManager.Resolve<IEntityManager>().GetComponent<TransformComponent>(_itemContainer.ContainedEntity).Coordinates = IoCManager.Resolve<IEntityManager>().GetComponent<TransformComponent>(Owner).Coordinates;
IoCManager.Resolve<IEntityManager>().GetComponent<TransformComponent>(contained).Coordinates = IoCManager.Resolve<IEntityManager>().GetComponent<TransformComponent>(Owner).Coordinates;
}
return true;
@@ -109,9 +111,9 @@ namespace Content.Server.Storage.Components
public void OnDestroy(DestructionEventArgs eventArgs)
{
// drop item inside
if (_itemContainer.ContainedEntity != null)
if (_itemContainer.ContainedEntity is {Valid: true} contained)
{
IoCManager.Resolve<IEntityManager>().GetComponent<TransformComponent>(_itemContainer.ContainedEntity).Coordinates = IoCManager.Resolve<IEntityManager>().GetComponent<TransformComponent>(Owner).Coordinates;
_entities.GetComponent<TransformComponent>(contained).Coordinates = _entities.GetComponent<TransformComponent>(Owner).Coordinates;
}
}
}

View File

@@ -452,9 +452,7 @@ namespace Content.Server.Storage.Components
{
EnsureInitialCalculated();
var player = session.AttachedEntity;
if (!player.Valid)
if (session.AttachedEntity is not {Valid: true} player)
{
break;
}
@@ -491,9 +489,7 @@ namespace Content.Server.Storage.Components
{
EnsureInitialCalculated();
var player = session.AttachedEntity;
if (player == null)
if (session.AttachedEntity is not {Valid: true} player)
{
break;
}
@@ -570,7 +566,7 @@ namespace Content.Server.Storage.Components
// Pick up all entities in a radius around the clicked location.
// The last half of the if is because carpets exist and this is terrible
if (_areaInsert && (eventArgs.Target == null || !_entityManager.HasComponent<SharedItemComponent>(eventArgs.Target)))
if (_areaInsert && (eventArgs.Target == null || !_entityManager.HasComponent<SharedItemComponent>(eventArgs.Target.Value)))
{
var validStorables = new List<EntityUid>();
foreach (var entity in IoCManager.Resolve<IEntityLookup>().GetEntitiesInRange(eventArgs.ClickLocation, _areaInsertRadius, LookupFlags.None))

View File

@@ -151,13 +151,13 @@ namespace Content.Server.Storage.EntitySystems
var attachedEntity = session.AttachedEntity;
// The component manages the set of sessions, so this invalid session should be removed soon.
if (attachedEntity == null || !IoCManager.Resolve<IEntityManager>().EntityExists(attachedEntity))
if (attachedEntity == null || !IoCManager.Resolve<IEntityManager>().EntityExists(attachedEntity.Value))
continue;
if (storageMap != IoCManager.Resolve<IEntityManager>().GetComponent<TransformComponent>(attachedEntity).MapID)
if (storageMap != IoCManager.Resolve<IEntityManager>().GetComponent<TransformComponent>(attachedEntity.Value).MapID)
continue;
var distanceSquared = (storagePos - IoCManager.Resolve<IEntityManager>().GetComponent<TransformComponent>(attachedEntity).WorldPosition).LengthSquared;
var distanceSquared = (storagePos - IoCManager.Resolve<IEntityManager>().GetComponent<TransformComponent>(attachedEntity.Value).WorldPosition).LengthSquared;
if (distanceSquared > InteractionSystem.InteractionRangeSquared)
{
storageComp.UnsubscribeSession(session);

View File

@@ -25,6 +25,8 @@ namespace Content.Server.Strip
[ComponentReference(typeof(SharedStrippableComponent))]
public sealed class StrippableComponent : SharedStrippableComponent
{
[Dependency] private readonly IEntityManager _entities = default!;
public const float StripDelay = 2f;
// TODO: This component needs localization.
@@ -45,17 +47,17 @@ namespace Content.Server.Strip
Owner.EnsureComponentWarn<HandsComponent>();
Owner.EnsureComponentWarn<CuffableComponent>();
if (IoCManager.Resolve<IEntityManager>().TryGetComponent(Owner, out CuffableComponent? cuffed))
if (_entities.TryGetComponent(Owner, out CuffableComponent? cuffed))
{
cuffed.OnCuffedStateChanged += UpdateSubscribed;
}
if (IoCManager.Resolve<IEntityManager>().TryGetComponent(Owner, out InventoryComponent? inventory))
if (_entities.TryGetComponent(Owner, out InventoryComponent? inventory))
{
inventory.OnItemChanged += UpdateSubscribed;
}
if (IoCManager.Resolve<IEntityManager>().TryGetComponent(Owner, out HandsComponent? hands))
if (_entities.TryGetComponent(Owner, out HandsComponent? hands))
{
hands.OnItemChanged += UpdateSubscribed;
}
@@ -80,7 +82,7 @@ namespace Content.Server.Strip
public override bool Drop(DragDropEvent args)
{
if (!IoCManager.Resolve<IEntityManager>().TryGetComponent(args.User, out ActorComponent? actor)) return false;
if (!_entities.TryGetComponent(args.User, out ActorComponent? actor)) return false;
OpenUserInterface(actor.PlayerSession);
return true;
@@ -90,14 +92,15 @@ namespace Content.Server.Strip
{
var dictionary = new Dictionary<EntityUid, string>();
if (!IoCManager.Resolve<IEntityManager>().TryGetComponent(Owner, out CuffableComponent? cuffed))
if (!_entities.TryGetComponent(Owner, out CuffableComponent? cuffed))
{
return dictionary;
}
foreach (EntityUid entity in cuffed.StoredEntities)
foreach (var entity in cuffed.StoredEntities)
{
dictionary.Add(entity, entity.Name);
var name = _entities.GetComponent<MetaDataComponent>(entity).EntityName;
dictionary.Add(entity, name);
}
return dictionary;
@@ -107,7 +110,7 @@ namespace Content.Server.Strip
{
var dictionary = new Dictionary<Slots, string>();
if (!IoCManager.Resolve<IEntityManager>().TryGetComponent(Owner, out InventoryComponent? inventory))
if (!_entities.TryGetComponent(Owner, out InventoryComponent? inventory))
{
return dictionary;
}
@@ -117,7 +120,7 @@ namespace Content.Server.Strip
var name = "None";
if (inventory.GetSlotItem(slot) is { } item)
name = item.Owner.Name;
name = _entities.GetComponent<MetaDataComponent>(item.Owner).EntityName;
dictionary[slot] = name;
}
@@ -129,7 +132,7 @@ namespace Content.Server.Strip
{
var dictionary = new Dictionary<string, string>();
if (!IoCManager.Resolve<IEntityManager>().TryGetComponent(Owner, out HandsComponent? hands))
if (!_entities.TryGetComponent(Owner, out HandsComponent? hands))
{
return dictionary;
}
@@ -138,13 +141,13 @@ namespace Content.Server.Strip
{
var owner = hands.GetItem(hand)?.Owner;
if ((owner != null ? IoCManager.Resolve<IEntityManager>().HasComponent<HandVirtualItemComponent>(owner) : (bool?) null) ?? true)
if (!owner.HasValue || _entities.HasComponent<HandVirtualItemComponent>(owner.Value))
{
dictionary[hand] = "None";
continue;
}
dictionary[hand] = owner.Name;
dictionary[hand] = _entities.GetComponent<MetaDataComponent>(owner.Value).EntityName;
}
return dictionary;
@@ -160,8 +163,8 @@ namespace Content.Server.Strip
/// </summary>
private async void PlaceActiveHandItemInInventory(EntityUid user, Slots slot)
{
var inventory = IoCManager.Resolve<IEntityManager>().GetComponent<InventoryComponent>(Owner);
var userHands = IoCManager.Resolve<IEntityManager>().GetComponent<HandsComponent>(user);
var inventory = _entities.GetComponent<InventoryComponent>(Owner);
var userHands = _entities.GetComponent<HandsComponent>(user);
var item = userHands.GetActiveHand;
bool Check()
@@ -225,8 +228,8 @@ namespace Content.Server.Strip
/// </summary>
private async void PlaceActiveHandItemInHands(EntityUid user, string hand)
{
var hands = IoCManager.Resolve<IEntityManager>().GetComponent<HandsComponent>(Owner);
var userHands = IoCManager.Resolve<IEntityManager>().GetComponent<HandsComponent>(user);
var hands = _entities.GetComponent<HandsComponent>(Owner);
var userHands = _entities.GetComponent<HandsComponent>(user);
var item = userHands.GetActiveHand;
bool Check()
@@ -291,8 +294,8 @@ namespace Content.Server.Strip
/// </summary>
private async void TakeItemFromInventory(EntityUid user, Slots slot)
{
var inventory = IoCManager.Resolve<IEntityManager>().GetComponent<InventoryComponent>(Owner);
var userHands = IoCManager.Resolve<IEntityManager>().GetComponent<HandsComponent>(user);
var inventory = _entities.GetComponent<InventoryComponent>(Owner);
var userHands = _entities.GetComponent<HandsComponent>(user);
bool Check()
{
@@ -347,8 +350,8 @@ namespace Content.Server.Strip
/// </summary>
private async void TakeItemFromHands(EntityUid user, string hand)
{
var hands = IoCManager.Resolve<IEntityManager>().GetComponent<HandsComponent>(Owner);
var userHands = IoCManager.Resolve<IEntityManager>().GetComponent<HandsComponent>(user);
var hands = _entities.GetComponent<HandsComponent>(Owner);
var userHands = _entities.GetComponent<HandsComponent>(user);
bool Check()
{
@@ -364,7 +367,7 @@ namespace Content.Server.Strip
return false;
}
if (IoCManager.Resolve<IEntityManager>().HasComponent<HandVirtualItemComponent>(heldItem.Owner))
if (_entities.HasComponent<HandVirtualItemComponent>(heldItem.Owner))
return false;
if (!hands.CanDrop(hand, false))
@@ -398,8 +401,9 @@ namespace Content.Server.Strip
private void HandleUserInterfaceMessage(ServerBoundUserInterfaceMessage obj)
{
var user = obj.Session.AttachedEntity;
if (user == null || !IoCManager.Resolve<IEntityManager>().TryGetComponent(user, out HandsComponent? userHands)) return;
if (obj.Session.AttachedEntity is not {Valid: true} user ||
!_entities.TryGetComponent(user, out HandsComponent? userHands))
return;
var placingItem = userHands.GetActiveHand != null;
@@ -407,7 +411,7 @@ namespace Content.Server.Strip
{
case StrippingInventoryButtonPressed inventoryMessage:
if (IoCManager.Resolve<IEntityManager>().TryGetComponent<InventoryComponent?>(Owner, out var inventory))
if (_entities.TryGetComponent<InventoryComponent?>(Owner, out var inventory))
{
if (inventory.TryGetSlotItem(inventoryMessage.Slot, out ItemComponent? _))
placingItem = false;
@@ -421,7 +425,7 @@ namespace Content.Server.Strip
case StrippingHandButtonPressed handMessage:
if (IoCManager.Resolve<IEntityManager>().TryGetComponent<HandsComponent?>(Owner, out var hands))
if (_entities.TryGetComponent<HandsComponent?>(Owner, out var hands))
{
if (hands.TryGetItem(handMessage.Hand, out _))
placingItem = false;
@@ -435,7 +439,7 @@ namespace Content.Server.Strip
case StrippingHandcuffButtonPressed handcuffMessage:
if (IoCManager.Resolve<IEntityManager>().TryGetComponent<CuffableComponent?>(Owner, out var cuffed))
if (_entities.TryGetComponent<CuffableComponent?>(Owner, out var cuffed))
{
foreach (var entity in cuffed.StoredEntities)
{

View File

@@ -10,6 +10,7 @@ using Content.Shared.Audio;
using Content.Shared.Examine;
using Content.Shared.Interaction;
using Content.Shared.Jittering;
using Content.Shared.Popups;
using Content.Shared.StatusEffect;
using Content.Shared.Stunnable;
using Content.Shared.Throwing;

View File

@@ -133,7 +133,7 @@ namespace Content.Server.UserInterface
public class ActivatableUIOpenAttemptEvent : CancellableEntityEventArgs
{
public EntityUidUser { get; }
public EntityUid user { get; }
public ActivatableUIOpenAttemptEvent(EntityUidwho)
{
User = who;

View File

@@ -208,18 +208,18 @@ namespace Content.Server.Weapon.Melee
return;
}
if (!args.Target.Valid)
if (!args.Target.HasValue)
return;
var location = IoCManager.Resolve<IEntityManager>().GetComponent<TransformComponent>(args.User).Coordinates;
var diff = args.ClickLocation.ToMapPos(IoCManager.Resolve<IEntityManager>()) - location.ToMapPos(IoCManager.Resolve<IEntityManager>());
var angle = Angle.FromWorldVec(diff);
var hitEvent = new MeleeInteractEvent(args.Target, args.User);
var hitEvent = new MeleeInteractEvent(args.Target.Value, args.User);
RaiseLocalEvent(owner, hitEvent, false);
if (!hitEvent.CanInteract) return;
SendAnimation(comp.ClickArc, angle, args.User, owner, new List<EntityUid>() { args.Target }, comp.ClickAttackEffect, false);
SendAnimation(comp.ClickArc, angle, args.User, owner, new List<EntityUid>() { args.Target.Value }, comp.ClickAttackEffect, false);
comp.LastAttackTime = curTime;
comp.CooldownEnd = comp.LastAttackTime + TimeSpan.FromSeconds(comp.CooldownTime);

View File

@@ -22,6 +22,8 @@ namespace Content.Server.Weapon.Ranged.Ammunition.Components
public sealed class AmmoBoxComponent : Component, IInteractUsing, IUse, IInteractHand, IMapInit, IExamine
#pragma warning restore 618
{
[Dependency] private readonly IEntityManager _entities = default!;
public override string Name => "AmmoBox";
[DataField("caliber")]
@@ -73,7 +75,7 @@ namespace Content.Server.Weapon.Ranged.Ammunition.Components
private void UpdateAppearance()
{
if (IoCManager.Resolve<IEntityManager>().TryGetComponent(Owner, out AppearanceComponent? appearanceComponent))
if (_entities.TryGetComponent(Owner, out AppearanceComponent? appearanceComponent))
{
appearanceComponent.SetData(MagazineBarrelVisuals.MagLoaded, true);
appearanceComponent.SetData(AmmoVisuals.AmmoCount, AmmoLeft);
@@ -81,7 +83,7 @@ namespace Content.Server.Weapon.Ranged.Ammunition.Components
}
}
public EntityUid TakeAmmo()
public EntityUid? TakeAmmo()
{
if (_spawnedAmmo.TryPop(out var ammo))
{
@@ -91,10 +93,10 @@ namespace Content.Server.Weapon.Ranged.Ammunition.Components
if (_unspawnedCount > 0)
{
ammo = IoCManager.Resolve<IEntityManager>().SpawnEntity(_fillPrototype, IoCManager.Resolve<IEntityManager>().GetComponent<TransformComponent>(Owner).Coordinates);
ammo = _entities.SpawnEntity(_fillPrototype, _entities.GetComponent<TransformComponent>(Owner).Coordinates);
// when dumping from held ammo box, this detaches the spawned ammo from the player.
IoCManager.Resolve<IEntityManager>().GetComponent<TransformComponent>(ammo).AttachParentToContainerOrGrid();
_entities.GetComponent<TransformComponent>(ammo).AttachParentToContainerOrGrid();
_unspawnedCount--;
}
@@ -104,7 +106,7 @@ namespace Content.Server.Weapon.Ranged.Ammunition.Components
public bool TryInsertAmmo(EntityUid user, EntityUid entity)
{
if (!IoCManager.Resolve<IEntityManager>().TryGetComponent(entity, out AmmoComponent? ammoComponent))
if (!_entities.TryGetComponent(entity, out AmmoComponent? ammoComponent))
{
return false;
}
@@ -129,12 +131,12 @@ namespace Content.Server.Weapon.Ranged.Ammunition.Components
async Task<bool> IInteractUsing.InteractUsing(InteractUsingEventArgs eventArgs)
{
if (IoCManager.Resolve<IEntityManager>().HasComponent<AmmoComponent>(eventArgs.Using))
if (_entities.HasComponent<AmmoComponent>(eventArgs.Using))
{
return TryInsertAmmo(eventArgs.User, eventArgs.Using);
}
if (IoCManager.Resolve<IEntityManager>().TryGetComponent(eventArgs.Using, out RangedMagazineComponent? rangedMagazine))
if (_entities.TryGetComponent(eventArgs.Using, out RangedMagazineComponent? rangedMagazine))
{
for (var i = 0; i < Math.Max(10, rangedMagazine.ShotsLeft); i++)
{
@@ -160,19 +162,17 @@ namespace Content.Server.Weapon.Ranged.Ammunition.Components
private bool TryUse(EntityUid user)
{
if (!IoCManager.Resolve<IEntityManager>().TryGetComponent(user, out HandsComponent? handsComponent))
if (!_entities.TryGetComponent(user, out HandsComponent? handsComponent))
{
return false;
}
var ammo = TakeAmmo();
if (ammo == null)
if (TakeAmmo() is not { } ammo)
{
return false;
}
if (IoCManager.Resolve<IEntityManager>().TryGetComponent(ammo, out ItemComponent? item))
if (_entities.TryGetComponent(ammo, out ItemComponent? item))
{
if (!handsComponent.CanPutInHand(item))
{
@@ -194,8 +194,7 @@ namespace Content.Server.Weapon.Ranged.Ammunition.Components
for (var i = 0; i < Math.Min(count, Capacity); i++)
{
var ammo = TakeAmmo();
if (ammo == null)
if (TakeAmmo() is not { } ammo)
{
break;
}

View File

@@ -259,24 +259,27 @@ namespace Content.Server.Weapon.Ranged.Barrels.Components
/// <param name="robustRandom"></param>
/// <param name="prototypeManager"></param>
/// <param name="ejectDirections"></param>
public void EjectCasing(
public static void EjectCasing(
EntityUid entity,
bool playSound = true,
Direction[]? ejectDirections = null,
IRobustRandom? robustRandom = null,
IPrototypeManager? prototypeManager = null,
Direction[]? ejectDirections = null)
IEntityManager? entities = null)
{
robustRandom ??= IoCManager.Resolve<IRobustRandom>();
IoCManager.Resolve(ref robustRandom, ref prototypeManager, ref entities);
ejectDirections ??= new[]
{Direction.East, Direction.North, Direction.NorthWest, Direction.South, Direction.SouthEast, Direction.West};
const float ejectOffset = 1.8f;
var ammo = _entities.GetComponent<AmmoComponent>(entity);
var ammo = entities.GetComponent<AmmoComponent>(entity);
var offsetPos = ((robustRandom.NextFloat() - 0.5f) * ejectOffset, (robustRandom.NextFloat() - 0.5f) * ejectOffset);
_entities.GetComponent<TransformComponent>(entity).Coordinates = _entities.GetComponent<TransformComponent>(entity).Coordinates.Offset(offsetPos);
_entities.GetComponent<TransformComponent>(entity).LocalRotation = robustRandom.Pick(ejectDirections).ToAngle();
entities.GetComponent<TransformComponent>(entity).Coordinates = entities.GetComponent<TransformComponent>(entity).Coordinates.Offset(offsetPos);
entities.GetComponent<TransformComponent>(entity).LocalRotation = robustRandom.Pick(ejectDirections).ToAngle();
SoundSystem.Play(Filter.Broadcast(), ammo.SoundCollectionEject.GetSound(), _entities.GetComponent<TransformComponent>(entity).Coordinates, AudioParams.Default.WithVolume(-1));
var coordinates = entities.GetComponent<TransformComponent>(entity).Coordinates;
SoundSystem.Play(Filter.Broadcast(), ammo.SoundCollectionEject.GetSound(), coordinates, AudioParams.Default.WithVolume(-1));
}
/// <summary>
@@ -284,7 +287,7 @@ namespace Content.Server.Weapon.Ranged.Barrels.Components
/// Wraps EjectCasing to make it less toxic for bulk ejections
/// </summary>
/// <param name="entities"></param>
public void EjectCasings(IEnumerable<EntityUid> entities)
public static void EjectCasings(IEnumerable<EntityUid> entities)
{
var robustRandom = IoCManager.Resolve<IRobustRandom>();
var prototypeManager = IoCManager.Resolve<IPrototypeManager>();
@@ -294,7 +297,7 @@ namespace Content.Server.Weapon.Ranged.Barrels.Components
foreach (var entity in entities)
{
EjectCasing(entity, playSound, robustRandom, prototypeManager, ejectDirections);
EjectCasing(entity, playSound, ejectDirections, robustRandom, prototypeManager);
soundPlayCount++;
if (soundPlayCount > 3)
{

View File

@@ -24,7 +24,7 @@ namespace Content.Shared.Pulling.Components
/// The current entity pulling this component.
/// SharedPullingStateManagementSystem should be writing this. This means definitely not you.
/// </summary>
public EntityUid Puller { get; set; }
public EntityUid? Puller { get; set; }
/// <summary>
/// The pull joint.
/// SharedPullingStateManagementSystem should be writing this. This means probably not you.

View File

@@ -17,7 +17,7 @@ namespace Content.Shared.Pulling.Components
public float SprintSpeedModifier => Pulling == default ? 1.0f : 0.75f;
[ViewVariables]
public EntityUid Pulling { get; set; }
public EntityUid? Pulling { get; set; }
protected override void Shutdown()
{

View File

@@ -20,7 +20,7 @@ namespace Content.Shared.Pulling.Systems
private void OnRelayMoveInput(EntityUid uid, SharedPullableComponent component, RelayMoveInputEvent args)
{
var entity = args.Session.AttachedEntity;
if (!entity.IsValid() || !_blocker.CanMove(entity)) return;
if (!entity.HasValue || !_blocker.CanMove(entity.Value)) return;
_pullSystem.TryStopPull(component);
}
}

View File

@@ -41,7 +41,7 @@ namespace Content.Shared.Verbs
// call ActionBlocker checks, just cache it for the verb request.
var canInteract = force || _actionBlockerSystem.CanInteract(user);
EntityUid? @using = null;
EntityUid @using = default;
if (EntityManager.TryGetComponent(user, out SharedHandsComponent? hands) && (force || _actionBlockerSystem.CanUse(user)))
{
hands.TryGetActiveHeldEntity(out @using);
@@ -49,9 +49,9 @@ namespace Content.Shared.Verbs
// Check whether the "Held" entity is a virtual pull entity. If yes, set that as the entity being "Used".
// This allows you to do things like buckle a dragged person onto a surgery table, without click-dragging
// their sprite.
if (@using != null && EntityManager.TryGetComponent<HandVirtualItemComponent?>(@using.Value, out var pull))
if (@using != default && EntityManager.TryGetComponent<HandVirtualItemComponent?>(@using, out var pull))
{
@using = pull.BlockingEntity
@using = pull.BlockingEntity;
}
}
@@ -110,25 +110,25 @@ namespace Content.Shared.Verbs
}
}
public void LogVerb(Verb verb, EntityUid userUid, EntityUid targetUid, bool forced)
public void LogVerb(Verb verb, EntityUid user, EntityUid target, bool forced)
{
// first get the held item. again.
EntityUid usedUid = default;
if (EntityManager.TryGetComponent(userUid, out SharedHandsComponent? hands) &&
if (EntityManager.TryGetComponent(user, out SharedHandsComponent? hands) &&
hands.TryGetActiveHeldEntity(out var heldEntity))
{
usedUid = heldEntity;
if (usedUid != null && EntityManager.TryGetComponent(usedUid.Value, out HandVirtualItemComponent? pull))
if (usedUid != default && EntityManager.TryGetComponent(usedUid, out HandVirtualItemComponent? pull))
usedUid = pull.BlockingEntity;
}
// get all the entities
if (!userUid.IsValid() || !targetUid.IsValid())
if (!user.IsValid() || !target.IsValid())
return;
EntityUid? used = null;
if (usedUid != null)
EntityManager.EntityExists(usedUid.Value);
if (usedUid != default)
EntityManager.EntityExists(usedUid);
// then prepare the basic log message body
var verbText = $"{verb.Category?.Text} {verb.Text}".Trim();
@@ -137,7 +137,7 @@ namespace Content.Shared.Verbs
: $"executed '{verbText}' verb targeting ";
// then log with entity information
if (usedUidused != null)
if (used != null)
_logSystem.Add(LogType.Verb, verb.Impact,
$"{user} {logText} {target} while holding {used}");
else