replacing sound (collection) names with SoundSpecifier - part 1

This commit is contained in:
Galactic Chimp
2021-07-10 17:35:33 +02:00
parent 4500b66f28
commit ce3c59e0e6
131 changed files with 934 additions and 587 deletions

View File

@@ -1,6 +1,4 @@
#nullable enable
using System;
using System.Linq;
using Content.Server.Act;
using Content.Server.Interaction;
using Content.Server.Notification;
@@ -11,9 +9,9 @@ using Content.Shared.Actions.Behaviors;
using Content.Shared.Actions.Components;
using Content.Shared.Audio;
using Content.Shared.Cooldown;
using Content.Shared.Interaction.Events;
using Content.Shared.Interaction.Helpers;
using Content.Shared.Notification.Managers;
using Content.Shared.Sound;
using JetBrains.Annotations;
using Robust.Server.GameObjects;
using Robust.Shared.Audio;
@@ -24,6 +22,9 @@ using Robust.Shared.Maths;
using Robust.Shared.Player;
using Robust.Shared.Random;
using Robust.Shared.Serialization.Manager.Attributes;
using Robust.Shared.ViewVariables;
using System;
using System.Linq;
namespace Content.Server.Actions.Actions
{
@@ -35,6 +36,14 @@ namespace Content.Server.Actions.Actions
[DataField("pushProb")] private float _pushProb = 0.4f;
[DataField("cooldown")] private float _cooldown = 1.5f;
[ViewVariables]
[DataField("punchMissSound")]
private SoundSpecifier PunchMissSound { get; } = new SoundPathSpecifier("/Audio/Weapons/punchmiss.ogg");
[ViewVariables]
[DataField("disarmSuccessSound")]
private SoundSpecifier DisarmSuccessSound { get; } = new SoundPathSpecifier("/Audio/Effects/thudswoosh.ogg");
public void DoTargetEntityAction(TargetEntityActionEventArgs args)
{
var disarmedActs = args.Target.GetAllComponents<IDisarmedAct>().ToArray();
@@ -70,8 +79,9 @@ namespace Content.Server.Actions.Actions
if (random.Prob(_failProb))
{
SoundSystem.Play(Filter.Pvs(args.Performer), "/Audio/Weapons/punchmiss.ogg", args.Performer,
AudioHelpers.WithVariation(0.025f));
if(PunchMissSound.TryGetSound(out var punchMissSound))
SoundSystem.Play(Filter.Pvs(args.Performer), punchMissSound, args.Performer, AudioHelpers.WithVariation(0.025f));
args.Performer.PopupMessageOtherClients(Loc.GetString("disarm-action-popup-message-other-clients",
("performerName", args.Performer.Name),
("targetName", args.Target.Name)));
@@ -94,8 +104,8 @@ namespace Content.Server.Actions.Actions
return;
}
SoundSystem.Play(Filter.Pvs(args.Performer), "/Audio/Effects/thudswoosh.ogg", args.Performer.Transform.Coordinates,
AudioHelpers.WithVariation(0.025f));
if(DisarmSuccessSound.TryGetSound(out var disarmSuccessSound))
SoundSystem.Play(Filter.Pvs(args.Performer), disarmSuccessSound, args.Performer.Transform.Coordinates, AudioHelpers.WithVariation(0.025f));
}
}
}

View File

