Carcat night vision (#1046)

* carcat night vision

* Update nightVision.yml
This commit is contained in:
Ed
2025-03-21 16:53:59 +03:00
committed by GitHub
parent a951193dba
commit 52e6e9b28f
7 changed files with 147 additions and 0 deletions

View File

@@ -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<CP14NightVisionComponent, CP14ToggleNightVisionEvent>(OnToggleNightVision);
SubscribeLocalEvent<CP14NightVisionComponent, PlayerDetachedEvent>(OnPlayerDetached);
}
protected override void OnRemove(Entity<CP14NightVisionComponent> ent, ref ComponentRemove args)
{
base.OnRemove(ent, ref args);
NightVisionOff(ent);
}
private void OnPlayerDetached(Entity<CP14NightVisionComponent> ent, ref PlayerDetachedEvent args)
{
NightVisionOff(ent);
}
private void OnToggleNightVision(Entity<CP14NightVisionComponent> ent, ref CP14ToggleNightVisionEvent args)
{
NightVisionToggle(ent);
}
private void NightVisionOn(Entity<CP14NightVisionComponent> 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<CP14NightVisionComponent> ent)
{
QueueDel(ent.Comp.LocalLightEntity);
ent.Comp.LocalLightEntity = null;
}
private void NightVisionToggle(Entity<CP14NightVisionComponent> ent)
{
if (ent.Comp.LocalLightEntity == null)
{
NightVisionOn(ent);
}
else
{
NightVisionOff(ent);
}
}
}

View File

@@ -0,0 +1,7 @@
using Content.Shared._CP14.NightVision;
namespace Content.Server._CP14.NightVision;
public sealed class CP14NightVisionSystem : CP14SharedNightVisionSystem
{
}

View File

@@ -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;
}

View File

@@ -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<CP14NightVisionComponent, MapInitEvent>(OnMapInit);
SubscribeLocalEvent<CP14NightVisionComponent, ComponentRemove>(OnRemove);
}
private void OnMapInit(Entity<CP14NightVisionComponent> ent, ref MapInitEvent args)
{
_actions.AddAction(ent, ref ent.Comp.ActionEntity, ent.Comp.ActionPrototype);
}
protected virtual void OnRemove(Entity<CP14NightVisionComponent> ent, ref ComponentRemove args)
{
_actions.RemoveAction(ent, ent.Comp.ActionEntity);
}
}
public sealed partial class CP14ToggleNightVisionEvent : InstantActionEvent { }

View File

@@ -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

View File

@@ -38,6 +38,7 @@
damage:
types:
Slash: 5 # 5 slash
- type: CP14NightVision #Night vision
- type: FootstepModifier
footstepSoundCollection: null # Silent footstep
- type: Inventory