bluespace love (#17315)

This commit is contained in:
Nemanja
2023-06-13 21:32:03 -04:00
committed by GitHub
parent 620678df98
commit 81cff32045
3 changed files with 36 additions and 14 deletions

View File

@@ -1,72 +0,0 @@
using System.Linq;
using Content.Shared.Anomaly.Components;
using Content.Shared.Anomaly.Effects.Components;
using Content.Shared.Mobs.Components;
using Content.Shared.Teleportation.Components;
using Robust.Shared.Random;
namespace Content.Shared.Anomaly.Effects;
public sealed class BluespaceAnomalySystem : EntitySystem
{
[Dependency] private readonly IRobustRandom _random = default!;
[Dependency] private readonly SharedAudioSystem _audio = default!;
[Dependency] private readonly EntityLookupSystem _lookup = default!;
[Dependency] private readonly SharedTransformSystem _xform = default!;
/// <inheritdoc/>
public override void Initialize()
{
SubscribeLocalEvent<BluespaceAnomalyComponent, AnomalyPulseEvent>(OnPulse);
SubscribeLocalEvent<BluespaceAnomalyComponent, AnomalySupercriticalEvent>(OnSupercritical);
SubscribeLocalEvent<BluespaceAnomalyComponent, AnomalySeverityChangedEvent>(OnSeverityChanged);
}
private void OnPulse(EntityUid uid, BluespaceAnomalyComponent component, ref AnomalyPulseEvent args)
{
var xform = Transform(uid);
var range = component.MaxShuffleRadius * args.Severity;
var allEnts = _lookup.GetComponentsInRange<MobStateComponent>(xform.Coordinates, range)
.Select(x => x.Owner).ToList();
allEnts.Add(uid);
var xformQuery = GetEntityQuery<TransformComponent>();
var coords = new List<Vector2>();
foreach (var ent in allEnts)
{
if (xformQuery.TryGetComponent(ent, out var xf))
coords.Add(xf.MapPosition.Position);
}
_random.Shuffle(coords);
for (var i = 0; i < allEnts.Count; i++)
{
_xform.SetWorldPosition(allEnts[i], coords[i], xformQuery);
}
}
private void OnSupercritical(EntityUid uid, BluespaceAnomalyComponent component, ref AnomalySupercriticalEvent args)
{
var xform = Transform(uid);
var mapPos = _xform.GetWorldPosition(xform);
var radius = component.SupercriticalTeleportRadius;
var gridBounds = new Box2(mapPos - (radius, radius), mapPos + (radius, radius));
foreach (var comp in _lookup.GetComponentsInRange<MobStateComponent>(xform.Coordinates, component.MaxShuffleRadius))
{
var ent = comp.Owner;
var randomX = _random.NextFloat(gridBounds.Left, gridBounds.Right);
var randomY = _random.NextFloat(gridBounds.Bottom, gridBounds.Top);
var pos = new Vector2(randomX, randomY);
_xform.SetWorldPosition(ent, pos);
_audio.PlayPvs(component.TeleportSound, ent);
}
}
private void OnSeverityChanged(EntityUid uid, BluespaceAnomalyComponent component, ref AnomalySeverityChangedEvent args)
{
if (!TryComp<PortalComponent>(uid, out var portal))
return;
portal.MaxRandomRadius = (component.MaxPortalRadius - component.MinPortalRadius) * args.Severity + component.MinPortalRadius;
}
}

View File

@@ -1,39 +0,0 @@
using Robust.Shared.Audio;
using Robust.Shared.GameStates;
namespace Content.Shared.Anomaly.Effects.Components;
[RegisterComponent, NetworkedComponent, Access(typeof(BluespaceAnomalySystem))]
public sealed class BluespaceAnomalyComponent : Component
{
/// <summary>
/// The maximum radius that the shuffle effect will extend for
/// scales with stability
/// </summary>
[DataField("maxShuffleRadius"), ViewVariables(VVAccess.ReadWrite)]
public float MaxShuffleRadius = 10;
/// <summary>
/// The maximum MAX distance the portal this anomaly is tied to can teleport you.
/// </summary>
[DataField("maxPortalRadius"), ViewVariables(VVAccess.ReadWrite)]
public float MaxPortalRadius = 25;
/// <summary>
/// The minimum MAX distance the portal this anomaly is tied to can teleport you.
/// </summary>
[DataField("minPortalRadius"), ViewVariables(VVAccess.ReadWrite)]
public float MinPortalRadius = 10;
/// <summary>
/// How far the supercritical event can teleport you
/// </summary>
[DataField("superCriticalTeleportRadius"), ViewVariables(VVAccess.ReadWrite)]
public float SupercriticalTeleportRadius = 50f;
/// <summary>
/// The sound played after players are shuffled/teleported around
/// </summary>
[DataField("teleportSound"), ViewVariables(VVAccess.ReadWrite)]
public SoundSpecifier TeleportSound = new SoundPathSpecifier("/Audio/Effects/teleport_arrival.ogg");
}

View File

@@ -1,4 +1,5 @@
using System.Linq;
using Content.Shared.Directions;
using Content.Shared.Projectiles;
using Content.Shared.Pulling;
using Content.Shared.Pulling.Components;
@@ -8,7 +9,6 @@ using Robust.Shared.Map;
using Robust.Shared.Network;
using Robust.Shared.Physics.Dynamics;
using Robust.Shared.Physics.Events;
using Robust.Shared.Player;
using Robust.Shared.Random;
namespace Content.Shared.Teleportation.Systems;
@@ -20,12 +20,16 @@ public abstract class SharedPortalSystem : EntitySystem
{
[Dependency] private readonly IRobustRandom _random = default!;
[Dependency] private readonly INetManager _netMan = default!;
[Dependency] private readonly EntityLookupSystem _lookup = default!;
[Dependency] private readonly SharedAudioSystem _audio = default!;
[Dependency] private readonly SharedTransformSystem _transform = default!;
[Dependency] private readonly SharedPullingSystem _pulling = default!;
private const string PortalFixture = "portalFixture";
private const string ProjectileFixture = "projectile";
private const int MaxRandomTeleportAttempts = 20;
/// <inheritdoc/>
public override void Initialize()
{
@@ -117,9 +121,7 @@ public abstract class SharedPortalSystem : EntitySystem
return;
// no linked entity--teleport randomly
var randVector = _random.NextVector2(component.MaxRandomRadius);
var newCoords = Transform(uid).Coordinates.Offset(randVector);
TeleportEntity(uid, subject, newCoords);
TeleportRandomly(uid, subject, component);
}
private void OnEndCollide(EntityUid uid, PortalComponent component, ref EndCollideEvent args)
@@ -155,12 +157,33 @@ public abstract class SharedPortalSystem : EntitySystem
LogTeleport(portal, subject, Transform(subject).Coordinates, target);
Transform(subject).Coordinates = target;
_transform.SetCoordinates(subject, target);
_audio.PlayPredicted(departureSound, portal, subject);
_audio.PlayPredicted(arrivalSound, subject, subject);
}
private void TeleportRandomly(EntityUid portal, EntityUid subject, PortalComponent? component = null)
{
if (!Resolve(portal, ref component))
return;
var xform = Transform(portal);
var coords = xform.Coordinates;
var newCoords = coords.Offset(_random.NextVector2(component.MaxRandomRadius));
for (var i = 0; i < MaxRandomTeleportAttempts; i++)
{
var randVector = _random.NextVector2(component.MaxRandomRadius);
newCoords = coords.Offset(randVector);
if (!_lookup.GetEntitiesIntersecting(newCoords.ToMap(EntityManager, _transform), LookupFlags.Static).Any())
{
break;
}
}
TeleportEntity(portal, subject, newCoords);
}
protected virtual void LogTeleport(EntityUid portal, EntityUid subject, EntityCoordinates source,
EntityCoordinates target)
{