Temporarily make singularity a bit harder to loose as non-antag (#33358)
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
using Content.Shared.Singularity.EntitySystems;
|
||||
using Content.Shared.Singularity.Components;
|
||||
|
||||
namespace Content.Client.Singularity.EntitySystems;
|
||||
namespace Content.Client.Singularity.Systems;
|
||||
|
||||
/// <summary>
|
||||
/// The client-side version of <see cref="SharedEventHorizonSystem"/>.
|
||||
|
||||
@@ -0,0 +1,12 @@
|
||||
using Content.Shared.Singularity.EntitySystems;
|
||||
using Content.Shared.Singularity.Components;
|
||||
|
||||
namespace Content.Client.Singularity.Systems;
|
||||
|
||||
/// <summary>
|
||||
/// The client-side version of <see cref="SharedSingularityGeneratorSystem"/>.
|
||||
/// Manages <see cref="SingularityGeneratorComponent"/>s.
|
||||
/// Exists to make relevant signal handlers (ie: <see cref="SharedSingularityGeneratorSystem.OnEmagged"/>) work on the client.
|
||||
/// </summary>
|
||||
public sealed class SingularityGeneratorSystem : SharedSingularityGeneratorSystem
|
||||
{}
|
||||
@@ -5,7 +5,7 @@ using Robust.Client.GameObjects;
|
||||
using Robust.Shared.GameStates;
|
||||
using Robust.Shared.Utility;
|
||||
|
||||
namespace Content.Client.Singularity.EntitySystems;
|
||||
namespace Content.Client.Singularity.Systems;
|
||||
|
||||
/// <summary>
|
||||
/// The client-side version of <see cref="SharedSingularitySystem"/>.
|
||||
|
||||
@@ -1,33 +0,0 @@
|
||||
using Robust.Shared.Prototypes;
|
||||
using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom.Prototype;
|
||||
|
||||
using Content.Server.Singularity.EntitySystems;
|
||||
|
||||
namespace Content.Server.Singularity.Components;
|
||||
|
||||
[RegisterComponent]
|
||||
public sealed partial class SingularityGeneratorComponent : Component
|
||||
{
|
||||
/// <summary>
|
||||
/// The amount of power this generator has accumulated.
|
||||
/// If you want to set this use <see cref="SingularityGeneratorSystem.SetPower"/>
|
||||
/// </summary>
|
||||
[DataField("power")]
|
||||
[Access(friends:typeof(SingularityGeneratorSystem))]
|
||||
public float Power = 0;
|
||||
|
||||
/// <summary>
|
||||
/// The power threshold at which this generator will spawn a singularity.
|
||||
/// If you want to set this use <see cref="SingularityGeneratorSystem.SetThreshold"/>
|
||||
/// </summary>
|
||||
[DataField("threshold")]
|
||||
[Access(friends:typeof(SingularityGeneratorSystem))]
|
||||
public float Threshold = 16;
|
||||
|
||||
/// <summary>
|
||||
/// The prototype ID used to spawn a singularity.
|
||||
/// </summary>
|
||||
[DataField("spawnId", customTypeSerializer: typeof(PrototypeIdSerializer<EntityPrototype>))]
|
||||
[ViewVariables(VVAccess.ReadWrite)]
|
||||
public string? SpawnPrototype = "Singularity";
|
||||
}
|
||||
@@ -1,14 +1,23 @@
|
||||
using Content.Server.ParticleAccelerator.Components;
|
||||
using Content.Server.Singularity.Components;
|
||||
using Content.Shared.Popups;
|
||||
using Content.Shared.Singularity.Components;
|
||||
using Content.Shared.Singularity.EntitySystems;
|
||||
using Robust.Server.GameObjects;
|
||||
using Robust.Shared.Physics;
|
||||
using Robust.Shared.Physics.Components;
|
||||
using Robust.Shared.Physics.Events;
|
||||
using Robust.Shared.Timing;
|
||||
|
||||
namespace Content.Server.Singularity.EntitySystems;
|
||||
|
||||
public sealed class SingularityGeneratorSystem : EntitySystem
|
||||
public sealed class SingularityGeneratorSystem : SharedSingularityGeneratorSystem
|
||||
{
|
||||
#region Dependencies
|
||||
[Dependency] private readonly IViewVariablesManager _vvm = default!;
|
||||
[Dependency] private readonly SharedTransformSystem _transformSystem = default!;
|
||||
[Dependency] private readonly PhysicsSystem _physics = default!;
|
||||
[Dependency] private readonly IGameTiming _timing = default!;
|
||||
[Dependency] private readonly MetaDataSystem _metadata = default!;
|
||||
#endregion Dependencies
|
||||
|
||||
public override void Initialize()
|
||||
@@ -100,11 +109,37 @@ public sealed class SingularityGeneratorSystem : EntitySystem
|
||||
/// <param name="args">The state of the beginning of the collision.</param>
|
||||
private void HandleParticleCollide(EntityUid uid, ParticleProjectileComponent component, ref StartCollideEvent args)
|
||||
{
|
||||
if (EntityManager.TryGetComponent<SingularityGeneratorComponent>(args.OtherEntity, out var singularityGeneratorComponent))
|
||||
if (!EntityManager.TryGetComponent<SingularityGeneratorComponent>(args.OtherEntity, out var generatorComp))
|
||||
return;
|
||||
|
||||
if (_timing.CurTime < _metadata.GetPauseTime(uid) + generatorComp.NextFailsafe && !generatorComp.FailsafeDisabled)
|
||||
{
|
||||
EntityManager.QueueDeleteEntity(uid);
|
||||
return;
|
||||
}
|
||||
|
||||
var contained = true;
|
||||
if (!generatorComp.FailsafeDisabled)
|
||||
{
|
||||
var transform = Transform(args.OtherEntity);
|
||||
var directions = Enum.GetValues<Direction>().Length;
|
||||
for (var i = 0; i < directions - 1; i += 2) // Skip every other direction, checking only cardinals
|
||||
{
|
||||
if (!CheckContainmentField((Direction)i, new Entity<SingularityGeneratorComponent>(args.OtherEntity, generatorComp), transform))
|
||||
contained = false;
|
||||
}
|
||||
}
|
||||
|
||||
if (!contained && !generatorComp.FailsafeDisabled)
|
||||
{
|
||||
generatorComp.NextFailsafe = _timing.CurTime + generatorComp.FailsafeCooldown;
|
||||
PopupSystem.PopupEntity(Loc.GetString("comp-generator-failsafe", ("target", args.OtherEntity)), args.OtherEntity, PopupType.LargeCaution);
|
||||
}
|
||||
else
|
||||
{
|
||||
SetPower(
|
||||
args.OtherEntity,
|
||||
singularityGeneratorComponent.Power + component.State switch
|
||||
generatorComp.Power + component.State switch
|
||||
{
|
||||
ParticleAcceleratorPowerState.Standby => 0,
|
||||
ParticleAcceleratorPowerState.Level0 => 1,
|
||||
@@ -113,10 +148,46 @@ public sealed class SingularityGeneratorSystem : EntitySystem
|
||||
ParticleAcceleratorPowerState.Level3 => 8,
|
||||
_ => 0
|
||||
},
|
||||
singularityGeneratorComponent
|
||||
generatorComp
|
||||
);
|
||||
EntityManager.QueueDeleteEntity(uid);
|
||||
}
|
||||
|
||||
EntityManager.QueueDeleteEntity(uid);
|
||||
}
|
||||
#endregion Event Handlers
|
||||
|
||||
/// <summary>
|
||||
/// Checks whether there's a containment field in a given direction away from the generator
|
||||
/// </summary>
|
||||
/// <param name="transform">The transform component of the singularity generator.</param>
|
||||
/// <remarks>Mostly copied from <see cref="ContainmentFieldGeneratorSystem"/> </remarks>
|
||||
private bool CheckContainmentField(Direction dir, Entity<SingularityGeneratorComponent> generator, TransformComponent transform)
|
||||
{
|
||||
var component = generator.Comp;
|
||||
|
||||
var (worldPosition, worldRotation) = _transformSystem.GetWorldPositionRotation(transform);
|
||||
var dirRad = dir.ToAngle() + worldRotation;
|
||||
|
||||
var ray = new CollisionRay(worldPosition, dirRad.ToVec(), component.CollisionMask);
|
||||
var rayCastResults = _physics.IntersectRay(transform.MapID, ray, component.FailsafeDistance, generator, false);
|
||||
var genQuery = GetEntityQuery<ContainmentFieldComponent>();
|
||||
|
||||
RayCastResults? closestResult = null;
|
||||
|
||||
foreach (var result in rayCastResults)
|
||||
{
|
||||
if (genQuery.HasComponent(result.HitEntity))
|
||||
closestResult = result;
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
if (closestResult == null)
|
||||
return false;
|
||||
|
||||
var ent = closestResult.Value.HitEntity;
|
||||
|
||||
// Check that the field can't be moved. The fields' transform parenting is weird, so skip that
|
||||
return TryComp<PhysicsComponent>(ent, out var collidableComponent) && collidableComponent.BodyType == BodyType.Static;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -96,6 +96,13 @@ public sealed class EmagSystem : EntitySystem
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Shows a popup to emag user (client side only!) and adds <see cref="EmaggedComponent"/> to the entity when handled
|
||||
/// </summary>
|
||||
/// <param name="UserUid">Emag user</param>
|
||||
/// <param name="Handled">Did the emagging succeed? Causes a user-only popup to show on client side</param>
|
||||
/// <param name="Repeatable">Can the entity be emagged more than once? Prevents adding of <see cref="EmaggedComponent"/></param>
|
||||
/// <remarks>Needs to be handled in shared/client, not just the server, to actually show the emagging popup</remarks>
|
||||
[ByRefEvent]
|
||||
public record struct GotEmaggedEvent(EntityUid UserUid, bool Handled = false, bool Repeatable = false);
|
||||
|
||||
|
||||
@@ -0,0 +1,69 @@
|
||||
using Robust.Shared.Prototypes;
|
||||
using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom.Prototype;
|
||||
|
||||
using Content.Shared.Physics;
|
||||
using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom;
|
||||
using Robust.Shared.GameStates;
|
||||
|
||||
namespace Content.Shared.Singularity.Components;
|
||||
|
||||
[RegisterComponent, AutoGenerateComponentPause, NetworkedComponent, AutoGenerateComponentState]
|
||||
public sealed partial class SingularityGeneratorComponent : Component
|
||||
{
|
||||
/// <summary>
|
||||
/// The amount of power this generator has accumulated.
|
||||
/// If you want to set this use <see cref="SingularityGeneratorSystem.SetPower"/>
|
||||
/// </summary>
|
||||
[DataField]
|
||||
public float Power = 0;
|
||||
|
||||
/// <summary>
|
||||
/// The power threshold at which this generator will spawn a singularity.
|
||||
/// If you want to set this use <see cref="SingularityGeneratorSystem.SetThreshold"/>
|
||||
/// </summary>
|
||||
[DataField]
|
||||
public float Threshold = 16;
|
||||
|
||||
/// <summary>
|
||||
/// Allows the generator to ignore all the failsafe stuff, e.g. when emagged
|
||||
/// </summary>
|
||||
[DataField, AutoNetworkedField]
|
||||
public bool FailsafeDisabled = false;
|
||||
|
||||
/// <summary>
|
||||
/// Maximum distance at which the generator will check for a field at
|
||||
/// </summary>
|
||||
[DataField]
|
||||
public float FailsafeDistance = 16;
|
||||
|
||||
/// <summary>
|
||||
/// The prototype ID used to spawn a singularity.
|
||||
/// </summary>
|
||||
[DataField("spawnId", customTypeSerializer: typeof(PrototypeIdSerializer<EntityPrototype>))]
|
||||
public string? SpawnPrototype = "Singularity";
|
||||
|
||||
/// <summary>
|
||||
/// The masks the raycast should not go through
|
||||
/// </summary>
|
||||
[DataField]
|
||||
public int CollisionMask = (int)CollisionGroup.FullTileMask;
|
||||
|
||||
/// <summary>
|
||||
/// Message to use when there's no containment field on cardinal directions
|
||||
/// </summary>
|
||||
[DataField]
|
||||
public LocId ContainmentFailsafeMessage = "comp-generator-failsafe";
|
||||
|
||||
/// <summary>
|
||||
/// For how long the failsafe will cause the generator to stop working and not issue a failsafe warning
|
||||
/// </summary>
|
||||
[DataField]
|
||||
public TimeSpan FailsafeCooldown = TimeSpan.FromSeconds(10);
|
||||
|
||||
/// <summary>
|
||||
/// How long until the generator can issue a failsafe warning again
|
||||
/// </summary>
|
||||
[DataField(customTypeSerializer: typeof(TimeOffsetSerializer))]
|
||||
[AutoPausedField]
|
||||
public TimeSpan NextFailsafe = TimeSpan.Zero;
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
using Content.Shared.Emag.Systems;
|
||||
using Content.Shared.Popups;
|
||||
using Content.Shared.Singularity.Components;
|
||||
|
||||
namespace Content.Shared.Singularity.EntitySystems;
|
||||
|
||||
/// <summary>
|
||||
/// Shared part of SingularitySingularityGeneratorSystem
|
||||
/// </summary>
|
||||
public abstract class SharedSingularityGeneratorSystem : EntitySystem
|
||||
{
|
||||
#region Dependencies
|
||||
[Dependency] protected readonly SharedPopupSystem PopupSystem = default!;
|
||||
#endregion Dependencies
|
||||
|
||||
public override void Initialize()
|
||||
{
|
||||
base.Initialize();
|
||||
|
||||
SubscribeLocalEvent<SingularityGeneratorComponent, GotEmaggedEvent>(OnEmagged);
|
||||
}
|
||||
|
||||
private void OnEmagged(EntityUid uid, SingularityGeneratorComponent component, ref GotEmaggedEvent args)
|
||||
{
|
||||
component.FailsafeDisabled = true;
|
||||
args.Handled = true;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
comp-generator-failsafe = The {$target} shakes as the containment failsafe triggers!
|
||||
comp-generator-failsafe-disabled = Something fizzles out inside of {$target}...
|
||||
@@ -1,7 +1,7 @@
|
||||
- type: entity
|
||||
id: SingularityGenerator
|
||||
name: gravitational singularity generator
|
||||
description: An Odd Device which produces a Gravitational Singularity when set up.
|
||||
description: An Odd Device which produces a Gravitational Singularity when set up. Comes with a temporary shutdown containment failsafe.
|
||||
placement:
|
||||
mode: SnapgridCenter
|
||||
components:
|
||||
|
||||
@@ -2,12 +2,12 @@
|
||||
id: TeslaGenerator
|
||||
name: tesla generator
|
||||
parent: BaseStructureDynamic
|
||||
description: An Odd Device which produces a powerful Tesla ball when set up.
|
||||
description: An Odd Device which produces a powerful Tesla ball when set up. Comes with a temporary shutdown containment failsafe.
|
||||
components:
|
||||
- type: Sprite
|
||||
noRot: true
|
||||
sprite: Structures/Power/Generation/Tesla/generator.rsi
|
||||
state: icon
|
||||
state: icon
|
||||
- type: SingularityGenerator # TODO: rename the generator
|
||||
spawnId: TeslaEnergyBall
|
||||
- type: InteractionOutline
|
||||
|
||||
Reference in New Issue
Block a user