2021-03-05 01:08:38 +01:00
|
|
|
|
#nullable enable
|
|
|
|
|
|
using System;
|
2020-12-13 14:28:20 -08:00
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
|
using Content.Server.GameObjects.Components.Mobs;
|
|
|
|
|
|
using Content.Shared.Actions;
|
|
|
|
|
|
using Content.Shared.Audio;
|
|
|
|
|
|
using Content.Shared.GameObjects.Components.Mobs;
|
2020-12-20 04:26:21 +01:00
|
|
|
|
using Content.Shared.GameObjects.EntitySystems.ActionBlocker;
|
2020-12-13 14:28:20 -08:00
|
|
|
|
using Content.Shared.Preferences;
|
|
|
|
|
|
using Content.Shared.Utility;
|
|
|
|
|
|
using JetBrains.Annotations;
|
2021-02-11 01:13:03 -08:00
|
|
|
|
using Robust.Server.GameObjects;
|
2020-12-13 14:28:20 -08:00
|
|
|
|
using Robust.Shared.Audio;
|
2021-02-11 01:13:03 -08:00
|
|
|
|
using Robust.Shared.GameObjects;
|
2020-12-13 14:28:20 -08:00
|
|
|
|
using Robust.Shared.IoC;
|
|
|
|
|
|
using Robust.Shared.Random;
|
2021-03-05 01:08:38 +01:00
|
|
|
|
using Robust.Shared.Serialization.Manager.Attributes;
|
2020-12-13 14:28:20 -08:00
|
|
|
|
|
|
|
|
|
|
namespace Content.Server.Actions
|
|
|
|
|
|
{
|
|
|
|
|
|
[UsedImplicitly]
|
2021-03-05 01:08:38 +01:00
|
|
|
|
[DataDefinition]
|
2020-12-13 14:28:20 -08:00
|
|
|
|
public class ScreamAction : IInstantAction
|
|
|
|
|
|
{
|
|
|
|
|
|
private const float Variation = 0.125f;
|
|
|
|
|
|
private const float Volume = 4f;
|
|
|
|
|
|
|
2021-03-05 01:08:38 +01:00
|
|
|
|
[Dependency] private readonly IRobustRandom _random = default!;
|
2020-12-13 14:28:20 -08:00
|
|
|
|
|
2021-03-05 01:08:38 +01:00
|
|
|
|
[DataField("male")] private List<string>? _male;
|
|
|
|
|
|
[DataField("female")] private List<string>? _female;
|
|
|
|
|
|
[DataField("wilhelm")] private string? _wilhelm;
|
2020-12-13 14:28:20 -08:00
|
|
|
|
|
2021-03-05 01:08:38 +01:00
|
|
|
|
/// seconds
|
|
|
|
|
|
[DataField("cooldown")] private float _cooldown = 10;
|
2020-12-13 14:28:20 -08:00
|
|
|
|
|
2021-03-05 01:08:38 +01:00
|
|
|
|
public ScreamAction()
|
2020-12-13 14:28:20 -08:00
|
|
|
|
{
|
2021-03-05 01:08:38 +01:00
|
|
|
|
IoCManager.InjectDependencies(this);
|
2020-12-13 14:28:20 -08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public void DoInstantAction(InstantActionEventArgs args)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (!ActionBlockerSystem.CanSpeak(args.Performer)) return;
|
|
|
|
|
|
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))
|
|
|
|
|
|
{
|
|
|
|
|
|
EntitySystem.Get<AudioSystem>().PlayFromEntity(_wilhelm, args.Performer, AudioParams.Default.WithVolume(Volume));
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
switch (humanoid.Sex)
|
|
|
|
|
|
{
|
|
|
|
|
|
case Sex.Male:
|
|
|
|
|
|
if (_male == null) break;
|
|
|
|
|
|
EntitySystem.Get<AudioSystem>().PlayFromEntity(_random.Pick(_male), args.Performer,
|
|
|
|
|
|
AudioHelpers.WithVariation(Variation).WithVolume(Volume));
|
|
|
|
|
|
break;
|
|
|
|
|
|
case Sex.Female:
|
|
|
|
|
|
if (_female == null) break;
|
|
|
|
|
|
EntitySystem.Get<AudioSystem>().PlayFromEntity(_random.Pick(_female), args.Performer,
|
|
|
|
|
|
AudioHelpers.WithVariation(Variation).WithVolume(Volume));
|
|
|
|
|
|
break;
|
|
|
|
|
|
default:
|
|
|
|
|
|
throw new ArgumentOutOfRangeException();
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
actions.Cooldown(args.ActionType, Cooldowns.SecondsFromNow(_cooldown));
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|