@@ -1,6 +1,4 @@
#nullable enable
using System;
using System.Collections.Generic;
using Content.Server.CharacterAppearance.Components;
using Content.Shared.ActionBlocker;
using Content.Shared.Actions.Behaviors;
@@ -8,7 +6,7 @@ using Content.Shared.Actions.Components;
using Content.Shared.Audio;
using Content.Shared.CharacterAppearance;
using Content.Shared.Cooldown;
using Content.Shared.Speech;
using Content.Shared.Sound;
using JetBrains.Annotations;
using Robust.Shared.Audio;
using Robust.Shared.GameObjects;
@@ -16,6 +14,7 @@ using Robust.Shared.IoC;
using Robust.Shared.Player;
using Robust.Shared.Random;
using Robust.Shared.Serialization.Manager.Attributes;
using System;
namespace Content.Server.Actions.Actions
{
@@ -28,9 +27,9 @@ namespace Content.Server.Actions.Actions
[Dependency] private readonly IRobustRandom _random = default!;
[DataField("male")] private List<string>? _male;
[DataField("female")] private List<string>? _female;
[DataField("wilhelm")] private string? _wilhelm;
[DataField("male")] private SoundSpecifier _male = default!;
[DataField("female")] private SoundSpecifier _female = default!;
[DataField("wilhelm")] private SoundSpecifier _wilhelm = default!;
/// seconds
[DataField("cooldown")] private float _cooldown = 10;
@@ -46,31 +45,27 @@ namespace Content.Server.Actions.Actions
if (!args.Performer.TryGetComponent<HumanoidAppearanceComponent>(out var humanoid)) return;
if (!args.Performer.TryGetComponent<SharedActionsComponent>(out var actions)) return;
if (_random.Prob(.01f) && !string.IsNullOrWhiteSpace(_wilhelm))
if (_random.Prob(.01f) && _wilhelm.TryGetSound(out var wilhelm))
{
SoundSystem.Play(Filter.Pvs(args.Performer), _wilhelm, args.Performer, AudioParams.Default.WithVolume(Volume));
SoundSystem.Play(Filter.Pvs(args.Performer), wilhelm, args.Performer, AudioParams.Default.WithVolume(Volume));
}
else
{
switch (humanoid.Sex)
{
case Sex.Male:
if (_male == null) break;
SoundSystem.Play(Filter.Pvs(args.Performer), _random.Pick(_male), args.Performer,
AudioHelpers.WithVariation(Variation).WithVolume(Volume));
if (_male.TryGetSound(out var male))
SoundSystem.Play(Filter.Pvs(args.Performer), male, args.Performer, AudioHelpers.WithVariation(Variation).WithVolume(Volume));
break;
case Sex.Female:
if (_female == null) break;
SoundSystem.Play(Filter.Pvs(args.Performer), _random.Pick(_female), args.Performer,
AudioHelpers.WithVariation(Variation).WithVolume(Volume));
if (_female.TryGetSound(out var female))
SoundSystem.Play(Filter.Pvs(args.Performer), female, args.Performer, AudioHelpers.WithVariation(Variation).WithVolume(Volume));
break;
default:
throw new ArgumentOutOfRangeException();
}
}
actions.Cooldown(args.ActionType, Cooldowns.SecondsFromNow(_cooldown));
}
}

View File

@@ -6,6 +6,7 @@ using Content.Shared.Actions.Behaviors;
using Content.Shared.Actions.Components;
using Content.Shared.Cooldown;
using Content.Shared.Notification.Managers;
using Content.Shared.Sound;
using JetBrains.Annotations;
using Robust.Shared.Audio;
using Robust.Shared.GameObjects;
@@ -27,7 +28,7 @@ namespace Content.Server.Actions.Spells
[ViewVariables] [DataField("cooldown")] public float CoolDown { get; set; } = 1f;
[ViewVariables] [DataField("spellItem")] public string ItemProto { get; set; } = default!;
[ViewVariables] [DataField("castSound")] public string? CastSound { get; set; } = default!;
[ViewVariables] [DataField("castSound")] public SoundSpecifier CastSound { get; set; } = default!;
//Rubber-band snapping items into player's hands, originally was a workaround, later found it works quite well with stuns
//Not sure if needs fixing
@@ -68,8 +69,8 @@ namespace Content.Server.Actions.Spells
handsComponent.PutInHandOrDrop(itemComponent);
if (CastSound != null)
SoundSystem.Play(Filter.Pvs(caster), CastSound, caster);
if (CastSound.TryGetSound(out var castSound))
SoundSystem.Play(Filter.Pvs(caster), castSound, caster);
}
}
}