Goes in-game now

This commit is contained in:
Vera Aguilera Puerto
2021-12-06 15:34:46 +01:00
parent af4eb3c7cd
commit c57b07a4d0
43 changed files with 129 additions and 130 deletions

View File

@@ -74,7 +74,8 @@ namespace Content.IntegrationTests.Tests.GameObjects.Components.Mobs
await server.WaitAssertion(() =>
{
var playerEnt = serverPlayerManager.Sessions.Single().AttachedEntity;
var playerEnt = serverPlayerManager.Sessions.Single().AttachedEntity.GetValueOrDefault();
Assert.That(playerEnt, Is.Not.EqualTo(default));
var actionsComponent = sEntities.GetComponent<ServerActionsComponent>(playerEnt);
// player should begin with their innate actions granted
@@ -102,7 +103,7 @@ namespace Content.IntegrationTests.Tests.GameObjects.Components.Mobs
{
var local = clientPlayerMgr.LocalPlayer;
var controlled = local!.ControlledEntity;
var actionsComponent = cEntities.GetComponent<ClientActionsComponent>(controlled!);
var actionsComponent = cEntities.GetComponent<ClientActionsComponent>(controlled!.Value);
// we should have our innate actions and debug1.
foreach (var innateAction in innateActions)
@@ -156,7 +157,8 @@ namespace Content.IntegrationTests.Tests.GameObjects.Components.Mobs
// now revoke the action and check that the client sees it as revoked
await server.WaitAssertion(() =>
{
var playerEnt = serverPlayerManager.Sessions.Single().AttachedEntity;
var playerEnt = serverPlayerManager.Sessions.Single().AttachedEntity.GetValueOrDefault();
Assert.That(playerEnt, Is.Not.EqualTo(default));
var actionsComponent = IoCManager.Resolve<IEntityManager>().GetComponent<ServerActionsComponent>(playerEnt);
actionsComponent.Revoke(ActionType.DebugInstant);
});
@@ -168,7 +170,7 @@ namespace Content.IntegrationTests.Tests.GameObjects.Components.Mobs
{
var local = clientPlayerMgr.LocalPlayer;
var controlled = local!.ControlledEntity;
var actionsComponent = IoCManager.Resolve<IEntityManager>().GetComponent<ClientActionsComponent>(controlled!);
var actionsComponent = IoCManager.Resolve<IEntityManager>().GetComponent<ClientActionsComponent>(controlled!.Value);
// we should have our innate actions, but debug1 should be revoked
foreach (var innateAction in innateActions)
@@ -250,7 +252,8 @@ namespace Content.IntegrationTests.Tests.GameObjects.Components.Mobs
await server.WaitAssertion(() =>
{
serverPlayerEnt = serverPlayerManager.Sessions.Single().AttachedEntity;
serverPlayerEnt = serverPlayerManager.Sessions.Single().AttachedEntity.GetValueOrDefault();
Assert.That(serverPlayerEnt, Is.Not.EqualTo(default));
serverActionsComponent = serverEntManager.GetComponent<ServerActionsComponent>(serverPlayerEnt);
// spawn and give them an item that has actions
@@ -291,7 +294,7 @@ namespace Content.IntegrationTests.Tests.GameObjects.Components.Mobs
{
var local = clientPlayerMgr.LocalPlayer;
var controlled = local!.ControlledEntity;
clientActionsComponent = clientEntities.GetComponent<ClientActionsComponent>(controlled!);
clientActionsComponent = clientEntities.GetComponent<ClientActionsComponent>(controlled!.Value);
var lightEntry = clientActionsComponent.ItemActionStates()
.Where(entry => entry.Value.ContainsKey(ItemActionType.ToggleLight))

View File

@@ -29,7 +29,7 @@ namespace Content.IntegrationTests.Tests.GameObjects.Components.Mobs
await server.WaitAssertion(() =>
{
var playerEnt = serverPlayerManager.Sessions.Single().AttachedEntity;
var playerEnt = serverPlayerManager.Sessions.Single().AttachedEntity.GetValueOrDefault();
Assert.That(playerEnt != default);
var alertsComponent = IoCManager.Resolve<IEntityManager>().GetComponent<ServerAlertsComponent>(playerEnt);
Assert.NotNull(alertsComponent);
@@ -69,8 +69,8 @@ namespace Content.IntegrationTests.Tests.GameObjects.Components.Mobs
await server.WaitAssertion(() =>
{
var playerEnt = serverPlayerManager.Sessions.Single().AttachedEntity;
Assert.That(playerEnt != default);
var playerEnt = serverPlayerManager.Sessions.Single().AttachedEntity.GetValueOrDefault();
Assert.That(playerEnt, Is.Not.EqualTo(default));
var alertsComponent = IoCManager.Resolve<IEntityManager>().GetComponent<ServerAlertsComponent>(playerEnt);
Assert.NotNull(alertsComponent);

View File

@@ -59,7 +59,7 @@ namespace Content.IntegrationTests.Tests.PDA
await server.WaitAssertion(() =>
{
var player = sPlayerManager.Sessions.Single().AttachedEntity;
var player = sPlayerManager.Sessions.Single().AttachedEntity.GetValueOrDefault();
Assert.That(player != default);

View File

@@ -17,15 +17,16 @@ namespace Content.Server.AI.Utility.Considerations.Containers
{
protected override float GetScore(Blackboard context)
{
var entMan = IoCManager.Resolve<IEntityManager>();
var target = context.GetState<TargetEntityState>().GetValue();
if (target == null)
if (!entMan.EntityExists(target))
{
return 0.0f;
}
if (target.TryGetContainer(out var container))
{
if (IoCManager.Resolve<IEntityManager>().TryGetComponent(container.Owner, out EntityStorageComponent? storageComponent))
if (entMan.TryGetComponent(container.Owner, out EntityStorageComponent? storageComponent))
{
if (storageComponent.IsWeldedShut && !storageComponent.Open)
{

View File

@@ -21,15 +21,13 @@ namespace Content.Server.Actions.Commands
public void Execute(IConsoleShell shell, string argStr, string[] args)
{
var player = shell.Player as IPlayerSession;
if (player == null) return;
var attachedEntity = player.AttachedEntity;
if (player?.AttachedEntity is not {} attachedEntity) return;
if (args.Length > 2)
{
var target = args[2];
if (!CommandUtils.TryGetAttachedEntityByUsernameOrId(shell, target, player, out attachedEntity)) return;
}
if (attachedEntity == default) return;
if (!IoCManager.Resolve<IEntityManager>().TryGetComponent(attachedEntity, out ServerActionsComponent? actionsComponent))
{
shell.WriteError("user has no actions component");

View File

@@ -19,8 +19,8 @@ namespace Content.Server.Actions.Commands
public void Execute(IConsoleShell shell, string argStr, string[] args)
{
var player = shell.Player as IPlayerSession;
if (player == null) return;
var attachedEntity = player.AttachedEntity;
if (player?.AttachedEntity == null) return;
var attachedEntity = player.AttachedEntity.Value;
if (args.Length > 1)
{
var target = args[1];

View File

@@ -20,8 +20,8 @@ namespace Content.Server.Actions.Commands
public void Execute(IConsoleShell shell, string argStr, string[] args)
{
var player = shell.Player as IPlayerSession;
if (player == null) return;
var attachedEntity = player.AttachedEntity;
if (player?.AttachedEntity == null) return;
var attachedEntity = player.AttachedEntity.Value;
if (args.Length > 1)
{
var target = args[1];

View File

@@ -125,12 +125,12 @@ namespace Content.Server.Administration
var name = session.Name;
var username = string.Empty;
if (session.AttachedEntity != default)
username = EntityManager.GetComponent<MetaDataComponent>(session.AttachedEntity).EntityName;
if (session.AttachedEntity != null)
username = EntityManager.GetComponent<MetaDataComponent>(session.AttachedEntity.Value).EntityName;
var antag = session.ContentData()?.Mind?.AllRoles.Any(r => r.Antagonist) ?? false;
return new PlayerInfo(name, username, antag, session.AttachedEntity, session.UserId);
return new PlayerInfo(name, username, antag, session.AttachedEntity.GetValueOrDefault(), session.UserId);
}
}
}

View File

@@ -42,9 +42,9 @@ namespace Content.Server.Administration.Commands
return;
}
var canReturn = mind.CurrentEntity != default;
var coordinates = player.AttachedEntity != default
? _entities.GetComponent<TransformComponent>(player.AttachedEntity).Coordinates
var canReturn = mind.CurrentEntity != null;
var coordinates = player.AttachedEntity != null
? _entities.GetComponent<TransformComponent>(player.AttachedEntity.Value).Coordinates
: EntitySystem.Get<GameTicker>().GetObserverSpawnPoint();
var ghost = _entities.SpawnEntity("AdminObserver", coordinates);

View File

@@ -30,12 +30,12 @@ namespace Content.Server.Administration.Commands
if (args.Length < 1 && shell.Player is IPlayerSession player) //Try to heal the users mob if applicable
{
shell.WriteLine(Loc.GetString("rejuvenate-command-self-heal-message"));
if (player.AttachedEntity == default)
if (player.AttachedEntity == null)
{
shell.WriteLine(Loc.GetString("rejuvenate-command-no-entity-attached-message"));
return;
}
PerformRejuvenate(player.AttachedEntity);
PerformRejuvenate(player.AttachedEntity.Value);
}
var entityManager = IoCManager.Resolve<IEntityManager>();

View File

@@ -26,7 +26,7 @@ namespace Content.Server.Alert.Commands
return;
}
var attachedEntity = player.AttachedEntity;
var attachedEntity = player.AttachedEntity.Value;
if (args.Length > 1)
{

View File

@@ -20,19 +20,13 @@ namespace Content.Server.Alert.Commands
public void Execute(IConsoleShell shell, string argStr, string[] args)
{
var player = shell.Player as IPlayerSession;
if (player == null)
if (player?.AttachedEntity == null)
{
shell.WriteLine("You cannot run this command from the server.");
shell.WriteLine("You cannot run this from the server or without an attached entity.");
return;
}
var attachedEntity = player.AttachedEntity;
if (attachedEntity == null)
{
shell.WriteLine("You don't have an entity.");
return;
}
var attachedEntity = player.AttachedEntity.Value;
if (args.Length > 2)
{

View File

@@ -56,7 +56,7 @@ namespace Content.Server.Alert
{
case ClickAlertMessage msg:
{
var player = session.AttachedEntity;
var player = session.AttachedEntity.GetValueOrDefault();
if (player != Owner)
{

View File

@@ -235,7 +235,7 @@ namespace Content.Server.Atmos.Components
if (handsComponent.GetActiveHand?.Owner is not {Valid: true} activeHandEntity ||
!_entities.TryGetComponent(activeHandEntity, out GasAnalyzerComponent? gasAnalyzer))
{
serverMsg.Session.AttachedEntity.PopupMessage(Loc.GetString("gas-analyzer-component-need-gas-analyzer-in-hand-message"));
serverMsg.Session.AttachedEntity.Value.PopupMessage(Loc.GetString("gas-analyzer-component-need-gas-analyzer-in-hand-message"));
return;
}

View File

@@ -44,13 +44,13 @@ namespace Content.Server.Body.Commands
return;
}
if (player.AttachedEntity == default)
if (player.AttachedEntity == null)
{
shell.WriteLine("You don't have an entity to add a hand to.");
return;
}
entity = player.AttachedEntity;
entity = player.AttachedEntity.Value;
hand = entityManager.SpawnEntity(DefaultHandPrototype, entityManager.GetComponent<TransformComponent>(entity).Coordinates);
break;
}
@@ -75,13 +75,13 @@ namespace Content.Server.Body.Commands
return;
}
if (player.AttachedEntity == default)
if (player.AttachedEntity == null)
{
shell.WriteLine("You don't have an entity to add a hand to.");
return;
}
entity = player.AttachedEntity;
entity = player.AttachedEntity.Value;
hand = entityManager.SpawnEntity(args[0], entityManager.GetComponent<TransformComponent>(entity).Coordinates);
}

View File

@@ -44,7 +44,7 @@ namespace Content.Server.Body.Commands
return;
}
entity = player.AttachedEntity;
entity = player.AttachedEntity.Value;
break;
case 2:

View File

@@ -31,13 +31,13 @@ namespace Content.Server.Body.Commands
return;
}
if (player.AttachedEntity == default)
if (player.AttachedEntity is not {} attached)
{
shell.WriteLine("You have no entity.");
return;
}
if (!IoCManager.Resolve<IEntityManager>().TryGetComponent(player.AttachedEntity, out SharedBodyComponent? body))
if (!IoCManager.Resolve<IEntityManager>().TryGetComponent(attached, out SharedBodyComponent? body))
{
var random = IoCManager.Resolve<IRobustRandom>();
var text = $"You have no body{(random.Prob(0.2f) ? " and you must scream." : ".")}";

View File

@@ -24,7 +24,7 @@ namespace Content.Server.Chat.Commands
return;
}
if (player.Status != SessionStatus.InGame || player.AttachedEntity == default)
if (player.Status != SessionStatus.InGame || player.AttachedEntity == null)
return;
if (args.Length < 1)

View File

@@ -25,9 +25,15 @@ namespace Content.Server.Chat.Commands
return;
}
if (player.Status != SessionStatus.InGame || player.AttachedEntity == default)
if (player.Status != SessionStatus.InGame)
return;
if (player.AttachedEntity is not {} playerEntity)
{
shell.WriteLine("You don't have an entity!");
return;
}
if (args.Length < 1)
return;
@@ -38,12 +44,6 @@ namespace Content.Server.Chat.Commands
var chat = IoCManager.Resolve<IChatManager>();
var chatSanitizer = IoCManager.Resolve<IChatSanitizationManager>();
if (player.AttachedEntity is not {Valid: true} playerEntity)
{
shell.WriteLine("You don't have an entity!");
return;
}
if (IoCManager.Resolve<IEntityManager>().HasComponent<GhostComponent>(playerEntity))
chat.SendDeadChat(player, message);
else

View File

@@ -306,7 +306,7 @@ namespace Content.Server.Chat.Managers
msg.MessageWrap = Loc.GetString("chat-manager-send-dead-chat-wrap-message",
("deadChannelName", Loc.GetString("chat-manager-dead-channel-name")),
("playerName", (playerName)));
msg.SenderEntity = player.AttachedEntity;
msg.SenderEntity = player.AttachedEntity.GetValueOrDefault();
_netManager.ServerSendToMany(msg, clients.ToList());
}

View File

@@ -89,6 +89,9 @@ namespace Content.Server.Chemistry.Components
public void UserInterfaceOnReceiveMessage(ServerBoundUserInterfaceMessage serverMsg)
{
if (serverMsg.Session.AttachedEntity == null)
return;
switch (serverMsg.Message)
{
case TransferAmountSetValueMessage svm:
@@ -96,7 +99,7 @@ namespace Content.Server.Chemistry.Components
var amount = Math.Clamp(sval, MinimumTransferAmount.Float(),
MaximumTransferAmount.Float());
serverMsg.Session.AttachedEntity.PopupMessage(Loc.GetString("comp-solution-transfer-set-amount",
serverMsg.Session.AttachedEntity.Value.PopupMessage(Loc.GetString("comp-solution-transfer-set-amount",
("amount", amount)));
SetTransferAmount(FixedPoint2.New(amount));
break;

View File

@@ -80,20 +80,21 @@ namespace Content.Server.Cloning.Components
private void OnUiReceiveMessage(ServerBoundUserInterfaceMessage obj)
{
if (obj.Message is not CloningPodUiButtonPressedMessage message) return;
if (obj.Message is not CloningPodUiButtonPressedMessage message || obj.Session.AttachedEntity == null)
return;
switch (message.Button)
{
case UiButton.Clone:
if (BodyContainer.ContainedEntity != null)
{
obj.Session.AttachedEntity.PopupMessageCursor(Loc.GetString("cloning-pod-component-msg-occupied"));
obj.Session.AttachedEntity.Value.PopupMessageCursor(Loc.GetString("cloning-pod-component-msg-occupied"));
return;
}
if (message.ScanId == null)
{
obj.Session.AttachedEntity.PopupMessageCursor(Loc.GetString("cloning-pod-component-msg-no-selection"));
obj.Session.AttachedEntity.Value.PopupMessageCursor(Loc.GetString("cloning-pod-component-msg-no-selection"));
return;
}
@@ -101,7 +102,7 @@ namespace Content.Server.Cloning.Components
if (!cloningSystem.IdToDNA.TryGetValue(message.ScanId.Value, out var dna))
{
obj.Session.AttachedEntity.PopupMessageCursor(Loc.GetString("cloning-pod-component-msg-bad-selection"));
obj.Session.AttachedEntity.Value.PopupMessageCursor(Loc.GetString("cloning-pod-component-msg-bad-selection"));
return; // ScanId is not in database
}
@@ -115,7 +116,7 @@ namespace Content.Server.Cloning.Components
_entities.TryGetComponent(clone, out MindComponent? cloneMindComp) &&
(cloneMindComp.Mind == null || cloneMindComp.Mind == mind))
{
obj.Session.AttachedEntity.PopupMessageCursor(Loc.GetString("cloning-pod-component-msg-already-cloning"));
obj.Session.AttachedEntity.Value.PopupMessageCursor(Loc.GetString("cloning-pod-component-msg-already-cloning"));
return; // Mind already has clone
}
@@ -126,14 +127,14 @@ namespace Content.Server.Cloning.Components
_entities.TryGetComponent<MobStateComponent?>(mind.OwnedEntity.Value, out var state) &&
!state.IsDead())
{
obj.Session.AttachedEntity.PopupMessageCursor(Loc.GetString("cloning-pod-component-msg-already-alive"));
obj.Session.AttachedEntity.Value.PopupMessageCursor(Loc.GetString("cloning-pod-component-msg-already-alive"));
return; // Body controlled by mind is not dead
}
// Yes, we still need to track down the client because we need to open the Eui
if (mind.UserId == null || !_playerManager.TryGetSessionById(mind.UserId.Value, out var client))
{
obj.Session.AttachedEntity.PopupMessageCursor(Loc.GetString("cloning-pod-component-msg-user-offline"));
obj.Session.AttachedEntity.Value.PopupMessageCursor(Loc.GetString("cloning-pod-component-msg-user-offline"));
return; // If we can't track down the client, we can't offer transfer. That'd be quite bad.
}

View File

@@ -43,13 +43,13 @@ namespace Content.Server.Commands
{
attachedEntity = default;
if (!TryGetSessionByUsernameOrId(shell, usernameOrId, performer, out var session)) return false;
if (session.AttachedEntity == default)
if (session.AttachedEntity == null)
{
shell.WriteLine("User has no attached entity.");
return false;
}
attachedEntity = session.AttachedEntity;
attachedEntity = session.AttachedEntity.Value;
return true;
}

View File

@@ -31,13 +31,13 @@ namespace Content.Server.Damage.Commands
return;
}
if (player.AttachedEntity == default)
if (player.AttachedEntity == null)
{
shell.WriteLine("An entity needs to be specified when you aren't attached to an entity.");
return;
}
entity = player.AttachedEntity;
entity = player.AttachedEntity.Value;
break;
case 1:
if (!EntityUid.TryParse(args[0], out var id))

View File

@@ -104,7 +104,7 @@ namespace Content.Server.Disposal.Tube.Components
private bool PlayerCanUseDisposalTagger(IPlayerSession session)
{
//Need player entity to check if they are still able to use the configuration interface
if (session.AttachedEntity == null)
if (session.AttachedEntity is not {} attached)
return false;
if (!Anchored)
return false;
@@ -112,7 +112,7 @@ namespace Content.Server.Disposal.Tube.Components
var actionBlocker = EntitySystem.Get<ActionBlockerSystem>();
var groupController = IoCManager.Resolve<IConGroupController>();
//Check if player can interact in their current state
if (!groupController.CanAdminMenu(session) && (!actionBlocker.CanInteract(session.AttachedEntity) || !actionBlocker.CanUse(session.AttachedEntity)))
if (!groupController.CanAdminMenu(session) && (!actionBlocker.CanInteract(attached) || !actionBlocker.CanUse(attached)))
return false;
return true;

View File

@@ -86,7 +86,7 @@ namespace Content.Server.Disposal.Tube.Components
private bool PlayerCanUseDisposalTagger(IPlayerSession session)
{
//Need player entity to check if they are still able to use the configuration interface
if (session.AttachedEntity == null)
if (session.AttachedEntity is not {} attached)
return false;
if (!Anchored)
return false;
@@ -94,7 +94,7 @@ namespace Content.Server.Disposal.Tube.Components
var actionBlocker = EntitySystem.Get<ActionBlockerSystem>();
var groupController = IoCManager.Resolve<IConGroupController>();
//Check if player can interact in their current state
if (!groupController.CanAdminMenu(session) && (!actionBlocker.CanInteract(session.AttachedEntity) || !actionBlocker.CanUse(session.AttachedEntity)))
if (!groupController.CanAdminMenu(session) && (!actionBlocker.CanInteract(attached) || !actionBlocker.CanUse(attached)))
return false;
return true;

View File

@@ -52,7 +52,7 @@ namespace Content.Server.Disposal
return;
}
tube.PopupDirections(player.AttachedEntity);
tube.PopupDirections(player.AttachedEntity.Value);
}
}
}

View File

@@ -30,7 +30,7 @@ namespace Content.Server.EntityList
return;
}
if (player.AttachedEntity == null)
if (player.AttachedEntity is not {} attached)
{
shell.WriteError("You must have an entity to run this command.");
return;
@@ -49,7 +49,7 @@ namespace Content.Server.EntityList
foreach (var entity in prototype.Entities(prototypeManager))
{
entityManager.SpawnEntity(entity.ID, entityManager.GetComponent<TransformComponent>(player.AttachedEntity).Coordinates);
entityManager.SpawnEntity(entity.ID, entityManager.GetComponent<TransformComponent>(attached).Coordinates);
i++;
}

View File

@@ -66,13 +66,13 @@ namespace Content.Server.GameTicking.Presets
foreach (var player in list)
{
if (!ReadyProfiles.ContainsKey(player.UserId))
if (!ReadyProfiles.ContainsKey(player.UserId) || player.AttachedEntity is not {} attached)
{
continue;
}
prefList.Add(player);
player.AttachedEntity.EnsureComponent<SuspicionRoleComponent>();
attached.EnsureComponent<SuspicionRoleComponent>();
}
var numTraitors = MathHelper.Clamp(readyPlayers.Count / PlayersPerTraitor,

View File

@@ -94,7 +94,10 @@ public sealed partial class InstrumentSystem : SharedInstrumentSystem
if (!EntityManager.TryGetComponent(uid, out InstrumentComponent? instrument))
return;
if (!instrument.Playing || args.SenderSession != instrument.InstrumentPlayer || instrument.InstrumentPlayer == null)
if (!instrument.Playing
|| args.SenderSession != instrument.InstrumentPlayer
|| instrument.InstrumentPlayer == null
|| args.SenderSession.AttachedEntity is not {} attached)
return;
var send = true;
@@ -108,11 +111,11 @@ public sealed partial class InstrumentSystem : SharedInstrumentSystem
{
if (instrument.LaggedBatches == (int) (MaxMidiLaggedBatches * (1 / 3d) + 1))
{
instrument.InstrumentPlayer.AttachedEntity.PopupMessage(
attached.PopupMessage(
Loc.GetString("instrument-component-finger-cramps-light-message"));
} else if (instrument.LaggedBatches == (int) (MaxMidiLaggedBatches * (2 / 3d) + 1))
{
instrument.InstrumentPlayer.AttachedEntity.PopupMessage(
attached.PopupMessage(
Loc.GetString("instrument-component-finger-cramps-serious-message"));
}
}

View File

@@ -25,7 +25,7 @@ namespace Content.Server.Interaction
public void Execute(IConsoleShell shell, string argStr, string[] args)
{
var player = shell.Player as IPlayerSession;
if (player?.AttachedEntity == null)
if (player?.AttachedEntity is not {} attached)
{
return;
}
@@ -49,9 +49,9 @@ namespace Content.Server.Interaction
}
var mapManager = IoCManager.Resolve<IMapManager>();
var playerGrid = _entities.GetComponent<TransformComponent>(player.AttachedEntity).GridID;
var playerGrid = _entities.GetComponent<TransformComponent>(attached).GridID;
var mapGrid = mapManager.GetGrid(playerGrid);
var playerPosition = _entities.GetComponent<TransformComponent>(player.AttachedEntity).Coordinates;
var playerPosition = _entities.GetComponent<TransformComponent>(attached).Coordinates;
var tileDefinitionManager = IoCManager.Resolve<ITileDefinitionManager>();
for (var i = -radius; i <= radius; i++)

View File

@@ -152,7 +152,7 @@ namespace Content.Server.Kitchen.EntitySystems
private void OnUIMessageReceived(EntityUid uid, ReagentGrinderComponent component,
ServerBoundUserInterfaceMessage message)
{
if (component.Busy)
if (component.Busy || message.Session.AttachedEntity is not {} attached)
{
return;
}
@@ -163,7 +163,7 @@ namespace Content.Server.Kitchen.EntitySystems
if (!EntityManager.TryGetComponent(component.Owner, out ApcPowerReceiverComponent? receiver) ||
!receiver.Powered) break;
ClickSound(component);
DoWork(component, message.Session.AttachedEntity,
DoWork(component, attached,
SharedReagentGrinderComponent.GrinderProgram.Grind);
break;
@@ -171,7 +171,7 @@ namespace Content.Server.Kitchen.EntitySystems
if (!EntityManager.TryGetComponent(component.Owner, out ApcPowerReceiverComponent? receiver2) ||
!receiver2.Powered) break;
ClickSound(component);
DoWork(component, message.Session.AttachedEntity,
DoWork(component, attached,
SharedReagentGrinderComponent.GrinderProgram.Juice);
break;

View File

@@ -116,6 +116,8 @@ namespace Content.Server.MachineLinking.System
private void OnReceiverUIMessage(EntityUid uid, SignalReceiverComponent component,
ServerBoundUserInterfaceMessage msg)
{
if (msg.Session.AttachedEntity is not { } attached) return;
switch (msg.Message)
{
case SignalPortSelected portSelected:
@@ -123,12 +125,12 @@ namespace Content.Server.MachineLinking.System
!EntityManager.TryGetComponent(msg.Session.AttachedEntity, out HandsComponent? hands) ||
!hands.TryGetActiveHeldEntity(out var heldEntity) ||
!EntityManager.TryGetComponent(heldEntity, out SignalLinkerComponent? signalLinkerComponent) ||
!_interaction.InRangeUnobstructed(msg.Session.AttachedEntity, component.Owner, ignoreInsideBlocker: true) ||
!_interaction.InRangeUnobstructed(attached, component.Owner, ignoreInsideBlocker: true) ||
!signalLinkerComponent.Port.HasValue ||
!signalLinkerComponent.Port.Value.transmitter.Outputs.ContainsPort(signalLinkerComponent.Port
.Value.port) || !component.Inputs.ContainsPort(portSelected.Port))
return;
LinkerInteraction(msg.Session.AttachedEntity, signalLinkerComponent.Port.Value.transmitter,
LinkerInteraction(attached, signalLinkerComponent.Port.Value.transmitter,
signalLinkerComponent.Port.Value.port, component, portSelected.Port);
break;
}
@@ -156,6 +158,9 @@ namespace Content.Server.MachineLinking.System
private void OnTransmitterUIMessage(EntityUid uid, SignalTransmitterComponent component,
ServerBoundUserInterfaceMessage msg)
{
if (msg.Session.AttachedEntity is not { } attached)
return;
switch (msg.Message)
{
case SignalPortSelected portSelected:
@@ -163,9 +168,9 @@ namespace Content.Server.MachineLinking.System
!EntityManager.TryGetComponent(msg.Session.AttachedEntity, out HandsComponent? hands) ||
!hands.TryGetActiveHeldEntity(out var heldEntity) ||
!EntityManager.TryGetComponent(heldEntity, out SignalLinkerComponent? signalLinkerComponent) ||
!_interaction.InRangeUnobstructed(msg.Session.AttachedEntity, component.Owner, ignoreInsideBlocker: true))
!_interaction.InRangeUnobstructed(attached, component.Owner, ignoreInsideBlocker: true))
return;
LinkerSaveInteraction(msg.Session.AttachedEntity, signalLinkerComponent, component,
LinkerSaveInteraction(attached, signalLinkerComponent, component,
portSelected.Port);
break;
}

View File

@@ -189,7 +189,7 @@ namespace Content.Server.Medical.Components
private void OnUiReceiveMessage(ServerBoundUserInterfaceMessage obj)
{
if (obj.Message is not UiButtonPressedMessage message) return;
if (obj.Message is not UiButtonPressedMessage message || obj.Session.AttachedEntity == null) return;
switch (message.Button)
{
@@ -200,7 +200,7 @@ namespace Content.Server.Medical.Components
if (!IoCManager.Resolve<IEntityManager>().TryGetComponent(_bodyContainer.ContainedEntity.Value, out MindComponent? mindComp) || mindComp.Mind == null)
{
obj.Session.AttachedEntity.PopupMessageCursor(Loc.GetString("medical-scanner-component-msg-no-soul"));
obj.Session.AttachedEntity.Value.PopupMessageCursor(Loc.GetString("medical-scanner-component-msg-no-soul"));
break;
}
@@ -215,7 +215,7 @@ namespace Content.Server.Medical.Components
if (mindUser == null)
{
// For now assume this means soul departed
obj.Session.AttachedEntity.PopupMessageCursor(Loc.GetString("medical-scanner-component-msg-soul-broken"));
obj.Session.AttachedEntity.Value.PopupMessageCursor(Loc.GetString("medical-scanner-component-msg-soul-broken"));
break;
}

View File

@@ -87,13 +87,11 @@ namespace Content.Server.Power.Components
private void UserInterfaceOnReceiveMessage(ServerBoundUserInterfaceMessage serverMsg)
{
if (serverMsg.Message is ApcToggleMainBreakerMessage)
{
var user = serverMsg.Session.AttachedEntity;
if (user == null) return;
if (serverMsg.Message is not ApcToggleMainBreakerMessage || serverMsg.Session.AttachedEntity is not {} attached)
return;
var accessSystem = EntitySystem.Get<AccessReaderSystem>();
if (_accessReader == null || accessSystem.IsAllowed(_accessReader, user))
if (_accessReader == null || accessSystem.IsAllowed(_accessReader, attached))
{
MainBreakerEnabled = !MainBreakerEnabled;
IoCManager.Resolve<IEntityManager>().GetComponent<PowerNetworkBatteryComponent>(Owner).CanDischarge = MainBreakerEnabled;
@@ -103,9 +101,7 @@ namespace Content.Server.Power.Components
}
else
{
user.PopupMessageCursor(Loc.GetString("apc-component-insufficient-access"));
}
attached.PopupMessageCursor(Loc.GetString("apc-component-insufficient-access"));
}
}

View File

@@ -115,7 +115,7 @@ namespace Content.Server.Sandbox
}
var player = _playerManager.GetSessionByChannel(message.MsgChannel);
if (player.AttachedEntity == default)
if (player.AttachedEntity is not {} attached)
{
return;
}
@@ -124,7 +124,7 @@ namespace Content.Server.Sandbox
.EnumeratePrototypes<AccessLevelPrototype>()
.Select(p => p.ID).ToArray();
if (_entityManager.TryGetComponent(player.AttachedEntity, out InventoryComponent? inv)
if (_entityManager.TryGetComponent(attached, out InventoryComponent? inv)
&& inv.TryGetSlotItem(Slots.IDCARD, out ItemComponent? wornItem))
{
if (_entityManager.HasComponent<AccessComponent>(wornItem.Owner))
@@ -148,10 +148,10 @@ namespace Content.Server.Sandbox
}
}
}
else if (_entityManager.TryGetComponent<HandsComponent?>(player.AttachedEntity, out var hands))
else if (_entityManager.TryGetComponent<HandsComponent?>(attached, out var hands))
{
var card = CreateFreshId();
if (!_entityManager.TryGetComponent(player.AttachedEntity, out inv) || !inv.Equip(Slots.IDCARD, card))
if (!_entityManager.TryGetComponent(attached, out inv) || !inv.Equip(Slots.IDCARD, card))
{
hands.PutInHandOrDrop(_entityManager.GetComponent<ItemComponent>(card));
}
@@ -170,10 +170,10 @@ namespace Content.Server.Sandbox
EntityUid CreateFreshId()
{
var card = _entityManager.SpawnEntity("CaptainIDCard", _entityManager.GetComponent<TransformComponent>(player.AttachedEntity).Coordinates);
var card = _entityManager.SpawnEntity("CaptainIDCard", _entityManager.GetComponent<TransformComponent>(attached).Coordinates);
UpgradeId(card);
_entityManager.GetComponent<IdCardComponent>(card).FullName = _entityManager.GetComponent<MetaDataComponent>(player.AttachedEntity).EntityName;
_entityManager.GetComponent<IdCardComponent>(card).FullName = _entityManager.GetComponent<MetaDataComponent>(attached).EntityName;
return card;
}
}

View File

@@ -149,10 +149,8 @@ namespace Content.Server.Storage.EntitySystems
foreach (var session in _sessionCache)
{
var attachedEntity = session.AttachedEntity;
// The component manages the set of sessions, so this invalid session should be removed soon.
if (attachedEntity == default || !IoCManager.Resolve<IEntityManager>().EntityExists(attachedEntity))
if (session.AttachedEntity is not {} attachedEntity || !IoCManager.Resolve<IEntityManager>().EntityExists(attachedEntity))
continue;
if (storageMap != IoCManager.Resolve<IEntityManager>().GetComponent<TransformComponent>(attachedEntity).MapID)

View File

@@ -35,12 +35,11 @@ namespace Content.Server.Traitor.Uplink.Commands
shell.WriteLine(Loc.GetString("shell-target-player-does-not-exist"));
return;
}
if (session.AttachedEntity == null)
if (session.AttachedEntity is not {} user)
{
shell.WriteLine(Loc.GetString("Selected player doesn't controll any entity"));
return;
}
var user = session.AttachedEntity;
// Get target item
EntityUid? uplinkEntity = null;

View File

@@ -116,7 +116,7 @@ namespace Content.Server.UserInterface
// Must ToList in order to close things safely.
foreach (var session in ui.SubscribedSessions.ToArray())
{
if (session.AttachedEntity == null || !_actionBlockerSystem.CanInteract(session.AttachedEntity))
if (session.AttachedEntity == null || !_actionBlockerSystem.CanInteract(session.AttachedEntity.Value))
{
ui.Close(session);
}

View File

@@ -1,4 +1,4 @@
using System;
using System;
using System.Linq;
using Content.Server.Administration;
using Content.Shared.Administration;
@@ -34,7 +34,7 @@ namespace Content.Server.Verbs.Commands
{
if (args[0] == "self" && shell.Player?.AttachedEntity != null)
{
playerEntity = shell.Player.AttachedEntity;
playerEntity = shell.Player.AttachedEntity.Value;
}
else
{

View File

@@ -21,9 +21,8 @@ namespace Content.Server.Verbs
public void HandleTryExecuteVerb(ExecuteVerbEvent args, EntitySessionEventArgs eventArgs)
{
var session = eventArgs.SenderSession;
var userEntity = session.AttachedEntity;
if (userEntity == null)
if (session.AttachedEntity is not {} userEntity)
{
Logger.Warning($"{nameof(HandleTryExecuteVerb)} called by player {session} with no attached entity.");
return;
@@ -61,7 +60,7 @@ namespace Content.Server.Verbs
return;
}
if (player.AttachedEntity == default)
if (player.AttachedEntity is not {} attached)
{
Logger.Warning($"{nameof(HandleVerbRequest)} called by player {player} with no attached entity.");
return;
@@ -71,7 +70,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(args.EntityUid, player.AttachedEntity, args.Type));
var response = new VerbsResponseEvent(args.EntityUid, GetLocalVerbs(args.EntityUid, attached, args.Type));
RaiseNetworkEvent(response, player.ConnectedClient);
}
}

View File

@@ -407,8 +407,7 @@ namespace Content.Server.WireHacking
{
case WiresActionMessage msg:
var wire = WiresList.Find(x => x.Id == msg.Id);
var player = serverMsg.Session.AttachedEntity;
if (wire == null || player == default)
if (wire == null || serverMsg.Session.AttachedEntity is not {} player)
{
return;
}

View File

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