Make more uids nullable (#5794)

This commit is contained in:
Leon Friedrich
2021-12-26 15:32:45 +13:00
committed by GitHub
parent 83114de0e4
commit afc3ae6335
42 changed files with 161 additions and 204 deletions

View File

@@ -14,9 +14,6 @@ namespace Content.Client.Body.UI
[ViewVariables]
private BodyScannerDisplay? _display;
[ViewVariables]
private EntityUid _entity;
public BodyScannerBoundUserInterface(ClientUserInterfaceComponent owner, object uiKey) : base(owner, uiKey) { }
protected override void Open()
@@ -43,7 +40,7 @@ namespace Content.Client.Body.UI
throw new ArgumentException($"Received an invalid entity with id {scannerState.Uid} for body scanner with id {Owner.Owner} at {entMan.GetComponent<TransformComponent>(Owner.Owner).MapPosition}");
}
_display?.UpdateDisplay(_entity);
_display?.UpdateDisplay(scannerState.Uid);
}
protected override void Dispose(bool disposing)

View File

@@ -13,7 +13,7 @@ namespace Content.Client.Body.UI
{
public sealed class BodyScannerDisplay : SS14Window
{
private EntityUid _currentEntity;
private EntityUid? _currentEntity;
private SharedBodyPartComponent? _currentBodyPart;
public BodyScannerDisplay(BodyScannerBoundUserInterface owner)
@@ -104,9 +104,6 @@ namespace Content.Client.Body.UI
public void UpdateDisplay(EntityUid entity)
{
if(entity == null)
return;
_currentEntity = entity;
BodyPartList.Clear();
@@ -125,12 +122,7 @@ namespace Content.Client.Body.UI
public void BodyPartOnItemSelected(ItemListSelectedEventArgs args)
{
if (_currentEntity == null)
return;
var body = IoCManager.Resolve<IEntityManager>().GetComponentOrNull<SharedBodyComponent>(_currentEntity);
if (body == null)
if (IoCManager.Resolve<IEntityManager>().TryGetComponent<SharedBodyComponent>(_currentEntity, out var body))
{
return;
}

View File

@@ -15,7 +15,7 @@ namespace Content.Client.ContextMenu.UI
/// <summary>
/// The entity that can be accessed by interacting with this element.
/// </summary>
public EntityUid Entity;
public EntityUid? Entity;
/// <summary>
/// How many entities are accessible through this element's sub-menus.
@@ -28,7 +28,7 @@ namespace Content.Client.ContextMenu.UI
public readonly Label CountLabel;
public readonly SpriteView EntityIcon = new() { OverrideDirection = Direction.South};
public EntityMenuElement(EntityUid entity = default)
public EntityMenuElement(EntityUid? entity = null)
{
IoCManager.InjectDependencies(this);
@@ -40,7 +40,7 @@ namespace Content.Client.ContextMenu.UI
LayoutContainer.SetGrowVertical(CountLabel, LayoutContainer.GrowDirection.Begin);
Entity = entity;
if (Entity != default)
if (Entity != null)
{
Count = 1;
CountLabel.Visible = false;
@@ -51,7 +51,7 @@ namespace Content.Client.ContextMenu.UI
protected override void Dispose(bool disposing)
{
base.Dispose(disposing);
Entity = default;
Entity = null;
Count = 0;
}
@@ -59,23 +59,25 @@ namespace Content.Client.ContextMenu.UI
/// Update the icon and text of this element based on the given entity or this element's own entity if none
/// is provided.
/// </summary>
public void UpdateEntity(EntityUid entity = default)
public void UpdateEntity(EntityUid? entity = null)
{
if (Entity != default && _entityManager.EntityExists(Entity) && !entity.Valid)
entity = Entity;
entity ??= Entity;
if (entity == default)
// check whether entity is null, invalid, or has been deleted.
// _entityManager.Deleted() implicitly checks all of these.
if (_entityManager.Deleted(entity))
{
Text = string.Empty;
EntityIcon.Sprite = null;
return;
}
EntityIcon.Sprite = _entityManager.GetComponentOrNull<ISpriteComponent>(entity);
if (UserInterfaceManager.DebugMonitors.Visible)
Text = $"{_entityManager.GetComponent<MetaDataComponent>(entity!).EntityName} ({entity})";
Text = _entityManager.ToPrettyString(entity.Value);
else
Text = _entityManager.GetComponent<MetaDataComponent>(entity!).EntityName;
Text = _entityManager.GetComponent<MetaDataComponent>(entity.Value).EntityName;
}
}
}

View File

@@ -101,18 +101,16 @@ namespace Content.Client.ContextMenu.UI
// get an entity associated with this element
var entity = entityElement.Entity;
if (!entity.Valid)
{
entity = GetFirstEntityOrNull(element.SubMenu);
}
entity ??= GetFirstEntityOrNull(element.SubMenu);
if (!entity.Valid)
// Deleted() automatically checks for null & existence.
if (_entityManager.Deleted(entity))
return;
// open verb menu?
if (args.Function == ContentKeyFunctions.OpenContextMenu)
{
_verbSystem.VerbMenu.OpenVerbMenu(entity);
_verbSystem.VerbMenu.OpenVerbMenu(entity.Value);
args.Handle();
return;
}
@@ -120,7 +118,7 @@ namespace Content.Client.ContextMenu.UI
// do examination?
if (args.Function == ContentKeyFunctions.ExamineEntity)
{
_systemManager.GetEntitySystem<ExamineSystem>().DoExamine(entity);
_systemManager.GetEntitySystem<ExamineSystem>().DoExamine(entity.Value);
args.Handle();
return;
}
@@ -139,7 +137,7 @@ namespace Content.Client.ContextMenu.UI
var funcId = _inputManager.NetworkBindMap.KeyFunctionID(func);
var message = new FullInputCmdMessage(_gameTiming.CurTick, _gameTiming.TickFraction, funcId,
BoundKeyState.Down, _entityManager.GetComponent<TransformComponent>(entity).Coordinates, args.PointerLocation, entity);
BoundKeyState.Down, _entityManager.GetComponent<TransformComponent>(entity.Value).Coordinates, args.PointerLocation, entity.Value);
var session = _playerManager.LocalPlayer?.Session;
if (session != null)
@@ -314,7 +312,7 @@ namespace Content.Client.ContextMenu.UI
element.SubMenu.Dispose();
element.SubMenu = null;
element.CountLabel.Visible = false;
Elements[entity] = element;
Elements[entity.Value] = element;
}
// update the parent element, so that it's count and entity icon gets updated.
@@ -326,17 +324,17 @@ namespace Content.Client.ContextMenu.UI
/// <summary>
/// Recursively look through a sub-menu and return the first entity.
/// </summary>
private EntityUid GetFirstEntityOrNull(ContextMenuPopup? menu)
private EntityUid? GetFirstEntityOrNull(ContextMenuPopup? menu)
{
if (menu == null)
return default;
return null;
foreach (var element in menu.MenuBody.Children)
{
if (element is not EntityMenuElement entityElement)
continue;
if (entityElement.Entity != default)
if (entityElement.Entity != null)
{
if (!_entityManager.Deleted(entityElement.Entity))
return entityElement.Entity;
@@ -345,11 +343,11 @@ namespace Content.Client.ContextMenu.UI
// if the element has no entity, its a group of entities with another attached sub-menu.
var entity = GetFirstEntityOrNull(entityElement.SubMenu);
if (entity != default)
if (entity != null)
return entity;
}
return default;
return null;
}
public override void OpenSubMenu(ContextMenuElement element)

View File

@@ -118,8 +118,8 @@ namespace Content.Client.DoAfter
if (doAfter.BreakOnTargetMove)
{
if (EntityManager.EntityExists(doAfter.TargetUid) &&
!Transform(doAfter.TargetUid).Coordinates.InRange(EntityManager, doAfter.TargetGrid,
if (!EntityManager.Deleted(doAfter.Target) &&
!Transform(doAfter.Target.Value).Coordinates.InRange(EntityManager, doAfter.TargetGrid,
doAfter.MovementThreshold))
{
comp.Cancel(id, currentTime);

View File

@@ -51,7 +51,7 @@ namespace Content.Client.Popups
PopupMessage(message, _eyeManager.CoordinatesToScreen(transform.Coordinates));
}
public void PopupMessage(string message, ScreenCoordinates coordinates, EntityUid entity = default)
public void PopupMessage(string message, ScreenCoordinates coordinates, EntityUid? entity = null)
{
var label = new PopupLabel(_eyeManager, EntityManager)
{
@@ -146,7 +146,7 @@ namespace Content.Client.Popups
public float TimeLeft { get; private set; }
public Vector2 InitialPos { get; set; }
public EntityUid Entity { get; set; }
public EntityUid? Entity { get; set; }
public PopupLabel(IEyeManager eyeManager, IEntityManager entityManager)
{
@@ -161,9 +161,9 @@ namespace Content.Client.Popups
{
TimeLeft += eventArgs.DeltaSeconds;
var position = Entity == default
var position = Entity == null
? InitialPos
: (_eyeManager.CoordinatesToScreen(_entityManager.GetComponent<TransformComponent>(Entity).Coordinates).Position / UIScale) - DesiredSize / 2;
: (_eyeManager.CoordinatesToScreen(_entityManager.GetComponent<TransformComponent>(Entity.Value).Coordinates).Position / UIScale) - DesiredSize / 2;
LayoutContainer.SetPosition(this, position - (0, 20 * (TimeLeft * TimeLeft + TimeLeft)));

View File

@@ -44,7 +44,7 @@ namespace Content.Client.Viewport
private IEventBus _eventBus => _entityManager.EventBus;
private EntityUid _lastHoveredEntity;
private EntityUid? _lastHoveredEntity;
private bool _outlineEnabled = true;
@@ -84,7 +84,7 @@ namespace Content.Client.Viewport
// lead to extremely thick outlines in the other viewports. Fixing this probably requires changing how the
// hover outline works, so that it only highlights the entity in a single viewport.
EntityUid entityToClick = default;
EntityUid? entityToClick = null;
var renderScale = 1;
if (UserInterfaceManager.CurrentlyHovered is IViewportControl vp)
{
@@ -107,15 +107,15 @@ namespace Content.Client.Viewport
}
var inRange = false;
if (localPlayer.ControlledEntity != default && entityToClick != default)
if (localPlayer.ControlledEntity != null && entityToClick != null)
{
inRange = localPlayer.InRangeUnobstructed(entityToClick, ignoreInsideBlocker: true);
inRange = localPlayer.InRangeUnobstructed(entityToClick.Value, ignoreInsideBlocker: true);
}
InteractionOutlineComponent? outline;
if(!_outlineEnabled || !ConfigurationManager.GetCVar(CCVars.OutlineEnabled))
{
if(entityToClick != default && _entityManager.TryGetComponent(entityToClick, out outline))
if(entityToClick != null && _entityManager.TryGetComponent(entityToClick, out outline))
{
outline.OnMouseLeave(); //Prevent outline remains from persisting post command.
}
@@ -124,7 +124,7 @@ namespace Content.Client.Viewport
if (entityToClick == _lastHoveredEntity)
{
if (entityToClick != default && _entityManager.TryGetComponent(entityToClick, out outline))
if (entityToClick != null && _entityManager.TryGetComponent(entityToClick, out outline))
{
outline.UpdateInRange(inRange, renderScale);
}
@@ -132,7 +132,7 @@ namespace Content.Client.Viewport
return;
}
if (_lastHoveredEntity != default && !_entityManager.Deleted(_lastHoveredEntity) &&
if (_lastHoveredEntity != null && !_entityManager.Deleted(_lastHoveredEntity) &&
_entityManager.TryGetComponent(_lastHoveredEntity, out outline))
{
outline.OnMouseLeave();
@@ -140,16 +140,16 @@ namespace Content.Client.Viewport
_lastHoveredEntity = entityToClick;
if (_lastHoveredEntity != default && _entityManager.TryGetComponent(_lastHoveredEntity, out outline))
if (_lastHoveredEntity != null && _entityManager.TryGetComponent(_lastHoveredEntity, out outline))
{
outline.OnMouseEnter(inRange, renderScale);
}
}
public EntityUid GetEntityUnderPosition(MapCoordinates coordinates)
public EntityUid? GetEntityUnderPosition(MapCoordinates coordinates)
{
var entitiesUnderPosition = GetEntitiesUnderPosition(coordinates);
return entitiesUnderPosition.Count > 0 ? entitiesUnderPosition[0] : default;
return entitiesUnderPosition.Count > 0 ? entitiesUnderPosition[0] : null;
}
public IList<EntityUid> GetEntitiesUnderPosition(EntityCoordinates coordinates)
@@ -257,7 +257,7 @@ namespace Content.Client.Viewport
var funcId = InputManager.NetworkBindMap.KeyFunctionID(func);
EntityCoordinates coordinates = default;
EntityUid entityToClick = default;
EntityUid? entityToClick = null;
if (args.Viewport is IViewportControl vp)
{
var mousePosWorld = vp.ScreenToMap(kArgs.PointerLocation.Position);
@@ -269,7 +269,7 @@ namespace Content.Client.Viewport
var message = new FullInputCmdMessage(Timing.CurTick, Timing.TickFraction, funcId, kArgs.State,
coordinates , kArgs.PointerLocation,
entityToClick);
entityToClick ?? default); // TODO make entityUid nullable
// client side command handlers will always be sent the local player session.
var session = PlayerManager.LocalPlayer?.Session;

View File

@@ -64,10 +64,11 @@ namespace Content.Client.Wall.Components
{
base.Shutdown();
EntityUid tempQualifier = _overlayEntity;
if (tempQualifier != null)
// _overlayEntity is non-nullable as it is set on startup.
// Should also never be default but might as well check.
if (_overlayEntity.Valid)
{
_entMan.DeleteEntity(tempQualifier);
_entMan.DeleteEntity(_overlayEntity);
}
}

View File

@@ -39,7 +39,7 @@ namespace Content.Server.AI.LoadBalancer
var entity = _request.Context.GetState<SelfState>().GetValue();
if (entity == null || !IoCManager.Resolve<IEntityManager>().HasComponent<AiControllerComponent>(entity))
if (!IoCManager.Resolve<IEntityManager>().HasComponent<AiControllerComponent>(entity))
{
return null;
}

View File

@@ -12,7 +12,7 @@ namespace Content.Server.AI.Utility.Considerations.ActionBlocker
{
var self = context.GetState<SelfState>().GetValue();
if (self == null || !EntitySystem.Get<ActionBlockerSystem>().CanMove(self))
if (!EntitySystem.Get<ActionBlockerSystem>().CanMove(self))
{
return 0.0f;
}

View File

@@ -24,7 +24,7 @@ namespace Content.Server.AI.Utility.Considerations.Containers
return 0.0f;
}
if (target.TryGetContainer(out var container))
if (target!.Value.TryGetContainer(out var container))
{
if (entMan.TryGetComponent(container.Owner, out EntityStorageComponent? storageComponent))
{
@@ -43,12 +43,7 @@ namespace Content.Server.AI.Utility.Considerations.Containers
var owner = context.GetState<SelfState>().GetValue();
if (owner == null)
{
return 0;
}
return EntitySystem.Get<AiReachableSystem>().CanAccess(owner, target, SharedInteractionSystem.InteractionRange) ? 1.0f : 0.0f;
return EntitySystem.Get<AiReachableSystem>().CanAccess(owner, target.Value, SharedInteractionSystem.InteractionRange) ? 1.0f : 0.0f;
}
}
}

View File

@@ -15,7 +15,7 @@ namespace Content.Server.AI.Utility.Considerations.Nutrition.Drink
if (target == null
|| IoCManager.Resolve<IEntityManager>().Deleted(target)
|| !EntitySystem.Get<SolutionContainerSystem>().TryGetSolution(target, DrinkComponent.DefaultSolutionName, out var drink))
|| !EntitySystem.Get<SolutionContainerSystem>().TryGetSolution(target.Value, DrinkComponent.DefaultSolutionName, out var drink))
{
return 0.0f;
}

View File

@@ -13,7 +13,7 @@ namespace Content.Server.AI.Utility.Considerations.Nutrition.Drink
{
var owner = context.GetState<SelfState>().GetValue();
if (owner == null || !IoCManager.Resolve<IEntityManager>().TryGetComponent(owner, out ThirstComponent? thirst))
if (!IoCManager.Resolve<IEntityManager>().TryGetComponent(owner, out ThirstComponent? thirst))
{
return 0.0f;
}

View File

@@ -13,8 +13,8 @@ namespace Content.Server.AI.Utility.Considerations.Nutrition.Food
{
var target = context.GetState<TargetEntityState>().GetValue();
if (target == null || !IoCManager.Resolve<IEntityManager>().TryGetComponent<FoodComponent?>(target, out var foodComp)
|| !EntitySystem.Get<SolutionContainerSystem>().TryGetSolution(target, foodComp.SolutionName, out var food))
if (target == null || !IoCManager.Resolve<IEntityManager>().TryGetComponent<FoodComponent?>(target.Value, out var foodComp)
|| !EntitySystem.Get<SolutionContainerSystem>().TryGetSolution(target.Value, foodComp.SolutionName, out var food))
{
return 0.0f;
}

View File

@@ -14,7 +14,7 @@ namespace Content.Server.AI.Utility.Considerations.Nutrition.Food
{
var owner = context.GetState<SelfState>().GetValue();
if (owner == null || !IoCManager.Resolve<IEntityManager>().TryGetComponent(owner, out HungerComponent? hunger))
if (!IoCManager.Resolve<IEntityManager>().TryGetComponent(owner, out HungerComponent? hunger))
{
return 0.0f;
}

View File

@@ -4,13 +4,13 @@ using Robust.Shared.GameObjects;
namespace Content.Server.AI.WorldState.States.Combat
{
[UsedImplicitly]
public sealed class WeaponEntityState : PlanningStateData<EntityUid>
public sealed class WeaponEntityState : PlanningStateData<EntityUid?>
{
// Similar to TargetEntity
public override string Name => "WeaponEntity";
public override void Reset()
{
Value = default;
Value = null;
}
}
}

View File

@@ -9,18 +9,13 @@ namespace Content.Server.AI.WorldState.States.Inventory
/// AKA what's in active hand
/// </summary>
[UsedImplicitly]
public sealed class EquippedEntityState : StateData<EntityUid>
public sealed class EquippedEntityState : StateData<EntityUid?>
{
public override string Name => "EquippedEntity";
public override EntityUid GetValue()
public override EntityUid? GetValue()
{
if (!IoCManager.Resolve<IEntityManager>().TryGetComponent(Owner, out HandsComponent? handsComponent))
{
return default;
}
return handsComponent.GetActiveHand?.Owner ?? default;
return IoCManager.Resolve<IEntityManager>().GetComponentOrNull<HandsComponent>(Owner)?.GetActiveHand?.Owner;
}
}
}

View File

@@ -4,12 +4,12 @@ using Robust.Shared.GameObjects;
namespace Content.Server.AI.WorldState.States.Movement
{
[UsedImplicitly]
public sealed class MoveTargetState : PlanningStateData<EntityUid>
public sealed class MoveTargetState : PlanningStateData<EntityUid?>
{
public override string Name => "MoveTarget";
public override void Reset()
{
Value = default;
Value = null;
}
}
}

View File

@@ -7,13 +7,13 @@ namespace Content.Server.AI.WorldState.States
/// Could be target item to equip, target to attack, etc.
/// </summary>
[UsedImplicitly]
public sealed class TargetEntityState : PlanningStateData<EntityUid>
public sealed class TargetEntityState : PlanningStateData<EntityUid?>
{
public override string Name => "TargetEntity";
public override void Reset()
{
Value = default;
Value = null;
}
}
}

View File

@@ -11,15 +11,15 @@ namespace Content.Server.Body.Components
[Dependency] private readonly IEntityManager _entMan = default!;
public override string Name => "Internals";
[ViewVariables] public EntityUid GasTankEntity { get; set; }
[ViewVariables] public EntityUid BreathToolEntity { get; set; }
[ViewVariables] public EntityUid? GasTankEntity { get; set; }
[ViewVariables] public EntityUid? BreathToolEntity { get; set; }
public void DisconnectBreathTool()
{
var old = BreathToolEntity;
BreathToolEntity = default;
BreathToolEntity = null;
if (old != default && _entMan.TryGetComponent(old, out BreathToolComponent? breathTool) )
if (_entMan.TryGetComponent(old, out BreathToolComponent? breathTool) )
{
breathTool.DisconnectInternals();
DisconnectTank();
@@ -28,7 +28,7 @@ namespace Content.Server.Body.Components
public void ConnectBreathTool(EntityUid toolEntity)
{
if (BreathToolEntity != default && _entMan.TryGetComponent(BreathToolEntity, out BreathToolComponent? tool))
if (_entMan.TryGetComponent(BreathToolEntity, out BreathToolComponent? tool))
{
tool.DisconnectInternals();
}
@@ -38,20 +38,20 @@ namespace Content.Server.Body.Components
public void DisconnectTank()
{
if (GasTankEntity != default && _entMan.TryGetComponent(GasTankEntity, out GasTankComponent? tank))
if (_entMan.TryGetComponent(GasTankEntity, out GasTankComponent? tank))
{
tank.DisconnectFromInternals(Owner);
}
GasTankEntity = default;
GasTankEntity = null;
}
public bool TryConnectTank(EntityUid tankEntity)
{
if (BreathToolEntity == default)
if (BreathToolEntity == null)
return false;
if (GasTankEntity != default && _entMan.TryGetComponent(GasTankEntity, out GasTankComponent? tank))
if (_entMan.TryGetComponent(GasTankEntity, out GasTankComponent? tank))
{
tank.DisconnectFromInternals(Owner);
}
@@ -62,12 +62,10 @@ namespace Content.Server.Body.Components
public bool AreInternalsWorking()
{
return BreathToolEntity != default &&
GasTankEntity != default &&
_entMan.TryGetComponent(BreathToolEntity, out BreathToolComponent? breathTool) &&
return _entMan.TryGetComponent(BreathToolEntity, out BreathToolComponent? breathTool) &&
breathTool.IsFunctional &&
_entMan.TryGetComponent(GasTankEntity, out GasTankComponent? gasTank) &&
gasTank.Air != default;
gasTank.Air != null;
}
}

View File

@@ -291,9 +291,6 @@ namespace Content.Server.Botany
{
AddToDatabase();
if (user == null)
return Enumerable.Empty<EntityUid>();
if (ProductPrototypes == null || ProductPrototypes.Count == 0 || Yield <= 0)
{
user.PopupMessageCursor(Loc.GetString("botany-harvest-fail-message"));

View File

@@ -115,7 +115,7 @@ namespace Content.Server.Climbing.Components
return false;
}
if (target == null || !_entities.HasComponent<ClimbingComponent>(dragged))
if (!_entities.HasComponent<ClimbingComponent>(dragged))
{
reason = Loc.GetString("comp-climbable-cant-climb");
return false;

View File

@@ -25,7 +25,7 @@ namespace Content.Server.Clothing
private void AddToggleVerb(EntityUid uid, MagbootsComponent component, GetActivationVerbsEvent args)
{
if (args.User == null || !args.CanAccess || !args.CanInteract)
if (!args.CanAccess || !args.CanInteract)
return;
Verb verb = new();

View File

@@ -90,11 +90,6 @@ namespace Content.Server.Disposal.Unit.Components
private bool PlayerCanUse(EntityUid player)
{
if (player == null)
{
return false;
}
var actionBlocker = EntitySystem.Get<ActionBlockerSystem>();
if (!actionBlocker.CanInteract(player) ||

View File

@@ -275,19 +275,19 @@ namespace Content.Server.Doors.Components
#region Opening
public void TryOpen(EntityUid user = default)
public void TryOpen(EntityUid? user = null)
{
var msg = new DoorOpenAttemptEvent();
_entMan.EventBus.RaiseLocalEvent(Owner, msg);
if (msg.Cancelled) return;
if (!user.Valid)
if (user == null)
{
// a machine opened it or something, idk
Open();
}
else if (CanOpenByEntity(user))
else if (CanOpenByEntity(user.Value))
{
Open();
@@ -422,14 +422,14 @@ namespace Content.Server.Doors.Components
#region Closing
public void TryClose(EntityUid user = default)
public void TryClose(EntityUid? user = null)
{
var msg = new DoorCloseAttemptEvent();
_entMan.EventBus.RaiseLocalEvent(Owner, msg);
if (msg.Cancelled) return;
if (user != default && !CanCloseByEntity(user))
if (user != null && !CanCloseByEntity(user.Value))
{
Deny();
return;

View File

@@ -99,23 +99,17 @@ namespace Content.Server.Hands.Components
var source = @event.Source;
var target = @event.Target;
if (source != null)
{
SoundSystem.Play(Filter.Pvs(source), _disarmedSound.GetSound(), source, AudioHelpers.WithVariation(0.025f));
SoundSystem.Play(Filter.Pvs(source), _disarmedSound.GetSound(), source, AudioHelpers.WithVariation(0.025f));
if (target != null)
{
if (ActiveHand != null && Drop(ActiveHand, false))
{
source.PopupMessageOtherClients(Loc.GetString("hands-component-disarm-success-others-message", ("disarmer", Name: _entities.GetComponent<MetaDataComponent>(source).EntityName), ("disarmed", Name: _entities.GetComponent<MetaDataComponent>(target).EntityName)));
source.PopupMessageCursor(Loc.GetString("hands-component-disarm-success-message", ("disarmed", Name: _entities.GetComponent<MetaDataComponent>(target).EntityName)));
}
else
{
source.PopupMessageOtherClients(Loc.GetString("hands-component-shove-success-others-message", ("shover", Name: _entities.GetComponent<MetaDataComponent>(source).EntityName), ("shoved", Name: _entities.GetComponent<MetaDataComponent>(target).EntityName)));
source.PopupMessageCursor(Loc.GetString("hands-component-shove-success-message", ("shoved", Name: _entities.GetComponent<MetaDataComponent>(target).EntityName)));
}
}
if (ActiveHand != null && Drop(ActiveHand, false))
{
source.PopupMessageOtherClients(Loc.GetString("hands-component-disarm-success-others-message", ("disarmer", Name: _entities.GetComponent<MetaDataComponent>(source).EntityName), ("disarmed", Name: _entities.GetComponent<MetaDataComponent>(target).EntityName)));
source.PopupMessageCursor(Loc.GetString("hands-component-disarm-success-message", ("disarmed", Name: _entities.GetComponent<MetaDataComponent>(target).EntityName)));
}
else
{
source.PopupMessageOtherClients(Loc.GetString("hands-component-shove-success-others-message", ("shover", Name: _entities.GetComponent<MetaDataComponent>(source).EntityName), ("shoved", Name: _entities.GetComponent<MetaDataComponent>(target).EntityName)));
source.PopupMessageCursor(Loc.GetString("hands-component-shove-success-message", ("shoved", Name: _entities.GetComponent<MetaDataComponent>(target).EntityName)));
}
return true;

View File

@@ -67,17 +67,14 @@ namespace Content.Server.Light.EntitySystems
// standard interaction checks
if (!_blocker.CanInteract(eventArgs.User)) return;
if (eventArgs.Used != null)
{
var usedUid = eventArgs.Used;
var usedUid = eventArgs.Used;
// want to insert a new light bulb?
if (EntityManager.TryGetComponent(usedUid, out LightBulbComponent ? bulb))
eventArgs.Handled = TryInsertBulb(uid, usedUid, eventArgs.User, true, component, bulb);
// add bulbs from storage?
else if (EntityManager.TryGetComponent(usedUid, out ServerStorageComponent? storage))
eventArgs.Handled = TryInsertBulbsFromStorage(uid, usedUid, eventArgs.User, component, storage);
}
// want to insert a new light bulb?
if (EntityManager.TryGetComponent(usedUid, out LightBulbComponent? bulb))
eventArgs.Handled = TryInsertBulb(uid, usedUid, eventArgs.User, true, component, bulb);
// add bulbs from storage?
else if (EntityManager.TryGetComponent(usedUid, out ServerStorageComponent? storage))
eventArgs.Handled = TryInsertBulbsFromStorage(uid, usedUid, eventArgs.User, component, storage);
}
/// <summary>
@@ -108,7 +105,7 @@ namespace Content.Server.Light.EntitySystems
(e) => EntityManager.GetComponentOrNull<LightBulbComponent>(e)?.Type == fixture.BulbType);
// found bulb in inserted storage
if (bulb != null)
if (bulb.Valid) // FirstOrDefault can return default/invalid uid.
{
// try to remove it
var hasRemoved = replacer.InsertedBulbs.Remove(bulb);

View File

@@ -129,7 +129,7 @@ namespace Content.Server.PAI
private void AddWipeVerb(EntityUid uid, PAIComponent pai, GetActivationVerbsEvent args)
{
if (args.User == null || !args.CanAccess || !args.CanInteract)
if (!args.CanAccess || !args.CanInteract)
return;
if (EntityManager.TryGetComponent<MindComponent>(uid, out var mind) && mind.HasMind)

View File

@@ -128,7 +128,7 @@ namespace Content.Server.PowerCell.Components
/// <param name="user">(optional) the user to give the removed cell to.</param>
/// <param name="playSound">Should <see cref="CellRemoveSound"/> be played upon removal?</param>
/// <returns>The cell component of the entity that was removed, or null if removal failed.</returns>
public PowerCellComponent? EjectCell(EntityUid user, bool playSound = true)
public PowerCellComponent? EjectCell(EntityUid? user = null, bool playSound = true)
{
var cell = Cell;
if (cell == null || !CanRemoveCell) return null;
@@ -138,7 +138,7 @@ namespace Content.Server.PowerCell.Components
{
if (!_entities.TryGetComponent(user, out HandsComponent? hands) || !hands.PutInHand(_entities.GetComponent<ItemComponent>(cell.Owner)))
{
_entities.GetComponent<TransformComponent>(cell.Owner).Coordinates = _entities.GetComponent<TransformComponent>(user).Coordinates;
_entities.GetComponent<TransformComponent>(cell.Owner).Coordinates = _entities.GetComponent<TransformComponent>(user.Value).Coordinates;
}
}
else

View File

@@ -235,11 +235,8 @@ namespace Content.Server.RCD.Systems
mode = (++mode) % _modes.Length; //Then, do a rollover on the value so it doesnt hit an invalid state
rcd.Mode = (RcdMode) mode; //Finally, cast the newly acquired int mode to an RCDmode so we can use it.
if (user != null)
{
var msg = Loc.GetString("rcd-component-change-mode", ("mode", rcd.Mode.ToString()));
rcd.Owner.PopupMessage(user, msg); //Prints an overhead message above the RCD
}
var msg = Loc.GetString("rcd-component-change-mode", ("mode", rcd.Mode.ToString()));
rcd.Owner.PopupMessage(user, msg); //Prints an overhead message above the RCD
}
}
}

View File

@@ -42,7 +42,7 @@ namespace Content.Server.Stack
public EntityUid? Split(EntityUid uid, int amount, EntityCoordinates spawnPosition, SharedStackComponent? stack = null)
{
if (!Resolve(uid, ref stack))
return default;
return null;
// Get a prototype ID to spawn the new entity. Null is also valid, although it should rarely be picked...
var prototype = _prototypeManager.TryIndex<StackPrototype>(stack.StackTypeId, out var stackType)
@@ -51,7 +51,7 @@ namespace Content.Server.Stack
// Try to remove the amount of things we want to split from the original stack...
if (!Use(uid, amount, stack))
return default;
return null;
// Set the output parameter in the event instance to the newly split stack.
var entity = Spawn(prototype, spawnPosition);

View File

@@ -37,9 +37,9 @@ namespace Content.Server.Storage.Components
if (lockers.Contains(Owner))
lockers.Remove(Owner);
var lockerEnt = _robustRandom.Pick(lockers);
if (lockers.Count == 0) return;
if (lockerEnt == null) return; // No valid lockers anywhere.
var lockerEnt = _robustRandom.Pick(lockers);
var locker = _entMan.GetComponent<EntityStorageComponent>(lockerEnt);

View File

@@ -27,7 +27,7 @@ namespace Content.Server.Storage.EntitySystems
return;
var alreadySpawnedGroups = new List<string>();
EntityUid entityToPlaceInHands = default;
EntityUid? entityToPlaceInHands = null;
foreach (var storageItem in component.Items)
{
if (!string.IsNullOrEmpty(storageItem.GroupId) &&
@@ -57,10 +57,10 @@ namespace Content.Server.Storage.EntitySystems
EntityManager.DeleteEntity(uid);
}
if (entityToPlaceInHands != default
if (entityToPlaceInHands != null
&& EntityManager.TryGetComponent<SharedHandsComponent?>(args.User, out var hands))
{
hands.TryPutInAnyHand(entityToPlaceInHands);
hands.TryPutInAnyHand(entityToPlaceInHands.Value);
}
}
}

View File

@@ -40,18 +40,12 @@ namespace Content.Server.Stunnable
var source = args.Source;
var target = args.Target;
if (source != null)
{
var knock = EntityManager.GetComponent<KnockedDownComponent>(uid);
SoundSystem.Play(Filter.Pvs(source), knock.StunAttemptSound.GetSound(), source, AudioHelpers.WithVariation(0.025f));
var knock = EntityManager.GetComponent<KnockedDownComponent>(uid);
SoundSystem.Play(Filter.Pvs(source), knock.StunAttemptSound.GetSound(), source, AudioHelpers.WithVariation(0.025f));
if (target != null)
{
// TODO: Use PopupSystem
source.PopupMessageOtherClients(Loc.GetString("stunned-component-disarm-success-others", ("source", Name: EntityManager.GetComponent<MetaDataComponent>(source).EntityName), ("target", Name: EntityManager.GetComponent<MetaDataComponent>(target).EntityName)));
source.PopupMessageCursor(Loc.GetString("stunned-component-disarm-success", ("target", Name: EntityManager.GetComponent<MetaDataComponent>(target).EntityName)));
}
}
// TODO: Use PopupSystem
source.PopupMessageOtherClients(Loc.GetString("stunned-component-disarm-success-others", ("source", Name(source)), ("target", Name(target))));
source.PopupMessageCursor(Loc.GetString("stunned-component-disarm-success", ("target", Name(target))));
_adminLogSystem.Add(LogType.DisarmedKnockdown, LogImpact.Medium, $"{ToPrettyString(args.Source):user} knocked down {ToPrettyString(args.Target):target}");

View File

@@ -29,7 +29,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 = default;
EntityUid? playerEntity = null;
if (!int.TryParse(args[0], out var intPlayerUid))
{
if (args[0] == "self" && shell.Player?.AttachedEntity != null)
@@ -54,7 +54,7 @@ namespace Content.Server.Verbs.Commands
return;
}
if (playerEntity == default)
if (playerEntity == null)
{
shell.WriteError(Loc.GetString("invoke-verb-command-invalid-player-entity"));
return;
@@ -68,14 +68,14 @@ namespace Content.Server.Verbs.Commands
}
var verbName = args[2].ToLowerInvariant();
var verbs = verbSystem.GetLocalVerbs(target, playerEntity, VerbType.All, true);
var verbs = verbSystem.GetLocalVerbs(target, playerEntity.Value, VerbType.All, true);
if ((Enum.TryParse(typeof(VerbType), verbName, ignoreCase: true, out var vtype) &&
vtype is VerbType key) &&
verbs.TryGetValue(key, out var vset) &&
vset.Any())
{
verbSystem.ExecuteVerb(vset.First(), playerEntity, target, forced: true);
verbSystem.ExecuteVerb(vset.First(), playerEntity.Value, target, forced: true);
shell.WriteLine(Loc.GetString("invoke-verb-command-success", ("verb", verbName), ("target", target), ("player", playerEntity)));
return;
}
@@ -86,7 +86,7 @@ namespace Content.Server.Verbs.Commands
{
if (verb.Text.ToLowerInvariant() == verbName)
{
verbSystem.ExecuteVerb(verb, playerEntity, target, forced: true);
verbSystem.ExecuteVerb(verb, playerEntity.Value, target, forced: true);
shell.WriteLine(Loc.GetString("invoke-verb-command-success", ("verb", verb.Text), ("target", target), ("player", playerEntity)));
return;
}

View File

@@ -120,7 +120,7 @@ namespace Content.Server.Weapon.Ranged.Ammunition.Components
public EntityUid? TakeAmmo()
{
EntityUid ammo = default;
EntityUid? ammo = null;
// If anything's spawned use that first, otherwise use the fill prototype as a fallback (if we have spawn count left)
if (_spawnedAmmo.TryPop(out var entity))
{

View File

@@ -133,13 +133,13 @@ namespace Content.Server.Weapon.Ranged.Barrels.Components
if (powerCellEntity == null)
{
return default;
return null;
}
var capacitor = _entities.GetComponent<BatteryComponent>(powerCellEntity.Value);
if (capacitor.CurrentCharge < _lowerChargeLimit)
{
return default;
return null;
}
// Can fire confirmed
@@ -149,7 +149,7 @@ namespace Content.Server.Weapon.Ranged.Barrels.Components
if (capacitor.UseCharge(chargeChange) < _lowerChargeLimit)
{
// Handling of funny exploding cells.
return default;
return null;
}
var energyRatio = chargeChange / _baseFireCost;

View File

@@ -193,19 +193,20 @@ namespace Content.Server.Weapon.Ranged.Barrels.Components
public override EntityUid? PeekAmmo()
{
return BoltOpen ? default : _chamberContainer.ContainedEntity;
return BoltOpen ? null : _chamberContainer.ContainedEntity;
}
public override EntityUid? TakeProjectile(EntityCoordinates spawnAt)
{
if (BoltOpen)
{
return default;
return null;
}
var entity = _chamberContainer.ContainedEntity ?? default;
var entity = _chamberContainer.ContainedEntity;
Cycle();
return entity != default ? EntitySystem.Get<GunSystem>().TakeBullet(_entities.GetComponent<AmmoComponent>(entity), spawnAt) : null;
return entity != null ? EntitySystem.Get<GunSystem>().TakeBullet(_entities.GetComponent<AmmoComponent>(entity.Value), spawnAt) : null;
}
private void Cycle(bool manual = false)
@@ -296,7 +297,7 @@ namespace Content.Server.Weapon.Ranged.Barrels.Components
}
// Try and pull a round from the magazine to replace the chamber if possible
var magazine = MagazineContainer.ContainedEntity ?? default;
var magazine = MagazineContainer.ContainedEntity;
if (_entities.GetComponentOrNull<RangedMagazineComponent>(magazine)?.TakeAmmo() is not {Valid: true} nextRound)
{
@@ -305,11 +306,11 @@ namespace Content.Server.Weapon.Ranged.Barrels.Components
_chamberContainer.Insert(nextRound);
if (_autoEjectMag && magazine != null && _entities.GetComponent<RangedMagazineComponent>(magazine).ShotsLeft == 0)
if (_autoEjectMag && magazine != null && _entities.GetComponent<RangedMagazineComponent>(magazine.Value).ShotsLeft == 0)
{
SoundSystem.Play(Filter.Pvs(Owner), _soundAutoEject.GetSound(), Owner, AudioParams.Default.WithVolume(-2));
MagazineContainer.Remove(magazine);
MagazineContainer.Remove(magazine.Value);
#pragma warning disable 618
SendNetworkMessage(new MagazineAutoEjectMessage());
#pragma warning restore 618

View File

@@ -151,9 +151,10 @@ namespace Content.Server.Wieldable
private void OnItemWielded(EntityUid uid, WieldableComponent component, ItemWieldedEvent args)
{
if (args.User == default)
if (args.User == null)
return;
if (!CanWield(uid, component, args.User) || component.Wielded)
if (!CanWield(uid, component, args.User.Value) || component.Wielded)
return;
if (EntityManager.TryGetComponent<ItemComponent>(uid, out var item))
@@ -171,16 +172,16 @@ namespace Content.Server.Wieldable
for (var i = 0; i < component.FreeHandsRequired; i++)
{
_virtualItemSystem.TrySpawnVirtualItemInHand(uid, args.User);
_virtualItemSystem.TrySpawnVirtualItemInHand(uid, args.User.Value);
}
args.User.PopupMessage(Loc.GetString("wieldable-component-successful-wield",
args.User.Value.PopupMessage(Loc.GetString("wieldable-component-successful-wield",
("item", uid)));
}
private void OnItemUnwielded(EntityUid uid, WieldableComponent component, ItemUnwieldedEvent args)
{
if (args.User == default)
if (args.User == null)
return;
if (!component.Wielded)
return;
@@ -200,11 +201,11 @@ namespace Content.Server.Wieldable
component.UnwieldSound.GetSound());
}
args.User.PopupMessage(Loc.GetString("wieldable-component-failed-wield",
args.User.Value.PopupMessage(Loc.GetString("wieldable-component-failed-wield",
("item", uid)));
}
_virtualItemSystem.DeleteInHandsMatching(args.User, uid);
_virtualItemSystem.DeleteInHandsMatching(args.User.Value, uid);
}
private void OnItemLeaveHand(EntityUid uid, WieldableComponent component, UnequippedHandEvent args)
@@ -245,9 +246,9 @@ namespace Content.Server.Wieldable
/// </summary>
public class ItemWieldedEvent : EntityEventArgs
{
public EntityUid User;
public EntityUid? User;
public ItemWieldedEvent(EntityUid user = default)
public ItemWieldedEvent(EntityUid? user = null)
{
User = user;
}
@@ -275,13 +276,13 @@ namespace Content.Server.Wieldable
/// </summary>
public class ItemUnwieldedEvent : EntityEventArgs
{
public EntityUid User;
public EntityUid? User;
/// <summary>
/// Whether the item is being forced to be unwielded, or if the player chose to unwield it themselves.
/// </summary>
public bool Force;
public ItemUnwieldedEvent(EntityUid user = default, bool force=false)
public ItemUnwieldedEvent(EntityUid? user = null, bool force=false)
{
User = user;
Force = force;

View File

@@ -52,7 +52,7 @@ namespace Content.Shared.DoAfter
public EntityCoordinates TargetGrid { get; }
public EntityUid TargetUid { get; }
public EntityUid? Target { get; }
public float Delay { get; }
@@ -63,7 +63,8 @@ namespace Content.Shared.DoAfter
public float MovementThreshold { get; }
public ClientDoAfter(byte id, EntityCoordinates userGrid, EntityCoordinates targetGrid, TimeSpan startTime, float delay, bool breakOnUserMove, bool breakOnTargetMove, float movementThreshold, EntityUid targetUid = default)
public ClientDoAfter(byte id, EntityCoordinates userGrid, EntityCoordinates targetGrid, TimeSpan startTime,
float delay, bool breakOnUserMove, bool breakOnTargetMove, float movementThreshold, EntityUid? target = null)
{
ID = id;
UserGrid = userGrid;
@@ -73,7 +74,7 @@ namespace Content.Shared.DoAfter
BreakOnUserMove = breakOnUserMove;
BreakOnTargetMove = breakOnTargetMove;
MovementThreshold = movementThreshold;
TargetUid = targetUid;
Target = target;
}
}
}

View File

@@ -650,7 +650,7 @@ namespace Content.Shared.Interaction
/// <param name="used"></param>
public void TryUseInteraction(EntityUid user, EntityUid used, bool altInteract = false)
{
if (user != null && used != null && _actionBlockerSystem.CanUse(user))
if (_actionBlockerSystem.CanUse(user))
{
if (altInteract)
AltInteract(user, used);
@@ -820,7 +820,7 @@ namespace Content.Shared.Interaction
/// </summary>
public bool TryDroppedInteraction(EntityUid user, EntityUid item)
{
if (user == null || item == null || !_actionBlockerSystem.CanDrop(user)) return false;
if (!_actionBlockerSystem.CanDrop(user)) return false;
DroppedInteraction(user, item);
return true;

View File

@@ -64,15 +64,17 @@ namespace Content.Shared.Verbs
// call ActionBlocker checks, just cache it for the verb request.
var canInteract = force || _actionBlockerSystem.CanInteract(user);
EntityUid @using = default;
if (EntityManager.TryGetComponent(user, out SharedHandsComponent? hands) && (force || _actionBlockerSystem.CanUse(user)))
EntityUid? @using = null;
if (TryComp(user, out SharedHandsComponent? hands) && (force || _actionBlockerSystem.CanUse(user)))
{
hands.TryGetActiveHeldEntity(out @using);
// TODO Hands remove nullable (#5634)
hands.TryGetActiveHeldEntity(out var nonNullableUsing);
@using = nonNullableUsing;
// Check whether the "Held" entity is a virtual pull entity. If yes, set that as the entity being "Used".
// This allows you to do things like buckle a dragged person onto a surgery table, without click-dragging
// their sprite.
if (@using != default && EntityManager.TryGetComponent<HandVirtualItemComponent?>(@using, out var pull))
if (@using != null && TryComp(@using, out HandVirtualItemComponent? pull))
{
@using = pull.BlockingEntity;
}