Make more uids nullable (#5794)
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -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"));
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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();
|
||||
|
||||
@@ -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) ||
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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);
|
||||
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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}");
|
||||
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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))
|
||||
{
|
||||
|
||||
@@ -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;
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user