2023-01-16 21:42:22 +13:00
|
|
|
using System.Linq;
|
2023-03-22 23:41:43 -04:00
|
|
|
using Content.Client.Guidebook.Components;
|
2023-01-16 21:42:22 +13:00
|
|
|
using Content.Client.Light;
|
|
|
|
|
using Content.Client.Verbs;
|
2024-06-07 00:05:58 +12:00
|
|
|
using Content.Shared.Guidebook;
|
2023-01-16 21:42:22 +13:00
|
|
|
using Content.Shared.Interaction;
|
2023-09-04 06:31:10 +01:00
|
|
|
using Content.Shared.Light.Components;
|
2023-01-16 21:42:22 +13:00
|
|
|
using Content.Shared.Speech;
|
|
|
|
|
using Content.Shared.Tag;
|
|
|
|
|
using Content.Shared.Verbs;
|
|
|
|
|
using Robust.Client.GameObjects;
|
|
|
|
|
using Robust.Client.Player;
|
2023-11-27 22:12:34 +11:00
|
|
|
using Robust.Shared.Audio;
|
|
|
|
|
using Robust.Shared.Audio.Systems;
|
2023-06-05 09:33:50 +12:00
|
|
|
using Robust.Shared.Map;
|
2023-01-16 21:42:22 +13:00
|
|
|
using Robust.Shared.Player;
|
2024-05-02 20:41:11 +03:00
|
|
|
using Robust.Shared.Prototypes;
|
2023-06-08 10:47:53 -04:00
|
|
|
using Robust.Shared.Timing;
|
2023-02-26 18:48:57 +11:00
|
|
|
using Robust.Shared.Utility;
|
2023-01-16 21:42:22 +13:00
|
|
|
|
|
|
|
|
namespace Content.Client.Guidebook;
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// This system handles the help-verb and interactions with various client-side entities that are embedded into guidebooks.
|
|
|
|
|
/// </summary>
|
|
|
|
|
public sealed class GuidebookSystem : EntitySystem
|
|
|
|
|
{
|
2023-06-08 10:47:53 -04:00
|
|
|
[Dependency] private readonly IGameTiming _timing = default!;
|
2023-01-16 21:42:22 +13:00
|
|
|
[Dependency] private readonly IPlayerManager _playerManager = default!;
|
|
|
|
|
[Dependency] private readonly SharedAudioSystem _audioSystem = default!;
|
|
|
|
|
[Dependency] private readonly VerbSystem _verbSystem = default!;
|
|
|
|
|
[Dependency] private readonly RgbLightControllerSystem _rgbLightControllerSystem = default!;
|
2023-03-22 23:41:43 -04:00
|
|
|
[Dependency] private readonly SharedPointLightSystem _pointLightSystem = default!;
|
2023-01-16 21:42:22 +13:00
|
|
|
[Dependency] private readonly TagSystem _tags = default!;
|
2024-11-18 14:40:52 +03:00
|
|
|
[Dependency] private readonly IPrototypeManager _proto = default!; //CrystallEdge guidebook filter
|
2024-05-02 20:41:11 +03:00
|
|
|
|
2024-06-07 00:05:58 +12:00
|
|
|
public event Action<List<ProtoId<GuideEntryPrototype>>,
|
|
|
|
|
List<ProtoId<GuideEntryPrototype>>?,
|
|
|
|
|
ProtoId<GuideEntryPrototype>?,
|
|
|
|
|
bool,
|
|
|
|
|
ProtoId<GuideEntryPrototype>?>? OnGuidebookOpen;
|
|
|
|
|
|
2023-01-16 21:42:22 +13:00
|
|
|
public const string GuideEmbedTag = "GuideEmbeded";
|
|
|
|
|
|
2023-06-05 09:33:50 +12:00
|
|
|
private EntityUid _defaultUser;
|
|
|
|
|
|
2023-01-16 21:42:22 +13:00
|
|
|
/// <inheritdoc/>
|
|
|
|
|
public override void Initialize()
|
|
|
|
|
{
|
2024-11-18 14:40:52 +03:00
|
|
|
SubscribeLocalEvent<GuideHelpComponent, MapInitEvent>(OnCrystallEdgeMapInit); //CrystallEdge guidebook filter
|
2023-01-16 21:42:22 +13:00
|
|
|
SubscribeLocalEvent<GuideHelpComponent, GetVerbsEvent<ExamineVerb>>(OnGetVerbs);
|
2023-03-22 23:41:43 -04:00
|
|
|
SubscribeLocalEvent<GuideHelpComponent, ActivateInWorldEvent>(OnInteract);
|
|
|
|
|
|
2023-01-16 21:42:22 +13:00
|
|
|
SubscribeLocalEvent<GuidebookControlsTestComponent, InteractHandEvent>(OnGuidebookControlsTestInteractHand);
|
|
|
|
|
SubscribeLocalEvent<GuidebookControlsTestComponent, ActivateInWorldEvent>(OnGuidebookControlsTestActivateInWorld);
|
|
|
|
|
SubscribeLocalEvent<GuidebookControlsTestComponent, GetVerbsEvent<AlternativeVerb>>(
|
|
|
|
|
OnGuidebookControlsTestGetAlternateVerbs);
|
|
|
|
|
}
|
|
|
|
|
|
2024-11-18 14:40:52 +03:00
|
|
|
//CrystallEdge guidebook filter
|
|
|
|
|
private void OnCrystallEdgeMapInit(Entity<GuideHelpComponent> ent, ref MapInitEvent args)
|
2024-05-02 20:41:11 +03:00
|
|
|
{
|
|
|
|
|
foreach (var guide in ent.Comp.Guides)
|
|
|
|
|
{
|
2024-11-18 14:40:52 +03:00
|
|
|
var guideProto = _proto.Index(guide);
|
2024-05-02 20:41:11 +03:00
|
|
|
if (!guideProto.CrystallPunkAllowed) //REMOVE unnecessary guidebook
|
|
|
|
|
{
|
|
|
|
|
RemComp<GuideHelpComponent>(ent);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2024-11-18 14:40:52 +03:00
|
|
|
//CrystallEdge guidebook filter end
|
2024-05-02 20:41:11 +03:00
|
|
|
|
2023-06-05 09:33:50 +12:00
|
|
|
/// <summary>
|
|
|
|
|
/// Gets a user entity to use for verbs and examinations. If the player has no attached entity, this will use a
|
|
|
|
|
/// dummy client-side entity so that users can still use the guidebook when not attached to anything (e.g., in the
|
|
|
|
|
/// lobby)
|
|
|
|
|
/// </summary>
|
|
|
|
|
public EntityUid GetGuidebookUser()
|
|
|
|
|
{
|
2024-02-13 22:48:39 +01:00
|
|
|
var user = _playerManager.LocalEntity;
|
2023-06-05 09:33:50 +12:00
|
|
|
if (user != null)
|
|
|
|
|
return user.Value;
|
|
|
|
|
|
|
|
|
|
if (!Exists(_defaultUser))
|
|
|
|
|
_defaultUser = Spawn(null, MapCoordinates.Nullspace);
|
|
|
|
|
|
|
|
|
|
return _defaultUser;
|
|
|
|
|
}
|
|
|
|
|
|
2023-01-16 21:42:22 +13:00
|
|
|
private void OnGetVerbs(EntityUid uid, GuideHelpComponent component, GetVerbsEvent<ExamineVerb> args)
|
|
|
|
|
{
|
|
|
|
|
if (component.Guides.Count == 0 || _tags.HasTag(uid, GuideEmbedTag))
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
args.Verbs.Add(new()
|
|
|
|
|
{
|
|
|
|
|
Text = Loc.GetString("guide-help-verb"),
|
2023-04-20 20:16:01 +10:00
|
|
|
Icon = new SpriteSpecifier.Texture(new ("/Textures/Interface/VerbIcons/information.svg.192dpi.png")),
|
2023-03-22 23:41:43 -04:00
|
|
|
Act = () => OnGuidebookOpen?.Invoke(component.Guides, null, null, component.IncludeChildren, component.Guides[0]),
|
2023-01-16 21:42:22 +13:00
|
|
|
ClientExclusive = true,
|
|
|
|
|
CloseMenu = true
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
2024-06-07 00:05:58 +12:00
|
|
|
public void OpenHelp(List<ProtoId<GuideEntryPrototype>> guides)
|
2024-05-10 19:21:18 -07:00
|
|
|
{
|
|
|
|
|
OnGuidebookOpen?.Invoke(guides, null, null, true, guides[0]);
|
|
|
|
|
}
|
|
|
|
|
|
2023-03-22 23:41:43 -04:00
|
|
|
private void OnInteract(EntityUid uid, GuideHelpComponent component, ActivateInWorldEvent args)
|
|
|
|
|
{
|
2023-06-08 10:47:53 -04:00
|
|
|
if (!_timing.IsFirstTimePredicted)
|
|
|
|
|
return;
|
|
|
|
|
|
2023-03-22 23:41:43 -04:00
|
|
|
if (!component.OpenOnActivation || component.Guides.Count == 0 || _tags.HasTag(uid, GuideEmbedTag))
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
OnGuidebookOpen?.Invoke(component.Guides, null, null, component.IncludeChildren, component.Guides[0]);
|
|
|
|
|
args.Handled = true;
|
|
|
|
|
}
|
|
|
|
|
|
2023-01-16 21:42:22 +13:00
|
|
|
private void OnGuidebookControlsTestGetAlternateVerbs(EntityUid uid, GuidebookControlsTestComponent component, GetVerbsEvent<AlternativeVerb> args)
|
|
|
|
|
{
|
|
|
|
|
args.Verbs.Add(new AlternativeVerb()
|
|
|
|
|
{
|
|
|
|
|
Act = () =>
|
|
|
|
|
{
|
2024-02-28 00:51:20 +11:00
|
|
|
if (Transform(uid).LocalRotation != Angle.Zero)
|
|
|
|
|
Transform(uid).LocalRotation -= Angle.FromDegrees(90);
|
2023-01-16 21:42:22 +13:00
|
|
|
},
|
|
|
|
|
Text = Loc.GetString("guidebook-monkey-unspin"),
|
|
|
|
|
Priority = -9999,
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
args.Verbs.Add(new AlternativeVerb()
|
|
|
|
|
{
|
|
|
|
|
Act = () =>
|
|
|
|
|
{
|
2023-03-22 23:41:43 -04:00
|
|
|
EnsureComp<PointLightComponent>(uid); // RGB demands this.
|
|
|
|
|
_pointLightSystem.SetEnabled(uid, false);
|
2023-01-16 21:42:22 +13:00
|
|
|
var rgb = EnsureComp<RgbLightControllerComponent>(uid);
|
|
|
|
|
|
|
|
|
|
var sprite = EnsureComp<SpriteComponent>(uid);
|
|
|
|
|
var layers = new List<int>();
|
|
|
|
|
|
|
|
|
|
for (var i = 0; i < sprite.AllLayers.Count(); i++)
|
|
|
|
|
{
|
|
|
|
|
layers.Add(i);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
_rgbLightControllerSystem.SetLayers(uid, layers, rgb);
|
|
|
|
|
},
|
|
|
|
|
Text = Loc.GetString("guidebook-monkey-disco"),
|
|
|
|
|
Priority = -9998,
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void OnGuidebookControlsTestActivateInWorld(EntityUid uid, GuidebookControlsTestComponent component, ActivateInWorldEvent args)
|
|
|
|
|
{
|
2024-02-28 00:51:20 +11:00
|
|
|
Transform(uid).LocalRotation += Angle.FromDegrees(90);
|
2023-01-16 21:42:22 +13:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void OnGuidebookControlsTestInteractHand(EntityUid uid, GuidebookControlsTestComponent component, InteractHandEvent args)
|
|
|
|
|
{
|
|
|
|
|
if (!TryComp<SpeechComponent>(uid, out var speech) || speech.SpeechSounds is null)
|
|
|
|
|
return;
|
|
|
|
|
|
2025-02-22 17:17:14 +01:00
|
|
|
// This code is broken because SpeechSounds isn't a file name or sound specifier directly.
|
|
|
|
|
// Commenting out to avoid compile failure with https://github.com/space-wizards/RobustToolbox/pull/5540
|
|
|
|
|
// _audioSystem.PlayGlobal(speech.SpeechSounds, Filter.Local(), false, speech.AudioParams);
|
2023-01-16 21:42:22 +13:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void FakeClientActivateInWorld(EntityUid activated)
|
|
|
|
|
{
|
2024-05-31 16:26:19 -04:00
|
|
|
var activateMsg = new ActivateInWorldEvent(GetGuidebookUser(), activated, true);
|
2023-06-05 09:33:50 +12:00
|
|
|
RaiseLocalEvent(activated, activateMsg);
|
2023-01-16 21:42:22 +13:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void FakeClientAltActivateInWorld(EntityUid activated)
|
|
|
|
|
{
|
|
|
|
|
// Get list of alt-interact verbs
|
2023-06-05 09:33:50 +12:00
|
|
|
var verbs = _verbSystem.GetLocalVerbs(activated, GetGuidebookUser(), typeof(AlternativeVerb), force: true);
|
2023-01-16 21:42:22 +13:00
|
|
|
|
|
|
|
|
if (!verbs.Any())
|
|
|
|
|
return;
|
|
|
|
|
|
2023-06-05 09:33:50 +12:00
|
|
|
_verbSystem.ExecuteVerb(verbs.First(), GetGuidebookUser(), activated);
|
2023-01-16 21:42:22 +13:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void FakeClientUse(EntityUid activated)
|
|
|
|
|
{
|
2023-06-05 09:33:50 +12:00
|
|
|
var activateMsg = new InteractHandEvent(GetGuidebookUser(), activated);
|
|
|
|
|
RaiseLocalEvent(activated, activateMsg);
|
2023-01-16 21:42:22 +13:00
|
|
|
}
|
|
|
|
|
}
|