Skip to content

Commit

Permalink
added orbit by clicking on chat
Browse files Browse the repository at this point in the history
  • Loading branch information
Legendaxe committed Jun 18, 2023
1 parent afe3256 commit 34aafbc
Show file tree
Hide file tree
Showing 3 changed files with 80 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
using Content.Client.Chat;
using Content.Client.Chat.TypingIndicator;
using Content.Client.Ghost;
using Content.Client.UserInterface.Systems.Chat.Controls;
using Content.Shared.Chat;
using Content.Shared.Input;
using Robust.Client.AutoGenerated;
using Robust.Client.Player;
using Robust.Client.UserInterface;
using Robust.Client.UserInterface.Controls;
using Robust.Client.UserInterface.XAML;
Expand All @@ -22,6 +24,8 @@ public partial class ChatBox : UIWidget
#pragma warning restore RA0003
{
private readonly ChatUIController _controller;
[Dependency] private readonly IEntityManager _entityManager = default!;
[Dependency] private readonly IPlayerManager _playerManager = default!;

public bool Main { get; set; }

Expand All @@ -30,7 +34,8 @@ public partial class ChatBox : UIWidget
public ChatBox()
{
RobustXamlLoader.Load(this);

IoCManager.InjectDependencies(this);

ChatInput.Input.OnTextEntered += OnTextEntered;
ChatInput.Input.OnKeyBindDown += OnKeyBindDown;
ChatInput.Input.OnTextChanged += OnTextChanged;
Expand Down Expand Up @@ -66,6 +71,13 @@ private void OnMessageAdded(ChatMessage msg)
? msg.MessageColorOverride.Value
: msg.Channel.TextColor();

if (_entityManager.HasComponent<GhostComponent>(_playerManager?.LocalPlayer?.ControlledEntity)
&& (msg.Channel & ChatChannel.IC) != ChatChannel.None
&& msg.SenderEntity != _playerManager?.LocalPlayer?.ControlledEntity)
{
msg.WrappedMessage += $"[cmdlink=\"({Loc.GetString("orbit-chat-click")})\" command=\"orbit {msg.SenderEntity}\"/]";
}

AddLine(msg.WrappedMessage, color);
}

Expand Down
66 changes: 66 additions & 0 deletions Content.Server/SS220/Commands/OrbitCommand.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
// © SS220, An EULA/CLA with a hosting restriction, full text: https://raw.githubusercontent.com/SerbiaStrong-220/space-station-14/master/CLA.txt

using Content.Server.Ghost.Components;
using Content.Shared.Administration;
using Content.Shared.Follower;
using Content.Shared.Follower.Components;
using Robust.Server.Player;
using Robust.Shared.Console;
using Robust.Shared.Enums;

namespace Content.Server.SS220.Commands;


[AnyCommand]
public sealed class OrbitCommand : IConsoleCommand
{
[Dependency] private readonly IEntityManager _entityManager = default!;

public string Command => "orbit";
public string Description => "You start following entity";

public string Help => "orbit <entityUid>\nEntityUid to follow";

public void Execute(IConsoleShell shell, string argStr, string[] args)
{
var player = shell.Player as IPlayerSession;

if (player == null)
{
shell.WriteLine("Only players can use this command");
return;
}

if (args.Length != 1)
{
shell.WriteLine("Expected a single argument.");
return;
}

if (!EntityUid.TryParse(args[0], out var entityToFollow))
{
shell.WriteError($"{args[0]} is not a valid entity UID.");
return;
}

if (player.Status != SessionStatus.InGame || player.AttachedEntity is not {Valid:true} playerEntity)
{
shell.WriteLine("You are not in-game!");
return;
}

if (!_entityManager.HasComponent<GhostComponent>(playerEntity))
{
shell.WriteLine("You are not a ghost");
return;
}

if (!_entityManager.HasComponent<FollowerComponent>(entityToFollow))
{
shell.WriteLine("You can't follow this entity");
return;
}

_entityManager.System<FollowerSystem>().StartFollowingEntity(playerEntity, entityToFollow);
}
}
1 change: 1 addition & 0 deletions Resources/Locale/ru-RU/ss220/orbit.ftl
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
orbit-chat-click = Наблюдать

0 comments on commit 34aafbc

Please sign in to comment.