diff --git a/Content.Client/Conveyor/Visualizers/ConveyorVisualizer.cs b/Content.Client/Conveyor/Visualizers/ConveyorVisualizer.cs index b845572dc2..5a40c18de5 100644 --- a/Content.Client/Conveyor/Visualizers/ConveyorVisualizer.cs +++ b/Content.Client/Conveyor/Visualizers/ConveyorVisualizer.cs @@ -23,7 +23,7 @@ namespace Content.Client.Conveyor.Visualizers private void ChangeState(AppearanceComponent appearance) { var entities = IoCManager.Resolve(); - if (!entities.TryGetComponent(appearance.OwnerUid, out ISpriteComponent? sprite)) + if (!entities.TryGetComponent(appearance.Owner, out ISpriteComponent? sprite)) { return; } diff --git a/Content.Client/Conveyor/Visualizers/TwoWayLeverVisualizer.cs b/Content.Client/Conveyor/Visualizers/TwoWayLeverVisualizer.cs index c36fd08ebb..6608578501 100644 --- a/Content.Client/Conveyor/Visualizers/TwoWayLeverVisualizer.cs +++ b/Content.Client/Conveyor/Visualizers/TwoWayLeverVisualizer.cs @@ -22,7 +22,7 @@ namespace Content.Client.Conveyor.Visualizers private void ChangeState(AppearanceComponent appearance) { var entities = IoCManager.Resolve(); - if (!entities.TryGetComponent(appearance.OwnerUid, out ISpriteComponent? sprite)) + if (!entities.TryGetComponent(appearance.Owner, out ISpriteComponent? sprite)) { return; } diff --git a/Content.Client/Disposal/Visualizers/DisposalUnitVisualizer.cs b/Content.Client/Disposal/Visualizers/DisposalUnitVisualizer.cs index d78bdfc145..0e5ec4935b 100644 --- a/Content.Client/Disposal/Visualizers/DisposalUnitVisualizer.cs +++ b/Content.Client/Disposal/Visualizers/DisposalUnitVisualizer.cs @@ -71,7 +71,7 @@ namespace Content.Client.Disposal.Visualizers } var entities = IoCManager.Resolve(); - if (!entities.TryGetComponent(appearance.OwnerUid, out ISpriteComponent? sprite)) + if (!entities.TryGetComponent(appearance.Owner, out ISpriteComponent? sprite)) { return; } @@ -90,7 +90,7 @@ namespace Content.Client.Disposal.Visualizers case VisualState.Flushing: sprite.LayerSetState(DisposalUnitVisualLayers.Base, _stateAnchored); - var animPlayer = IoCManager.Resolve().GetComponent(appearance.OwnerUid); + var animPlayer = IoCManager.Resolve().GetComponent(appearance.Owner); if (!animPlayer.HasRunningAnimation(AnimationKey)) { diff --git a/Content.Client/Disposal/Visualizers/DisposalVisualizer.cs b/Content.Client/Disposal/Visualizers/DisposalVisualizer.cs index d8f8a03c90..98b9a33eea 100644 --- a/Content.Client/Disposal/Visualizers/DisposalVisualizer.cs +++ b/Content.Client/Disposal/Visualizers/DisposalVisualizer.cs @@ -24,7 +24,7 @@ namespace Content.Client.Disposal.Visualizers private void ChangeState(AppearanceComponent appearance) { var entities = IoCManager.Resolve(); - if (!entities.TryGetComponent(appearance.OwnerUid, out ISpriteComponent? sprite)) + if (!entities.TryGetComponent(appearance.Owner, out ISpriteComponent? sprite)) { return; } @@ -48,9 +48,9 @@ namespace Content.Client.Disposal.Visualizers { appearance.Owner.EnsureComponent(); } - else if (IoCManager.Resolve().HasComponent(appearance.OwnerUid)) + else if (entities.HasComponent(appearance.Owner)) { - IoCManager.Resolve().RemoveComponent(appearance.OwnerUid); + entities.RemoveComponent(appearance.Owner); } } diff --git a/Content.Client/Singularity/SingularityOverlay.cs b/Content.Client/Singularity/SingularityOverlay.cs index a1abd79119..9157e859a1 100644 --- a/Content.Client/Singularity/SingularityOverlay.cs +++ b/Content.Client/Singularity/SingularityOverlay.cs @@ -76,7 +76,7 @@ namespace Content.Client.Singularity var distortions = _entityManager.EntityQuery(); foreach (var distortion in distortions) //Add all singulos that are not added yet but qualify { - var singuloEntity = distortion.OwnerUid; + var singuloEntity = distortion.Owner; if (!_singularities.Keys.Contains(singuloEntity) && SinguloQualifies(singuloEntity, currentEyeLoc)) { diff --git a/Content.Client/StationEvents/RadiationPulseOverlay.cs b/Content.Client/StationEvents/RadiationPulseOverlay.cs index 79b22b680d..a4f8f0ad15 100644 --- a/Content.Client/StationEvents/RadiationPulseOverlay.cs +++ b/Content.Client/StationEvents/RadiationPulseOverlay.cs @@ -84,7 +84,7 @@ namespace Content.Client.StationEvents var pulses = _entityManager.EntityQuery(); foreach (var pulse in pulses) //Add all pulses that are not added yet but qualify { - var pulseEntity = pulse.OwnerUid; + var pulseEntity = pulse.Owner; if (!_pulses.Keys.Contains(pulseEntity) && PulseQualifies(pulseEntity, currentEyeLoc)) { diff --git a/Content.Server/Access/Systems/AccessReaderSystem.cs b/Content.Server/Access/Systems/AccessReaderSystem.cs index 4557d8983a..0a14852427 100644 --- a/Content.Server/Access/Systems/AccessReaderSystem.cs +++ b/Content.Server/Access/Systems/AccessReaderSystem.cs @@ -84,7 +84,7 @@ namespace Content.Server.Access.Systems { if (inventoryComponent.HasSlot(EquipmentSlotDefines.Slots.IDCARD) && inventoryComponent.TryGetSlotItem(EquipmentSlotDefines.Slots.IDCARD, out ItemComponent? item) && - FindAccessTagsItem(item.OwnerUid, out tags) + FindAccessTagsItem(item.Owner, out tags) ) { return tags; diff --git a/Content.Server/Advertise/AdvertiseSystem.cs b/Content.Server/Advertise/AdvertiseSystem.cs index a0572699c2..3ffdc39eb1 100644 --- a/Content.Server/Advertise/AdvertiseSystem.cs +++ b/Content.Server/Advertise/AdvertiseSystem.cs @@ -3,7 +3,6 @@ using Content.Server.Advertisements; using Content.Server.Chat.Managers; using Content.Server.Power.Components; using Content.Server.VendingMachines; -using Content.Shared.Acts; using Robust.Shared.GameObjects; using Robust.Shared.IoC; using Robust.Shared.Localization; @@ -61,7 +60,7 @@ namespace Content.Server.Advertise return; if (_prototypeManager.TryIndex(advertise.PackPrototypeId, out AdvertisementsPackPrototype? advertisements)) - _chatManager.EntitySay(advertise.OwnerUid, Loc.GetString(_random.Pick(advertisements.Advertisements)), hideChat: true); + _chatManager.EntitySay(advertise.Owner, Loc.GetString(_random.Pick(advertisements.Advertisements)), hideChat: true); if(refresh) RefreshTimer(uid, true, advertise); @@ -117,7 +116,7 @@ namespace Content.Server.Advertise if (advertise.NextAdvertisementTime > curTime) continue; - SayAdvertisement(advertise.OwnerUid, true, advertise); + SayAdvertisement(advertise.Owner, true, advertise); } } } diff --git a/Content.Server/Atmos/EntitySystems/AirtightSystem.cs b/Content.Server/Atmos/EntitySystems/AirtightSystem.cs index f128b7437a..8765ec1fcd 100644 --- a/Content.Server/Atmos/EntitySystems/AirtightSystem.cs +++ b/Content.Server/Atmos/EntitySystems/AirtightSystem.cs @@ -29,7 +29,7 @@ namespace Content.Server.Atmos.EntitySystems { if (airtight.FixAirBlockedDirectionInitialize) { - var rotateEvent = new RotateEvent(airtight.OwnerUid, Angle.Zero, IoCManager.Resolve().GetComponent(airtight.Owner).WorldRotation); + var rotateEvent = new RotateEvent(airtight.Owner, Angle.Zero, IoCManager.Resolve().GetComponent(airtight.Owner).WorldRotation); OnAirtightRotated(uid, airtight, ref rotateEvent); } @@ -79,7 +79,7 @@ namespace Content.Server.Atmos.EntitySystems { airtight.AirBlocked = airblocked; UpdatePosition(airtight); - RaiseLocalEvent(((IComponent) airtight).OwnerUid, new AirtightChanged(airtight)); + RaiseLocalEvent(((IComponent) airtight).Owner, new AirtightChanged(airtight)); } public void UpdatePosition(AirtightComponent airtight) diff --git a/Content.Server/Hands/Systems/HandsSystem.cs b/Content.Server/Hands/Systems/HandsSystem.cs index cf03c09f3f..774dcf8fea 100644 --- a/Content.Server/Hands/Systems/HandsSystem.cs +++ b/Content.Server/Hands/Systems/HandsSystem.cs @@ -218,11 +218,8 @@ namespace Content.Server.Hands.Systems if (session is not IPlayerSession playerSession) return false; - var maybePlayer = playerSession.AttachedEntity; - if (!maybePlayer.HasValue) return false; - var player = maybePlayer.Value; - - if (!EntityManager.EntityExists(player) || + if (playerSession.AttachedEntity is not {Valid: true} player || + !EntityManager.EntityExists(player) || player.IsInContainer() || !EntityManager.TryGetComponent(player, out SharedHandsComponent? hands) || !hands.TryGetActiveHeldEntity(out var throwEnt) || @@ -231,7 +228,7 @@ namespace Content.Server.Hands.Systems if (EntityManager.TryGetComponent(throwEnt, out StackComponent? stack) && stack.Count > 1 && stack.ThrowIndividually) { - var splitStack = _stackSystem.Split(throwEnt, 1, EntityManager.GetComponent(playerEnt).Coordinates, stack); + var splitStack = _stackSystem.Split(throwEnt, 1, EntityManager.GetComponent(player).Coordinates, stack); if (splitStack is not {Valid: true}) return false; @@ -241,14 +238,14 @@ namespace Content.Server.Hands.Systems else if (!hands.Drop(throwEnt)) return false; - var direction = coords.ToMapPos(EntityManager) - EntityManager.GetComponent(playerEnt).WorldPosition; + var direction = coords.ToMapPos(EntityManager) - EntityManager.GetComponent(player).WorldPosition; if (direction == Vector2.Zero) return true; direction = direction.Normalized * Math.Min(direction.Length, hands.ThrowRange); var throwStrength = hands.ThrowForceMultiplier; - throwEnt.TryThrow(direction, throwStrength, playerEnt); + throwEnt.TryThrow(direction, throwStrength, player); return true; } @@ -276,7 +273,7 @@ namespace Content.Server.Hands.Systems return; if (!inventory.TryGetSlotItem(equipmentSlot, out ItemComponent? equipmentItem) || - !EntityManager.TryGetComponent(equipmentItem.OwnerUid, out ServerStorageComponent? storageComponent)) + !EntityManager.TryGetComponent(equipmentItem.Owner, out ServerStorageComponent? storageComponent)) { plyEnt.PopupMessage(Loc.GetString("hands-system-missing-equipment-slot", ("slotName", SlotNames[equipmentSlot].ToLower()))); return; diff --git a/Content.Server/Headset/HeadsetComponent.cs b/Content.Server/Headset/HeadsetComponent.cs index 2e3232ec84..92970f1e6c 100644 --- a/Content.Server/Headset/HeadsetComponent.cs +++ b/Content.Server/Headset/HeadsetComponent.cs @@ -59,7 +59,7 @@ namespace Content.Server.Headset { if (Owner.TryGetContainer(out var container)) { - if (!IoCManager.Resolve().TryGetComponent(container.OwnerUid, out ActorComponent? actor)) + if (!IoCManager.Resolve().TryGetComponent(container.Owner, out ActorComponent? actor)) return; var playerChannel = actor.PlayerSession.ConnectedClient; diff --git a/Content.Server/Medical/MedicalScannerSystem.cs b/Content.Server/Medical/MedicalScannerSystem.cs index c7be09be5b..783e8ae7c0 100644 --- a/Content.Server/Medical/MedicalScannerSystem.cs +++ b/Content.Server/Medical/MedicalScannerSystem.cs @@ -1,7 +1,7 @@ using Content.Server.Medical.Components; using Content.Shared.ActionBlocker; -using Content.Shared.Verbs; using Content.Shared.Movement; +using Content.Shared.Verbs; using JetBrains.Annotations; using Robust.Shared.GameObjects; using Robust.Shared.IoC; @@ -32,13 +32,13 @@ namespace Content.Server.Medical !args.CanAccess || !args.CanInteract || component.IsOccupied || - !component.CanInsert(args.Using)) + !component.CanInsert(args.Using.Value)) return; Verb verb = new(); - verb.Act = () => component.InsertBody(args.Using); + verb.Act = () => component.InsertBody(args.Using.Value); verb.Category = VerbCategory.Insert; - verb.Text = IoCManager.Resolve().GetComponent(args.Using).EntityName; + verb.Text = IoCManager.Resolve().GetComponent(args.Using.Value).EntityName; args.Verbs.Add(verb); } diff --git a/Content.Server/Mind/Components/MindComponent.cs b/Content.Server/Mind/Components/MindComponent.cs index 407fc6dc08..e39478324b 100644 --- a/Content.Server/Mind/Components/MindComponent.cs +++ b/Content.Server/Mind/Components/MindComponent.cs @@ -84,8 +84,7 @@ namespace Content.Server.Mind.Components if (HasMind) { - var visiting = Mind?.VisitingEntity; - if (visiting != null) + if (Mind?.VisitingEntity is {Valid: true} visiting) { if (IoCManager.Resolve().TryGetComponent(visiting, out GhostComponent? ghost)) { diff --git a/Content.Server/Mind/Mind.cs b/Content.Server/Mind/Mind.cs index 09368d1d3f..eb473652ed 100644 --- a/Content.Server/Mind/Mind.cs +++ b/Content.Server/Mind/Mind.cs @@ -263,25 +263,25 @@ namespace Content.Server.Mind /// /// Thrown if is already owned by another mind. /// - public void TransferTo(EntityUid entity = default, bool ghostCheckOverride = false) + public void TransferTo(EntityUid? entity, bool ghostCheckOverride = false) { var entMan = IoCManager.Resolve(); MindComponent? component = null; var alreadyAttached = false; - if (entity != default) + if (entity != null) { - if (!entMan.TryGetComponent(entity, out component)) + if (!entMan.TryGetComponent(entity.Value, out component)) { - component = entMan.AddComponent(entity); + component = entMan.AddComponent(entity.Value); } else if (component!.HasMind) { EntitySystem.Get().OnGhostAttempt(component.Mind!, false); } - if (entMan.TryGetComponent(entity, out var actor)) + if (entMan.TryGetComponent(entity.Value, out var actor)) { // Happens when transferring to your currently visited entity. if (actor.PlayerSession != Session) diff --git a/Content.Server/PneumaticCannon/PneumaticCannonComponent.cs b/Content.Server/PneumaticCannon/PneumaticCannonComponent.cs index f2b3028402..3272486ad9 100644 --- a/Content.Server/PneumaticCannon/PneumaticCannonComponent.cs +++ b/Content.Server/PneumaticCannon/PneumaticCannonComponent.cs @@ -78,7 +78,7 @@ namespace Content.Server.PneumaticCannon public struct FireData { - public EntityUid User, + public EntityUid User; public float Strength; public Vector2 Direction; } diff --git a/Content.Server/PneumaticCannon/PneumaticCannonSystem.cs b/Content.Server/PneumaticCannon/PneumaticCannonSystem.cs index 0e2f6762a6..0c4e95a72d 100644 --- a/Content.Server/PneumaticCannon/PneumaticCannonSystem.cs +++ b/Content.Server/PneumaticCannon/PneumaticCannonSystem.cs @@ -9,6 +9,7 @@ using Content.Server.Items; using Content.Server.Nutrition.Components; using Content.Server.Storage.Components; using Content.Server.Stunnable; +using Content.Server.Throwing; using Content.Server.Tools.Components; using Content.Shared.CombatMode; using Content.Shared.Interaction; @@ -92,7 +93,7 @@ namespace Content.Server.PneumaticCannon private void OnInteractUsing(EntityUid uid, PneumaticCannonComponent component, InteractUsingEvent args) { args.Handled = true; - if (IoCManager.Resolve().HasComponent(args.Used) + if (EntityManager.HasComponent(args.Used) && component.GasTankSlot.CanInsert(args.Used) && component.GasTankRequired) { @@ -103,7 +104,7 @@ namespace Content.Server.PneumaticCannon return; } - if (IoCManager.Resolve().TryGetComponent(args.Used, out var tool)) + if (EntityManager.TryGetComponent(args.Used, out var tool)) { if (tool.Qualities.Contains(component.ToolModifyMode)) { @@ -132,8 +133,8 @@ namespace Content.Server.PneumaticCannon // this overrides the ServerStorageComponent's insertion stuff because // it's not event-based yet and I can't cancel it, so tools and stuff // will modify mode/power then get put in anyway - if (IoCManager.Resolve().TryGetComponent(args.Used, out var item) - && IoCManager.Resolve().TryGetComponent(component.Owner, out var storage)) + if (EntityManager.TryGetComponent(args.Used, out var item) + && EntityManager.TryGetComponent(component.Owner, out var storage)) { if (storage.CanInsert(args.Used)) { @@ -169,7 +170,7 @@ namespace Content.Server.PneumaticCannon public void AddToQueue(PneumaticCannonComponent comp, EntityUid user, EntityCoordinates click) { - if (!IoCManager.Resolve().TryGetComponent(comp.Owner, out var storage)) + if (!EntityManager.TryGetComponent(comp.Owner, out var storage)) return; if (storage.StoredEntities == null) return; if (storage.StoredEntities.Count == 0) @@ -189,7 +190,7 @@ namespace Content.Server.PneumaticCannon for (int i = 0; i < entCounts; i++) { - var dir = (click.ToMapPos(EntityManager) - IoCManager.Resolve().GetComponent(user).WorldPosition).Normalized; + var dir = (click.ToMapPos(EntityManager) - EntityManager.GetComponent(user).WorldPosition).Normalized; var randomAngle = GetRandomFireAngleFromPower(comp.Power).RotateVec(dir); var randomStrengthMult = _random.NextFloat(0.75f, 1.25f); @@ -215,20 +216,20 @@ namespace Content.Server.PneumaticCannon return; } - if (!IoCManager.Resolve().TryGetComponent(comp.Owner, out var storage)) + if (!EntityManager.TryGetComponent(comp.Owner, out var storage)) return; - if ((!IoCManager.Resolve().EntityExists(data.User) ? EntityLifeStage.Deleted : IoCManager.Resolve().GetComponent(data.User).EntityLifeStage) >= EntityLifeStage.Deleted) + if ((!EntityManager.EntityExists(data.User) ? EntityLifeStage.Deleted : EntityManager.GetComponent(data.User).EntityLifeStage) >= EntityLifeStage.Deleted) return; if (storage.StoredEntities == null) return; if (storage.StoredEntities.Count == 0) return; // click sound? - EntityUident = _random.Pick(storage.StoredEntities); + var ent = _random.Pick(storage.StoredEntities); storage.Remove(ent); SoundSystem.Play(Filter.Pvs(data.User), comp.FireSound.GetSound(), ((IComponent) comp).Owner, AudioParams.Default); - if (IoCManager.Resolve().TryGetComponent(data.User, out var recoil)) + if (EntityManager.TryGetComponent(data.User, out var recoil)) { recoil.Kick(Vector2.One * data.Strength); } @@ -238,7 +239,7 @@ namespace Content.Server.PneumaticCannon // lasagna, anybody? ent.EnsureComponent(); - if(IoCManager.Resolve().TryGetComponent(data.User, out var status) + if(EntityManager.TryGetComponent(data.User, out var status) && comp.Power == PneumaticCannonPower.High) { _stun.TryParalyze(data.User, TimeSpan.FromSeconds(comp.HighPowerStunTime), status); @@ -246,11 +247,11 @@ namespace Content.Server.PneumaticCannon ("cannon", comp.Owner))); } - if (comp.GasTankSlot.ContainedEntity != null && comp.GasTankRequired) + if (comp.GasTankSlot.ContainedEntity is {Valid: true} contained && comp.GasTankRequired) { // we checked for this earlier in HasGas so a GetComp is okay - var gas = IoCManager.Resolve().GetComponent(comp.GasTankSlot.ContainedEntity); - var environment = _atmos.GetTileMixture(IoCManager.Resolve().GetComponent(comp.Owner).Coordinates, true); + var gas = EntityManager.GetComponent(contained); + var environment = _atmos.GetTileMixture(EntityManager.GetComponent(comp.Owner).Coordinates, true); var removed = gas.RemoveAir(GetMoleUsageFromPower(comp.Power)); if (environment != null && removed != null) { @@ -266,11 +267,11 @@ namespace Content.Server.PneumaticCannon { var usage = GetMoleUsageFromPower(component.Power); - if (component.GasTankSlot.ContainedEntity == null) + if (component.GasTankSlot.ContainedEntity is not {Valid: true } contained) return false; // not sure how it wouldnt, but it might not! who knows - if (IoCManager.Resolve().TryGetComponent(component.GasTankSlot.ContainedEntity, out var tank)) + if (EntityManager.TryGetComponent(contained, out var tank)) { if (tank.Air.TotalMoles < usage) return false; @@ -307,30 +308,29 @@ namespace Content.Server.PneumaticCannon public void TryRemoveGasTank(PneumaticCannonComponent component, EntityUid user) { - if (component.GasTankSlot.ContainedEntity == null) + if (component.GasTankSlot.ContainedEntity is not {Valid: true} contained) { user.PopupMessage(Loc.GetString("pneumatic-cannon-component-gas-tank-none", ("cannon", component.Owner))); return; } - var ent = component.GasTankSlot.ContainedEntity; - if (component.GasTankSlot.Remove(ent)) + if (component.GasTankSlot.Remove(contained)) { - if (IoCManager.Resolve().TryGetComponent(user, out var hands)) + if (EntityManager.TryGetComponent(user, out var hands)) { - hands.TryPutInActiveHandOrAny(ent); + hands.TryPutInActiveHandOrAny(contained); } user.PopupMessage(Loc.GetString("pneumatic-cannon-component-gas-tank-remove", - ("tank", ent), ("cannon", component.Owner))); + ("tank", contained), ("cannon", component.Owner))); UpdateAppearance(component); } } public void TryEjectAllItems(PneumaticCannonComponent component, EntityUid user) { - if (IoCManager.Resolve().TryGetComponent(component.Owner, out var storage)) + if (EntityManager.TryGetComponent(component.Owner, out var storage)) { if (storage.StoredEntities == null) return; foreach (var entity in storage.StoredEntities.ToArray()) @@ -345,7 +345,7 @@ namespace Content.Server.PneumaticCannon private void UpdateAppearance(PneumaticCannonComponent component) { - if (IoCManager.Resolve().TryGetComponent(component.Owner, out var appearance)) + if (EntityManager.TryGetComponent(component.Owner, out var appearance)) { appearance.SetData(PneumaticCannonVisuals.Tank, component.GasTankSlot.ContainedEntities.Count != 0); diff --git a/Content.Server/Pointing/Components/RoguePointingArrowComponent.cs b/Content.Server/Pointing/Components/RoguePointingArrowComponent.cs index 90bbe6468a..3c8b8914db 100644 --- a/Content.Server/Pointing/Components/RoguePointingArrowComponent.cs +++ b/Content.Server/Pointing/Components/RoguePointingArrowComponent.cs @@ -13,7 +13,7 @@ namespace Content.Server.Pointing.Components public class RoguePointingArrowComponent : SharedRoguePointingArrowComponent { [ViewVariables] - public EntityUid Chasing; + public EntityUid? Chasing; [ViewVariables(VVAccess.ReadWrite)] [DataField("turningDelay")] diff --git a/Content.Server/Pointing/EntitySystems/PointingSystem.cs b/Content.Server/Pointing/EntitySystems/PointingSystem.cs index 3516121b85..adc23667bc 100644 --- a/Content.Server/Pointing/EntitySystems/PointingSystem.cs +++ b/Content.Server/Pointing/EntitySystems/PointingSystem.cs @@ -7,6 +7,7 @@ using Content.Server.Visible; using Content.Shared.Input; using Content.Shared.Interaction; using Content.Shared.Interaction.Helpers; +using Content.Shared.Popups; using Content.Shared.Verbs; using JetBrains.Annotations; using Robust.Server.GameObjects; @@ -58,8 +59,7 @@ namespace Content.Server.Pointing.EntitySystems { foreach (var viewer in viewers) { - var viewerEntity = viewer.AttachedEntity; - if (viewerEntity == null) + if (viewer.AttachedEntity is not {Valid: true} viewerEntity) { continue; } @@ -76,9 +76,9 @@ namespace Content.Server.Pointing.EntitySystems public bool InRange(EntityUid pointer, EntityCoordinates coordinates) { - if (IoCManager.Resolve().HasComponent(pointer)) + if (EntityManager.HasComponent(pointer)) { - return IoCManager.Resolve().GetComponent(pointer).Coordinates.InRange(EntityManager, coordinates, 15); + return EntityManager.GetComponent(pointer).Coordinates.InRange(EntityManager, coordinates, 15); } else { @@ -86,11 +86,10 @@ namespace Content.Server.Pointing.EntitySystems } } - public bool TryPoint(ICommonSession? session, EntityCoordinates coords, EntityUid uid) + public bool TryPoint(ICommonSession? session, EntityCoordinates coords, EntityUid pointed) { var mapCoords = coords.ToMap(EntityManager); - var player = (session as IPlayerSession)?.ContentData()?.Mind?.CurrentEntity; - if (player == null) + if ((session as IPlayerSession)?.ContentData()?.Mind?.CurrentEntity is not { } player) { return false; } @@ -101,7 +100,7 @@ namespace Content.Server.Pointing.EntitySystems return false; } - if (EntityManager.EntityExists(uid) + if (EntityManager.EntityExists(pointed)) { // this is a pointing arrow. no pointing here... return false; @@ -118,7 +117,7 @@ namespace Content.Server.Pointing.EntitySystems var arrow = EntityManager.SpawnEntity("pointingarrow", mapCoords); var layer = (int) VisibilityFlags.Normal; - if (IoCManager.Resolve().TryGetComponent(player, out VisibilityComponent? playerVisibility)) + if (EntityManager.TryGetComponent(player, out VisibilityComponent? playerVisibility)) { var arrowVisibility = arrow.EnsureComponent(); layer = arrowVisibility.Layer = playerVisibility.Layer; @@ -127,11 +126,12 @@ namespace Content.Server.Pointing.EntitySystems // Get players that are in range and whose visibility layer matches the arrow's. bool ViewerPredicate(IPlayerSession playerSession) { - var ent = playerSession.ContentData()?.Mind?.CurrentEntity; + if (playerSession.ContentData()?.Mind?.CurrentEntity is not {Valid: true} ent || + !EntityManager.TryGetComponent(ent, out var eyeComp) || + (eyeComp.VisibilityMask & layer) == 0) + return false; - if (ent is null || (!IoCManager.Resolve().TryGetComponent(ent, out var eyeComp) || (eyeComp.VisibilityMask & layer) == 0)) return false; - - return IoCManager.Resolve().GetComponent(ent).MapPosition.InRange(IoCManager.Resolve().GetComponent(player).MapPosition, PointingRange); + return EntityManager.GetComponent(ent).MapPosition.InRange(EntityManager.GetComponent(player).MapPosition, PointingRange); } var viewers = Filter.Empty() @@ -142,17 +142,17 @@ namespace Content.Server.Pointing.EntitySystems string viewerMessage; string? viewerPointedAtMessage = null; - if (EntityManager.EntityExists(uid) + if (EntityManager.EntityExists(pointed)) { selfMessage = player == pointed ? Loc.GetString("pointing-system-point-at-self") : Loc.GetString("pointing-system-point-at-other", ("other", pointed)); viewerMessage = player == pointed - ? Loc.GetString("pointing-system-point-at-self-others", ("otherName", Name: IoCManager.Resolve().GetComponent(player).EntityName), ("other", player)) - : Loc.GetString("pointing-system-point-at-other-others", ("otherName", Name: IoCManager.Resolve().GetComponent(player).EntityName), ("other", pointed)); + ? Loc.GetString("pointing-system-point-at-self-others", ("otherName", Name: EntityManager.GetComponent(player).EntityName), ("other", player)) + : Loc.GetString("pointing-system-point-at-other-others", ("otherName", Name: EntityManager.GetComponent(player).EntityName), ("other", pointed)); - viewerPointedAtMessage = Loc.GetString("pointing-system-point-at-you-other", ("otherName", Name: IoCManager.Resolve().GetComponent(player).EntityName)); + viewerPointedAtMessage = Loc.GetString("pointing-system-point-at-you-other", ("otherName", Name: EntityManager.GetComponent(player).EntityName)); } else { @@ -167,10 +167,10 @@ namespace Content.Server.Pointing.EntitySystems selfMessage = Loc.GetString("pointing-system-point-at-tile", ("tileName", tileDef.DisplayName)); - viewerMessage = Loc.GetString("pointing-system-other-point-at-tile", ("otherName", Name: IoCManager.Resolve().GetComponent(player).EntityName), ("tileName", tileDef.DisplayName)); + viewerMessage = Loc.GetString("pointing-system-other-point-at-tile", ("otherName", Name: EntityManager.GetComponent(player).EntityName), ("tileName", tileDef.DisplayName)); } - _pointers[session!] = _gameTiming.CurTime; + _pointers[session] = _gameTiming.CurTime; SendMessage(player, viewers, pointed, selfMessage, viewerMessage, viewerPointedAtMessage); @@ -196,17 +196,17 @@ namespace Content.Server.Pointing.EntitySystems return; //Check if the object is already being pointed at - if (IoCManager.Resolve().HasComponent(args.Target)) + if (EntityManager.HasComponent(args.Target)) return; - if (!IoCManager.Resolve().TryGetComponent(args.User, out var actor) || - !InRange(args.User, IoCManager.Resolve().GetComponent(args.Target).Coordinates)) + if (!EntityManager.TryGetComponent(args.User, out var actor) || + !InRange(args.User, EntityManager.GetComponent(args.Target).Coordinates)) return; Verb verb = new(); verb.Text = Loc.GetString("pointing-verb-get-data-text"); verb.IconTexture = "/Textures/Interface/VerbIcons/point.svg.192dpi.png"; - verb.Act = () => TryPoint(actor.PlayerSession, IoCManager.Resolve().GetComponent(args.Target).Coordinates, args.Target); ; + verb.Act = () => TryPoint(actor.PlayerSession, EntityManager.GetComponent(args.Target).Coordinates, args.Target); ; args.Verbs.Add(verb); } diff --git a/Content.Server/Pointing/EntitySystems/RoguePointingSystem.cs b/Content.Server/Pointing/EntitySystems/RoguePointingSystem.cs index e1078f6dc3..c21db27180 100644 --- a/Content.Server/Pointing/EntitySystems/RoguePointingSystem.cs +++ b/Content.Server/Pointing/EntitySystems/RoguePointingSystem.cs @@ -37,7 +37,7 @@ namespace Content.Server.Pointing.EntitySystems } } - private EntityUid RandomNearbyPlayer(EntityUid uid, RoguePointingArrowComponent? component = null, TransformComponent? transform = null) + private EntityUid? RandomNearbyPlayer(EntityUid uid, RoguePointingArrowComponent? component = null, TransformComponent? transform = null) { if (!Resolve(uid, ref component, ref transform)) return null; @@ -68,7 +68,7 @@ namespace Content.Server.Pointing.EntitySystems var uid = component.Owner; component.Chasing ??= RandomNearbyPlayer(uid, component, transform); - if (component.Chasing == null) + if (component.Chasing is not {Valid: true} chasing) { EntityManager.QueueDeleteEntity(uid); return; @@ -78,7 +78,7 @@ namespace Content.Server.Pointing.EntitySystems if (component.TurningDelay > 0) { - var difference = IoCManager.Resolve().GetComponent(component.Chasing).WorldPosition - transform.WorldPosition; + var difference = IoCManager.Resolve().GetComponent(chasing).WorldPosition - transform.WorldPosition; var angle = difference.ToAngle(); var adjusted = angle.Degrees + 90; var newAngle = Angle.FromDegrees(adjusted); @@ -93,7 +93,7 @@ namespace Content.Server.Pointing.EntitySystems UpdateAppearance(uid, component, transform); - var toChased = IoCManager.Resolve().GetComponent(component.Chasing).WorldPosition - transform.WorldPosition; + var toChased = IoCManager.Resolve().GetComponent(chasing).WorldPosition - transform.WorldPosition; transform.WorldPosition += toChased * frameTime * component.ChasingSpeed; diff --git a/Content.Server/Popups/PopupExtensions.cs b/Content.Server/Popups/PopupExtensions.cs index 8a34b3e1c6..a10414556f 100644 --- a/Content.Server/Popups/PopupExtensions.cs +++ b/Content.Server/Popups/PopupExtensions.cs @@ -1,10 +1,6 @@ -using System.Collections.Generic; -using System.Linq; using Content.Shared.Popups; using Robust.Server.Player; using Robust.Shared.GameObjects; -using Robust.Shared.IoC; -using Robust.Shared.Map; using Robust.Shared.Player; namespace Content.Server.Popups @@ -25,14 +21,12 @@ namespace Content.Server.Popups foreach (var viewer in viewers) { - var viewerEntity = viewer.AttachedEntity; - - if (viewerEntity == null || source == viewerEntity || viewer.AttachedEntity == null) + if (viewer.AttachedEntity is not {Valid: true} viewerEntity || source == viewerEntity || viewer.AttachedEntity == null) { continue; } - source.PopupMessage(viewer.AttachedEntity, message); + source.PopupMessage(viewerEntity, message); } } diff --git a/Content.Server/Popups/PopupMsgCommand.cs b/Content.Server/Popups/PopupMsgCommand.cs index 85392bc712..499522f4e5 100644 --- a/Content.Server/Popups/PopupMsgCommand.cs +++ b/Content.Server/Popups/PopupMsgCommand.cs @@ -3,7 +3,6 @@ using Content.Shared.Administration; using Content.Shared.Popups; using Robust.Shared.Console; using Robust.Shared.GameObjects; -using Robust.Shared.IoC; namespace Content.Server.Popups { @@ -16,13 +15,11 @@ namespace Content.Server.Popups public void Execute(IConsoleShell shell, string argStr, string[] args) { - var entityMgr = IoCManager.Resolve(); - var source = EntityUid.Parse(args[0]); var viewer = EntityUid.Parse(args[1]); var msg = args[2]; - entityMgr.GetEntity(source).PopupMessage(entityMgr.GetEntity(viewer), msg); + source.PopupMessage(viewer, msg); } } } diff --git a/Content.Server/Power/Components/ApcComponent.cs b/Content.Server/Power/Components/ApcComponent.cs index 145a4957db..a34eb242bd 100644 --- a/Content.Server/Power/Components/ApcComponent.cs +++ b/Content.Server/Power/Components/ApcComponent.cs @@ -93,7 +93,7 @@ namespace Content.Server.Power.Components if (user == null) return; var accessSystem = EntitySystem.Get(); - if (_accessReader == null || accessSystem.IsAllowed(_accessReader, user)) + if (_accessReader == null || accessSystem.IsAllowed(_accessReader, user.Value)) { MainBreakerEnabled = !MainBreakerEnabled; IoCManager.Resolve().GetComponent(Owner).CanDischarge = MainBreakerEnabled; @@ -103,7 +103,7 @@ namespace Content.Server.Power.Components } else { - user.PopupMessageCursor(Loc.GetString("apc-component-insufficient-access")); + user.Value.PopupMessageCursor(Loc.GetString("apc-component-insufficient-access")); } } diff --git a/Content.Server/Power/Components/BaseCharger.cs b/Content.Server/Power/Components/BaseCharger.cs index a657da4ce3..f393984765 100644 --- a/Content.Server/Power/Components/BaseCharger.cs +++ b/Content.Server/Power/Components/BaseCharger.cs @@ -90,8 +90,7 @@ namespace Content.Server.Power.Components /// public void RemoveItem(EntityUid user) { - var heldItem = Container.ContainedEntity; - if (heldItem == null) + if (Container.ContainedEntity is not {Valid: true} heldItem) { return; } diff --git a/Content.Server/Power/EntitySystems/BaseChargerSystem.cs b/Content.Server/Power/EntitySystems/BaseChargerSystem.cs index 0e70a3d56b..fe75406d6f 100644 --- a/Content.Server/Power/EntitySystems/BaseChargerSystem.cs +++ b/Content.Server/Power/EntitySystems/BaseChargerSystem.cs @@ -43,7 +43,7 @@ namespace Content.Server.Power.EntitySystems return; Verb verb = new(); - verb.Text = IoCManager.Resolve().GetComponent(component.Container.ContainedEntity!).EntityName; + verb.Text = IoCManager.Resolve().GetComponent(component.Container.ContainedEntity!.Value).EntityName; verb.Category = VerbCategory.Eject; verb.Act = () => component.RemoveItem(args.User); args.Verbs.Add(verb); @@ -51,18 +51,18 @@ namespace Content.Server.Power.EntitySystems private void AddInsertVerb(EntityUid uid, BaseCharger component, GetInteractionVerbsEvent args) { - if (args.Using == null || + if (args.Using is not {Valid: true} @using || !args.CanAccess || !args.CanInteract || component.HasCell || - !component.IsEntityCompatible(args.Using) || + !component.IsEntityCompatible(@using) || !_actionBlockerSystem.CanDrop(args.User)) return; Verb verb = new(); - verb.Text = IoCManager.Resolve().GetComponent(args.Using).EntityName; + verb.Text = IoCManager.Resolve().GetComponent(@using).EntityName; verb.Category = VerbCategory.Insert; - verb.Act = () => component.TryInsertItem(args.Using); + verb.Act = () => component.TryInsertItem(@using); args.Verbs.Add(verb); } } diff --git a/Content.Server/Power/EntitySystems/ExtensionCableSystem.cs b/Content.Server/Power/EntitySystems/ExtensionCableSystem.cs index 8550c10c9b..89e0f55fc9 100644 --- a/Content.Server/Power/EntitySystems/ExtensionCableSystem.cs +++ b/Content.Server/Power/EntitySystems/ExtensionCableSystem.cs @@ -75,10 +75,8 @@ namespace Content.Server.Power.EntitySystems } } - private IEnumerable FindAvailableReceivers(EntityUid uid, float range) + private IEnumerable FindAvailableReceivers(EntityUid owner, float range) { - var owner = uid - var nearbyEntities = IoCManager.Resolve() .GetEntitiesInRange(owner, range); diff --git a/Content.Server/PowerCell/Components/PowerCellSlotComponent.cs b/Content.Server/PowerCell/Components/PowerCellSlotComponent.cs index 375365d06a..d5138ef1bc 100644 --- a/Content.Server/PowerCell/Components/PowerCellSlotComponent.cs +++ b/Content.Server/PowerCell/Components/PowerCellSlotComponent.cs @@ -25,6 +25,8 @@ namespace Content.Server.PowerCell.Components public class PowerCellSlotComponent : Component, IExamine, IMapInit #pragma warning restore 618 { + [Dependency] private readonly IEntityManager _entities = default!; + public override string Name => "PowerCellSlot"; /// @@ -81,7 +83,7 @@ namespace Content.Server.PowerCell.Components get { if (_cellContainer.ContainedEntity == null) return null; - return IoCManager.Resolve().TryGetComponent(_cellContainer.ContainedEntity, out PowerCellComponent? cell) ? cell : null; + return _entities.TryGetComponent(_cellContainer.ContainedEntity.Value, out PowerCellComponent? cell) ? cell : null; } } @@ -134,14 +136,14 @@ namespace Content.Server.PowerCell.Components //Dirty(); if (user != null) { - if (!IoCManager.Resolve().TryGetComponent(user, out HandsComponent? hands) || !hands.PutInHand(IoCManager.Resolve().GetComponent(cell.Owner))) + if (!_entities.TryGetComponent(user, out HandsComponent? hands) || !hands.PutInHand(_entities.GetComponent(cell.Owner))) { - IoCManager.Resolve().GetComponent(cell.Owner).Coordinates = IoCManager.Resolve().GetComponent(user).Coordinates; + _entities.GetComponent(cell.Owner).Coordinates = _entities.GetComponent(user).Coordinates; } } else { - IoCManager.Resolve().GetComponent(cell.Owner).Coordinates = IoCManager.Resolve().GetComponent(Owner).Coordinates; + _entities.GetComponent(cell.Owner).Coordinates = _entities.GetComponent(Owner).Coordinates; } if (playSound) @@ -149,7 +151,7 @@ namespace Content.Server.PowerCell.Components SoundSystem.Play(Filter.Pvs(Owner), CellRemoveSound.GetSound(), Owner, AudioHelpers.WithVariation(0.125f)); } - IoCManager.Resolve().EventBus.RaiseLocalEvent(Owner, new PowerCellChangedEvent(true), false); + _entities.EventBus.RaiseLocalEvent(Owner, new PowerCellChangedEvent(true), false); return cell; } @@ -162,8 +164,8 @@ namespace Content.Server.PowerCell.Components public bool InsertCell(EntityUid cell, bool playSound = true) { if (Cell != null) return false; - if (!IoCManager.Resolve().TryGetComponent((EntityUid) cell, out (ItemComponent?) var _)) return false; - if (!IoCManager.Resolve().TryGetComponent(cell, out var cellComponent)) return false; + if (!_entities.HasComponent(cell)) return false; + if (!_entities.TryGetComponent(cell, out var cellComponent)) return false; if (cellComponent.CellSize != SlotSize) return false; if (!_cellContainer.Insert(cell)) return false; //Dirty(); @@ -172,7 +174,7 @@ namespace Content.Server.PowerCell.Components SoundSystem.Play(Filter.Pvs(Owner), CellInsertSound.GetSound(), Owner, AudioHelpers.WithVariation(0.125f)); } - IoCManager.Resolve().EventBus.RaiseLocalEvent(Owner, new PowerCellChangedEvent(false), false); + _entities.EventBus.RaiseLocalEvent(Owner, new PowerCellChangedEvent(false), false); return true; } @@ -199,7 +201,7 @@ namespace Content.Server.PowerCell.Components }; } - var cell = IoCManager.Resolve().SpawnEntity(type, IoCManager.Resolve().GetComponent(Owner).Coordinates); + var cell = _entities.SpawnEntity(type, _entities.GetComponent(Owner).Coordinates); _cellContainer.Insert(cell); } } diff --git a/Content.Server/PowerCell/PowerCellSystem.cs b/Content.Server/PowerCell/PowerCellSystem.cs index 1d8e9ee306..a7950fcb39 100644 --- a/Content.Server/PowerCell/PowerCellSystem.cs +++ b/Content.Server/PowerCell/PowerCellSystem.cs @@ -43,18 +43,18 @@ namespace Content.Server.PowerCell private void AddInsertVerb(EntityUid uid, PowerCellSlotComponent component, GetInteractionVerbsEvent args) { - if (args.Using == null || + if (args.Using is not {Valid: true} @using || !args.CanAccess || !args.CanInteract || component.HasCell || - !IoCManager.Resolve().HasComponent(args.Using) || + !IoCManager.Resolve().HasComponent(@using) || !_actionBlockerSystem.CanDrop(args.User)) return; Verb verb = new(); - verb.Text = IoCManager.Resolve().GetComponent(args.Using).EntityName; + verb.Text = IoCManager.Resolve().GetComponent(@using).EntityName; verb.Category = VerbCategory.Insert; - verb.Act = () => component.InsertCell(args.Using); + verb.Act = () => component.InsertCell(@using); args.Verbs.Add(verb); } diff --git a/Content.Server/Projectiles/Components/HitscanComponent.cs b/Content.Server/Projectiles/Components/HitscanComponent.cs index eccd27af5b..e802b512cf 100644 --- a/Content.Server/Projectiles/Components/HitscanComponent.cs +++ b/Content.Server/Projectiles/Components/HitscanComponent.cs @@ -47,7 +47,7 @@ namespace Content.Server.Projectiles.Components [DataField("soundHitWall")] private SoundSpecifier _soundHitWall = new SoundPathSpecifier("/Audio/Weapons/Guns/Hits/laser_sear_wall.ogg"); - public void FireEffects(EntityUid user, float distance, Angle angle, EntityUid hitEntity = null) + public void FireEffects(EntityUid user, float distance, Angle angle, EntityUid? hitEntity = null) { var effectSystem = EntitySystem.Get(); _startTime = _gameTiming.CurTime; diff --git a/Content.Server/Projectiles/ProjectileSystem.cs b/Content.Server/Projectiles/ProjectileSystem.cs index 244a593931..631a0d20f9 100644 --- a/Content.Server/Projectiles/ProjectileSystem.cs +++ b/Content.Server/Projectiles/ProjectileSystem.cs @@ -38,7 +38,7 @@ namespace Content.Server.Projectiles var coordinates = IoCManager.Resolve().GetComponent(args.OtherFixture.Body.Owner).Coordinates; var playerFilter = Filter.Pvs(coordinates); - if (!((!IoCManager.Resolve().EntityExists(otherEntity) ? EntityLifeStage.Deleted : IoCManager.Resolve().GetComponent(otherEntity).EntityLifeStage) >= EntityLifeStage.Deleted) && component.SoundHitSpecies != null && + if (!EntityManager.GetComponent(otherEntity).EntityDeleted && component.SoundHitSpecies != null && IoCManager.Resolve().HasComponent(otherEntity)) { SoundSystem.Play(playerFilter, component.SoundHitSpecies.GetSound(), coordinates); @@ -51,18 +51,19 @@ namespace Content.Server.Projectiles SoundSystem.Play(playerFilter, soundHit, coordinates); } - if (!((!IoCManager.Resolve().EntityExists(otherEntity) ? EntityLifeStage.Deleted : IoCManager.Resolve().GetComponent(otherEntity).EntityLifeStage) >= EntityLifeStage.Deleted)) + if (!EntityManager.GetComponent(otherEntity).EntityDeleted) { var dmg = _damageableSystem.TryChangeDamage(otherEntity, component.Damage); component.DamagedEntity = true; - if (dmg is not null && EntityManager.EntityExists(component.Shooter) + if (dmg is not null && EntityManager.EntityExists(component.Shooter)) _adminLogSystem.Add(LogType.BulletHit, LogImpact.Low, - $"Projectile {component.Owner} shot by {shooter} hit {otherEntity} and dealt {dmg.Total} damage"); + $"Projectile {component.Owner} shot by {component.Shooter:shooter} hit {otherEntity} and dealt {dmg.Total} damage"); } // Damaging it can delete it - if (!((!IoCManager.Resolve().EntityExists(otherEntity) ? EntityLifeStage.Deleted : IoCManager.Resolve().GetComponent(otherEntity).EntityLifeStage) >= EntityLifeStage.Deleted) && IoCManager.Resolve().TryGetComponent(otherEntity, out CameraRecoilComponent? recoilComponent)) + if (!EntityManager.GetComponent(otherEntity).EntityDeleted && + EntityManager.TryGetComponent(otherEntity, out CameraRecoilComponent? recoilComponent)) { var direction = args.OurFixture.Body.LinearVelocity.Normalized; recoilComponent.Kick(direction); diff --git a/Content.Server/Pulling/PullingSystem.cs b/Content.Server/Pulling/PullingSystem.cs index a4cc18196d..7cb76f9d24 100644 --- a/Content.Server/Pulling/PullingSystem.cs +++ b/Content.Server/Pulling/PullingSystem.cs @@ -3,9 +3,7 @@ using Content.Shared.Pulling; using Content.Shared.Pulling.Components; using JetBrains.Annotations; using Robust.Server.GameObjects; -using Robust.Shared.GameObjects; using Robust.Shared.Input.Binding; -using Robust.Shared.IoC; using Robust.Shared.Players; namespace Content.Server.Pulling @@ -29,9 +27,7 @@ namespace Content.Server.Pulling private void HandleReleasePulledObject(ICommonSession? session) { - var player = session?.AttachedEntity; - - if (player == null) + if (session?.AttachedEntity is not {Valid: true} player) { return; } @@ -41,7 +37,7 @@ namespace Content.Server.Pulling return; } - if (!IoCManager.Resolve().TryGetComponent(pulled, out SharedPullableComponent? pullable)) + if (!EntityManager.TryGetComponent(pulled.Value, out SharedPullableComponent? pullable)) { return; } diff --git a/Content.Server/RCD/Systems/RCDAmmoSystem.cs b/Content.Server/RCD/Systems/RCDAmmoSystem.cs index c1eb63f5f1..d88754c105 100644 --- a/Content.Server/RCD/Systems/RCDAmmoSystem.cs +++ b/Content.Server/RCD/Systems/RCDAmmoSystem.cs @@ -1,11 +1,10 @@ +using System; using Content.Server.RCD.Components; using Content.Shared.Examine; -using Content.Shared.Hands.Components; using Content.Shared.Interaction; using Content.Shared.Popups; using Robust.Shared.GameObjects; using Robust.Shared.Localization; -using System; namespace Content.Server.RCD.Systems { @@ -29,7 +28,8 @@ namespace Content.Server.RCD.Systems if (args.Handled || !args.CanReach) return; - if (args.Target == null || !EntityManager.TryGetComponent(args.Target, out RCDComponent? rcdComponent)) + if (args.Target is not {Valid: true} target || + !EntityManager.TryGetComponent(target, out RCDComponent? rcdComponent)) return; if (rcdComponent.MaxAmmo - rcdComponent.CurrentAmmo < component.RefillAmmo) diff --git a/Content.Server/RCD/Systems/RCDSystem.cs b/Content.Server/RCD/Systems/RCDSystem.cs index 62f1f768c8..b915ed892d 100644 --- a/Content.Server/RCD/Systems/RCDSystem.cs +++ b/Content.Server/RCD/Systems/RCDSystem.cs @@ -8,6 +8,7 @@ using Content.Shared.Interaction; using Content.Shared.Interaction.Helpers; using Content.Shared.Maps; using Content.Shared.Popups; +using Content.Shared.Tag; using Robust.Shared.Audio; using Robust.Shared.GameObjects; using Robust.Shared.IoC; @@ -117,10 +118,9 @@ namespace Content.Server.RCD.Systems } else //Delete what the user targeted { - EntityUid tempQualifier = args.Target; - if (tempQualifier != null) + if (args.Target is {Valid: true} target) { - IoCManager.Resolve().DeleteEntity(tempQualifier); + EntityManager.DeleteEntity(target); } } break; @@ -189,7 +189,7 @@ namespace Content.Server.RCD.Systems return false; } //They tried to decon a non-turf but it's not in the whitelist - if (eventArgs.Target != null && !eventArgs.Target.HasTag("RCDDeconstructWhitelist")) + if (eventArgs.Target != null && !eventArgs.Target.Value.HasTag("RCDDeconstructWhitelist")) { rcd.Owner.PopupMessage(eventArgs.User, Loc.GetString("rcd-component-deconstruct-target-not-on-whitelist-message")); return false; diff --git a/Content.Server/Sandbox/SandboxManager.cs b/Content.Server/Sandbox/SandboxManager.cs index 4f4bcf05c4..3ffeb3b6c9 100644 --- a/Content.Server/Sandbox/SandboxManager.cs +++ b/Content.Server/Sandbox/SandboxManager.cs @@ -124,19 +124,19 @@ namespace Content.Server.Sandbox .EnumeratePrototypes() .Select(p => p.ID).ToArray(); - if (IoCManager.Resolve().TryGetComponent(player.AttachedEntity, out InventoryComponent? inv) + if (_entityManager.TryGetComponent(player.AttachedEntity.Value, out InventoryComponent? inv) && inv.TryGetSlotItem(Slots.IDCARD, out ItemComponent? wornItem)) { - if (IoCManager.Resolve().HasComponent(wornItem.Owner)) + if (_entityManager.HasComponent(wornItem.Owner)) { UpgradeId(wornItem.Owner); } - else if (IoCManager.Resolve().TryGetComponent(wornItem.Owner, out PDAComponent? pda)) + else if (_entityManager.TryGetComponent(wornItem.Owner, out PDAComponent? pda)) { if (pda.ContainedID == null) { var newID = CreateFreshId(); - if (IoCManager.Resolve().TryGetComponent(pda.Owner, out ItemSlotsComponent? itemSlots)) + if (_entityManager.TryGetComponent(pda.Owner, out ItemSlotsComponent? itemSlots)) { _entityManager.EntitySysManager.GetEntitySystem(). TryInsert(wornItem.Owner, pda.IdSlot, newID); @@ -148,12 +148,12 @@ namespace Content.Server.Sandbox } } } - else if (IoCManager.Resolve().TryGetComponent(player.AttachedEntity, out var hands)) + else if (_entityManager.TryGetComponent(player.AttachedEntity.Value, out var hands)) { var card = CreateFreshId(); - if (!IoCManager.Resolve().TryGetComponent(player.AttachedEntity, out inv) || !inv.Equip(Slots.IDCARD, card)) + if (!_entityManager.TryGetComponent(player.AttachedEntity.Value, out inv) || !inv.Equip(Slots.IDCARD, card)) { - hands.PutInHandOrDrop(IoCManager.Resolve().GetComponent(card)); + hands.PutInHandOrDrop(_entityManager.GetComponent(card)); } } @@ -162,18 +162,18 @@ namespace Content.Server.Sandbox var accessSystem = EntitySystem.Get(); accessSystem.TrySetTags(id, allAccess); - if (IoCManager.Resolve().TryGetComponent(id, out SpriteComponent? sprite)) + if (_entityManager.TryGetComponent(id, out SpriteComponent? sprite)) { sprite.LayerSetState(0, "gold"); } } - EntityUidCreateFreshId() + EntityUid CreateFreshId() { - var card = _entityManager.SpawnEntity("CaptainIDCard", IoCManager.Resolve().GetComponent(player.AttachedEntity).Coordinates); + var card = _entityManager.SpawnEntity("CaptainIDCard", _entityManager.GetComponent(player.AttachedEntity.Value).Coordinates); UpgradeId(card); - IoCManager.Resolve().GetComponent(card).FullName = IoCManager.Resolve().GetComponent(player.AttachedEntity).EntityName; + _entityManager.GetComponent(card).FullName = _entityManager.GetComponent(player.AttachedEntity.Value).EntityName; return card; } } diff --git a/Content.Server/Shuttles/EntitySystems/DockingSystem.cs b/Content.Server/Shuttles/EntitySystems/DockingSystem.cs index 2441ce8c75..c507736e53 100644 --- a/Content.Server/Shuttles/EntitySystems/DockingSystem.cs +++ b/Content.Server/Shuttles/EntitySystems/DockingSystem.cs @@ -110,7 +110,7 @@ namespace Content.Server.Shuttles.EntitySystems if (dockingFixture == null) { DebugTools.Assert(false); - Logger.ErrorS("docking", $"Found null fixture on {((IComponent) body).OwnerUid}"); + Logger.ErrorS("docking", $"Found null fixture on {((IComponent) body).Owner}"); return null; } @@ -200,8 +200,8 @@ namespace Content.Server.Shuttles.EntitySystems dockA.DockedWith = null; // If these grids are ever invalid then need to look at fixing ordering for unanchored events elsewhere. - var gridAUid = _mapManager.GetGrid(EntityManager.GetComponent(((IComponent) dockA).OwnerUid).GridID).GridEntityId; - var gridBUid = _mapManager.GetGrid(EntityManager.GetComponent(((IComponent) dockB).OwnerUid).GridID).GridEntityId; + var gridAUid = _mapManager.GetGrid(EntityManager.GetComponent(((IComponent) dockA).Owner).GridID).GridEntityId; + var gridBUid = _mapManager.GetGrid(EntityManager.GetComponent(((IComponent) dockB).Owner).GridID).GridEntityId; var msg = new UndockEvent { @@ -211,8 +211,8 @@ namespace Content.Server.Shuttles.EntitySystems GridBUid = gridBUid, }; - EntityManager.EventBus.RaiseLocalEvent(((IComponent) dockA).OwnerUid, msg, false); - EntityManager.EventBus.RaiseLocalEvent(((IComponent) dockB).OwnerUid, msg, false); + EntityManager.EventBus.RaiseLocalEvent(((IComponent) dockA).Owner, msg, false); + EntityManager.EventBus.RaiseLocalEvent(((IComponent) dockB).Owner, msg, false); EntityManager.EventBus.RaiseEvent(EventSource.Local, msg); } @@ -308,8 +308,8 @@ namespace Content.Server.Shuttles.EntitySystems // We could also potentially use a prismatic joint? Depending if we want clamps that can extend or whatever - var dockAXform = EntityManager.GetComponent(((IComponent) dockA).OwnerUid); - var dockBXform = EntityManager.GetComponent(((IComponent) dockB).OwnerUid); + var dockAXform = EntityManager.GetComponent(((IComponent) dockA).Owner); + var dockBXform = EntityManager.GetComponent(((IComponent) dockB).Owner); var gridA = _mapManager.GetGrid(dockAXform.GridID).GridEntityId; var gridB = _mapManager.GetGrid(dockBXform.GridID).GridEntityId; @@ -344,13 +344,13 @@ namespace Content.Server.Shuttles.EntitySystems dockA.DockJoint = joint; dockB.DockJoint = joint; - if (EntityManager.TryGetComponent(((IComponent) dockA).OwnerUid, out ServerDoorComponent? doorA)) + if (EntityManager.TryGetComponent(((IComponent) dockA).Owner, out ServerDoorComponent? doorA)) { doorA.ChangeAirtight = false; doorA.Open(); } - if (EntityManager.TryGetComponent(((IComponent) dockB).OwnerUid, out ServerDoorComponent? doorB)) + if (EntityManager.TryGetComponent(((IComponent) dockB).Owner, out ServerDoorComponent? doorB)) { doorB.ChangeAirtight = false; doorB.Open(); @@ -364,8 +364,8 @@ namespace Content.Server.Shuttles.EntitySystems GridBUid = gridB, }; - EntityManager.EventBus.RaiseLocalEvent(((IComponent) dockA).OwnerUid, msg, false); - EntityManager.EventBus.RaiseLocalEvent(((IComponent) dockB).OwnerUid, msg, false); + EntityManager.EventBus.RaiseLocalEvent(((IComponent) dockA).Owner, msg, false); + EntityManager.EventBus.RaiseLocalEvent(((IComponent) dockB).Owner, msg, false); EntityManager.EventBus.RaiseEvent(EventSource.Local, msg); } @@ -374,8 +374,8 @@ namespace Content.Server.Shuttles.EntitySystems /// private void TryDock(DockingComponent dockA, DockingComponent dockB) { - if (!EntityManager.TryGetComponent(((IComponent) dockA).OwnerUid, out PhysicsComponent? bodyA) || - !EntityManager.TryGetComponent(((IComponent) dockB).OwnerUid, out PhysicsComponent? bodyB) || + if (!EntityManager.TryGetComponent(((IComponent) dockA).Owner, out PhysicsComponent? bodyA) || + !EntityManager.TryGetComponent(((IComponent) dockB).Owner, out PhysicsComponent? bodyB) || !dockA.Enabled || !dockB.Enabled) { @@ -425,13 +425,13 @@ namespace Content.Server.Shuttles.EntitySystems return; } - if (EntityManager.TryGetComponent(((IComponent) dock).OwnerUid, out ServerDoorComponent? doorA)) + if (EntityManager.TryGetComponent(((IComponent) dock).Owner, out ServerDoorComponent? doorA)) { doorA.ChangeAirtight = true; doorA.Close(); } - if (EntityManager.TryGetComponent(((IComponent) dock.DockedWith).OwnerUid, out ServerDoorComponent? doorB)) + if (EntityManager.TryGetComponent(((IComponent) dock.DockedWith).Owner, out ServerDoorComponent? doorB)) { doorB.ChangeAirtight = true; doorB.Close(); diff --git a/Content.Server/Stack/StackSystem.cs b/Content.Server/Stack/StackSystem.cs index 0a6d0dfe88..05fd3d66ea 100644 --- a/Content.Server/Stack/StackSystem.cs +++ b/Content.Server/Stack/StackSystem.cs @@ -185,8 +185,7 @@ namespace Content.Server.Stack return; } - var split = Split(uid, amount, userTransform.Coordinates, stack); - if (!split.Valid) + if (Split(uid, amount, userTransform.Coordinates, stack) is not {Valid: true} split) return; if (EntityManager.TryGetComponent(split, out var item)) diff --git a/Content.Server/Tabletop/TabletopSystem.Draggable.cs b/Content.Server/Tabletop/TabletopSystem.Draggable.cs index d5e20b086e..384d8234ac 100644 --- a/Content.Server/Tabletop/TabletopSystem.Draggable.cs +++ b/Content.Server/Tabletop/TabletopSystem.Draggable.cs @@ -4,7 +4,6 @@ using Content.Shared.Tabletop.Events; using Robust.Server.Player; using Robust.Shared.GameObjects; using Robust.Shared.GameStates; -using Robust.Shared.IoC; using Robust.Shared.Map; using Robust.Shared.Maths; using DrawDepth = Content.Shared.DrawDepth.DrawDepth; @@ -43,29 +42,29 @@ namespace Content.Server.Tabletop return; // Check if moved entity exists and has tabletop draggable component - if (!EntityManager.EntityExists(msg.MovedEntityUid) + if (!EntityManager.EntityExists(msg.MovedEntityUid)) return; - if (!EntityManager.HasComponent(movedEntity)) + if (!EntityManager.HasComponent(msg.MovedEntityUid)) return; // TODO: some permission system, disallow movement if you're not permitted to move the item // Move the entity and dirty it (we use the map ID from the entity so noone can try to be funny and move the item to another map) - var transform = EntityManager.GetComponent(movedEntity); + var transform = EntityManager.GetComponent(msg.MovedEntityUid); var entityCoordinates = new EntityCoordinates(_mapManager.GetMapEntityId(transform.MapID), msg.Coordinates.Position); transform.Coordinates = entityCoordinates; } private void OnDraggingPlayerChanged(TabletopDraggingPlayerChangedEvent msg) { - var draggedmsg.DraggedEntityUid + var dragged = msg.DraggedEntityUid; - if (!IoCManager.Resolve().TryGetComponent(draggedEntity, out var draggableComponent)) return; + if (!EntityManager.TryGetComponent(dragged, out var draggableComponent)) return; draggableComponent.DraggingPlayer = msg.DraggingPlayer; - if (!IoCManager.Resolve().TryGetComponent(draggedEntity, out var appearance)) return; + if (!EntityManager.TryGetComponent(dragged, out var appearance)) return; if (draggableComponent.DraggingPlayer != null) { diff --git a/Content.Server/Throwing/ThrowHelper.cs b/Content.Server/Throwing/ThrowHelper.cs index 0dc6e55f72..2f36b4b76f 100644 --- a/Content.Server/Throwing/ThrowHelper.cs +++ b/Content.Server/Throwing/ThrowHelper.cs @@ -33,9 +33,10 @@ namespace Content.Server.Throwing /// The ratio of impulse applied to the thrower internal static void TryThrow(this EntityUid entity, Vector2 direction, float strength = 1.0f, EntityUid? user = null, float pushbackRatio = 1.0f) { - if ((!IoCManager.Resolve().EntityExists(entity) ? EntityLifeStage.Deleted : IoCManager.Resolve().GetComponent(entity).EntityLifeStage) >= EntityLifeStage.Deleted || + var entities = IoCManager.Resolve(); + if (entities.GetComponent(entity).EntityDeleted || strength <= 0f || - !IoCManager.Resolve().TryGetComponent(entity, out PhysicsComponent? physicsComponent)) + !entities.TryGetComponent(entity, out PhysicsComponent? physicsComponent)) { return; } @@ -46,14 +47,14 @@ namespace Content.Server.Throwing return; } - if (IoCManager.Resolve().HasComponent(entity)) + if (entities.HasComponent(entity)) { Logger.Warning("Throwing not supported for mobs!"); return; } var comp = entity.EnsureComponent(); - if (IoCManager.Resolve().HasComponent(entity)) + if (entities.HasComponent(entity)) { comp.Thrower = user; // Give it a l'il spin. @@ -63,11 +64,11 @@ namespace Content.Server.Throwing } else if(direction != Vector2.Zero) { - IoCManager.Resolve().GetComponent(entity).LocalRotation = direction.ToWorldAngle() - Math.PI; + entities.GetComponent(entity).LocalRotation = direction.ToWorldAngle() - Math.PI; } if (user != null) - EntitySystem.Get().ThrownInteraction(user, entity); + EntitySystem.Get().ThrownInteraction(user.Value, entity); } var impulseVector = direction.Normalized * strength * physicsComponent.Mass; @@ -94,10 +95,10 @@ namespace Content.Server.Throwing } // Give thrower an impulse in the other direction - if (user != null && pushbackRatio > 0.0f && IoCManager.Resolve().TryGetComponent(user, out IPhysBody? body)) + if (user != null && pushbackRatio > 0.0f && entities.TryGetComponent(user.Value, out IPhysBody? body)) { var msg = new ThrowPushbackAttemptEvent(); - IoCManager.Resolve().EventBus.RaiseLocalEvent(body.Owner, msg); + entities.EventBus.RaiseLocalEvent(body.Owner, msg); if (!msg.Cancelled) { diff --git a/Content.Server/Tools/ToolSystem.Welder.cs b/Content.Server/Tools/ToolSystem.Welder.cs index e82f48bbdb..b937389bbf 100644 --- a/Content.Server/Tools/ToolSystem.Welder.cs +++ b/Content.Server/Tools/ToolSystem.Welder.cs @@ -6,7 +6,6 @@ using Content.Server.Chemistry.EntitySystems; using Content.Server.Items; using Content.Server.Tools.Components; using Content.Shared.Audio; -using Content.Shared.Chemistry.Reagent; using Content.Shared.Examine; using Content.Shared.FixedPoint; using Content.Shared.Interaction; @@ -17,7 +16,6 @@ using Robust.Server.GameObjects; using Robust.Shared.Audio; using Robust.Shared.GameObjects; using Robust.Shared.GameStates; -using Robust.Shared.IoC; using Robust.Shared.Localization; using Robust.Shared.Player; @@ -115,7 +113,7 @@ namespace Content.Server.Tools SoundSystem.Play(Filter.Pvs(uid), welder.WelderOnSounds.GetSound(), uid, AudioHelpers.WithVariation(0.125f).WithVolume(-5f)); // TODO: Use TransformComponent directly. - _atmosphereSystem.HotspotExpose(IoCManager.Resolve().GetComponent(welder.Owner).Coordinates, 700, 50, true); + _atmosphereSystem.HotspotExpose(EntityManager.GetComponent(welder.Owner).Coordinates, 700, 50, true); welder.Dirty(); @@ -205,27 +203,27 @@ namespace Content.Server.Tools if (args.Handled) return; - if (args.Target == null || !args.CanReach) + if (args.Target is not {Valid: true} target || !args.CanReach) return; // TODO: Clean up this inherited oldcode. - if (IoCManager.Resolve().TryGetComponent(args.Target, out ReagentTankComponent? tank) + if (EntityManager.TryGetComponent(target, out ReagentTankComponent? tank) && tank.TankType == ReagentTankType.Fuel - && _solutionContainerSystem.TryGetDrainableSolution(args.Target, out var targetSolution) + && _solutionContainerSystem.TryGetDrainableSolution(target, out var targetSolution) && _solutionContainerSystem.TryGetSolution(uid, welder.FuelSolution, out var welderSolution)) { var trans = FixedPoint2.Min(welderSolution.AvailableVolume, targetSolution.DrainAvailable); if (trans > 0) { - var drained = _solutionContainerSystem.Drain(args.Target, targetSolution, trans); + var drained = _solutionContainerSystem.Drain(target, targetSolution, trans); _solutionContainerSystem.TryAddSolution(uid, welderSolution, drained); SoundSystem.Play(Filter.Pvs(uid), welder.WelderRefill.GetSound(), uid); - args.Target.PopupMessage(args.User, Loc.GetString("welder-component-after-interact-refueled-message")); + target.PopupMessage(args.User, Loc.GetString("welder-component-after-interact-refueled-message")); } else { - args.Target.PopupMessage(args.User, Loc.GetString("welder-component-no-fuel-in-tank", ("owner", args.Target))); + target.PopupMessage(args.User, Loc.GetString("welder-component-no-fuel-in-tank", ("owner", args.Target))); } } @@ -318,7 +316,7 @@ namespace Content.Server.Tools continue; // TODO: Use TransformComponent directly. - _atmosphereSystem.HotspotExpose(IoCManager.Resolve().GetComponent(welder.Owner).Coordinates, 700, 50, true); + _atmosphereSystem.HotspotExpose(EntityManager.GetComponent(welder.Owner).Coordinates, 700, 50, true); solution.RemoveReagent(welder.FuelReagent, welder.FuelConsumption * _welderTimer); diff --git a/Content.Server/Traitor/Uplink/Account/UplinkAccountsSystem.cs b/Content.Server/Traitor/Uplink/Account/UplinkAccountsSystem.cs index 31d5584e83..decaf4a236 100644 --- a/Content.Server/Traitor/Uplink/Account/UplinkAccountsSystem.cs +++ b/Content.Server/Traitor/Uplink/Account/UplinkAccountsSystem.cs @@ -69,7 +69,7 @@ namespace Content.Server.Traitor.Uplink.Account } - public bool TryPurchaseItem(UplinkAccount acc, string itemId, EntityCoordinates spawnCoords, [NotNullWhen(true)] out EntityUid purchasedItem) + public bool TryPurchaseItem(UplinkAccount acc, string itemId, EntityCoordinates spawnCoords, [NotNullWhen(true)] out EntityUid? purchasedItem) { purchasedItem = null; diff --git a/Content.Server/Traitor/Uplink/Commands/AddUplinkCommand.cs b/Content.Server/Traitor/Uplink/Commands/AddUplinkCommand.cs index 33e6d43264..900d2198f7 100644 --- a/Content.Server/Traitor/Uplink/Commands/AddUplinkCommand.cs +++ b/Content.Server/Traitor/Uplink/Commands/AddUplinkCommand.cs @@ -43,7 +43,7 @@ namespace Content.Server.Traitor.Uplink.Commands var user = session.AttachedEntity; // Get target item - EntityUid uplinkEntity = null; + EntityUid? uplinkEntity = null; var entityManager = IoCManager.Resolve(); if (args.Length >= 2) { @@ -60,7 +60,7 @@ namespace Content.Server.Traitor.Uplink.Commands return; } - uplinkeUid + uplinkEntity = eUid; } // Get TC count @@ -74,7 +74,7 @@ namespace Content.Server.Traitor.Uplink.Commands // Finally add uplink if (!entityManager.EntitySysManager.GetEntitySystem() - .AddUplink(user, uplinkAccount!, uplinkEntity)) + .AddUplink(user.Value, uplinkAccount, uplinkEntity)) { shell.WriteLine(Loc.GetString("Failed to add uplink to the player")); return; diff --git a/Content.Server/Traitor/Uplink/UplinkSystem.cs b/Content.Server/Traitor/Uplink/UplinkSystem.cs index a8f3405c0f..458defd0e2 100644 --- a/Content.Server/Traitor/Uplink/UplinkSystem.cs +++ b/Content.Server/Traitor/Uplink/UplinkSystem.cs @@ -113,12 +113,11 @@ namespace Content.Server.Traitor.Uplink private void OnBuy(EntityUid uid, UplinkComponent uplink, UplinkBuyListingMessage message) { - var player = message.Session.AttachedEntity; - if (player == null) return; + if (message.Session.AttachedEntity is not {Valid: true} player) return; if (uplink.UplinkAccount == null) return; if (!_accounts.TryPurchaseItem(uplink.UplinkAccount, message.ItemId, - IoCManager.Resolve().GetComponent(player).Coordinates, out var entity)) + EntityManager.GetComponent(player).Coordinates, out var entity)) { SoundSystem.Play(Filter.SinglePlayer(message.Session), uplink.InsufficientFundsSound.GetSound(), uplink.Owner, AudioParams.Default); @@ -126,8 +125,8 @@ namespace Content.Server.Traitor.Uplink return; } - if (IoCManager.Resolve().TryGetComponent(player, out HandsComponent? hands) && - IoCManager.Resolve().TryGetComponent(entity, out ItemComponent? item)) + if (EntityManager.TryGetComponent(player, out HandsComponent? hands) && + EntityManager.TryGetComponent(entity.Value, out ItemComponent? item)) { hands.PutInHandOrDrop(item); } @@ -144,17 +143,16 @@ namespace Content.Server.Traitor.Uplink if (acc == null) return; - var player = args.Session.AttachedEntity; - if (player == null) return; - var cords = IoCManager.Resolve().GetComponent(player).Coordinates; + if (args.Session.AttachedEntity is not {Valid: true} player) return; + var cords = EntityManager.GetComponent(player).Coordinates; // try to withdraw TCs from account if (!_accounts.TryWithdrawTC(acc, args.TC, cords, out var tcUid)) return; // try to put it into players hands - if (IoCManager.Resolve().TryGetComponent(player, out SharedHandsComponent? hands)) - hands.TryPutInAnyHand(tcUid.Value) + if (EntityManager.TryGetComponent(player, out SharedHandsComponent? hands)) + hands.TryPutInAnyHand(tcUid.Value); // play buying sound SoundSystem.Play(Filter.SinglePlayer(args.Session), uplink.BuySuccessSound.GetSound(), @@ -189,7 +187,7 @@ namespace Content.Server.Traitor.Uplink ui.SetState(new UplinkUpdateState(accData, listings)); } - public bool AddUplink(EntityUid user, UplinkAccount account, EntityUid uplinkEntity = null) + public bool AddUplink(EntityUid user, UplinkAccount account, EntityUid? uplinkEntity = null) { // Try to find target item if (uplinkEntity == null) @@ -199,16 +197,16 @@ namespace Content.Server.Traitor.Uplink return false; } - var uplink = uplinkEntity.EnsureComponent(); + var uplink = uplinkEntity.Value.EnsureComponent(); SetAccount(uplink, account); return true; } - private EntityUid FindUplinkTarget(EntityUid user) + private EntityUid? FindUplinkTarget(EntityUid user) { // Try to find PDA in inventory - if (IoCManager.Resolve().TryGetComponent(user, out InventoryComponent? inventory)) + if (EntityManager.TryGetComponent(user, out InventoryComponent? inventory)) { var foundPDA = inventory.LookupItems().FirstOrDefault(); if (foundPDA != null) @@ -216,12 +214,12 @@ namespace Content.Server.Traitor.Uplink } // Also check hands - if (IoCManager.Resolve().TryGetComponent(user, out HandsComponent? hands)) + if (EntityManager.TryGetComponent(user, out HandsComponent? hands)) { var heldItems = hands.GetAllHeldItems(); foreach (var item in heldItems) { - if (IoCManager.Resolve().HasComponent(item.Owner)) + if (EntityManager.HasComponent(item.Owner)) return item.Owner; } } diff --git a/Content.Server/TraitorDeathMatch/Components/TraitorDeathMatchRedemptionComponent.cs b/Content.Server/TraitorDeathMatch/Components/TraitorDeathMatchRedemptionComponent.cs index d1e68313c4..654562cf1d 100644 --- a/Content.Server/TraitorDeathMatch/Components/TraitorDeathMatchRedemptionComponent.cs +++ b/Content.Server/TraitorDeathMatch/Components/TraitorDeathMatchRedemptionComponent.cs @@ -63,10 +63,9 @@ namespace Content.Server.TraitorDeathMatch.Components return false; } - var userPDAEntity = userInv.GetSlotItem(EquipmentSlotDefines.Slots.IDCARD)?.Owner; UplinkComponent? userUplink = null; - if (userPDAEntity != null) + if (userInv.GetSlotItem(EquipmentSlotDefines.Slots.IDCARD)?.Owner is {Valid: true} userPDAEntity) if (IoCManager.Resolve().TryGetComponent(userPDAEntity, out var userUplinkComponent)) userUplink = userUplinkComponent; diff --git a/Content.Server/VendingMachines/VendingMachineComponent.cs b/Content.Server/VendingMachines/VendingMachineComponent.cs index 52ea270bb7..cd0f07f226 100644 --- a/Content.Server/VendingMachines/VendingMachineComponent.cs +++ b/Content.Server/VendingMachines/VendingMachineComponent.cs @@ -188,12 +188,12 @@ namespace Content.Server.VendingMachines SoundSystem.Play(Filter.Pvs(Owner), _soundVend.GetSound(), Owner, AudioParams.Default.WithVolume(-2f)); } - private void TryEject(string id, EntityUid sender) + private void TryEject(string id, EntityUid? sender) { if (IoCManager.Resolve().TryGetComponent(Owner, out var accessReader)) { var accessSystem = EntitySystem.Get(); - if (sender == null || !accessSystem.IsAllowed(accessReader, sender)) + if (sender == null || !accessSystem.IsAllowed(accessReader, sender.Value)) { Owner.PopupMessageEveryone(Loc.GetString("vending-machine-component-try-eject-access-denied")); Deny(); diff --git a/Content.Server/Verbs/Commands/InvokeVerbCommand.cs b/Content.Server/Verbs/Commands/InvokeVerbCommand.cs index bf31e5ab89..34c4311abd 100644 --- a/Content.Server/Verbs/Commands/InvokeVerbCommand.cs +++ b/Content.Server/Verbs/Commands/InvokeVerbCommand.cs @@ -34,7 +34,7 @@ namespace Content.Server.Verbs.Commands { if (args[0] == "self" && shell.Player?.AttachedEntity != null) { - playerEntity = shell.Player.AttachedEntityUid.Value; + playerEntity = shell.Player.AttachedEntity.Value; } else { @@ -60,17 +60,15 @@ namespace Content.Server.Verbs.Commands return; } - var entUid = new EntityUid(intUid); - if (!entityManager.EntityExists(entUid)) + var target = new EntityUid(intUid); + if (!entityManager.EntityExists(target)) { shell.WriteError(Loc.GetString("invoke-verb-command-invalid-target-entity")); return; } var verbName = args[2].ToLowerInvariant(); - var verbs = verbSystem.GetLocalVerbs( - target, playerEntity, VerbType.All, true - ); + var verbs = verbSystem.GetLocalVerbs(target, playerEntity, VerbType.All, true); if ((Enum.TryParse(typeof(VerbType), verbName, ignoreCase: true, out var vtype) && vtype is VerbType key) && diff --git a/Content.Server/Verbs/Commands/ListVerbsCommand.cs b/Content.Server/Verbs/Commands/ListVerbsCommand.cs index 675b90403f..b4af5bccd7 100644 --- a/Content.Server/Verbs/Commands/ListVerbsCommand.cs +++ b/Content.Server/Verbs/Commands/ListVerbsCommand.cs @@ -27,7 +27,7 @@ namespace Content.Server.Verbs.Commands var verbSystem = EntitySystem.Get(); // get the 'player' entity (defaulting to command user, otherwise uses a uid) - EntityUid playerEntity = null; + EntityUid? playerEntity = null; if (!int.TryParse(args[0], out var intPlayerUid)) { if (args[0] == "self" && shell.Player?.AttachedEntity != null) @@ -58,16 +58,14 @@ namespace Content.Server.Verbs.Commands return; } - var entUid = new EntityUid(intUid); - if (!entityManager.EntityExists(entUid) + var target = new EntityUid(intUid); + if (!entityManager.EntityExists(target)) { shell.WriteError(Loc.GetString("list-verbs-command-invalid-target-entity")); return; } - var verbs = verbSystem.GetLocalVerbs( - target, playerEntity, VerbType.All, true - ); + var verbs = verbSystem.GetLocalVerbs(target, playerEntity.Value, VerbType.All, true); foreach (var (type, set) in verbs) { diff --git a/Content.Server/Verbs/VerbSystem.cs b/Content.Server/Verbs/VerbSystem.cs index 021970b04f..0ce54b8892 100644 --- a/Content.Server/Verbs/VerbSystem.cs +++ b/Content.Server/Verbs/VerbSystem.cs @@ -29,14 +29,14 @@ namespace Content.Server.Verbs return; } - if (!EntityManager.EntityExists(args.Target) + if (!EntityManager.EntityExists(args.Target)) { return; } // Get the list of verbs. This effectively also checks that the requested verb is in fact a valid verb that // the user can perform. - var verbs = GetLocalVerbs(targetEntity, userEntity, args.Type)[args.Type]; + var verbs = GetLocalVerbs(args.Target, userEntity.Value, args.Type)[args.Type]; // Note that GetLocalVerbs might waste time checking & preparing unrelated verbs even though we know // precisely which one we want to run. However, MOST entities will only have 1 or 2 verbs of a given type. @@ -44,7 +44,7 @@ namespace Content.Server.Verbs // Find the requested verb. if (verbs.TryGetValue(args.RequestedVerb, out var verb)) - ExecuteVerb(verb, userEntity, args.Target); + ExecuteVerb(verb, userEntity.Value, args.Target); else // 404 Verb not found. Note that this could happen due to something as simple as opening the verb menu, walking away, then trying // to run the pickup-item verb. So maybe this shouldn't even be logged? @@ -55,7 +55,7 @@ namespace Content.Server.Verbs { var player = (IPlayerSession) eventArgs.SenderSession; - if (!EntityManager.EntityExists(args.EntityUid) + if (!EntityManager.EntityExists(args.EntityUid)) { Logger.Warning($"{nameof(HandleVerbRequest)} called on a non-existent entity with id {args.EntityUid} by player {player}."); return; @@ -71,7 +71,7 @@ namespace Content.Server.Verbs // this, and some verbs (e.g. view variables) won't even care about whether an entity is accessible through // the entity menu or not. - var response = new VerbsResponseEvent(args.EntityUid, GetLocalVerbs(target, player.AttachedEntity, args.Type)); + var response = new VerbsResponseEvent(args.EntityUid, GetLocalVerbs(args.EntityUid, player.AttachedEntity.Value, args.Type)); RaiseNetworkEvent(response, player.ConnectedClient); } } diff --git a/Content.Server/Weapon/Ranged/Ammunition/Components/AmmoComponent.cs b/Content.Server/Weapon/Ranged/Ammunition/Components/AmmoComponent.cs index 9c6e69f81f..d5ee001c85 100644 --- a/Content.Server/Weapon/Ranged/Ammunition/Components/AmmoComponent.cs +++ b/Content.Server/Weapon/Ranged/Ammunition/Components/AmmoComponent.cs @@ -104,7 +104,7 @@ namespace Content.Server.Weapon.Ranged.Ammunition.Components } } - public EntityUid TakeBullet(EntityCoordinates spawnAt) + public EntityUid? TakeBullet(EntityCoordinates spawnAt) { if (_ammoIsProjectile) { diff --git a/Content.Server/Weapon/Ranged/Barrels/BarrelSystem.cs b/Content.Server/Weapon/Ranged/Barrels/BarrelSystem.cs index dc443ef7f0..1f3f069b14 100644 --- a/Content.Server/Weapon/Ranged/Barrels/BarrelSystem.cs +++ b/Content.Server/Weapon/Ranged/Barrels/BarrelSystem.cs @@ -76,7 +76,7 @@ namespace Content.Server.Weapon.Ranged.Barrels Verb verb = new() { - Text = IoCManager.Resolve().GetComponent(component.PowerCell.Owner).EntityName, + Text = EntityManager.GetComponent(component.PowerCell.Owner).EntityName, Category = VerbCategory.Eject, Act = () => component.TryEjectCell(args.User) }; @@ -85,18 +85,18 @@ namespace Content.Server.Weapon.Ranged.Barrels private void AddInsertCellVerb(EntityUid uid, ServerBatteryBarrelComponent component, GetInteractionVerbsEvent args) { - if (args.Using == null || + if (args.Using is not {Valid: true} @using || !args.CanAccess || !args.CanInteract || component.PowerCell != null || - !IoCManager.Resolve().HasComponent(args.Using) || + !EntityManager.HasComponent(@using) || !_actionBlockerSystem.CanDrop(args.User)) return; Verb verb = new(); - verb.Text = IoCManager.Resolve().GetComponent(args.Using).EntityName; + verb.Text = EntityManager.GetComponent(@using).EntityName; verb.Category = VerbCategory.Insert; - verb.Act = () => component.TryInsertPowerCell(args.Using); + verb.Act = () => component.TryInsertPowerCell(@using); args.Verbs.Add(verb); } @@ -113,7 +113,7 @@ namespace Content.Server.Weapon.Ranged.Barrels return; Verb verb = new(); - verb.Text = IoCManager.Resolve().GetComponent(component.MagazineContainer.ContainedEntity!).EntityName; + verb.Text = EntityManager.GetComponent(component.MagazineContainer.ContainedEntity!.Value).EntityName; verb.Category = VerbCategory.Eject; verb.Act = () => component.RemoveMagazine(args.User); args.Verbs.Add(verb); @@ -135,16 +135,16 @@ namespace Content.Server.Weapon.Ranged.Barrels args.Verbs.Add(toggleBolt); // Are we holding a mag that we can insert? - if (args.Using == null || - !component.CanInsertMagazine(args.User, args.Using) || + if (args.Using is not {Valid: true} @using || + !component.CanInsertMagazine(args.User, @using) || !_actionBlockerSystem.CanDrop(args.User)) return; // Insert mag verb Verb insert = new(); - insert.Text = IoCManager.Resolve().GetComponent(args.Using).EntityName; + insert.Text = EntityManager.GetComponent(@using).EntityName; insert.Category = VerbCategory.Insert; - insert.Act = () => component.InsertMagazine(args.User, args.Using); + insert.Act = () => component.InsertMagazine(args.User, @using); args.Verbs.Add(insert); } } diff --git a/Content.Server/Weapon/Ranged/Barrels/Components/BoltActionBarrelComponent.cs b/Content.Server/Weapon/Ranged/Barrels/Components/BoltActionBarrelComponent.cs index 1f2ee3cde7..7f23503c54 100644 --- a/Content.Server/Weapon/Ranged/Barrels/Components/BoltActionBarrelComponent.cs +++ b/Content.Server/Weapon/Ranged/Barrels/Components/BoltActionBarrelComponent.cs @@ -31,6 +31,7 @@ namespace Content.Server.Weapon.Ranged.Barrels.Components { // Originally I had this logic shared with PumpBarrel and used a couple of variables to control things // but it felt a lot messier to play around with, especially when adding verbs + [Dependency] private readonly IEntityManager _entities = default!; public override string Name => "BoltActionBarrel"; @@ -110,7 +111,7 @@ namespace Content.Server.Weapon.Ranged.Barrels.Components if (_unspawnedCount > 0) { _unspawnedCount--; - var chamberEntity = IoCManager.Resolve().SpawnEntity(_fillPrototype, IoCManager.Resolve().GetComponent(Owner).Coordinates); + var chamberEntity = _entities.SpawnEntity(_fillPrototype, _entities.GetComponent(Owner).Coordinates); _chamberContainer.Insert(chamberEntity); } } @@ -124,7 +125,7 @@ namespace Content.Server.Weapon.Ranged.Barrels.Components // (Is one chambered?, is the bullet spend) var chamber = (chamberedExists, false); - if (chamberedExists && IoCManager.Resolve().TryGetComponent(_chamberContainer.ContainedEntity!, out var ammo)) + if (chamberedExists && _entities.TryGetComponent(_chamberContainer.ContainedEntity!.Value, out var ammo)) { chamber.Item2 = ammo.Spent; } @@ -154,7 +155,7 @@ namespace Content.Server.Weapon.Ranged.Barrels.Components _chamberContainer = ContainerHelpers.EnsureContainer(Owner, $"{Name}-chamber-container"); - if (IoCManager.Resolve().TryGetComponent(Owner, out AppearanceComponent? appearanceComponent)) + if (_entities.TryGetComponent(Owner, out AppearanceComponent? appearanceComponent)) { _appearanceComponent = appearanceComponent; } @@ -171,14 +172,13 @@ namespace Content.Server.Weapon.Ranged.Barrels.Components _appearanceComponent?.SetData(AmmoVisuals.AmmoMax, Capacity); } - public override EntityUid PeekAmmo() + public override EntityUid? PeekAmmo() { return _chamberContainer.ContainedEntity; } - public override EntityUid TakeProjectile(EntityCoordinates spawnAt) + public override EntityUid? TakeProjectile(EntityCoordinates spawnAt) { - var chamberEntity = _chamberContainer.ContainedEntity; if (_autoCycle) { Cycle(); @@ -188,10 +188,10 @@ namespace Content.Server.Weapon.Ranged.Barrels.Components Dirty(); } - if (chamberEntity == null) + if (_chamberContainer.ContainedEntity is not {Valid: true} chamberEntity) return null; - return IoCManager.Resolve().GetComponentOrNull(chamberEntity)?.TakeBullet(spawnAt); + return _entities.GetComponentOrNull(chamberEntity)?.TakeBullet(spawnAt); } protected override bool WeaponCanFire() @@ -229,7 +229,7 @@ namespace Content.Server.Weapon.Ranged.Barrels.Components public bool TryInsertBullet(EntityUid user, EntityUid ammo) { - if (!IoCManager.Resolve().TryGetComponent(ammo, out AmmoComponent? ammoComponent)) + if (!_entities.TryGetComponent(ammo, out AmmoComponent? ammoComponent)) { return false; } @@ -291,16 +291,15 @@ namespace Content.Server.Weapon.Ranged.Barrels.Components private bool TryEjectChamber() { - var chamberedEntity = _chamberContainer.ContainedEntity; - if (chamberedEntity != null) + if (_chamberContainer.ContainedEntity is {Valid: true} chambered) { - if (!_chamberContainer.Remove(chamberedEntity)) + if (!_chamberContainer.Remove(chambered)) { return false; } - if (!IoCManager.Resolve().GetComponent(chamberedEntity).Caseless) + if (!_entities.GetComponent(chambered).Caseless) { - EjectCasing(chamberedEntity); + EjectCasing(chambered); } return true; } @@ -322,7 +321,7 @@ namespace Content.Server.Weapon.Ranged.Barrels.Components else if (_unspawnedCount > 0) { _unspawnedCount--; - var ammoEntity = IoCManager.Resolve().SpawnEntity(_fillPrototype, IoCManager.Resolve().GetComponent(Owner).Coordinates); + var ammoEntity = _entities.SpawnEntity(_fillPrototype, _entities.GetComponent(Owner).Coordinates); _chamberContainer.Insert(ammoEntity); return true; } diff --git a/Content.Server/Weapon/Ranged/Barrels/Components/PumpBarrelComponent.cs b/Content.Server/Weapon/Ranged/Barrels/Components/PumpBarrelComponent.cs index 72e64e0337..8daffb7ace 100644 --- a/Content.Server/Weapon/Ranged/Barrels/Components/PumpBarrelComponent.cs +++ b/Content.Server/Weapon/Ranged/Barrels/Components/PumpBarrelComponent.cs @@ -85,7 +85,7 @@ namespace Content.Server.Weapon.Ranged.Barrels.Components // (Is one chambered?, is the bullet spend) var chamber = (chamberedExists, false); - if (chamberedExists && IoCManager.Resolve().TryGetComponent(_chamberContainer.ContainedEntity!, out var ammo)) + if (chamberedExists && IoCManager.Resolve().TryGetComponent(_chamberContainer.ContainedEntity!.Value, out var ammo)) { chamber.Item2 = ammo.Spent; } @@ -140,15 +140,13 @@ namespace Content.Server.Weapon.Ranged.Barrels.Components _appearanceComponent?.SetData(AmmoVisuals.AmmoMax, Capacity); } - public override EntityUid PeekAmmo() + public override EntityUid? PeekAmmo() { return _chamberContainer.ContainedEntity; } - public override EntityUid TakeProjectile(EntityCoordinates spawnAt) + public override EntityUid? TakeProjectile(EntityCoordinates spawnAt) { - var chamberEntity = _chamberContainer.ContainedEntity; - if (!_manualCycle) { Cycle(); @@ -158,7 +156,7 @@ namespace Content.Server.Weapon.Ranged.Barrels.Components Dirty(); } - if (chamberEntity == null) + if (_chamberContainer.ContainedEntity is not {Valid: true} chamberEntity) return null; return IoCManager.Resolve().GetComponentOrNull(chamberEntity)?.TakeBullet(spawnAt); @@ -166,8 +164,7 @@ namespace Content.Server.Weapon.Ranged.Barrels.Components private void Cycle(bool manual = false) { - var chamberedEntity = _chamberContainer.ContainedEntity; - if (chamberedEntity != null) + if (_chamberContainer.ContainedEntity is {Valid: true} chamberedEntity) { _chamberContainer.Remove(chamberedEntity); var ammoComponent = IoCManager.Resolve().GetComponent(chamberedEntity); diff --git a/Content.Server/Weapon/Ranged/Barrels/Components/RevolverBarrelComponent.cs b/Content.Server/Weapon/Ranged/Barrels/Components/RevolverBarrelComponent.cs index 227e9c95db..236764bfa9 100644 --- a/Content.Server/Weapon/Ranged/Barrels/Components/RevolverBarrelComponent.cs +++ b/Content.Server/Weapon/Ranged/Barrels/Components/RevolverBarrelComponent.cs @@ -71,7 +71,7 @@ namespace Content.Server.Weapon.Ranged.Barrels.Components void ISerializationHooks.AfterDeserialization() { - _ammoSlots = new IEntity[_serializedCapacity]; + _ammoSlots = new EntityUid[_serializedCapacity]; } public override ComponentState GetComponentState() @@ -81,7 +81,7 @@ namespace Content.Server.Weapon.Ranged.Barrels.Components { slotsSpent[i] = null; var ammoEntity = _ammoSlots[i]; - if (ammoEntity != null && IoCManager.Resolve().TryGetComponent(ammoEntity, out AmmoComponent? ammo)) + if (ammoEntity != default && IoCManager.Resolve().TryGetComponent(ammoEntity, out AmmoComponent? ammo)) { slotsSpent[i] = ammo.Spent; } @@ -155,7 +155,7 @@ namespace Content.Server.Weapon.Ranged.Barrels.Components for (var i = _ammoSlots.Length - 1; i >= 0; i--) { var slot = _ammoSlots[i]; - if (slot == null) + if (slot == default) { _currentSlot = i; _ammoSlots[i] = entity; @@ -191,7 +191,7 @@ namespace Content.Server.Weapon.Ranged.Barrels.Components Dirty(); } - public override EntityUid PeekAmmo() + public override EntityUid? PeekAmmo() { return _ammoSlots[_currentSlot]; } @@ -202,17 +202,17 @@ namespace Content.Server.Weapon.Ranged.Barrels.Components /// /// /// - public override EntityUid TakeProjectile(EntityCoordinates spawnAt) + public override EntityUid? TakeProjectile(EntityCoordinates spawnAt) { var ammo = _ammoSlots[_currentSlot]; - EntityUid bullet = null; - if (ammo != null) + EntityUid? bullet = null; + if (ammo != default) { var ammoComponent = IoCManager.Resolve().GetComponent(ammo); bullet = ammoComponent.TakeBullet(spawnAt); if (ammoComponent.Caseless) { - _ammoSlots[_currentSlot] = null; + _ammoSlots[_currentSlot] = default; _ammoContainer.Remove(ammo); } } @@ -226,14 +226,14 @@ namespace Content.Server.Weapon.Ranged.Barrels.Components for (var i = 0; i < _ammoSlots.Length; i++) { var entity = _ammoSlots[i]; - if (entity == null) + if (entity == default) { continue; } _ammoContainer.Remove(entity); EjectCasing(entity); - _ammoSlots[i] = null; + _ammoSlots[i] = default; } if (_ammoContainer.ContainedEntities.Count > 0) @@ -243,7 +243,6 @@ namespace Content.Server.Weapon.Ranged.Barrels.Components // May as well point back at the end? _currentSlot = _ammoSlots.Length - 1; - return; } /// diff --git a/Content.Server/Weapon/Ranged/Barrels/Components/ServerBatteryBarrelComponent.cs b/Content.Server/Weapon/Ranged/Barrels/Components/ServerBatteryBarrelComponent.cs index 4c72d1a6be..bd7ebb5cab 100644 --- a/Content.Server/Weapon/Ranged/Barrels/Components/ServerBatteryBarrelComponent.cs +++ b/Content.Server/Weapon/Ranged/Barrels/Components/ServerBatteryBarrelComponent.cs @@ -127,7 +127,7 @@ namespace Content.Server.Weapon.Ranged.Barrels.Components Dirty(); } - public override EntityUid PeekAmmo() + public override EntityUid? PeekAmmo() { // Spawn a dummy entity because it's easier to work with I guess // This will get re-used for the projectile @@ -141,7 +141,7 @@ namespace Content.Server.Weapon.Ranged.Barrels.Components return ammo.Value; } - public override EntityUid TakeProjectile(EntityCoordinates spawnAt) + public override EntityUid? TakeProjectile(EntityCoordinates spawnAt) { var powerCellEntity = _powerCellContainer.ContainedEntity; diff --git a/Content.Server/Weapon/Ranged/Barrels/Components/ServerMagazineBarrelComponent.cs b/Content.Server/Weapon/Ranged/Barrels/Components/ServerMagazineBarrelComponent.cs index 522a256c9f..53140aa692 100644 --- a/Content.Server/Weapon/Ranged/Barrels/Components/ServerMagazineBarrelComponent.cs +++ b/Content.Server/Weapon/Ranged/Barrels/Components/ServerMagazineBarrelComponent.cs @@ -191,12 +191,12 @@ namespace Content.Server.Weapon.Ranged.Barrels.Components UpdateAppearance(); } - public override EntityUid PeekAmmo() + public override EntityUid? PeekAmmo() { return BoltOpen ? default : _chamberContainer.ContainedEntity; } - public override EntityUid TakeProjectile(EntityCoordinates spawnAt) + public override EntityUid? TakeProjectile(EntityCoordinates spawnAt) { if (BoltOpen) { diff --git a/Content.Server/Weapon/Ranged/Barrels/Components/ServerRangedBarrelComponent.cs b/Content.Server/Weapon/Ranged/Barrels/Components/ServerRangedBarrelComponent.cs index 989c73a6dd..599394c6d6 100644 --- a/Content.Server/Weapon/Ranged/Barrels/Components/ServerRangedBarrelComponent.cs +++ b/Content.Server/Weapon/Ranged/Barrels/Components/ServerRangedBarrelComponent.cs @@ -57,8 +57,8 @@ namespace Content.Server.Weapon.Ranged.Barrels.Components // _lastFire is when we actually fired (so if we hold the button then recoil doesn't build up if we're not firing) private TimeSpan _lastFire; - public abstract EntityUid PeekAmmo(); - public abstract EntityUid TakeProjectile(EntityCoordinates spawnAt); + public abstract EntityUid? PeekAmmo(); + public abstract EntityUid? TakeProjectile(EntityCoordinates spawnAt); // Recoil / spray control [DataField("minAngle")] @@ -202,8 +202,7 @@ namespace Content.Server.Weapon.Ranged.Barrels.Components } var ammo = PeekAmmo(); - var projectile = TakeProjectile(_entities.GetComponent(shooter).Coordinates); - if (projectile == default) + if (TakeProjectile(_entities.GetComponent(shooter).Coordinates) is not {Valid: true} projectile) { SoundSystem.Play(Filter.Broadcast(), SoundEmpty.GetSound(), Owner); return; @@ -225,9 +224,9 @@ namespace Content.Server.Weapon.Ranged.Barrels.Components } else if (_entities.HasComponent(projectile) && ammo != default && - _entities.TryGetComponent(ammo, out AmmoComponent? ammoComponent)) + _entities.TryGetComponent(ammo.Value, out AmmoComponent? ammoComponent)) { - FireProjectiles(shooter, projectile, ammoComponent.ProjectilesFired, ammoComponent.EvenSpreadAngle, angle, ammoComponent.Velocity, ammo); + FireProjectiles(shooter, projectile, ammoComponent.ProjectilesFired, ammoComponent.EvenSpreadAngle, angle, ammoComponent.Velocity, ammo.Value); if (CanMuzzleFlash) { @@ -236,7 +235,7 @@ namespace Content.Server.Weapon.Ranged.Barrels.Components if (ammoComponent.Caseless) { - _entities.DeleteEntity(ammo); + _entities.DeleteEntity(ammo.Value); } } else diff --git a/Content.Server/Weapon/Ranged/ServerRangedWeaponComponent.cs b/Content.Server/Weapon/Ranged/ServerRangedWeaponComponent.cs index 94bf293b89..0a68f8c03c 100644 --- a/Content.Server/Weapon/Ranged/ServerRangedWeaponComponent.cs +++ b/Content.Server/Weapon/Ranged/ServerRangedWeaponComponent.cs @@ -104,8 +104,7 @@ namespace Content.Server.Weapon.Ranged switch (message) { case FirePosComponentMessage msg: - var user = session.AttachedEntity; - if (user == null) + if (session.AttachedEntity is not {Valid: true} user) { return; }