mirror of
https://github.com/WWhiteDreamProject/wwdpublic.git
synced 2026-04-17 21:48:58 +03:00
<!-- Explain this PR in as much detail as applicable Some example prompts to consider: How might this affect the game? The codebase? What might be some alternatives to this? How/Who does this benefit/hurt [the game/codebase]? --> Ports Shadowlings from SS13 to SS14 with a remake to make them fun to play. Minimal Design Doc (not up-to-date, read comments in this repo for updates): https://github.com/Lumminal/SS14-Design-Docs-Lumminal/blob/main/Shadowling.md --- - Abilities - [X] Hatch - [x] Glare - [X] Enthrall - [x] Veil - [x] Shadow Walk - [x] Icy Veins - [x] Collective Mind - [x] Rapid Re-Hatch - [x] Destroy Engines - [x] Sonic Screech - [x] Blindness Smoke - [x] Null Charge - [x] Black Recuperation - [x] Empowered Enthrall - [x] Nox Imperii - [x] Ascension - [x] Annihilate - [x] Hypnosis - [x] Plane-Shift - [x] Lighting Storm - [x] Ascendant Broadcast - Antags - [X] Thrall - [x] Guise - [x] Thrall Darksight - [x] Lesser Shadowling - Passive - [x] Light Resistance Scaling - [x] Shadowmind - [x] Damage on Light - Other - [x] Sounds - [x] Sprites - [x] Psionic Interactions - [x] Handle Edge Cases --- <details><summary><h1>Media</h1></summary> <p> https://www.youtube.com/watch?v=H-Ee5wuRINc </p> </details> --- 🆑 - add: The shadows have awakened, and their ascendance is soon to follow. Do not enter maints. --------- Signed-off-by: Lumminal <81829924+Lumminal@users.noreply.github.com>
107 lines
3.3 KiB
C#
107 lines
3.3 KiB
C#
using Content.Shared._EE.Shadowling.Components;
|
|
using Content.Shared.Mobs.Systems;
|
|
using Content.Shared.Physics;
|
|
using Robust.Server.GameObjects;
|
|
using Robust.Shared.Physics;
|
|
using Robust.Shared.Timing;
|
|
|
|
|
|
namespace Content.Server._EE.Shadowling;
|
|
|
|
|
|
/// <summary>
|
|
/// This system detects if an entity is standing on light.
|
|
/// It casts rays from the PointLight to the player.
|
|
/// </summary>
|
|
public sealed class LightDetectionSystem : EntitySystem
|
|
{
|
|
/// <inheritdoc/>
|
|
[Dependency] private readonly PhysicsSystem _physicsSystem = default!;
|
|
[Dependency] private readonly TransformSystem _transformSystem = default!;
|
|
[Dependency] private readonly IGameTiming _timing = default!;
|
|
[Dependency] private readonly MobStateSystem _mobStateSystem = default!;
|
|
|
|
public override void Initialize()
|
|
{
|
|
base.Initialize();
|
|
|
|
SubscribeLocalEvent<LightDetectionComponent, ComponentStartup>(OnComponentStartup);
|
|
}
|
|
|
|
private void OnComponentStartup(EntityUid uid, LightDetectionComponent component, ComponentStartup args)
|
|
{
|
|
component.NextUpdate = _timing.CurTime;
|
|
}
|
|
public override void Update(float frameTime)
|
|
{
|
|
var query = EntityQueryEnumerator<LightDetectionComponent>();
|
|
while (query.MoveNext(out var uid, out var comp))
|
|
{
|
|
// Skip dead entities
|
|
if (_mobStateSystem.IsDead(uid))
|
|
continue;
|
|
|
|
if (_timing.CurTime < comp.NextUpdate)
|
|
continue;
|
|
|
|
comp.NextUpdate += comp.UpdateInterval;
|
|
DetectLight(uid, comp);
|
|
}
|
|
}
|
|
|
|
private void DetectLight(EntityUid uid, LightDetectionComponent comp)
|
|
{
|
|
var xform = EntityManager.GetComponent<TransformComponent>(uid);
|
|
var worldPos = _transformSystem.GetWorldPosition(uid);
|
|
|
|
// We want to avoid this expensive operation if the user has not moved
|
|
if ((comp.LastKnownPosition - worldPos).LengthSquared() < 0.01f)
|
|
return;
|
|
|
|
comp.LastKnownPosition = worldPos;
|
|
comp.IsOnLight = false;
|
|
var query = EntityQueryEnumerator<PointLightComponent>();
|
|
while (query.MoveNext(out var point, out var pointLight))
|
|
{
|
|
if (!pointLight.Enabled)
|
|
continue;
|
|
|
|
var lightPos = _transformSystem.GetWorldPosition(point);
|
|
var distance = (lightPos - worldPos).Length();
|
|
|
|
if (distance <= 0.01f) // So the debug stops crashing
|
|
continue;
|
|
|
|
if (distance > pointLight.Radius)
|
|
continue;
|
|
|
|
var direction = (worldPos - lightPos).Normalized();
|
|
var ray = new CollisionRay(lightPos, direction, (int)CollisionGroup.Opaque);
|
|
|
|
var rayResults = _physicsSystem.IntersectRay(
|
|
xform.MapID,
|
|
ray,
|
|
distance,
|
|
point); // todo: remove this once slings get night vision action
|
|
|
|
|
|
var hasBeenBlocked = false;
|
|
foreach (var result in rayResults)
|
|
{
|
|
if (result.HitEntity != uid)
|
|
{
|
|
hasBeenBlocked = true;
|
|
break;
|
|
}
|
|
}
|
|
|
|
if (!hasBeenBlocked)
|
|
{
|
|
comp.IsOnLight = true;
|
|
return;
|
|
}
|
|
}
|
|
|
|
}
|
|
}
|