From 52e6e9b28f6832eb99b4546b0e8765f3aac4fa74 Mon Sep 17 00:00:00 2001 From: Ed <96445749+TheShuEd@users.noreply.github.com> Date: Fri, 21 Mar 2025 16:53:59 +0300 Subject: [PATCH] Carcat night vision (#1046) * carcat night vision * Update nightVision.yml --- .../CP14ClientNightVisionSystem.cs | 65 +++++++++++++++++++ .../NightVision/CP14NightVisionSystem.cs | 7 ++ .../NightVision/CP14NightVisionComponent.cs | 20 ++++++ .../CP14SharedNightVisionSystem.cs | 28 ++++++++ .../Actions/{zLevels.yml => ghost.yml} | 0 .../_CP14/Entities/Actions/nightVision.yml | 26 ++++++++ .../_CP14/Entities/Mobs/Species/carcat.yml | 1 + 7 files changed, 147 insertions(+) create mode 100644 Content.Client/_CP14/NightVision/CP14ClientNightVisionSystem.cs create mode 100644 Content.Server/_CP14/NightVision/CP14NightVisionSystem.cs create mode 100644 Content.Shared/_CP14/NightVision/CP14NightVisionComponent.cs create mode 100644 Content.Shared/_CP14/NightVision/CP14SharedNightVisionSystem.cs rename Resources/Prototypes/_CP14/Entities/Actions/{zLevels.yml => ghost.yml} (100%) create mode 100644 Resources/Prototypes/_CP14/Entities/Actions/nightVision.yml diff --git a/Content.Client/_CP14/NightVision/CP14ClientNightVisionSystem.cs b/Content.Client/_CP14/NightVision/CP14ClientNightVisionSystem.cs new file mode 100644 index 0000000000..081552662d --- /dev/null +++ b/Content.Client/_CP14/NightVision/CP14ClientNightVisionSystem.cs @@ -0,0 +1,65 @@ +using Content.Shared._CP14.NightVision; +using Robust.Client.Player; +using Robust.Shared.Player; + +namespace Content.Client._CP14.NightVision; + +public sealed class CP14ClientNightVisionSystem : CP14SharedNightVisionSystem +{ + [Dependency] private readonly SharedTransformSystem _transform = default!; + [Dependency] private readonly IPlayerManager _playerManager = default!; + + public override void Initialize() + { + base.Initialize(); + + SubscribeLocalEvent(OnToggleNightVision); + SubscribeLocalEvent(OnPlayerDetached); + } + + protected override void OnRemove(Entity ent, ref ComponentRemove args) + { + base.OnRemove(ent, ref args); + + NightVisionOff(ent); + } + + private void OnPlayerDetached(Entity ent, ref PlayerDetachedEvent args) + { + NightVisionOff(ent); + } + + private void OnToggleNightVision(Entity ent, ref CP14ToggleNightVisionEvent args) + { + NightVisionToggle(ent); + } + + private void NightVisionOn(Entity ent) + { + if (_playerManager.LocalSession?.AttachedEntity != ent) + return; + + var nightVisionLight = Spawn(ent.Comp.LightPrototype, Transform(ent).Coordinates); + _transform.SetParent(nightVisionLight, ent); + _transform.SetWorldRotation(nightVisionLight, _transform.GetWorldRotation(ent)); + ent.Comp.LocalLightEntity = nightVisionLight; + } + + private void NightVisionOff(Entity ent) + { + QueueDel(ent.Comp.LocalLightEntity); + ent.Comp.LocalLightEntity = null; + } + + private void NightVisionToggle(Entity ent) + { + if (ent.Comp.LocalLightEntity == null) + { + NightVisionOn(ent); + } + else + { + NightVisionOff(ent); + } + } +} diff --git a/Content.Server/_CP14/NightVision/CP14NightVisionSystem.cs b/Content.Server/_CP14/NightVision/CP14NightVisionSystem.cs new file mode 100644 index 0000000000..28fd1a23e2 --- /dev/null +++ b/Content.Server/_CP14/NightVision/CP14NightVisionSystem.cs @@ -0,0 +1,7 @@ +using Content.Shared._CP14.NightVision; + +namespace Content.Server._CP14.NightVision; + +public sealed class CP14NightVisionSystem : CP14SharedNightVisionSystem +{ +} diff --git a/Content.Shared/_CP14/NightVision/CP14NightVisionComponent.cs b/Content.Shared/_CP14/NightVision/CP14NightVisionComponent.cs new file mode 100644 index 0000000000..2e805a01f8 --- /dev/null +++ b/Content.Shared/_CP14/NightVision/CP14NightVisionComponent.cs @@ -0,0 +1,20 @@ +using Robust.Shared.GameStates; +using Robust.Shared.Prototypes; + +namespace Content.Shared._CP14.NightVision; + +[RegisterComponent, NetworkedComponent] +public sealed partial class CP14NightVisionComponent : Component +{ + [DataField] + public EntityUid? LocalLightEntity = null; + + [DataField] + public EntProtoId LightPrototype = "CP14NightVisionLight"; + + [DataField] + public EntProtoId ActionPrototype = "CP14ActionToggleNightVision"; + + [DataField] + public EntityUid? ActionEntity = null; +} diff --git a/Content.Shared/_CP14/NightVision/CP14SharedNightVisionSystem.cs b/Content.Shared/_CP14/NightVision/CP14SharedNightVisionSystem.cs new file mode 100644 index 0000000000..439367fab3 --- /dev/null +++ b/Content.Shared/_CP14/NightVision/CP14SharedNightVisionSystem.cs @@ -0,0 +1,28 @@ +using Content.Shared.Actions; + +namespace Content.Shared._CP14.NightVision; + +public abstract class CP14SharedNightVisionSystem : EntitySystem +{ + [Dependency] private readonly SharedActionsSystem _actions = default!; + + public override void Initialize() + { + base.Initialize(); + + SubscribeLocalEvent(OnMapInit); + SubscribeLocalEvent(OnRemove); + } + + private void OnMapInit(Entity ent, ref MapInitEvent args) + { + _actions.AddAction(ent, ref ent.Comp.ActionEntity, ent.Comp.ActionPrototype); + } + + protected virtual void OnRemove(Entity ent, ref ComponentRemove args) + { + _actions.RemoveAction(ent, ent.Comp.ActionEntity); + } +} + +public sealed partial class CP14ToggleNightVisionEvent : InstantActionEvent { } diff --git a/Resources/Prototypes/_CP14/Entities/Actions/zLevels.yml b/Resources/Prototypes/_CP14/Entities/Actions/ghost.yml similarity index 100% rename from Resources/Prototypes/_CP14/Entities/Actions/zLevels.yml rename to Resources/Prototypes/_CP14/Entities/Actions/ghost.yml diff --git a/Resources/Prototypes/_CP14/Entities/Actions/nightVision.yml b/Resources/Prototypes/_CP14/Entities/Actions/nightVision.yml new file mode 100644 index 0000000000..9e5927efbe --- /dev/null +++ b/Resources/Prototypes/_CP14/Entities/Actions/nightVision.yml @@ -0,0 +1,26 @@ +- type: entity + id: CP14ActionToggleNightVision + name: Toggle Night Vision + description: You begin to see the world in a special way that allows you to see even in total darkness. + components: + - type: InstantAction + icon: Interface/VerbIcons/light.svg.192dpi.png + clientExclusive: true + checkCanInteract: false + event: !type:CP14ToggleNightVisionEvent + +- type: entity + id: CP14NightVisionLight + categories: [ HideSpawnMenu ] + components: + - type: Tag + tags: + - HideContextMenu + - type: PointLight + radius: 15 + energy: 1.3 + softness: 10 + color: "#ffa38c" + netsync: false + mask: /Textures/_CP14/Effects/LightMasks/crystal_cone.png + autoRot: true \ No newline at end of file diff --git a/Resources/Prototypes/_CP14/Entities/Mobs/Species/carcat.yml b/Resources/Prototypes/_CP14/Entities/Mobs/Species/carcat.yml index 00d6137b5d..dff84fe6aa 100644 --- a/Resources/Prototypes/_CP14/Entities/Mobs/Species/carcat.yml +++ b/Resources/Prototypes/_CP14/Entities/Mobs/Species/carcat.yml @@ -38,6 +38,7 @@ damage: types: Slash: 5 # 5 slash + - type: CP14NightVision #Night vision - type: FootstepModifier footstepSoundCollection: null # Silent footstep - type: Inventory