Fix more errors

This commit is contained in:
DrSmugleaf
2021-12-06 00:52:58 +01:00
parent 2b1fecbe02
commit 215cae5655
55 changed files with 262 additions and 297 deletions

View File

@@ -23,7 +23,7 @@ namespace Content.Client.Conveyor.Visualizers
private void ChangeState(AppearanceComponent appearance)
{
var entities = IoCManager.Resolve<IEntityManager>();
if (!entities.TryGetComponent(appearance.OwnerUid, out ISpriteComponent? sprite))
if (!entities.TryGetComponent(appearance.Owner, out ISpriteComponent? sprite))
{
return;
}

View File

@@ -22,7 +22,7 @@ namespace Content.Client.Conveyor.Visualizers
private void ChangeState(AppearanceComponent appearance)
{
var entities = IoCManager.Resolve<IEntityManager>();
if (!entities.TryGetComponent(appearance.OwnerUid, out ISpriteComponent? sprite))
if (!entities.TryGetComponent(appearance.Owner, out ISpriteComponent? sprite))
{
return;
}

View File

@@ -71,7 +71,7 @@ namespace Content.Client.Disposal.Visualizers
}
var entities = IoCManager.Resolve<IEntityManager>();
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<IEntityManager>().GetComponent<AnimationPlayerComponent>(appearance.OwnerUid);
var animPlayer = IoCManager.Resolve<IEntityManager>().GetComponent<AnimationPlayerComponent>(appearance.Owner);
if (!animPlayer.HasRunningAnimation(AnimationKey))
{

View File

@@ -24,7 +24,7 @@ namespace Content.Client.Disposal.Visualizers
private void ChangeState(AppearanceComponent appearance)
{
var entities = IoCManager.Resolve<IEntityManager>();
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<SubFloorHideComponent>();
}
else if (IoCManager.Resolve<IEntityManager>().HasComponent<SubFloorHideComponent>(appearance.OwnerUid))
else if (entities.HasComponent<SubFloorHideComponent>(appearance.Owner))
{
IoCManager.Resolve<IEntityManager>().RemoveComponent<SubFloorHideComponent>(appearance.OwnerUid);
entities.RemoveComponent<SubFloorHideComponent>(appearance.Owner);
}
}

View File

@@ -76,7 +76,7 @@ namespace Content.Client.Singularity
var distortions = _entityManager.EntityQuery<SingularityDistortionComponent>();
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))
{

View File

@@ -84,7 +84,7 @@ namespace Content.Client.StationEvents
var pulses = _entityManager.EntityQuery<RadiationPulseComponent>();
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))
{

View File

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

View File

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

View File

@@ -29,7 +29,7 @@ namespace Content.Server.Atmos.EntitySystems
{
if (airtight.FixAirBlockedDirectionInitialize)
{
var rotateEvent = new RotateEvent(airtight.OwnerUid, Angle.Zero, IoCManager.Resolve<IEntityManager>().GetComponent<TransformComponent>(airtight.Owner).WorldRotation);
var rotateEvent = new RotateEvent(airtight.Owner, Angle.Zero, IoCManager.Resolve<IEntityManager>().GetComponent<TransformComponent>(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)

View File

@@ -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<TransformComponent>(playerEnt).Coordinates, stack);
var splitStack = _stackSystem.Split(throwEnt, 1, EntityManager.GetComponent<TransformComponent>(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<TransformComponent>(playerEnt).WorldPosition;
var direction = coords.ToMapPos(EntityManager) - EntityManager.GetComponent<TransformComponent>(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;

View File

@@ -59,7 +59,7 @@ namespace Content.Server.Headset
{
if (Owner.TryGetContainer(out var container))
{
if (!IoCManager.Resolve<IEntityManager>().TryGetComponent(container.OwnerUid, out ActorComponent? actor))
if (!IoCManager.Resolve<IEntityManager>().TryGetComponent(container.Owner, out ActorComponent? actor))
return;
var playerChannel = actor.PlayerSession.ConnectedClient;

View File

@@ -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<IEntityManager>().GetComponent<MetaDataComponent>(args.Using).EntityName;
verb.Text = IoCManager.Resolve<IEntityManager>().GetComponent<MetaDataComponent>(args.Using.Value).EntityName;
args.Verbs.Add(verb);
}

View File

@@ -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<IEntityManager>().TryGetComponent(visiting, out GhostComponent? ghost))
{

View File

@@ -263,25 +263,25 @@ namespace Content.Server.Mind
/// <exception cref="ArgumentException">
/// Thrown if <paramref name="entity"/> is already owned by another mind.
/// </exception>
public void TransferTo(EntityUid entity = default, bool ghostCheckOverride = false)
public void TransferTo(EntityUid? entity, bool ghostCheckOverride = false)
{
var entMan = IoCManager.Resolve<IEntityManager>();
MindComponent? component = null;
var alreadyAttached = false;
if (entity != default)
if (entity != null)
{
if (!entMan.TryGetComponent<MindComponent>(entity, out component))
if (!entMan.TryGetComponent<MindComponent>(entity.Value, out component))
{
component = entMan.AddComponent<MindComponent>(entity);
component = entMan.AddComponent<MindComponent>(entity.Value);
}
else if (component!.HasMind)
{
EntitySystem.Get<GameTicker>().OnGhostAttempt(component.Mind!, false);
}
if (entMan.TryGetComponent<ActorComponent>(entity, out var actor))
if (entMan.TryGetComponent<ActorComponent>(entity.Value, out var actor))
{
// Happens when transferring to your currently visited entity.
if (actor.PlayerSession != Session)

View File

@@ -78,7 +78,7 @@ namespace Content.Server.PneumaticCannon
public struct FireData
{
public EntityUid User,
public EntityUid User;
public float Strength;
public Vector2 Direction;
}

View File

@@ -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<IEntityManager>().HasComponent<GasTankComponent>(args.Used)
if (EntityManager.HasComponent<GasTankComponent>(args.Used)
&& component.GasTankSlot.CanInsert(args.Used)
&& component.GasTankRequired)
{
@@ -103,7 +104,7 @@ namespace Content.Server.PneumaticCannon
return;
}
if (IoCManager.Resolve<IEntityManager>().TryGetComponent<ToolComponent?>(args.Used, out var tool))
if (EntityManager.TryGetComponent<ToolComponent?>(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<IEntityManager>().TryGetComponent<ItemComponent?>(args.Used, out var item)
&& IoCManager.Resolve<IEntityManager>().TryGetComponent<ServerStorageComponent?>(component.Owner, out var storage))
if (EntityManager.TryGetComponent<ItemComponent?>(args.Used, out var item)
&& EntityManager.TryGetComponent<ServerStorageComponent?>(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<IEntityManager>().TryGetComponent<ServerStorageComponent?>(comp.Owner, out var storage))
if (!EntityManager.TryGetComponent<ServerStorageComponent?>(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<IEntityManager>().GetComponent<TransformComponent>(user).WorldPosition).Normalized;
var dir = (click.ToMapPos(EntityManager) - EntityManager.GetComponent<TransformComponent>(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<IEntityManager>().TryGetComponent<ServerStorageComponent?>(comp.Owner, out var storage))
if (!EntityManager.TryGetComponent<ServerStorageComponent?>(comp.Owner, out var storage))
return;
if ((!IoCManager.Resolve<IEntityManager>().EntityExists(data.User) ? EntityLifeStage.Deleted : IoCManager.Resolve<IEntityManager>().GetComponent<MetaDataComponent>(data.User).EntityLifeStage) >= EntityLifeStage.Deleted)
if ((!EntityManager.EntityExists(data.User) ? EntityLifeStage.Deleted : EntityManager.GetComponent<MetaDataComponent>(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<IEntityManager>().TryGetComponent<CameraRecoilComponent?>(data.User, out var recoil))
if (EntityManager.TryGetComponent<CameraRecoilComponent?>(data.User, out var recoil))
{
recoil.Kick(Vector2.One * data.Strength);
}
@@ -238,7 +239,7 @@ namespace Content.Server.PneumaticCannon
// lasagna, anybody?
ent.EnsureComponent<ForcefeedOnCollideComponent>();
if(IoCManager.Resolve<IEntityManager>().TryGetComponent<StatusEffectsComponent?>(data.User, out var status)
if(EntityManager.TryGetComponent<StatusEffectsComponent?>(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<IEntityManager>().GetComponent<GasTankComponent>(comp.GasTankSlot.ContainedEntity);
var environment = _atmos.GetTileMixture(IoCManager.Resolve<IEntityManager>().GetComponent<TransformComponent>(comp.Owner).Coordinates, true);
var gas = EntityManager.GetComponent<GasTankComponent>(contained);
var environment = _atmos.GetTileMixture(EntityManager.GetComponent<TransformComponent>(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<IEntityManager>().TryGetComponent<GasTankComponent?>(component.GasTankSlot.ContainedEntity, out var tank))
if (EntityManager.TryGetComponent<GasTankComponent?>(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<IEntityManager>().TryGetComponent<HandsComponent?>(user, out var hands))
if (EntityManager.TryGetComponent<HandsComponent?>(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<IEntityManager>().TryGetComponent<ServerStorageComponent?>(component.Owner, out var storage))
if (EntityManager.TryGetComponent<ServerStorageComponent?>(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<IEntityManager>().TryGetComponent<AppearanceComponent?>(component.Owner, out var appearance))
if (EntityManager.TryGetComponent<AppearanceComponent?>(component.Owner, out var appearance))
{
appearance.SetData(PneumaticCannonVisuals.Tank,
component.GasTankSlot.ContainedEntities.Count != 0);

View File

@@ -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")]

View File

@@ -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<IEntityManager>().HasComponent<GhostComponent>(pointer))
if (EntityManager.HasComponent<GhostComponent>(pointer))
{
return IoCManager.Resolve<IEntityManager>().GetComponent<TransformComponent>(pointer).Coordinates.InRange(EntityManager, coordinates, 15);
return EntityManager.GetComponent<TransformComponent>(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<IEntityManager>().TryGetComponent(player, out VisibilityComponent? playerVisibility))
if (EntityManager.TryGetComponent(player, out VisibilityComponent? playerVisibility))
{
var arrowVisibility = arrow.EnsureComponent<VisibilityComponent>();
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<EyeComponent?>(ent, out var eyeComp) ||
(eyeComp.VisibilityMask & layer) == 0)
return false;
if (ent is null || (!IoCManager.Resolve<IEntityManager>().TryGetComponent<EyeComponent?>(ent, out var eyeComp) || (eyeComp.VisibilityMask & layer) == 0)) return false;
return IoCManager.Resolve<IEntityManager>().GetComponent<TransformComponent>(ent).MapPosition.InRange(IoCManager.Resolve<IEntityManager>().GetComponent<TransformComponent>(player).MapPosition, PointingRange);
return EntityManager.GetComponent<TransformComponent>(ent).MapPosition.InRange(EntityManager.GetComponent<TransformComponent>(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<IEntityManager>().GetComponent<MetaDataComponent>(player).EntityName), ("other", player))
: Loc.GetString("pointing-system-point-at-other-others", ("otherName", Name: IoCManager.Resolve<IEntityManager>().GetComponent<MetaDataComponent>(player).EntityName), ("other", pointed));
? Loc.GetString("pointing-system-point-at-self-others", ("otherName", Name: EntityManager.GetComponent<MetaDataComponent>(player).EntityName), ("other", player))
: Loc.GetString("pointing-system-point-at-other-others", ("otherName", Name: EntityManager.GetComponent<MetaDataComponent>(player).EntityName), ("other", pointed));
viewerPointedAtMessage = Loc.GetString("pointing-system-point-at-you-other", ("otherName", Name: IoCManager.Resolve<IEntityManager>().GetComponent<MetaDataComponent>(player).EntityName));
viewerPointedAtMessage = Loc.GetString("pointing-system-point-at-you-other", ("otherName", Name: EntityManager.GetComponent<MetaDataComponent>(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<IEntityManager>().GetComponent<MetaDataComponent>(player).EntityName), ("tileName", tileDef.DisplayName));
viewerMessage = Loc.GetString("pointing-system-other-point-at-tile", ("otherName", Name: EntityManager.GetComponent<MetaDataComponent>(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<IEntityManager>().HasComponent<PointingArrowComponent>(args.Target))
if (EntityManager.HasComponent<PointingArrowComponent>(args.Target))
return;
if (!IoCManager.Resolve<IEntityManager>().TryGetComponent<ActorComponent?>(args.User, out var actor) ||
!InRange(args.User, IoCManager.Resolve<IEntityManager>().GetComponent<TransformComponent>(args.Target).Coordinates))
if (!EntityManager.TryGetComponent<ActorComponent?>(args.User, out var actor) ||
!InRange(args.User, EntityManager.GetComponent<TransformComponent>(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<IEntityManager>().GetComponent<TransformComponent>(args.Target).Coordinates, args.Target); ;
verb.Act = () => TryPoint(actor.PlayerSession, EntityManager.GetComponent<TransformComponent>(args.Target).Coordinates, args.Target); ;
args.Verbs.Add(verb);
}

View File

@@ -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<IEntityManager>().GetComponent<TransformComponent>(component.Chasing).WorldPosition - transform.WorldPosition;
var difference = IoCManager.Resolve<IEntityManager>().GetComponent<TransformComponent>(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<IEntityManager>().GetComponent<TransformComponent>(component.Chasing).WorldPosition - transform.WorldPosition;
var toChased = IoCManager.Resolve<IEntityManager>().GetComponent<TransformComponent>(chasing).WorldPosition - transform.WorldPosition;
transform.WorldPosition += toChased * frameTime * component.ChasingSpeed;

View File

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

View File

@@ -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<IEntityManager>();
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);
}
}
}

View File

@@ -93,7 +93,7 @@ namespace Content.Server.Power.Components
if (user == null) return;
var accessSystem = EntitySystem.Get<AccessReaderSystem>();
if (_accessReader == null || accessSystem.IsAllowed(_accessReader, user))
if (_accessReader == null || accessSystem.IsAllowed(_accessReader, user.Value))
{
MainBreakerEnabled = !MainBreakerEnabled;
IoCManager.Resolve<IEntityManager>().GetComponent<PowerNetworkBatteryComponent>(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"));
}
}

View File

@@ -90,8 +90,7 @@ namespace Content.Server.Power.Components
/// <param name="user"></param>
public void RemoveItem(EntityUid user)
{
var heldItem = Container.ContainedEntity;
if (heldItem == null)
if (Container.ContainedEntity is not {Valid: true} heldItem)
{
return;
}

View File

@@ -43,7 +43,7 @@ namespace Content.Server.Power.EntitySystems
return;
Verb verb = new();
verb.Text = IoCManager.Resolve<IEntityManager>().GetComponent<MetaDataComponent>(component.Container.ContainedEntity!).EntityName;
verb.Text = IoCManager.Resolve<IEntityManager>().GetComponent<MetaDataComponent>(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<IEntityManager>().GetComponent<MetaDataComponent>(args.Using).EntityName;
verb.Text = IoCManager.Resolve<IEntityManager>().GetComponent<MetaDataComponent>(@using).EntityName;
verb.Category = VerbCategory.Insert;
verb.Act = () => component.TryInsertItem(args.Using);
verb.Act = () => component.TryInsertItem(@using);
args.Verbs.Add(verb);
}
}

View File

@@ -75,10 +75,8 @@ namespace Content.Server.Power.EntitySystems
}
}
private IEnumerable<ExtensionCableReceiverComponent> FindAvailableReceivers(EntityUid uid, float range)
private IEnumerable<ExtensionCableReceiverComponent> FindAvailableReceivers(EntityUid owner, float range)
{
var owner = uid
var nearbyEntities = IoCManager.Resolve<IEntityLookup>()
.GetEntitiesInRange(owner, range);

View File

@@ -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";
/// <summary>
@@ -81,7 +83,7 @@ namespace Content.Server.PowerCell.Components
get
{
if (_cellContainer.ContainedEntity == null) return null;
return IoCManager.Resolve<IEntityManager>().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<IEntityManager>().TryGetComponent(user, out HandsComponent? hands) || !hands.PutInHand(IoCManager.Resolve<IEntityManager>().GetComponent<ItemComponent>(cell.Owner)))
if (!_entities.TryGetComponent(user, out HandsComponent? hands) || !hands.PutInHand(_entities.GetComponent<ItemComponent>(cell.Owner)))
{
IoCManager.Resolve<IEntityManager>().GetComponent<TransformComponent>(cell.Owner).Coordinates = IoCManager.Resolve<IEntityManager>().GetComponent<TransformComponent>(user).Coordinates;
_entities.GetComponent<TransformComponent>(cell.Owner).Coordinates = _entities.GetComponent<TransformComponent>(user).Coordinates;
}
}
else
{
IoCManager.Resolve<IEntityManager>().GetComponent<TransformComponent>(cell.Owner).Coordinates = IoCManager.Resolve<IEntityManager>().GetComponent<TransformComponent>(Owner).Coordinates;
_entities.GetComponent<TransformComponent>(cell.Owner).Coordinates = _entities.GetComponent<TransformComponent>(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<IEntityManager>().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<IEntityManager>().TryGetComponent((EntityUid) cell, out (ItemComponent?) var _)) return false;
if (!IoCManager.Resolve<IEntityManager>().TryGetComponent<PowerCellComponent?>(cell, out var cellComponent)) return false;
if (!_entities.HasComponent<ItemComponent>(cell)) return false;
if (!_entities.TryGetComponent<PowerCellComponent?>(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<IEntityManager>().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<IEntityManager>().SpawnEntity(type, IoCManager.Resolve<IEntityManager>().GetComponent<TransformComponent>(Owner).Coordinates);
var cell = _entities.SpawnEntity(type, _entities.GetComponent<TransformComponent>(Owner).Coordinates);
_cellContainer.Insert(cell);
}
}

View File

@@ -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<IEntityManager>().HasComponent<PowerCellComponent>(args.Using) ||
!IoCManager.Resolve<IEntityManager>().HasComponent<PowerCellComponent>(@using) ||
!_actionBlockerSystem.CanDrop(args.User))
return;
Verb verb = new();
verb.Text = IoCManager.Resolve<IEntityManager>().GetComponent<MetaDataComponent>(args.Using).EntityName;
verb.Text = IoCManager.Resolve<IEntityManager>().GetComponent<MetaDataComponent>(@using).EntityName;
verb.Category = VerbCategory.Insert;
verb.Act = () => component.InsertCell(args.Using);
verb.Act = () => component.InsertCell(@using);
args.Verbs.Add(verb);
}

View File

@@ -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<EffectSystem>();
_startTime = _gameTiming.CurTime;

View File

@@ -38,7 +38,7 @@ namespace Content.Server.Projectiles
var coordinates = IoCManager.Resolve<IEntityManager>().GetComponent<TransformComponent>(args.OtherFixture.Body.Owner).Coordinates;
var playerFilter = Filter.Pvs(coordinates);
if (!((!IoCManager.Resolve<IEntityManager>().EntityExists(otherEntity) ? EntityLifeStage.Deleted : IoCManager.Resolve<IEntityManager>().GetComponent<MetaDataComponent>(otherEntity).EntityLifeStage) >= EntityLifeStage.Deleted) && component.SoundHitSpecies != null &&
if (!EntityManager.GetComponent<MetaDataComponent>(otherEntity).EntityDeleted && component.SoundHitSpecies != null &&
IoCManager.Resolve<IEntityManager>().HasComponent<SharedBodyComponent>(otherEntity))
{
SoundSystem.Play(playerFilter, component.SoundHitSpecies.GetSound(), coordinates);
@@ -51,18 +51,19 @@ namespace Content.Server.Projectiles
SoundSystem.Play(playerFilter, soundHit, coordinates);
}
if (!((!IoCManager.Resolve<IEntityManager>().EntityExists(otherEntity) ? EntityLifeStage.Deleted : IoCManager.Resolve<IEntityManager>().GetComponent<MetaDataComponent>(otherEntity).EntityLifeStage) >= EntityLifeStage.Deleted))
if (!EntityManager.GetComponent<MetaDataComponent>(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<IEntityManager>().EntityExists(otherEntity) ? EntityLifeStage.Deleted : IoCManager.Resolve<IEntityManager>().GetComponent<MetaDataComponent>(otherEntity).EntityLifeStage) >= EntityLifeStage.Deleted) && IoCManager.Resolve<IEntityManager>().TryGetComponent(otherEntity, out CameraRecoilComponent? recoilComponent))
if (!EntityManager.GetComponent<MetaDataComponent>(otherEntity).EntityDeleted &&
EntityManager.TryGetComponent(otherEntity, out CameraRecoilComponent? recoilComponent))
{
var direction = args.OurFixture.Body.LinearVelocity.Normalized;
recoilComponent.Kick(direction);

View File

@@ -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<IEntityManager>().TryGetComponent(pulled, out SharedPullableComponent? pullable))
if (!EntityManager.TryGetComponent(pulled.Value, out SharedPullableComponent? pullable))
{
return;
}

View File

@@ -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)

View File

@@ -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<IEntityManager>().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;

View File

@@ -124,19 +124,19 @@ namespace Content.Server.Sandbox
.EnumeratePrototypes<AccessLevelPrototype>()
.Select(p => p.ID).ToArray();
if (IoCManager.Resolve<IEntityManager>().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<IEntityManager>().HasComponent<AccessComponent>(wornItem.Owner))
if (_entityManager.HasComponent<AccessComponent>(wornItem.Owner))
{
UpgradeId(wornItem.Owner);
}
else if (IoCManager.Resolve<IEntityManager>().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<IEntityManager>().TryGetComponent(pda.Owner, out ItemSlotsComponent? itemSlots))
if (_entityManager.TryGetComponent(pda.Owner, out ItemSlotsComponent? itemSlots))
{
_entityManager.EntitySysManager.GetEntitySystem<ItemSlotsSystem>().
TryInsert(wornItem.Owner, pda.IdSlot, newID);
@@ -148,12 +148,12 @@ namespace Content.Server.Sandbox
}
}
}
else if (IoCManager.Resolve<IEntityManager>().TryGetComponent<HandsComponent?>(player.AttachedEntity, out var hands))
else if (_entityManager.TryGetComponent<HandsComponent?>(player.AttachedEntity.Value, out var hands))
{
var card = CreateFreshId();
if (!IoCManager.Resolve<IEntityManager>().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<IEntityManager>().GetComponent<ItemComponent>(card));
hands.PutInHandOrDrop(_entityManager.GetComponent<ItemComponent>(card));
}
}
@@ -162,18 +162,18 @@ namespace Content.Server.Sandbox
var accessSystem = EntitySystem.Get<AccessSystem>();
accessSystem.TrySetTags(id, allAccess);
if (IoCManager.Resolve<IEntityManager>().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<IEntityManager>().GetComponent<TransformComponent>(player.AttachedEntity).Coordinates);
var card = _entityManager.SpawnEntity("CaptainIDCard", _entityManager.GetComponent<TransformComponent>(player.AttachedEntity.Value).Coordinates);
UpgradeId(card);
IoCManager.Resolve<IEntityManager>().GetComponent<IdCardComponent>(card).FullName = IoCManager.Resolve<IEntityManager>().GetComponent<MetaDataComponent>(player.AttachedEntity).EntityName;
_entityManager.GetComponent<IdCardComponent>(card).FullName = _entityManager.GetComponent<MetaDataComponent>(player.AttachedEntity.Value).EntityName;
return card;
}
}

View File

@@ -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<TransformComponent>(((IComponent) dockA).OwnerUid).GridID).GridEntityId;
var gridBUid = _mapManager.GetGrid(EntityManager.GetComponent<TransformComponent>(((IComponent) dockB).OwnerUid).GridID).GridEntityId;
var gridAUid = _mapManager.GetGrid(EntityManager.GetComponent<TransformComponent>(((IComponent) dockA).Owner).GridID).GridEntityId;
var gridBUid = _mapManager.GetGrid(EntityManager.GetComponent<TransformComponent>(((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<TransformComponent>(((IComponent) dockA).OwnerUid);
var dockBXform = EntityManager.GetComponent<TransformComponent>(((IComponent) dockB).OwnerUid);
var dockAXform = EntityManager.GetComponent<TransformComponent>(((IComponent) dockA).Owner);
var dockBXform = EntityManager.GetComponent<TransformComponent>(((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
/// </summary>
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();

View File

@@ -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<ItemComponent>(split, out var item))

View File

@@ -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<TabletopDraggableComponent>(movedEntity))
if (!EntityManager.HasComponent<TabletopDraggableComponent>(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<TransformComponent>(movedEntity);
var transform = EntityManager.GetComponent<TransformComponent>(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<IEntityManager>().TryGetComponent<TabletopDraggableComponent?>(draggedEntity, out var draggableComponent)) return;
if (!EntityManager.TryGetComponent<TabletopDraggableComponent?>(dragged, out var draggableComponent)) return;
draggableComponent.DraggingPlayer = msg.DraggingPlayer;
if (!IoCManager.Resolve<IEntityManager>().TryGetComponent<AppearanceComponent?>(draggedEntity, out var appearance)) return;
if (!EntityManager.TryGetComponent<AppearanceComponent?>(dragged, out var appearance)) return;
if (draggableComponent.DraggingPlayer != null)
{

View File

@@ -33,9 +33,10 @@ namespace Content.Server.Throwing
/// <param name="pushbackRatio">The ratio of impulse applied to the thrower</param>
internal static void TryThrow(this EntityUid entity, Vector2 direction, float strength = 1.0f, EntityUid? user = null, float pushbackRatio = 1.0f)
{
if ((!IoCManager.Resolve<IEntityManager>().EntityExists(entity) ? EntityLifeStage.Deleted : IoCManager.Resolve<IEntityManager>().GetComponent<MetaDataComponent>(entity).EntityLifeStage) >= EntityLifeStage.Deleted ||
var entities = IoCManager.Resolve<IEntityManager>();
if (entities.GetComponent<MetaDataComponent>(entity).EntityDeleted ||
strength <= 0f ||
!IoCManager.Resolve<IEntityManager>().TryGetComponent(entity, out PhysicsComponent? physicsComponent))
!entities.TryGetComponent(entity, out PhysicsComponent? physicsComponent))
{
return;
}
@@ -46,14 +47,14 @@ namespace Content.Server.Throwing
return;
}
if (IoCManager.Resolve<IEntityManager>().HasComponent<MobStateComponent>(entity))
if (entities.HasComponent<MobStateComponent>(entity))
{
Logger.Warning("Throwing not supported for mobs!");
return;
}
var comp = entity.EnsureComponent<ThrownItemComponent>();
if (IoCManager.Resolve<IEntityManager>().HasComponent<ItemComponent>(entity))
if (entities.HasComponent<ItemComponent>(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<IEntityManager>().GetComponent<TransformComponent>(entity).LocalRotation = direction.ToWorldAngle() - Math.PI;
entities.GetComponent<TransformComponent>(entity).LocalRotation = direction.ToWorldAngle() - Math.PI;
}
if (user != null)
EntitySystem.Get<InteractionSystem>().ThrownInteraction(user, entity);
EntitySystem.Get<InteractionSystem>().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<IEntityManager>().TryGetComponent(user, out IPhysBody? body))
if (user != null && pushbackRatio > 0.0f && entities.TryGetComponent(user.Value, out IPhysBody? body))
{
var msg = new ThrowPushbackAttemptEvent();
IoCManager.Resolve<IEntityManager>().EventBus.RaiseLocalEvent(body.Owner, msg);
entities.EventBus.RaiseLocalEvent(body.Owner, msg);
if (!msg.Cancelled)
{

View File

@@ -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<IEntityManager>().GetComponent<TransformComponent>(welder.Owner).Coordinates, 700, 50, true);
_atmosphereSystem.HotspotExpose(EntityManager.GetComponent<TransformComponent>(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<IEntityManager>().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<IEntityManager>().GetComponent<TransformComponent>(welder.Owner).Coordinates, 700, 50, true);
_atmosphereSystem.HotspotExpose(EntityManager.GetComponent<TransformComponent>(welder.Owner).Coordinates, 700, 50, true);
solution.RemoveReagent(welder.FuelReagent, welder.FuelConsumption * _welderTimer);

View File

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

View File

@@ -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<IEntityManager>();
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<UplinkSystem>()
.AddUplink(user, uplinkAccount!, uplinkEntity))
.AddUplink(user.Value, uplinkAccount, uplinkEntity))
{
shell.WriteLine(Loc.GetString("Failed to add uplink to the player"));
return;

View File

@@ -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<IEntityManager>().GetComponent<TransformComponent>(player).Coordinates, out var entity))
EntityManager.GetComponent<TransformComponent>(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<IEntityManager>().TryGetComponent(player, out HandsComponent? hands) &&
IoCManager.Resolve<IEntityManager>().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<IEntityManager>().GetComponent<TransformComponent>(player).Coordinates;
if (args.Session.AttachedEntity is not {Valid: true} player) return;
var cords = EntityManager.GetComponent<TransformComponent>(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<IEntityManager>().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<UplinkComponent>();
var uplink = uplinkEntity.Value.EnsureComponent<UplinkComponent>();
SetAccount(uplink, account);
return true;
}
private EntityUid FindUplinkTarget(EntityUid user)
private EntityUid? FindUplinkTarget(EntityUid user)
{
// Try to find PDA in inventory
if (IoCManager.Resolve<IEntityManager>().TryGetComponent(user, out InventoryComponent? inventory))
if (EntityManager.TryGetComponent(user, out InventoryComponent? inventory))
{
var foundPDA = inventory.LookupItems<PDAComponent>().FirstOrDefault();
if (foundPDA != null)
@@ -216,12 +214,12 @@ namespace Content.Server.Traitor.Uplink
}
// Also check hands
if (IoCManager.Resolve<IEntityManager>().TryGetComponent(user, out HandsComponent? hands))
if (EntityManager.TryGetComponent(user, out HandsComponent? hands))
{
var heldItems = hands.GetAllHeldItems();
foreach (var item in heldItems)
{
if (IoCManager.Resolve<IEntityManager>().HasComponent<PDAComponent>(item.Owner))
if (EntityManager.HasComponent<PDAComponent>(item.Owner))
return item.Owner;
}
}

View File

@@ -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<IEntityManager>().TryGetComponent<UplinkComponent?>(userPDAEntity, out var userUplinkComponent))
userUplink = userUplinkComponent;

View File

@@ -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<IEntityManager>().TryGetComponent<AccessReader?>(Owner, out var accessReader))
{
var accessSystem = EntitySystem.Get<AccessReaderSystem>();
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();

View File

@@ -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) &&

View File

@@ -27,7 +27,7 @@ namespace Content.Server.Verbs.Commands
var verbSystem = EntitySystem.Get<SharedVerbSystem>();
// 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)
{

View File

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

View File

@@ -104,7 +104,7 @@ namespace Content.Server.Weapon.Ranged.Ammunition.Components
}
}
public EntityUid TakeBullet(EntityCoordinates spawnAt)
public EntityUid? TakeBullet(EntityCoordinates spawnAt)
{
if (_ammoIsProjectile)
{

View File

@@ -76,7 +76,7 @@ namespace Content.Server.Weapon.Ranged.Barrels
Verb verb = new()
{
Text = IoCManager.Resolve<IEntityManager>().GetComponent<MetaDataComponent>(component.PowerCell.Owner).EntityName,
Text = EntityManager.GetComponent<MetaDataComponent>(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<IEntityManager>().HasComponent<BatteryComponent>(args.Using) ||
!EntityManager.HasComponent<BatteryComponent>(@using) ||
!_actionBlockerSystem.CanDrop(args.User))
return;
Verb verb = new();
verb.Text = IoCManager.Resolve<IEntityManager>().GetComponent<MetaDataComponent>(args.Using).EntityName;
verb.Text = EntityManager.GetComponent<MetaDataComponent>(@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<IEntityManager>().GetComponent<MetaDataComponent>(component.MagazineContainer.ContainedEntity!).EntityName;
verb.Text = EntityManager.GetComponent<MetaDataComponent>(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<IEntityManager>().GetComponent<MetaDataComponent>(args.Using).EntityName;
insert.Text = EntityManager.GetComponent<MetaDataComponent>(@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);
}
}

View File

@@ -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<IEntityManager>().SpawnEntity(_fillPrototype, IoCManager.Resolve<IEntityManager>().GetComponent<TransformComponent>(Owner).Coordinates);
var chamberEntity = _entities.SpawnEntity(_fillPrototype, _entities.GetComponent<TransformComponent>(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<IEntityManager>().TryGetComponent<AmmoComponent?>(_chamberContainer.ContainedEntity!, out var ammo))
if (chamberedExists && _entities.TryGetComponent<AmmoComponent?>(_chamberContainer.ContainedEntity!.Value, out var ammo))
{
chamber.Item2 = ammo.Spent;
}
@@ -154,7 +155,7 @@ namespace Content.Server.Weapon.Ranged.Barrels.Components
_chamberContainer = ContainerHelpers.EnsureContainer<ContainerSlot>(Owner, $"{Name}-chamber-container");
if (IoCManager.Resolve<IEntityManager>().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<IEntityManager>().GetComponentOrNull<AmmoComponent>(chamberEntity)?.TakeBullet(spawnAt);
return _entities.GetComponentOrNull<AmmoComponent>(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<IEntityManager>().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<IEntityManager>().GetComponent<AmmoComponent>(chamberedEntity).Caseless)
if (!_entities.GetComponent<AmmoComponent>(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<IEntityManager>().SpawnEntity(_fillPrototype, IoCManager.Resolve<IEntityManager>().GetComponent<TransformComponent>(Owner).Coordinates);
var ammoEntity = _entities.SpawnEntity(_fillPrototype, _entities.GetComponent<TransformComponent>(Owner).Coordinates);
_chamberContainer.Insert(ammoEntity);
return true;
}

View File

@@ -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<IEntityManager>().TryGetComponent<AmmoComponent?>(_chamberContainer.ContainedEntity!, out var ammo))
if (chamberedExists && IoCManager.Resolve<IEntityManager>().TryGetComponent<AmmoComponent?>(_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<IEntityManager>().GetComponentOrNull<AmmoComponent>(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<IEntityManager>().GetComponent<AmmoComponent>(chamberedEntity);

View File

@@ -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<IEntityManager>().TryGetComponent(ammoEntity, out AmmoComponent? ammo))
if (ammoEntity != default && IoCManager.Resolve<IEntityManager>().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
/// </summary>
/// <returns></returns>
/// <exception cref="NotImplementedException"></exception>
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<IEntityManager>().GetComponent<AmmoComponent>(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;
}
/// <summary>

View File

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

View File

@@ -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)
{

View File

@@ -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<TransformComponent>(shooter).Coordinates);
if (projectile == default)
if (TakeProjectile(_entities.GetComponent<TransformComponent>(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<ProjectileComponent>(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

View File

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