Tippy, the helpful hint clown! (#26767)
* Tippy is BACK * Clean up clippy from aprils fools * Changed names from clippy to tippy, added localization, removed local_clippy command, made it easier to target a specific player * Rename clippy.yml to tippy.yml --------- Co-authored-by: Kara <lunarautomaton6@gmail.com>
This commit is contained in:
@@ -1,9 +1,13 @@
|
||||
using Content.Server.Chat.Managers;
|
||||
using Content.Server.Chat.Managers;
|
||||
using Content.Server.GameTicking;
|
||||
using Content.Shared.CCVar;
|
||||
using Content.Shared.Chat;
|
||||
using Content.Shared.Dataset;
|
||||
using Content.Shared.Tips;
|
||||
using Robust.Server.GameObjects;
|
||||
using Robust.Server.Player;
|
||||
using Robust.Shared.Configuration;
|
||||
using Robust.Shared.Console;
|
||||
using Robust.Shared.Player;
|
||||
using Robust.Shared.Prototypes;
|
||||
using Robust.Shared.Random;
|
||||
@@ -22,11 +26,14 @@ public sealed class TipsSystem : EntitySystem
|
||||
[Dependency] private readonly IGameTiming _timing = default!;
|
||||
[Dependency] private readonly IRobustRandom _random = default!;
|
||||
[Dependency] private readonly GameTicker _ticker = default!;
|
||||
[Dependency] private readonly IConsoleHost _conHost = default!;
|
||||
[Dependency] private readonly IPlayerManager _playerManager = default!;
|
||||
|
||||
private bool _tipsEnabled;
|
||||
private float _tipTimeOutOfRound;
|
||||
private float _tipTimeInRound;
|
||||
private string _tipsDataset = "";
|
||||
private float _tipTippyChance;
|
||||
|
||||
[ViewVariables(VVAccess.ReadWrite)]
|
||||
private TimeSpan _nextTipTime = TimeSpan.Zero;
|
||||
@@ -40,10 +47,101 @@ public sealed class TipsSystem : EntitySystem
|
||||
Subs.CVar(_cfg, CCVars.TipFrequencyInRound, SetInRound, true);
|
||||
Subs.CVar(_cfg, CCVars.TipsEnabled, SetEnabled, true);
|
||||
Subs.CVar(_cfg, CCVars.TipsDataset, SetDataset, true);
|
||||
Subs.CVar(_cfg, CCVars.TipsTippyChance, SetTippyChance, true);
|
||||
|
||||
RecalculateNextTipTime();
|
||||
_conHost.RegisterCommand("tippy", Loc.GetString("cmd-tippy-desc"), Loc.GetString("cmd-tippy-help"), SendTippy, SendTippyHelper);
|
||||
_conHost.RegisterCommand("tip", Loc.GetString("cmd-tip-desc"), "tip", SendTip);
|
||||
}
|
||||
|
||||
private CompletionResult SendTippyHelper(IConsoleShell shell, string[] args)
|
||||
{
|
||||
return args.Length switch
|
||||
{
|
||||
1 => CompletionResult.FromHintOptions(CompletionHelper.SessionNames(), Loc.GetString("cmd-tippy-auto-1")),
|
||||
2 => CompletionResult.FromHint(Loc.GetString("cmd-tippy-auto-2")),
|
||||
3 => CompletionResult.FromHintOptions(CompletionHelper.PrototypeIDs<EntityPrototype>(), Loc.GetString("cmd-tippy-auto-3")),
|
||||
4 => CompletionResult.FromHint(Loc.GetString("cmd-tippy-auto-4")),
|
||||
5 => CompletionResult.FromHint(Loc.GetString("cmd-tippy-auto-5")),
|
||||
6 => CompletionResult.FromHint(Loc.GetString("cmd-tippy-auto-6")),
|
||||
_ => CompletionResult.Empty
|
||||
};
|
||||
}
|
||||
|
||||
private void SendTip(IConsoleShell shell, string argstr, string[] args)
|
||||
{
|
||||
AnnounceRandomTip();
|
||||
RecalculateNextTipTime();
|
||||
}
|
||||
|
||||
private void SendTippy(IConsoleShell shell, string argstr, string[] args)
|
||||
{
|
||||
if (args.Length < 2)
|
||||
{
|
||||
shell.WriteLine(Loc.GetString("cmd-tippy-help"));
|
||||
return;
|
||||
}
|
||||
|
||||
ActorComponent? actor = null;
|
||||
if (args[0] != "all")
|
||||
{
|
||||
ICommonSession? session;
|
||||
if (args.Length > 0)
|
||||
{
|
||||
// Get player entity
|
||||
if (!_playerManager.TryGetSessionByUsername(args[0], out session))
|
||||
{
|
||||
shell.WriteLine(Loc.GetString("cmd-tippy-error-no-user"));
|
||||
return;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
session = shell.Player;
|
||||
}
|
||||
|
||||
if (session?.AttachedEntity is not { } user)
|
||||
{
|
||||
shell.WriteLine(Loc.GetString("cmd-tippy-error-no-user"));
|
||||
return;
|
||||
}
|
||||
|
||||
if (!TryComp(user, out actor))
|
||||
{
|
||||
shell.WriteError(Loc.GetString("cmd-tippy-error-no-user"));
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
var ev = new TippyEvent(args[1]);
|
||||
|
||||
string proto;
|
||||
if (args.Length > 2)
|
||||
{
|
||||
ev.Proto = args[2];
|
||||
if (!_prototype.HasIndex<EntityPrototype>(args[2]))
|
||||
{
|
||||
shell.WriteError(Loc.GetString("cmd-tippy-error-no-prototype", ("proto", args[2])));
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (args.Length > 3)
|
||||
ev.SpeakTime = float.Parse(args[3]);
|
||||
|
||||
if (args.Length > 4)
|
||||
ev.SlideTime = float.Parse(args[4]);
|
||||
|
||||
if (args.Length > 5)
|
||||
ev.WaddleInterval = float.Parse(args[5]);
|
||||
|
||||
if (actor != null)
|
||||
RaiseNetworkEvent(ev, actor.PlayerSession);
|
||||
else
|
||||
RaiseNetworkEvent(ev);
|
||||
}
|
||||
|
||||
|
||||
public override void Update(float frameTime)
|
||||
{
|
||||
base.Update(frameTime);
|
||||
@@ -81,6 +179,11 @@ public sealed class TipsSystem : EntitySystem
|
||||
_tipsDataset = value;
|
||||
}
|
||||
|
||||
private void SetTippyChance(float value)
|
||||
{
|
||||
_tipTippyChance = value;
|
||||
}
|
||||
|
||||
private void AnnounceRandomTip()
|
||||
{
|
||||
if (!_prototype.TryIndex<DatasetPrototype>(_tipsDataset, out var tips))
|
||||
@@ -89,8 +192,16 @@ public sealed class TipsSystem : EntitySystem
|
||||
var tip = _random.Pick(tips.Values);
|
||||
var msg = Loc.GetString("tips-system-chat-message-wrap", ("tip", tip));
|
||||
|
||||
_chat.ChatMessageToManyFiltered(Filter.Broadcast(), ChatChannel.OOC, tip, msg,
|
||||
if (_random.Prob(_tipTippyChance))
|
||||
{
|
||||
var ev = new TippyEvent(msg);
|
||||
ev.SpeakTime = 1 + tip.Length * 0.05f;
|
||||
RaiseNetworkEvent(ev);
|
||||
} else
|
||||
{
|
||||
_chat.ChatMessageToManyFiltered(Filter.Broadcast(), ChatChannel.OOC, tip, msg,
|
||||
EntityUid.Invalid, false, false, Color.MediumPurple);
|
||||
}
|
||||
}
|
||||
|
||||
private void RecalculateNextTipTime()
|
||||
|
||||
Reference in New Issue
Block a user