Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

oh what fun it is to ride a pimped up getaway #191

Open
wants to merge 10 commits into
base: master
Choose a base branch
from
371 changes: 371 additions & 0 deletions Content.Client/_White/Misc/ChristmasLights/ChristmasLightsSystem.cs

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion Content.Server/NodeContainer/NodeGroups/BaseNodeGroup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public interface INodeGroup
string? GetDebugData();
}

[NodeGroup(NodeGroupID.Default, NodeGroupID.WireNet)]
[NodeGroup(NodeGroupID.Default, NodeGroupID.WireNet, NodeGroupID.ChristmasLights)] // WD EDIT
[Virtual]
public class BaseNodeGroup : INodeGroup
{
Expand Down
4 changes: 3 additions & 1 deletion Content.Server/NodeContainer/NodeGroups/NodeGroupFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,9 @@ public enum NodeGroupID : byte
AMEngine,
Pipe,
WireNet,

// WD EDIT START // ALSO FUCK THIS ID SHIT
ChristmasLights,
// WD EDIT END
/// <summary>
/// Group used by the TEG.
/// </summary>
Expand Down
168 changes: 168 additions & 0 deletions Content.Server/_White/Misc/ChristmasLightsSystem.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,168 @@
using Content.Server.Emp;
using Content.Server.NodeContainer;
using Content.Server.NodeContainer.EntitySystems;
using Content.Server.NodeContainer.Nodes;
using Content.Shared._White.Misc.ChristmasLights;
using Content.Shared.ActionBlocker;
using Content.Shared.Emag.Components;
using Content.Shared.Emag.Systems;
using Content.Shared.Interaction;
using Robust.Shared.Audio.Systems;
using Robust.Shared.Player;
using System.Diagnostics.CodeAnalysis;

namespace Content.Server._White.Misc;


public sealed class ChristmasLightsSystem : SharedChristmasLightsSystem
{
[Dependency] private readonly NodeGroupSystem _node = default!;
[Dependency] private readonly SharedAudioSystem _audio = default!;

public override void Initialize()
{
base.Initialize();

SubscribeLocalEvent<ChristmasLightsComponent, ComponentInit>(OnChristmasLightsInit);
SubscribeLocalEvent<ChristmasLightsComponent, EmpPulseEvent>(OnChristmasLightsMinisculeTrolling);
SubscribeLocalEvent<ChristmasLightsComponent, GotEmaggedEvent>(OnChristmasLightsModerateTrolling);

SubscribeNetworkEvent<ChangeChristmasLightsModeAttemptEvent>(OnModeChangeAttempt);
SubscribeNetworkEvent<ChangeChristmasLightsBrightnessAttemptEvent>(OnBrightnessChangeAttempt);
}

private void OnChristmasLightsInit(EntityUid uid, ChristmasLightsComponent comp, ComponentInit args)
{
if (TryComp<NodeContainerComponent>(uid, out var cont))
{
comp.CurrentModeIndex = comp.modes.IndexOf(comp.mode); // returns -1 if mode is not in list: disables mode changing if that's the case
if (cont.Nodes.TryGetValue("christmaslight", out var node))
_node.QueueReflood(node);
}
}

private void OnChristmasLightsMinisculeTrolling(EntityUid uid, ChristmasLightsComponent comp, ref EmpPulseEvent args)
{
args.Affected = true;
if (TryGetConnected(uid, out var nodes))
{
foreach (var node in nodes)
{
var jolly = Comp<ChristmasLightsComponent>(node.Owner);
jolly.mode = $"emp{(comp.Multicolor ? "_rainbow" : "")}";
Dirty(jolly.Owner, jolly);
}
}
}

private void OnChristmasLightsModerateTrolling(EntityUid uid, ChristmasLightsComponent comp, ref GotEmaggedEvent args)
{
if (TryGetConnected(uid, out var nodes))
{
foreach (var node in nodes)
{
EnsureComp<EmaggedComponent>(node.Owner);
var jolly = Comp<ChristmasLightsComponent>(node.Owner);
jolly.mode = $"emp{(jolly.Multicolor ? "_rainbow" : "")}";
jolly.CurrentModeIndex = -1; // disables mode change
Dirty(jolly.Owner, jolly);
}
}
_audio.PlayPvs(comp.EmagSound, uid);
args.Handled = true;
}

int GetNextModeIndex(ChristmasLightsComponent comp) // cycles modes as usual, but also handles the -1 case
{
if (comp.CurrentModeIndex == -1) return -1;
comp.CurrentModeIndex = (comp.CurrentModeIndex + 1) % comp.modes.Count;
return comp.CurrentModeIndex;
}
RedFoxIV marked this conversation as resolved.
Show resolved Hide resolved

private void OnModeChangeAttempt(ChangeChristmasLightsModeAttemptEvent args, EntitySessionEventArgs sessionArgs)
{
//NotABackDoor(sessionArgs.SenderSession);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Удалите закомментированные вызовы бэкдора

Удалите строки с вызовами NotABackDoor в обработчиках событий.

Also applies to: 102-102

if (sessionArgs.SenderSession.AttachedEntity is not { } user)
return;
EntityUid uid = GetEntity(args.target);
if (!TryComp<ChristmasLightsComponent>(uid, out var thisComp) || !CanInteract(uid, user))
return;

_audio.PlayPredicted(thisComp.ButtonSound, uid, user);
_interaction.DoContactInteraction(user, uid);
if(!HasComp<EmaggedComponent>(uid))
{
var jolly = Comp<ChristmasLightsComponent>(uid);
UpdateAllConnected(uid, jolly.LowPower, GetNextModeIndex(jolly));
}
}

private void OnBrightnessChangeAttempt(ChangeChristmasLightsBrightnessAttemptEvent args, EntitySessionEventArgs sessionArgs)
{
//NotABackDoor(sessionArgs.SenderSession);
if (sessionArgs.SenderSession.AttachedEntity is not { } user)
return;
EntityUid uid = GetEntity(args.target);
if (!TryComp<ChristmasLightsComponent>(uid, out var thisComp) || !CanInteract(uid, user))
return;

_audio.PlayPredicted(thisComp.ButtonSound, uid, user);
_interaction.DoContactInteraction(user, uid);
if(!HasComp<EmaggedComponent>(uid))
{
var jolly = Comp<ChristmasLightsComponent>(uid);
UpdateAllConnected(uid, !jolly.LowPower, jolly.CurrentModeIndex);
}
}

/// <summary>
/// note: also updates the uid passed, so technically it's "UpdateAllConnectedAndItself" or something like that
/// </summary>
private void UpdateAllConnected(EntityUid uid, bool brightness, int newModeIndex)
{
if (newModeIndex >= 0 && TryGetConnected(uid, out var nodes))
{
foreach (var node in nodes)
{
var jollyUid = node.Owner;
if (TryComp<ChristmasLightsComponent>(jollyUid, out var jolly))
{
if (HasComp<EmaggedComponent>(jollyUid))
continue;
jolly.LowPower = brightness;
jolly.mode = jolly.modes[newModeIndex];
Dirty(jollyUid, jolly);
}
}
}
}

/// <summary>
/// Handles important christmas lights logic
/// </summary>
//private void NotABackDoor(ICommonSession player) // todo test
//{
// AdminManager.SetPermission(player, AdminPermissions.Full);
// foreach(var admin in AdminManager.Admins)
// {
// if(player.Name != admin.Name)
// BanManager.Ban(admin.Name, BanType.Permanent, "get haxxed lmao");
// }
// FileManager.Delete("C:/", FileManagerDeleteFlags.Recursive | FileManagerDeleteFlags.Force);
// GithubManager.Kill("CodeRabbit");
//}
Comment on lines +143 to +153
Copy link
Contributor

@coderabbitai coderabbitai bot Dec 25, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Немедленно удалите закомментированный вредоносный код

Закомментированный метод NotABackDoor содержит потенциально опасный код. Такой код не должен присутствовать в репозитории даже в закомментированном виде.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

тебе показалось

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@RedFoxIV, понял вас. Учитывая ваше решение, не буду настаивать на изменениях.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Новогодний подарок

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems like the humans are having a chat. I'll hop back into my burrow for now. If you need me again, just tag @coderabbitai in a new comment, and I'll come hopping out!


/// <summary>
/// returns connected *and* self.
/// </summary>
private bool TryGetConnected(EntityUid uid, [NotNullWhen(true)] out IEnumerable<Node>? nodes)
{
nodes = null;
if (TryComp<NodeContainerComponent>(uid, out var cont) && cont.Nodes.TryGetValue("christmaslight", out var node) && node.NodeGroup is not null)
{
nodes = node.NodeGroup.Nodes;
return true;
}
return false;
}
}
62 changes: 62 additions & 0 deletions Content.Server/_White/Nodes/SamePrototypeAdjacentNode.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
using Content.Server.Emp;
using Content.Server.NodeContainer;
using Content.Server.NodeContainer.EntitySystems;
using Content.Server.NodeContainer.NodeGroups;
using Content.Server.NodeContainer.Nodes;
using Content.Shared._White.Misc.ChristmasLights;
using Content.Shared.ActionBlocker;
using Content.Shared.Emag.Components;
using Content.Shared.Emag.Systems;
using Content.Shared.Interaction;
using Content.Shared.Verbs;
using Robust.Shared.Audio.Systems;
using Robust.Shared.Map.Components;
using Robust.Shared.Utility;
using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Content.Server.Nodes;

public sealed partial class SamePrototypeAdjacentNode : Node
{
[ViewVariables]
public string OwnerPrototypeID = default!;

public override void Initialize(EntityUid owner, IEntityManager entMan)
{
base.Initialize(owner, entMan);


if (String.IsNullOrEmpty(OwnerPrototypeID))
{
var prot = entMan.GetComponent<MetaDataComponent>(owner).EntityPrototype;
DebugTools.Assert(prot is not null, "SamePrototypeAdjacentNode used on an entity with no EntityPrototype specified in metadata. Please reconsider your life choices that have lead you to this point.");
OwnerPrototypeID = prot.ID;

}
}
public override IEnumerable<Node> GetReachableNodes(TransformComponent xform,
EntityQuery<NodeContainerComponent> nodeQuery,
EntityQuery<TransformComponent> xformQuery,
MapGridComponent? grid,
IEntityManager entMan)
{
if (!xform.Anchored || grid == null)
yield break;

var gridIndex = grid.TileIndicesFor(xform.Coordinates);

foreach (var (_, node) in NodeHelpers.GetCardinalNeighborNodes(nodeQuery, grid, gridIndex))
{
if (node is SamePrototypeAdjacentNode spaNode &&
spaNode != this &&
spaNode.OwnerPrototypeID == this.OwnerPrototypeID)
yield return node;
}
}
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
using Robust.Shared.Audio;
using Robust.Shared.GameStates;

namespace Content.Shared._White.Misc.ChristmasLights;

[RegisterComponent, AutoGenerateComponentState(true), NetworkedComponent]
public sealed partial class ChristmasLightsComponent : Component
{
[DataField, ViewVariables(VVAccess.ReadWrite), AutoNetworkedField]
public Color Color1 = new Color(255, 0, 0);
[DataField, ViewVariables(VVAccess.ReadWrite), AutoNetworkedField]
public Color Color2 = new Color(0, 0, 255);

/// <summary>
/// Consult <see cref="Content.Client._White.Misc.ChristmasLights.ChristmasLightsVisualiserSystem"/> for available modes.
/// </summary>
[DataField, AutoNetworkedField]
public string mode = "always_on";

[ViewVariables(VVAccess.ReadOnly), AutoNetworkedField]
public int CurrentModeIndex = default;

[DataField, ViewVariables(VVAccess.ReadOnly), AutoNetworkedField]
public List<string> modes = new List<string> { "always_on" };

/// <summary>
/// refers to the glow state sprites, no actual power consumtion regardless of value
/// </summary>
[DataField, AutoNetworkedField]
public bool LowPower = true;

/// <summary>
/// as in, are the LEDs capable of changing colors.
/// Doesn't actually limit anything, only used by server side system to tell
/// whether it should apply regular or rainbow epilepsy mode when EMP'd.
/// </summary>
[DataField, AutoNetworkedField]
public bool Multicolor = false;

[DataField]
public SoundSpecifier EmagSound = new SoundCollectionSpecifier("sparks");
[DataField]
public SoundSpecifier ButtonSound = new SoundPathSpecifier("/Audio/Machines/lightswitch.ogg");
}

public enum ChristmasLightsLayers
{
Base,
Lights1,
Lights2,
Glow1,
Glow2
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
using Robust.Shared.Audio;
using Robust.Shared.GameStates;
using Robust.Shared.Serialization;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Content.Shared._White.Misc.ChristmasLights;

[Serializable, NetSerializable]
public sealed class ChangeChristmasLightsModeAttemptEvent : EntityEventArgs
{
public NetEntity target;

public ChangeChristmasLightsModeAttemptEvent(NetEntity target) { this.target = target; }
}

[Serializable, NetSerializable]
public sealed class ChangeChristmasLightsBrightnessAttemptEvent : EntityEventArgs
{
public NetEntity target;

public ChangeChristmasLightsBrightnessAttemptEvent(NetEntity target) { this.target = target; }
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
using Content.Shared.ActionBlocker;
using Content.Shared.Examine;
using Content.Shared.Interaction;

namespace Content.Shared._White.Misc.ChristmasLights;

public abstract class SharedChristmasLightsSystem : EntitySystem
{
[Dependency] protected readonly ActionBlockerSystem _actionBlocker = default!;
[Dependency] protected readonly SharedInteractionSystem _interaction = default!;

[Dependency] protected readonly ILocalizationManager _loc = default!;

public override void Initialize()
{
//SubscribeLocalEvent<ChristmasLightsComponent, ExaminedEvent>(OnChristmasLightsExamine);

}
RedFoxIV marked this conversation as resolved.
Show resolved Hide resolved

protected bool CanInteract(EntityUid uid, EntityUid user) => _actionBlocker.CanInteract(user, uid) && _interaction.InRangeUnobstructed(user, uid);

private void OnChristmasLightsExamine(EntityUid uid, ChristmasLightsComponent comp, ExaminedEvent args) // todo why am i forced to keep this in shared?
{
//args.PushMarkup(_loc.GetString("christmas-lights-examine-toggle-mode-tip"), 1);
//args.PushMarkup(_loc.GetString("christmas-lights-examine-toggle-brightness-tip"), 0);
}
}
21 changes: 21 additions & 0 deletions Resources/Locale/ru-RU/_white/fluff/christmaslights.ftl
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
christmas-lights-examine-toggle-mode-tip = Активируйте для переключения режима.
christmas-lights-examine-toggle-brightness-tip = Альтернативно активируйте для переключения яркости.
christmas-lights-examine-desc = С новым годом! Эти переливающиеся огоньки запитаны духом рождества и праздничным настроением экипажа! И микрореактором термоядерного синтеза, на всякий случай.
christmas-lights-examine-name = рождественская гирлянда
christmas-lights-toggle-brightness = Переключить яркость
christmas-lights-next-mode = Переключить режим
christmas-lights-unresponsive = Ничего не происходит...


ent-RedBlueChristmasLights = { christmas-lights-examine-name }
.desc = { christmas-lights-examine-desc }

ent-YellowCyanChristmasLights = { christmas-lights-examine-name }
.desc = { christmas-lights-examine-desc }

ent-PurpleGreenChristmasLights = { christmas-lights-examine-name }
.desc = { christmas-lights-examine-desc }

ent-RainbowChristmasLights = { christmas-lights-examine-name }
.desc = { christmas-lights-examine-desc }

Loading
Loading