Skip to content

Commit

Permalink
Merge branch 'master' into deletesomething
Browse files Browse the repository at this point in the history
  • Loading branch information
1Stepka1 authored Aug 17, 2024
2 parents c2a8aca + 48f3ce1 commit 2948528
Show file tree
Hide file tree
Showing 78 changed files with 1,162 additions and 141 deletions.
117 changes: 117 additions & 0 deletions Content.Client/ADT/NightVision/NightVisionOverlay.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
// taken and adapted from https://github.com/RMC-14/RMC-14?ysclid=lzx00zxd6e53093995

using System.Numerics;
using Content.Shared.ADT.NightVision;
// using Content.Shared._RMC14.Xenonids;
using Robust.Client.GameObjects;
using Robust.Client.Graphics;
using Robust.Client.Player;
using Robust.Shared.Enums;
using Robust.Shared.Map;

namespace Content.Client.ADT.NightVision;

public sealed class NightVisionOverlay : Overlay
{
[Dependency] private readonly IEntityManager _entity = default!;
[Dependency] private readonly IPlayerManager _players = default!;

private readonly ContainerSystem _container;
private readonly TransformSystem _transform;
// private readonly EntityQuery<XenoComponent> _xenoQuery;

public override OverlaySpace Space => OverlaySpace.WorldSpace;

private readonly List<NightVisionRenderEntry> _entries = new();

public NightVisionOverlay()
{
IoCManager.InjectDependencies(this);

_container = _entity.System<ContainerSystem>();
_transform = _entity.System<TransformSystem>();
// _xenoQuery = _entity.GetEntityQuery<XenoComponent>();
}

protected override void Draw(in OverlayDrawArgs args)
{
if (!_entity.TryGetComponent(_players.LocalEntity, out NightVisionComponent? nightVision) ||
nightVision.State == NightVisionState.Off)
{
return;
}

var handle = args.WorldHandle;
var eye = args.Viewport.Eye;
var eyeRot = eye?.Rotation ?? default;

_entries.Clear();
var entities = _entity.EntityQueryEnumerator<NightVisionVisibleComponent, SpriteComponent, TransformComponent>();
while (entities.MoveNext(out var uid, out var visible, out var sprite, out var xform))
{
_entries.Add(new NightVisionRenderEntry((uid, sprite, xform),
eye?.Position.MapId,
eyeRot,
nightVision.SeeThroughContainers,
visible.Priority,
visible.Transparency));
}

_entries.Sort(SortPriority);

foreach (var entry in _entries)
{
Render(entry.Ent,
entry.Map,
handle,
entry.EyeRot,
entry.NightVisionSeeThroughContainers,
entry.Transparency);
}

handle.SetTransform(Matrix3x2.Identity);
}

private static int SortPriority(NightVisionRenderEntry x, NightVisionRenderEntry y)
{
return x.Priority.CompareTo(y.Priority);
}

private void Render(Entity<SpriteComponent, TransformComponent> ent,
MapId? map,
DrawingHandleWorld handle,
Angle eyeRot,
bool seeThroughContainers,
float? transparency)
{
var (uid, sprite, xform) = ent;
if (xform.MapID != map)
return;

var seeThrough = seeThroughContainers; // && !_xenoQuery.HasComp(uid);
if (!seeThrough && _container.IsEntityOrParentInContainer(uid, xform: xform))
return;

var (position, rotation) = _transform.GetWorldPositionRotation(xform);

var colorCache = sprite.Color;
if (transparency != null)
{
var color = sprite.Color * Color.White.WithAlpha(transparency.Value);
sprite.Color = color;
}
sprite.Render(handle, eyeRot, rotation, position: position);
if (transparency != null)
{
sprite.Color = colorCache;
}
}
}

public record struct NightVisionRenderEntry(
(EntityUid, SpriteComponent, TransformComponent) Ent,
MapId? Map,
Angle EyeRot,
bool NightVisionSeeThroughContainers,
int Priority,
float? Transparency);
84 changes: 84 additions & 0 deletions Content.Client/ADT/NightVision/NightVisionSystem.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
// taken and adapted from https://github.com/RMC-14/RMC-14?ysclid=lzx00zxd6e53093995

using Content.Shared.ADT.NightVision;
using Robust.Client.Graphics;
using Robust.Client.Player;
using Robust.Shared.Player;

namespace Content.Client.ADT.NightVision;

public sealed class NightVisionSystem : SharedNightVisionSystem
{
[Dependency] private readonly ILightManager _light = default!;
[Dependency] private readonly IOverlayManager _overlay = default!;
[Dependency] private readonly IPlayerManager _player = default!;

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

SubscribeLocalEvent<NightVisionComponent, LocalPlayerAttachedEvent>(OnNightVisionAttached);
SubscribeLocalEvent<NightVisionComponent, LocalPlayerDetachedEvent>(OnNightVisionDetached);
}

private void OnNightVisionAttached(Entity<NightVisionComponent> ent, ref LocalPlayerAttachedEvent args)
{
NightVisionChanged(ent);
}

private void OnNightVisionDetached(Entity<NightVisionComponent> ent, ref LocalPlayerDetachedEvent args)
{
Off();
}

protected override void NightVisionChanged(Entity<NightVisionComponent> ent)
{
if (ent != _player.LocalEntity)
return;

switch (ent.Comp.State)
{
case NightVisionState.Off:
Off();
break;
case NightVisionState.Half:
Half(ent);
break;
case NightVisionState.Full:
Full(ent);
break;
default:
throw new ArgumentOutOfRangeException();
}
}

protected override void NightVisionRemoved(Entity<NightVisionComponent> ent)
{
if (ent != _player.LocalEntity)
return;

Off();
}

private void Off()
{
_overlay.RemoveOverlay(new NightVisionOverlay());
_light.DrawLighting = true;
}

private void Half(Entity<NightVisionComponent> ent)
{
if (ent.Comp.Overlay)
_overlay.AddOverlay(new NightVisionOverlay());

_light.DrawLighting = true;
}

private void Full(Entity<NightVisionComponent> ent)
{
if (ent.Comp.Overlay)
_overlay.AddOverlay(new NightVisionOverlay());

_light.DrawLighting = false;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,8 @@ public bool StartEpidemicHallucinations(EntityUid target, string proto)
return false;

var hallucinations = EnsureComp<HallucinationsDiseaseComponent>(target);
hallucinations.EndTime = _timing.CurTime + TimeSpan.FromSeconds(15);

hallucinations.Proto = prototype;
hallucinations.Spawns = prototype.Entities;
hallucinations.Range = prototype.Range;
Expand Down Expand Up @@ -224,6 +226,12 @@ public override void Update(float frameTime)
var diseaseQuery = EntityQueryEnumerator<HallucinationsDiseaseComponent, TransformComponent>();
while (diseaseQuery.MoveNext(out var uid, out var stat, out var xform))
{
if (_timing.CurTime >= stat.EndTime)
{
RemCompDeferred<HallucinationsDiseaseComponent>(uid);
continue;
}

if (_timing.CurTime < stat.NextSecond)
continue;
var rate = stat.SpawnRate;
Expand Down
7 changes: 7 additions & 0 deletions Content.Server/ADT/NightVision/NightVisionSystem.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
// taken and adapted from https://github.com/RMC-14/RMC-14?ysclid=lzx00zxd6e53093995

using Content.Shared.ADT.NightVision;

namespace Content.Server.ADT.NightVision;

public sealed class NightVisionSystem : SharedNightVisionSystem;
Loading

0 comments on commit 2948528

Please sign in to comment.