# Conflicts: # Content.Server/Antag/AntagSelectionSystem.cs # Content.Server/Changeling/ChangelingRuleSystem.cs # Content.Server/Changeling/ChangelingSystem.Abilities.cs # Content.Server/Doors/Systems/DoorSystem.cs # Content.Server/GameTicking/Rules/NukeopsRuleSystem.cs # Content.Server/GameTicking/Rules/RevolutionaryRuleSystem.cs # Content.Server/GameTicking/Rules/TraitorRuleSystem.cs # Content.Server/GameTicking/Rules/ZombieRuleSystem.cs # Content.Server/Holosign/HolosignSystem.cs # Content.Server/Revenant/EntitySystems/RevenantSystem.Abilities.cs # Content.Server/_White/Cult/GameRule/CultRuleComponent.cs # Content.Server/_White/Cult/GameRule/CultRuleSystem.cs # Content.Server/_White/Cult/Runes/Systems/CultSystem.Rune.cs # Content.Server/_White/Keyhole/KeyholeSystem.cs # Content.Server/_White/MeatyOre/MeatyOreStoreSystem.cs # Content.Shared/Projectiles/SharedProjectileSystem.cs # Content.Shared/Weapons/Melee/SharedMeleeWeaponSystem.cs # Content.Shared/_White/Keyhole/Components/KeyBaseComponent.cs # Resources/Locale/ru-RU/White/stuff.ftl/runes-entities.ftl # Resources/Locale/ru-RU/_white/cult/blood-spear.ftl # Resources/Locale/ru-RU/_white/cult/bolt-barrage.ftl # Resources/Locale/ru-RU/_white/cult/cult.ftl # Resources/Locale/ru-RU/_white/cult/gui.ftl # Resources/Locale/ru-RU/cult/cult-structure.ftl # Resources/Locale/ru-RU/cult/pylon.ftl # Resources/Maps/White/Scoupidia.yml # Resources/Maps/White/Void.yml # Resources/Maps/White/WonderBox.yml # Resources/Prototypes/Actions/types.yml # Resources/Prototypes/Atmospherics/gases.yml # Resources/Prototypes/Catalog/Cargo/cargo_atmospherics.yml # Resources/Prototypes/Catalog/Cargo/cargo_vending.yml # Resources/Prototypes/Catalog/Fills/Lockers/dressers.yml # Resources/Prototypes/Catalog/Fills/Lockers/heads.yml # Resources/Prototypes/Catalog/Fills/Lockers/misc.yml # Resources/Prototypes/Catalog/uplink_catalog.yml # Resources/Prototypes/Entities/Clothing/OuterClothing/armor.yml # Resources/Prototypes/Entities/Objects/Misc/subdermal_implants.yml # Resources/Prototypes/Entities/Objects/Tools/jaws_of_life.yml # Resources/Prototypes/Entities/Objects/Weapons/Melee/sledgehammer.yml # Resources/Prototypes/Entities/Objects/Weapons/Melee/sword.yml # Resources/Prototypes/Entities/Structures/Doors/Airlocks/base_assembly.yml # Resources/Prototypes/Entities/Structures/Doors/Airlocks/base_structureairlocks.yml # Resources/Prototypes/Entities/Structures/Doors/Firelocks/firelock.yml # Resources/Prototypes/Entities/Structures/Doors/Firelocks/frame.yml # Resources/Prototypes/Entities/Structures/Doors/SecretDoor/secret_door.yml # Resources/Prototypes/Entities/Structures/Doors/Windoors/assembly.yml # Resources/Prototypes/Entities/Structures/Doors/Windoors/base_structurewindoors.yml # Resources/Prototypes/Entities/Structures/Furniture/dresser.yml # Resources/Prototypes/Entities/Structures/Lighting/base_lighting.yml # Resources/Prototypes/Entities/Structures/Power/cable_terminal.yml # Resources/Prototypes/Entities/Structures/Walls/grille.yml # Resources/Prototypes/Entities/Structures/Walls/walls.yml # Resources/Prototypes/Entities/Structures/stairs.yml # Resources/Prototypes/_White/Entities/Objects/Misc/books.yml
157 lines
6.1 KiB
C#
157 lines
6.1 KiB
C#
using Content.Server.Explosion.Components;
|
|
using Content.Server.Speech;
|
|
using Content.Server.Speech.Components;
|
|
using Content.Shared.Database;
|
|
using Content.Shared.Examine;
|
|
using Content.Shared.Interaction.Events;
|
|
using Content.Shared.Verbs;
|
|
|
|
namespace Content.Server.Explosion.EntitySystems
|
|
{
|
|
public sealed partial class TriggerSystem
|
|
{
|
|
private void InitializeVoice()
|
|
{
|
|
SubscribeLocalEvent<TriggerOnVoiceComponent, ComponentInit>(OnVoiceInit);
|
|
SubscribeLocalEvent<TriggerOnVoiceComponent, ExaminedEvent>(OnVoiceExamine);
|
|
SubscribeLocalEvent<TriggerOnVoiceComponent, GetVerbsEvent<AlternativeVerb>>(OnVoiceGetAltVerbs);
|
|
SubscribeLocalEvent<TriggerOnVoiceComponent, ListenEvent>(OnListen);
|
|
SubscribeLocalEvent<TriggerOnVoiceComponent, UseInHandEvent>(OnUseInHand);
|
|
}
|
|
|
|
private void OnVoiceInit(EntityUid uid, TriggerOnVoiceComponent component, ComponentInit args)
|
|
{
|
|
if (component.IsListening)
|
|
EnsureComp<ActiveListenerComponent>(uid).Range = component.ListenRange;
|
|
else
|
|
RemCompDeferred<ActiveListenerComponent>(uid);
|
|
}
|
|
|
|
private void OnListen(Entity<TriggerOnVoiceComponent> ent, ref ListenEvent args)
|
|
{
|
|
var component = ent.Comp;
|
|
var message = args.Message.Trim();
|
|
|
|
if (component.IsRecording)
|
|
{
|
|
var ev = new ListenAttemptEvent(args.Source);
|
|
RaiseLocalEvent(ent, ev);
|
|
|
|
if (ev.Cancelled)
|
|
return;
|
|
|
|
if (message.Length >= component.MinLength && message.Length <= component.MaxLength)
|
|
FinishRecording(ent, args.Source, args.Message);
|
|
else if (message.Length > component.MaxLength)
|
|
_popupSystem.PopupEntity(Loc.GetString("popup-trigger-voice-record-failed-too-long"), ent);
|
|
else if (message.Length < component.MinLength)
|
|
_popupSystem.PopupEntity(Loc.GetString("popup-trigger-voice-record-failed-too-short"), ent);
|
|
|
|
return;
|
|
}
|
|
|
|
if (!string.IsNullOrWhiteSpace(component.KeyPhrase) && message.Contains(component.KeyPhrase, StringComparison.InvariantCultureIgnoreCase))
|
|
{
|
|
_adminLogger.Add(LogType.Trigger, LogImpact.High,
|
|
$"A voice-trigger on {ToPrettyString(ent):entity} was triggered by {ToPrettyString(args.Source):speaker} speaking the key-phrase {component.KeyPhrase}.");
|
|
Trigger(ent, args.Source);
|
|
}
|
|
}
|
|
|
|
private void OnVoiceGetAltVerbs(Entity<TriggerOnVoiceComponent> ent, ref GetVerbsEvent<AlternativeVerb> args)
|
|
{
|
|
if (!args.CanInteract || !args.CanAccess)
|
|
return;
|
|
|
|
var component = ent.Comp;
|
|
|
|
var @event = args;
|
|
args.Verbs.Add(new AlternativeVerb()
|
|
{
|
|
Text = Loc.GetString(component.IsRecording ? "verb-trigger-voice-stop" : "verb-trigger-voice-record"),
|
|
Act = () =>
|
|
{
|
|
if (component.IsRecording)
|
|
StopRecording(ent);
|
|
else
|
|
StartRecording(ent, @event.User);
|
|
},
|
|
Priority = 1
|
|
});
|
|
|
|
if (string.IsNullOrWhiteSpace(component.KeyPhrase))
|
|
return;
|
|
|
|
args.Verbs.Add(new AlternativeVerb()
|
|
{
|
|
Text = Loc.GetString("verb-trigger-voice-clear"),
|
|
Act = () =>
|
|
{
|
|
component.KeyPhrase = null;
|
|
component.IsRecording = false;
|
|
RemComp<ActiveListenerComponent>(ent);
|
|
}
|
|
});
|
|
}
|
|
|
|
public void OnUseInHand(Entity<TriggerOnVoiceComponent> ent, ref UseInHandEvent args)
|
|
{
|
|
if(args.Handled)
|
|
return;
|
|
|
|
if (ent.Comp.IsRecording)
|
|
{
|
|
StopRecording(ent);
|
|
}
|
|
else
|
|
{
|
|
StartRecording(ent, args.User);
|
|
}
|
|
}
|
|
|
|
public void StartRecording(Entity<TriggerOnVoiceComponent> ent, EntityUid user)
|
|
{
|
|
var component = ent.Comp;
|
|
component.IsRecording = true;
|
|
EnsureComp<ActiveListenerComponent>(ent).Range = component.ListenRange;
|
|
|
|
_adminLogger.Add(LogType.Trigger, LogImpact.Low,
|
|
$"A voice-trigger on {ToPrettyString(ent):entity} has started recording. User: {ToPrettyString(user):user}");
|
|
|
|
_popupSystem.PopupEntity(Loc.GetString("popup-trigger-voice-start-recording"), ent);
|
|
}
|
|
|
|
public void StopRecording(Entity<TriggerOnVoiceComponent> ent)
|
|
{
|
|
var component = ent.Comp;
|
|
component.IsRecording = false;
|
|
if (string.IsNullOrWhiteSpace(component.KeyPhrase))
|
|
RemComp<ActiveListenerComponent>(ent);
|
|
|
|
_popupSystem.PopupEntity(Loc.GetString("popup-trigger-voice-stop-recording"), ent);
|
|
}
|
|
|
|
public void FinishRecording(Entity<TriggerOnVoiceComponent> ent, EntityUid source, string message)
|
|
{
|
|
var component = ent.Comp;
|
|
component.KeyPhrase = message;
|
|
component.IsRecording = false;
|
|
|
|
_adminLogger.Add(LogType.Trigger, LogImpact.Low,
|
|
$"A voice-trigger on {ToPrettyString(ent):entity} has recorded a new keyphrase: '{component.KeyPhrase}'. Recorded from {ToPrettyString(source):speaker}");
|
|
|
|
_popupSystem.PopupEntity(Loc.GetString("popup-trigger-voice-recorded", ("keyphrase", component.KeyPhrase!)), ent);
|
|
}
|
|
|
|
private void OnVoiceExamine(EntityUid uid, TriggerOnVoiceComponent component, ExaminedEvent args)
|
|
{
|
|
if (args.IsInDetailsRange)
|
|
{
|
|
args.PushText(string.IsNullOrWhiteSpace(component.KeyPhrase)
|
|
? Loc.GetString("trigger-voice-uninitialized")
|
|
: Loc.GetString("examine-trigger-voice", ("keyphrase", component.KeyPhrase)));
|
|
}
|
|
}
|
|
}
|
|
}
|