Instruments have a property for enabling/disabling MIDI limits.

- Added unlimited super synth that doesn't respect MIDI limits! Adminbuse it to your heart's content and blast your epic MIDIs, fellow badmins.
This commit is contained in:
Vera Aguilera Puerto
2020-12-20 01:43:29 +01:00
parent c0a0547b39
commit c9e9d9f4dd
4 changed files with 54 additions and 16 deletions

View File

@@ -52,6 +52,8 @@ namespace Content.Client.GameObjects.Components.Instruments
private bool _allowProgramChange; private bool _allowProgramChange;
private bool _respectMidiLimits;
/// <summary> /// <summary>
/// A queue of MidiEvents to be sent to the server. /// A queue of MidiEvents to be sent to the server.
/// </summary> /// </summary>
@@ -239,6 +241,7 @@ namespace Content.Client.GameObjects.Components.Instruments
serializer.DataField(ref _instrumentBank, "bank", (byte) 0); serializer.DataField(ref _instrumentBank, "bank", (byte) 0);
serializer.DataField(ref _allowPercussion, "allowPercussion", false); serializer.DataField(ref _allowPercussion, "allowPercussion", false);
serializer.DataField(ref _allowProgramChange, "allowProgramChange", false); serializer.DataField(ref _allowProgramChange, "allowProgramChange", false);
serializer.DataField(ref _respectMidiLimits, "respectMidiLimits", true);
} }
public override void HandleNetworkMessage(ComponentMessage message, INetChannel channel, ICommonSession? session = null) public override void HandleNetworkMessage(ComponentMessage message, INetChannel channel, ICommonSession? session = null)
@@ -429,7 +432,9 @@ namespace Content.Client.GameObjects.Components.Instruments
if (_midiEventBuffer.Count == 0) return; if (_midiEventBuffer.Count == 0) return;
var max = Math.Min(_instrumentSystem.MaxMidiEventsPerBatch, _instrumentSystem.MaxMidiEventsPerSecond - _sentWithinASec); var max = _respectMidiLimits ?
Math.Min(_instrumentSystem.MaxMidiEventsPerBatch, _instrumentSystem.MaxMidiEventsPerSecond - _sentWithinASec)
: _midiEventBuffer.Count;
if (max <= 0) if (max <= 0)
{ {

View File

@@ -78,8 +78,8 @@ namespace Content.Server.GameObjects.Components.Instruments
private byte _instrumentBank; private byte _instrumentBank;
private bool _allowPercussion; private bool _allowPercussion;
private bool _allowProgramChange; private bool _allowProgramChange;
private bool _respectMidiLimits;
[ViewVariables(VVAccess.ReadWrite)]
public override byte InstrumentProgram { get => _instrumentProgram; public override byte InstrumentProgram { get => _instrumentProgram;
set set
{ {
@@ -88,7 +88,6 @@ namespace Content.Server.GameObjects.Components.Instruments
} }
} }
[ViewVariables(VVAccess.ReadWrite)]
public override byte InstrumentBank { get => _instrumentBank; public override byte InstrumentBank { get => _instrumentBank;
set set
{ {
@@ -97,7 +96,6 @@ namespace Content.Server.GameObjects.Components.Instruments
} }
} }
[ViewVariables(VVAccess.ReadWrite)]
public override bool AllowPercussion { get => _allowPercussion; public override bool AllowPercussion { get => _allowPercussion;
set set
{ {
@@ -106,7 +104,6 @@ namespace Content.Server.GameObjects.Components.Instruments
} }
} }
[ViewVariables(VVAccess.ReadWrite)]
public override bool AllowProgramChange { get => _allowProgramChange; public override bool AllowProgramChange { get => _allowProgramChange;
set set
{ {
@@ -115,6 +112,14 @@ namespace Content.Server.GameObjects.Components.Instruments
} }
} }
public override bool RespectMidiLimits { get => _respectMidiLimits;
set
{
_respectMidiLimits = value;
Dirty();
}
}
/// <summary> /// <summary>
/// Whether the instrument is an item which can be held or not. /// Whether the instrument is an item which can be held or not.
/// </summary> /// </summary>
@@ -181,11 +186,12 @@ namespace Content.Server.GameObjects.Components.Instruments
serializer.DataField(ref _instrumentBank, "bank", (byte) 0); serializer.DataField(ref _instrumentBank, "bank", (byte) 0);
serializer.DataField(ref _allowPercussion, "allowPercussion", false); serializer.DataField(ref _allowPercussion, "allowPercussion", false);
serializer.DataField(ref _allowProgramChange, "allowProgramChange", false); serializer.DataField(ref _allowProgramChange, "allowProgramChange", false);
serializer.DataField(ref _respectMidiLimits, "respectMidiLimits", true);
} }
public override ComponentState GetComponentState() public override ComponentState GetComponentState()
{ {
return new InstrumentState(Playing, InstrumentProgram, InstrumentBank, AllowPercussion, AllowProgramChange, _lastSequencerTick); return new InstrumentState(Playing, InstrumentProgram, InstrumentBank, AllowPercussion, AllowProgramChange, RespectMidiLimits, _lastSequencerTick);
} }
public override void HandleNetworkMessage(ComponentMessage message, INetChannel channel, ICommonSession? session = null) public override void HandleNetworkMessage(ComponentMessage message, INetChannel channel, ICommonSession? session = null)
@@ -217,14 +223,17 @@ namespace Content.Server.GameObjects.Components.Instruments
_laggedBatches++; _laggedBatches++;
if (_laggedBatches == (int) (maxMidiLaggedBatches * (1 / 3d) + 1)) if (_respectMidiLimits)
{ {
Owner.PopupMessage(InstrumentPlayer.AttachedEntity, if (_laggedBatches == (int) (maxMidiLaggedBatches * (1 / 3d) + 1))
Loc.GetString("Your fingers are beginning to a cramp a little!")); {
} else if (_laggedBatches == (int) (maxMidiLaggedBatches * (2 / 3d) + 1)) Owner.PopupMessage(InstrumentPlayer.AttachedEntity,
{ Loc.GetString("Your fingers are beginning to a cramp a little!"));
Owner.PopupMessage(InstrumentPlayer.AttachedEntity, } else if (_laggedBatches == (int) (maxMidiLaggedBatches * (2 / 3d) + 1))
Loc.GetString("Your fingers are seriously cramping up!")); {
Owner.PopupMessage(InstrumentPlayer.AttachedEntity,
Loc.GetString("Your fingers are seriously cramping up!"));
}
} }
if (_laggedBatches > maxMidiLaggedBatches) if (_laggedBatches > maxMidiLaggedBatches)
@@ -250,7 +259,7 @@ namespace Content.Server.GameObjects.Components.Instruments
send = false; send = false;
} }
if (send) if (send || !_respectMidiLimits)
{ {
SendNetworkMessage(midiEventMsg); SendNetworkMessage(midiEventMsg);
} }
@@ -367,7 +376,7 @@ namespace Content.Server.GameObjects.Components.Instruments
if ((_batchesDropped >= maxMidiBatchDropped if ((_batchesDropped >= maxMidiBatchDropped
|| _laggedBatches >= maxMidiLaggedBatches) || _laggedBatches >= maxMidiLaggedBatches)
&& InstrumentPlayer != null) && InstrumentPlayer != null && _respectMidiLimits)
{ {
var mob = InstrumentPlayer.AttachedEntity; var mob = InstrumentPlayer.AttachedEntity;

View File

@@ -11,11 +11,21 @@ namespace Content.Shared.GameObjects.Components.Instruments
public override string Name => "Instrument"; public override string Name => "Instrument";
public override uint? NetID => ContentNetIDs.INSTRUMENTS; public override uint? NetID => ContentNetIDs.INSTRUMENTS;
[ViewVariables(VVAccess.ReadWrite)]
public virtual byte InstrumentProgram { get; set; } public virtual byte InstrumentProgram { get; set; }
[ViewVariables(VVAccess.ReadWrite)]
public virtual byte InstrumentBank { get; set; } public virtual byte InstrumentBank { get; set; }
[ViewVariables(VVAccess.ReadWrite)]
public virtual bool AllowPercussion { get; set; } public virtual bool AllowPercussion { get; set; }
[ViewVariables(VVAccess.ReadWrite)]
public virtual bool AllowProgramChange { get ; set; } public virtual bool AllowProgramChange { get ; set; }
[ViewVariables(VVAccess.ReadWrite)]
public virtual bool RespectMidiLimits { get; set; }
public virtual void Update(float delta) public virtual void Update(float delta)
{ {
} }
@@ -61,14 +71,16 @@ namespace Content.Shared.GameObjects.Components.Instruments
public byte InstrumentBank { get; } public byte InstrumentBank { get; }
public bool AllowPercussion { get; } public bool AllowPercussion { get; }
public bool AllowProgramChange { get; } public bool AllowProgramChange { get; }
public bool RespectMidiLimits { get; }
public InstrumentState(bool playing, byte instrumentProgram, byte instrumentBank, bool allowPercussion, bool allowProgramChange, uint sequencerTick = 0) : base(ContentNetIDs.INSTRUMENTS) public InstrumentState(bool playing, byte instrumentProgram, byte instrumentBank, bool allowPercussion, bool allowProgramChange, bool respectMidiLimits, uint sequencerTick = 0) : base(ContentNetIDs.INSTRUMENTS)
{ {
Playing = playing; Playing = playing;
InstrumentProgram = instrumentProgram; InstrumentProgram = instrumentProgram;
InstrumentBank = instrumentBank; InstrumentBank = instrumentBank;
AllowPercussion = allowPercussion; AllowPercussion = allowPercussion;
AllowProgramChange = allowProgramChange; AllowProgramChange = allowProgramChange;
RespectMidiLimits = respectMidiLimits;
} }
} }

View File

@@ -223,3 +223,15 @@
- type: Item - type: Item
size: 24 size: 24
sprite: Objects/Fun/Instruments/h_synthesizer.rsi sprite: Objects/Fun/Instruments/h_synthesizer.rsi
- type: entity
name: super synthesizer
suffix: no MIDI limits
description: Blasting the ghetto with Touhou MIDIs since 2020.
id: SuperSynthesizerUnlimitedInstrument
parent: SuperSynthesizerInstrument
components:
- type: Instrument
allowPercussion: true
allowProgramChange: true
respectMidiLimits: false