Salvage dungeons (#14520)
This commit is contained in:
@@ -16,6 +16,7 @@ using Content.Server.Shuttles.Events;
|
||||
using Content.Shared.Buckle.Components;
|
||||
using Content.Shared.Doors.Components;
|
||||
using Robust.Shared.Map.Components;
|
||||
using Robust.Shared.Physics;
|
||||
using Robust.Shared.Physics.Components;
|
||||
|
||||
namespace Content.Server.Shuttles.Systems;
|
||||
@@ -71,12 +72,6 @@ public sealed partial class ShuttleSystem
|
||||
private void InitializeFTL()
|
||||
{
|
||||
SubscribeLocalEvent<StationGridAddedEvent>(OnStationGridAdd);
|
||||
SubscribeLocalEvent<FTLDestinationComponent, EntityPausedEvent>(OnDestinationPause);
|
||||
}
|
||||
|
||||
private void OnDestinationPause(EntityUid uid, FTLDestinationComponent component, ref EntityPausedEvent args)
|
||||
{
|
||||
_console.RefreshShuttleConsoles();
|
||||
}
|
||||
|
||||
private void OnStationGridAdd(StationGridAddedEvent ev)
|
||||
@@ -216,7 +211,8 @@ public sealed partial class ShuttleSystem
|
||||
|
||||
if (comp.Accumulator > 0f) continue;
|
||||
|
||||
var xform = Transform(comp.Owner);
|
||||
var uid = comp.Owner;
|
||||
var xform = Transform(uid);
|
||||
PhysicsComponent? body;
|
||||
ShuttleComponent? shuttle;
|
||||
|
||||
@@ -228,16 +224,17 @@ public sealed partial class ShuttleSystem
|
||||
|
||||
comp.State = FTLState.Travelling;
|
||||
|
||||
var width = Comp<MapGridComponent>(comp.Owner).LocalAABB.Width;
|
||||
var width = Comp<MapGridComponent>(uid).LocalAABB.Width;
|
||||
xform.Coordinates = new EntityCoordinates(_mapManager.GetMapEntityId(_hyperSpaceMap!.Value), new Vector2(_index + width / 2f, 0f));
|
||||
xform.LocalRotation = Angle.Zero;
|
||||
_index += width + Buffer;
|
||||
comp.Accumulator += comp.TravelTime - DefaultArrivalTime;
|
||||
|
||||
if (TryComp(comp.Owner, out body))
|
||||
if (TryComp(uid, out body))
|
||||
{
|
||||
_physics.SetLinearVelocity(comp.Owner, new Vector2(0f, 20f), body: body);
|
||||
_physics.SetAngularVelocity(comp.Owner, 0f, body: body);
|
||||
Enable(uid, body);
|
||||
_physics.SetLinearVelocity(uid, new Vector2(0f, 20f), body: body);
|
||||
_physics.SetAngularVelocity(uid, 0f, body: body);
|
||||
_physics.SetLinearDamping(body, 0f);
|
||||
_physics.SetAngularDamping(body, 0f);
|
||||
}
|
||||
@@ -245,11 +242,11 @@ public sealed partial class ShuttleSystem
|
||||
if (comp.TravelSound != null)
|
||||
{
|
||||
comp.TravelStream = SoundSystem.Play(comp.TravelSound.GetSound(),
|
||||
Filter.Pvs(comp.Owner, 4f, entityManager: EntityManager), comp.TravelSound.Params);
|
||||
Filter.Pvs(uid, 4f, entityManager: EntityManager), comp.TravelSound.Params);
|
||||
}
|
||||
|
||||
SetDockBolts(comp.Owner, true);
|
||||
_console.RefreshShuttleConsoles(comp.Owner);
|
||||
SetDockBolts(uid, true);
|
||||
_console.RefreshShuttleConsoles(uid);
|
||||
break;
|
||||
// Arriving, play effects
|
||||
case FTLState.Travelling:
|
||||
@@ -258,29 +255,22 @@ public sealed partial class ShuttleSystem
|
||||
// TODO: Arrival effects
|
||||
// For now we'll just use the ss13 bubbles but we can do fancier.
|
||||
|
||||
if (TryComp(comp.Owner, out shuttle))
|
||||
if (TryComp(uid, out shuttle))
|
||||
{
|
||||
_thruster.DisableLinearThrusters(shuttle);
|
||||
_thruster.EnableLinearThrustDirection(shuttle, DirectionFlag.South);
|
||||
}
|
||||
|
||||
_console.RefreshShuttleConsoles(comp.Owner);
|
||||
_console.RefreshShuttleConsoles(uid);
|
||||
break;
|
||||
// Arrived
|
||||
case FTLState.Arriving:
|
||||
DoTheDinosaur(xform);
|
||||
SetDockBolts(comp.Owner, false);
|
||||
SetDocks(comp.Owner, true);
|
||||
SetDockBolts(uid, false);
|
||||
SetDocks(uid, true);
|
||||
|
||||
if (TryComp(comp.Owner, out body))
|
||||
{
|
||||
_physics.SetLinearVelocity(comp.Owner, Vector2.Zero, body: body);
|
||||
_physics.SetAngularVelocity(comp.Owner, 0f, body: body);
|
||||
_physics.SetLinearDamping(body, ShuttleLinearDamping);
|
||||
_physics.SetAngularDamping(body, ShuttleAngularDamping);
|
||||
}
|
||||
|
||||
TryComp(comp.Owner, out shuttle);
|
||||
TryComp(uid, out shuttle);
|
||||
MapId mapId;
|
||||
|
||||
if (comp.TargetUid != null && shuttle != null)
|
||||
{
|
||||
@@ -288,10 +278,30 @@ public sealed partial class ShuttleSystem
|
||||
TryFTLDock(shuttle, comp.TargetUid.Value);
|
||||
else
|
||||
TryFTLProximity(shuttle, comp.TargetUid.Value);
|
||||
|
||||
mapId = Transform(comp.TargetUid.Value).MapID;
|
||||
}
|
||||
else
|
||||
{
|
||||
xform.Coordinates = comp.TargetCoordinates;
|
||||
mapId = comp.TargetCoordinates.GetMapId(EntityManager);
|
||||
}
|
||||
|
||||
if (TryComp(uid, out body))
|
||||
{
|
||||
_physics.SetLinearVelocity(uid, Vector2.Zero, body: body);
|
||||
_physics.SetAngularVelocity(uid, 0f, body: body);
|
||||
|
||||
// Disable shuttle if it's on a planet; unfortunately can't do this in parent change messages due
|
||||
// to event ordering and awake body shenanigans (at least for now).
|
||||
if (HasComp<MapGridComponent>(xform.MapUid))
|
||||
{
|
||||
Disable(uid, body);
|
||||
}
|
||||
else
|
||||
{
|
||||
Enable(uid, body);
|
||||
}
|
||||
}
|
||||
|
||||
if (shuttle != null)
|
||||
@@ -305,25 +315,28 @@ public sealed partial class ShuttleSystem
|
||||
comp.TravelStream = null;
|
||||
}
|
||||
|
||||
SoundSystem.Play(_arrivalSound.GetSound(), Filter.Empty().AddInRange(Transform(comp.Owner).MapPosition, GetSoundRange(comp.Owner)), _arrivalSound.Params);
|
||||
SoundSystem.Play(_arrivalSound.GetSound(), Filter.Empty().AddInRange(Transform(uid).MapPosition, GetSoundRange(uid)), _arrivalSound.Params);
|
||||
|
||||
if (TryComp<FTLDestinationComponent>(comp.Owner, out var dest))
|
||||
if (TryComp<FTLDestinationComponent>(uid, out var dest))
|
||||
{
|
||||
dest.Enabled = true;
|
||||
}
|
||||
|
||||
comp.State = FTLState.Cooldown;
|
||||
comp.Accumulator += FTLCooldown;
|
||||
_console.RefreshShuttleConsoles(comp.Owner);
|
||||
RaiseLocalEvent(new HyperspaceJumpCompletedEvent());
|
||||
_console.RefreshShuttleConsoles(uid);
|
||||
var mapUid = _mapManager.GetMapEntityId(mapId);
|
||||
_mapManager.SetMapPaused(mapId, false);
|
||||
var ftlEvent = new FTLCompletedEvent();
|
||||
RaiseLocalEvent(mapUid, ref ftlEvent, true);
|
||||
break;
|
||||
case FTLState.Cooldown:
|
||||
RemComp<FTLComponent>(comp.Owner);
|
||||
_console.RefreshShuttleConsoles(comp.Owner);
|
||||
RemComp<FTLComponent>(uid);
|
||||
_console.RefreshShuttleConsoles(uid);
|
||||
break;
|
||||
default:
|
||||
_sawmill.Error($"Found invalid FTL state {comp.State} for {comp.Owner}");
|
||||
RemComp<FTLComponent>(comp.Owner);
|
||||
_sawmill.Error($"Found invalid FTL state {comp.State} for {uid}");
|
||||
RemComp<FTLComponent>(uid);
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -452,6 +465,7 @@ public sealed partial class ShuttleSystem
|
||||
public bool TryFTLProximity(ShuttleComponent component, EntityUid targetUid, TransformComponent? xform = null, TransformComponent? targetXform = null)
|
||||
{
|
||||
if (!Resolve(targetUid, ref targetXform) ||
|
||||
targetXform.GridUid == null ||
|
||||
targetXform.MapUid == null ||
|
||||
!targetXform.MapUid.Value.IsValid() ||
|
||||
!Resolve(component.Owner, ref xform))
|
||||
@@ -466,7 +480,7 @@ public sealed partial class ShuttleSystem
|
||||
// Spawn nearby.
|
||||
// We essentially expand the Box2 of the target area until nothing else is added then we know it's valid.
|
||||
// Can't just get an AABB of every grid as we may spawn very far away.
|
||||
if (TryComp<MapGridComponent>(targetUid, out var targetGrid))
|
||||
if (TryComp<MapGridComponent>(targetXform.GridUid, out var targetGrid))
|
||||
{
|
||||
targetLocalAABB = targetGrid.LocalAABB;
|
||||
}
|
||||
@@ -477,7 +491,7 @@ public sealed partial class ShuttleSystem
|
||||
|
||||
var targetAABB = _transform.GetWorldMatrix(targetXform, xformQuery)
|
||||
.TransformBox(targetLocalAABB).Enlarged(shuttleAABB.Size.Length);
|
||||
var nearbyGrids = new HashSet<EntityUid>(1) { targetUid };
|
||||
var nearbyGrids = new HashSet<EntityUid>(1) { targetXform.GridUid.Value };
|
||||
var iteration = 0;
|
||||
var lastCount = 1;
|
||||
var mapId = targetXform.MapID;
|
||||
@@ -518,8 +532,7 @@ public sealed partial class ShuttleSystem
|
||||
break;
|
||||
}
|
||||
|
||||
var minRadius = (MathF.Max(targetAABB.Width, targetAABB.Height) + MathF.Max(shuttleAABB.Width, shuttleAABB.Height)) / 2f;
|
||||
var spawnPos = targetAABB.Center + _random.NextVector2(minRadius, minRadius + 64f);
|
||||
Vector2 spawnPos;
|
||||
|
||||
if (TryComp<PhysicsComponent>(component.Owner, out var shuttleBody))
|
||||
{
|
||||
@@ -527,8 +540,34 @@ public sealed partial class ShuttleSystem
|
||||
_physics.SetAngularVelocity(component.Owner, 0f, body: shuttleBody);
|
||||
}
|
||||
|
||||
// TODO: This is pretty crude for multiple landings.
|
||||
if (nearbyGrids.Count > 1 || !HasComp<MapComponent>(targetXform.GridUid.Value))
|
||||
{
|
||||
var minRadius = (MathF.Max(targetAABB.Width, targetAABB.Height) + MathF.Max(shuttleAABB.Width, shuttleAABB.Height)) / 2f;
|
||||
spawnPos = targetAABB.Center + _random.NextVector2(minRadius, minRadius + 64f);
|
||||
}
|
||||
else if (shuttleBody != null)
|
||||
{
|
||||
var (targetPos, targetRot) = _transform.GetWorldPositionRotation(targetXform, xformQuery);
|
||||
var transform = new Transform(targetPos, targetRot);
|
||||
spawnPos = Robust.Shared.Physics.Transform.Mul(transform, -shuttleBody.LocalCenter);
|
||||
}
|
||||
else
|
||||
{
|
||||
spawnPos = _transform.GetWorldPosition(targetXform, xformQuery);
|
||||
}
|
||||
|
||||
xform.Coordinates = new EntityCoordinates(targetXform.MapUid.Value, spawnPos);
|
||||
xform.WorldRotation = _random.NextAngle();
|
||||
|
||||
if (!HasComp<MapComponent>(targetXform.GridUid.Value))
|
||||
{
|
||||
_transform.SetLocalRotation(xform, _random.NextAngle());
|
||||
}
|
||||
else
|
||||
{
|
||||
_transform.SetLocalRotation(xform, Angle.Zero);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user