diff --git a/Content.Client/GameObjects/Components/Instruments/InstrumentComponent.cs b/Content.Client/GameObjects/Components/Instruments/InstrumentComponent.cs
index ed530f9237..2791aa7ddb 100644
--- a/Content.Client/GameObjects/Components/Instruments/InstrumentComponent.cs
+++ b/Content.Client/GameObjects/Components/Instruments/InstrumentComponent.cs
@@ -109,6 +109,12 @@ namespace Content.Client.GameObjects.Components.Instruments
}
}
+ ///
+ /// Whether this instrument is handheld or not.
+ ///
+ [ViewVariables]
+ public bool Handheld { get; set; } // TODO: Replace this by simply checking if the entity has an ItemComponent.
+
///
/// Whether there's a midi song being played or not.
///
@@ -198,6 +204,7 @@ namespace Content.Client.GameObjects.Components.Instruments
public override void ExposeData(ObjectSerializer serializer)
{
base.ExposeData(serializer);
+ serializer.DataField(this, x => Handheld, "handheld", false);
serializer.DataField(ref _instrumentProgram, "program", (byte) 1);
serializer.DataField(ref _instrumentBank, "bank", (byte) 0);
}
diff --git a/Content.Client/Instruments/InstrumentMenu.cs b/Content.Client/Instruments/InstrumentMenu.cs
index 81154acd55..50f480143d 100644
--- a/Content.Client/Instruments/InstrumentMenu.cs
+++ b/Content.Client/Instruments/InstrumentMenu.cs
@@ -1,12 +1,16 @@
using System.Threading.Tasks;
using Content.Client.GameObjects.Components.Instruments;
using Content.Client.UserInterface.Stylesheets;
+using Content.Shared.GameObjects.EntitySystems;
using Robust.Client.Audio.Midi;
using Robust.Client.Graphics.Drawing;
using Robust.Client.Interfaces.UserInterface;
+using Robust.Client.Player;
using Robust.Client.UserInterface;
using Robust.Client.UserInterface.Controls;
using Robust.Client.UserInterface.CustomControls;
+using Robust.Shared.Containers;
+using Robust.Shared.GameObjects.Systems;
using Robust.Shared.IoC;
using Robust.Shared.Localization;
using Robust.Shared.Log;
@@ -176,8 +180,30 @@ namespace Content.Client.Instruments
var filters = new FileDialogFilters(new FileDialogFilters.Group("mid", "midi"));
var filename = await _fileDialogManager.OpenFile(filters);
+ var instrumentEnt = _owner.Instrument.Owner;
+ var instrument = _owner.Instrument;
+
+ ContainerHelpers.TryGetContainerMan(_owner.Instrument.Owner, out var conMan);
+
+ var localPlayer = IoCManager.Resolve().LocalPlayer;
+
+ // The following checks are only in place to prevent players from playing MIDI songs locally.
+ // There are equivalents for these checks on the server.
+
if (string.IsNullOrEmpty(filename)) return;
+ // If we don't have a player or controlled entity, we return.
+ if(localPlayer?.ControlledEntity == null) return;
+
+ // If the instrument is handheld and we're not holding it, we return.
+ if((instrument.Handheld && (conMan == null
+ || conMan.Owner != localPlayer.ControlledEntity))) return;
+
+ // We check that we're in range unobstructed just in case.
+ if(!EntitySystem.Get()
+ .InRangeUnobstructed(localPlayer.ControlledEntity.Transform.MapPosition,
+ instrumentEnt.Transform.MapPosition, ignoredEnt:instrumentEnt)) return;
+
if (!_midiManager.IsMidiFile(filename))
{
Logger.Warning($"Not a midi file! Chosen file: {filename}");