Adds Handheld Radio/Listener system (#1457)
* re-do of old PR that got fuckied upp * simplify foreach as suggested * pass distance to PassSpeechData for a check, remove GetListenRange() * adds RadioQuery instead of subscribing/unsubscribing * change SpreadMessage to accept owner rather than component * change RadioQuery to EntityQuery * remove declared EntityQuery (oops, didn't know what shadowcommander meant) * refactor ListeningSystem & refactor added chat logic into listen sys * IGNORE the oopsie STOP LOOKING
This commit is contained in:
90
Content.Server/GameObjects/Components/RadioComponent.cs
Normal file
90
Content.Server/GameObjects/Components/RadioComponent.cs
Normal file
@@ -0,0 +1,90 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using Content.Server.GameObjects.EntitySystems;
|
||||
using Content.Server.Interfaces;
|
||||
using Content.Server.Interfaces.Chat;
|
||||
using Content.Server.Interfaces.GameObjects.Components.Interaction;
|
||||
using Content.Shared.Interfaces.GameObjects.Components;
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.GameObjects.Components;
|
||||
using Robust.Shared.Interfaces.GameObjects;
|
||||
using Robust.Shared.IoC;
|
||||
using Robust.Shared.Localization;
|
||||
using Robust.Shared.ViewVariables;
|
||||
|
||||
namespace Content.Server.GameObjects.Components.Interactable
|
||||
{
|
||||
[RegisterComponent]
|
||||
class RadioComponent : Component, IUse, IListen
|
||||
{
|
||||
#pragma warning disable 649
|
||||
[Dependency] private readonly IEntitySystemManager _entitySystemManager = default!;
|
||||
[Dependency] private readonly IServerNotifyManager _notifyManager = default!;
|
||||
#pragma warning restore 649
|
||||
|
||||
public override string Name => "Radio";
|
||||
|
||||
private bool _radioOn;
|
||||
private int _listenRange = 7;
|
||||
private RadioSystem _radioSystem = default!;
|
||||
|
||||
[ViewVariables]
|
||||
public bool RadioOn
|
||||
{
|
||||
get => _radioOn;
|
||||
private set
|
||||
{
|
||||
_radioOn = value;
|
||||
Dirty();
|
||||
}
|
||||
}
|
||||
|
||||
public override void Initialize()
|
||||
{
|
||||
base.Initialize();
|
||||
|
||||
_radioSystem = _entitySystemManager.GetEntitySystem<RadioSystem>();
|
||||
|
||||
RadioOn = false;
|
||||
}
|
||||
|
||||
public void PassOnMessage(string message)
|
||||
{
|
||||
if(RadioOn)
|
||||
{
|
||||
_radioSystem.SpreadMessage(Owner, message);
|
||||
}
|
||||
}
|
||||
|
||||
public void Speaker(string message)
|
||||
{
|
||||
var chat = IoCManager.Resolve<IChatManager>();
|
||||
chat.EntitySay(Owner, message);
|
||||
}
|
||||
|
||||
public bool UseEntity(UseEntityEventArgs eventArgs)
|
||||
{
|
||||
RadioOn = !RadioOn;
|
||||
if(RadioOn)
|
||||
{
|
||||
_notifyManager.PopupMessage(Owner, eventArgs.User, "The radio is now on.");
|
||||
}
|
||||
else
|
||||
{
|
||||
_notifyManager.PopupMessage(Owner, eventArgs.User, "The radio is now off.");
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public void HeardSpeech(string speech, IEntity source)
|
||||
{
|
||||
PassOnMessage(speech);
|
||||
}
|
||||
|
||||
public int GetListenRange()
|
||||
{
|
||||
return _listenRange;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user