Instruments can no longer be played 'remotely'. Fixes #1168

This commit is contained in:
Víctor Aguilera Puerto
2020-06-25 15:27:22 +02:00
parent b8eb9289a6
commit f07cb9042b
2 changed files with 33 additions and 0 deletions

View File

@@ -109,6 +109,12 @@ namespace Content.Client.GameObjects.Components.Instruments
}
}
/// <summary>
/// Whether this instrument is handheld or not.
/// </summary>
[ViewVariables]
public bool Handheld { get; set; } // TODO: Replace this by simply checking if the entity has an ItemComponent.
/// <summary>
/// Whether there's a midi song being played or not.
/// </summary>
@@ -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);
}

View File

@@ -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<IPlayerManager>().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<SharedInteractionSystem>()
.InRangeUnobstructed(localPlayer.ControlledEntity.Transform.MapPosition,
instrumentEnt.Transform.MapPosition, ignoredEnt:instrumentEnt)) return;
if (!_midiManager.IsMidiFile(filename))
{
Logger.Warning($"Not a midi file! Chosen file: {filename}");