mirror of
https://github.com/space-syndicate/space-station-14.git
synced 2026-10-10 02:41:18 +03:00
* Scope creep my ass * why was this shit not pushed???? * gone... * fix that * review plus buildd * asfsafsafsafsafas * grug * burber * I'll fix this later * shrimply die * also this * it's snerf or snuthin * assaads * round snend * aaaa * fix this shit for real * actually, don't start GameRules until MapInit now that I think aboot it. * forgot u * don't actually need this part nullable * Deffer comp removal * one liner * do that too * chungus * Honestly makes more sense here, plus WHY are we doing all that shit on "GameRuleAdded" rather than GameRuleStarted(?) * deferred removal :V * aaaaaaaaaaaaaaa * whhop * Whoop * better * landmine that I placed for myself then forgot about lmao * cleanup * FUCKING `!` * gotovo * amogus * please don't check by metadata I beg * waawsasfdfsasfa * sfafsasfafsas * fdsaasffsasfa * code * fix * fasasffasfasfsad * chungaas * I may be stupid * gra * graaaaaaaaaaaaaaaaa * comment * gra * clearing is not predicted and would require major refactors, so don't cache on client. * lame shit :P * last holes * nukeopsfsafsasafsfafsa * why was that shit public bruh * bubrbgwahrghfaka * dynamic * revert change that did nothing lmao
91 lines
3.3 KiB
C#
91 lines
3.3 KiB
C#
using Content.Server.Chat.Systems;
|
|
using Content.Server.Ninja.Systems;
|
|
using Content.Shared.Communications;
|
|
using Content.Shared.DoAfter;
|
|
using Content.Shared.GameTicking;
|
|
using Content.Shared.Interaction;
|
|
using Content.Shared.Random;
|
|
using Content.Shared.Random.Helpers;
|
|
using Robust.Shared.Random;
|
|
|
|
namespace Content.Server.Communications;
|
|
|
|
public sealed partial class CommsHackerSystem : SharedCommsHackerSystem
|
|
{
|
|
[Dependency] private ChatSystem _chat = default!;
|
|
[Dependency] private GameTicker _gameTicker = default!;
|
|
[Dependency] private IRobustRandom _random = default!;
|
|
// TODO: remove when generic check event is used
|
|
[Dependency] private NinjaGlovesSystem _gloves = default!;
|
|
[Dependency] private SharedDoAfterSystem _doAfter = default!;
|
|
|
|
public override void Initialize()
|
|
{
|
|
base.Initialize();
|
|
|
|
SubscribeLocalEvent<CommsHackerComponent, BeforeInteractHandEvent>(OnBeforeInteractHand);
|
|
SubscribeLocalEvent<CommsHackerComponent, TerrorDoAfterEvent>(OnDoAfter);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Start the doafter to hack a comms console
|
|
/// </summary>
|
|
private void OnBeforeInteractHand(EntityUid uid, CommsHackerComponent comp, BeforeInteractHandEvent args)
|
|
{
|
|
if (args.Handled || !HasComp<CommunicationsConsoleComponent>(args.Target))
|
|
return;
|
|
|
|
// TODO: generic check event
|
|
if (!_gloves.AbilityCheck(uid, args, out var target))
|
|
return;
|
|
|
|
var doAfterArgs = new DoAfterArgs(EntityManager, uid, comp.Delay, new TerrorDoAfterEvent(), target: target, used: uid, eventTarget: uid)
|
|
{
|
|
BreakOnDamage = true,
|
|
BreakOnMove = true,
|
|
MovementThreshold = 0.5f,
|
|
CancelDuplicate = false
|
|
};
|
|
|
|
_doAfter.TryStartDoAfter(doAfterArgs);
|
|
args.Handled = true;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Call in a random threat and do cleanup.
|
|
/// </summary>
|
|
private void OnDoAfter(EntityUid uid, CommsHackerComponent comp, TerrorDoAfterEvent args)
|
|
{
|
|
if (args.Cancelled || args.Handled || args.Target == null)
|
|
return;
|
|
|
|
var threats = ProtoMan.Index<WeightedRandomPrototype>(comp.Threats);
|
|
var threat = threats.Pick(_random);
|
|
CallInThreat(ProtoMan.Index<NinjaHackingThreatPrototype>(threat));
|
|
|
|
// prevent calling in multiple threats
|
|
RemComp<CommsHackerComponent>(uid);
|
|
|
|
var ev = new ThreatCalledInEvent(uid, args.Target.Value);
|
|
RaiseLocalEvent(args.User, ref ev);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Makes announcement and adds game rule of the threat.
|
|
/// </summary>
|
|
public void CallInThreat(NinjaHackingThreatPrototype ninjaHackingThreat)
|
|
{
|
|
_gameTicker.StartGameRule(ninjaHackingThreat.Rule, out _);
|
|
_chat.DispatchGlobalAnnouncement(Loc.GetString(ninjaHackingThreat.Announcement), playSound: true, colorOverride: Color.Red);
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Raised on the user when a threat is called in on the communications console.
|
|
/// </summary>
|
|
/// <remarks>
|
|
/// If you add <see cref="CommsHackerComponent"/>, make sure to use this event to prevent adding it twice.
|
|
/// For example, you could add a marker component after a threat is called in then check if the user doesn't have that marker before adding CommsHackerComponent.
|
|
/// </remarks>
|
|
[ByRefEvent]
|
|
public record struct ThreatCalledInEvent(EntityUid Used, EntityUid Target);
|