Splits the singularity into its component parts + ECS singularity + Support for singularities in containers. (#12132)
* InitialCommit (Broken) * Fixes compile errors * PR comments. More doc comments. Fixes * Makes a singularity/event horizon without radiation/physics a valid state to be in * VV 'fake' setters, fixes the visualizer, fixes the singularity trying to eat itself instead of nearby things. * Removes unused dependency from Content.Client.GravityWellSystem * Testing containment and fake VV setters for SingularityGeneratorComponent * Fixes gravity wells (broken due to LookupFlags.None). Adds recursive Event Horizon consumption * Fix merge skew * Fixes for the master merge * Fix engine commit * Dirty is obsolete * Switch over dirty * Fix requested changes * ambiant -> ambient * Moves EventHorionComponent to Shared * Proper container handling * Fixes master merge. Fixes post insertion assertions for singularities. Extends proper container handling to gravity wells and the distortion shader. * Better support for admemes throwing singularities. * Moves update timing from accumulators to target times * Update doc comments
This commit is contained in:
@@ -0,0 +1,206 @@
|
||||
using Robust.Shared.Map.Components;
|
||||
using Robust.Shared.Physics.Collision.Shapes;
|
||||
using Robust.Shared.Physics.Components;
|
||||
using Robust.Shared.Physics.Events;
|
||||
using Robust.Shared.Physics.Systems;
|
||||
|
||||
using Content.Shared.Ghost;
|
||||
using Content.Shared.Singularity.Components;
|
||||
|
||||
namespace Content.Shared.Singularity.EntitySystems;
|
||||
|
||||
/// <summary>
|
||||
/// The entity system primarily responsible for managing <see cref="EventHorizonComponent"/>s.
|
||||
/// </summary>
|
||||
public abstract class SharedEventHorizonSystem : EntitySystem
|
||||
{
|
||||
#region Dependencies
|
||||
[Dependency] private readonly FixtureSystem _fixtures = default!;
|
||||
[Dependency] protected readonly IViewVariablesManager Vvm = default!;
|
||||
#endregion Dependencies
|
||||
public override void Initialize()
|
||||
{
|
||||
base.Initialize();
|
||||
|
||||
// Allows for predicted collisions with singularities.
|
||||
SubscribeLocalEvent<EventHorizonComponent, ComponentStartup>(OnEventHorizonStartup);
|
||||
SubscribeLocalEvent<EventHorizonComponent, PreventCollideEvent>(OnPreventCollide);
|
||||
|
||||
var vvHandle = Vvm.GetTypeHandler<EventHorizonComponent>();
|
||||
vvHandle.AddPath(nameof(EventHorizonComponent.Radius), (_, comp) => comp.Radius, (uid, value, comp) => SetRadius(uid, value, eventHorizon: comp));
|
||||
vvHandle.AddPath(nameof(EventHorizonComponent.CanBreachContainment), (_, comp) => comp.CanBreachContainment, (uid, value, comp) => SetCanBreachContainment(uid, value, eventHorizon: comp));
|
||||
vvHandle.AddPath(nameof(EventHorizonComponent.HorizonFixtureId), (_, comp) => comp.HorizonFixtureId, (uid, value, comp) => SetHorizonFixtureId(uid, value, eventHorizon: comp));
|
||||
}
|
||||
|
||||
public override void Shutdown()
|
||||
{
|
||||
var vvHandle = Vvm.GetTypeHandler<EventHorizonComponent>();
|
||||
vvHandle.RemovePath(nameof(EventHorizonComponent.Radius));
|
||||
vvHandle.RemovePath(nameof(EventHorizonComponent.CanBreachContainment));
|
||||
vvHandle.RemovePath(nameof(EventHorizonComponent.HorizonFixtureId));
|
||||
|
||||
base.Shutdown();
|
||||
}
|
||||
|
||||
#region Getters/Setters
|
||||
|
||||
/// <summary>
|
||||
/// Setter for <see cref="EventHorizonComponent.Radius"/>
|
||||
/// May also update the fixture associated with the event horizon.
|
||||
/// </summary>
|
||||
/// <param name="uid">The uid of the event horizon to change the radius of.</param>
|
||||
/// <param name="value">The new radius of the event horizon.</param>
|
||||
/// <param name="updateFixture">Whether to update the associated fixture upon changing the radius of the event horizon.</param>
|
||||
/// <param name="eventHorizon">The state of the event horizon to change the radius of.</param>
|
||||
public void SetRadius(EntityUid uid, float value, bool updateFixture = true, EventHorizonComponent? eventHorizon = null)
|
||||
{
|
||||
if(!Resolve(uid, ref eventHorizon))
|
||||
return;
|
||||
|
||||
var oldValue = eventHorizon.Radius;
|
||||
if (value == oldValue)
|
||||
return;
|
||||
|
||||
eventHorizon.Radius = value;
|
||||
EntityManager.Dirty(eventHorizon);
|
||||
if (updateFixture)
|
||||
UpdateEventHorizonFixture(uid, eventHorizon: eventHorizon);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Setter for <see cref="EventHorizonComponent.CanBreachContainment"/>
|
||||
/// May also update the fixture associated with the event horizon.
|
||||
/// </summary>
|
||||
/// <param name="uid">The uid of the event horizon to make (in)capable of breaching containment.</param>
|
||||
/// <param name="value">Whether the event horizon should be able to breach containment.</param>
|
||||
/// <param name="updateFixture">Whether to update the associated fixture upon changing whether the event horizon can breach containment.</param>
|
||||
/// <param name="eventHorizon">The state of the event horizon to make (in)capable of breaching containment.</param>
|
||||
public void SetCanBreachContainment(EntityUid uid, bool value, bool updateFixture = true, EventHorizonComponent? eventHorizon = null)
|
||||
{
|
||||
if(!Resolve(uid, ref eventHorizon))
|
||||
return;
|
||||
|
||||
var oldValue = eventHorizon.CanBreachContainment;
|
||||
if (value == oldValue)
|
||||
return;
|
||||
|
||||
eventHorizon.CanBreachContainment = value;
|
||||
EntityManager.Dirty(eventHorizon);
|
||||
if (updateFixture)
|
||||
UpdateEventHorizonFixture(uid, eventHorizon: eventHorizon);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Setter for <see cref="EventHorizonComponent.HorizonFixtureId"/>
|
||||
/// May also update the fixture associated with the event horizon.
|
||||
/// </summary>
|
||||
/// <param name="uid">The uid of the event horizon with the fixture ID to change.</param>
|
||||
/// <param name="value">The new fixture ID to associate the event horizon with.</param>
|
||||
/// <param name="updateFixture">Whether to update the associated fixture upon changing whether the event horizon can breach containment.</param>
|
||||
/// <param name="eventHorizon">The state of the event horizon with the fixture ID to change.</param>
|
||||
public void SetHorizonFixtureId(EntityUid uid, string? value, bool updateFixture = true, EventHorizonComponent? eventHorizon = null)
|
||||
{
|
||||
if(!Resolve(uid, ref eventHorizon))
|
||||
return;
|
||||
|
||||
var oldValue = eventHorizon.HorizonFixtureId;
|
||||
if (value == oldValue)
|
||||
return;
|
||||
|
||||
eventHorizon.HorizonFixtureId = value;
|
||||
EntityManager.Dirty(eventHorizon);
|
||||
if (updateFixture)
|
||||
UpdateEventHorizonFixture(uid, eventHorizon: eventHorizon);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Updates the state of the fixture associated with the event horizon.
|
||||
/// </summary>
|
||||
/// <param name="eventHorizon">The uid of the event horizon associated with the fixture to update.</param>
|
||||
/// <param name="fixtures">The physics component containing the fixture to update.</param>
|
||||
/// <param name="eventHorizon">The state of the event horizon associated with the fixture to update.</param>
|
||||
public void UpdateEventHorizonFixture(EntityUid uid, PhysicsComponent? fixtures = null, EventHorizonComponent? eventHorizon = null)
|
||||
{
|
||||
if(!Resolve(uid, ref eventHorizon))
|
||||
return;
|
||||
|
||||
var fixtureId = eventHorizon.HorizonFixtureId;
|
||||
if (fixtureId == null || !Resolve(eventHorizon.Owner, ref fixtures, logMissing: false))
|
||||
return;
|
||||
|
||||
var fixture = _fixtures.GetFixtureOrNull(fixtures, fixtureId);
|
||||
if (fixture == null)
|
||||
return;
|
||||
|
||||
var shape = (PhysShapeCircle)fixture.Shape;
|
||||
shape.Radius = eventHorizon.Radius;
|
||||
fixture.Hard = !eventHorizon.CanBreachContainment;
|
||||
EntityManager.Dirty(fixtures);
|
||||
}
|
||||
|
||||
#endregion Getters/Setters
|
||||
|
||||
|
||||
#region EventHandlers
|
||||
|
||||
/// <summary>
|
||||
/// Syncs the state of the fixture associated with the event horizon upon startup.
|
||||
/// </summary>
|
||||
/// <param name="uid">The entity that has just gained an event horizon component.</param>
|
||||
/// <param name="comp">The event horizon component that is starting up.</param>
|
||||
/// <param name="args">The event arguments.</param>
|
||||
private void OnEventHorizonStartup(EntityUid uid, EventHorizonComponent comp, ComponentStartup args)
|
||||
{
|
||||
UpdateEventHorizonFixture(uid, eventHorizon: comp);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Prevents the event horizon from colliding with anything it cannot consume.
|
||||
/// Most notably map grids and ghosts.
|
||||
/// Also makes event horizons phase through containment if it can breach.
|
||||
/// </summary>
|
||||
/// <param name="uid">The entity that is trying to collide with another entity.</param>
|
||||
/// <param name="comp">The event horizon of the former.</param>
|
||||
/// <param name="args">The event arguments.</param>
|
||||
private void OnPreventCollide(EntityUid uid, EventHorizonComponent comp, ref PreventCollideEvent args)
|
||||
{
|
||||
if(!args.Cancelled)
|
||||
PreventCollide(uid, comp, ref args);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The actual, functional part of SharedEventHorizonSystem.OnPreventCollide.
|
||||
/// The return value allows for overrides to early return if the base successfully handles collision prevention.
|
||||
/// </summary>
|
||||
/// <param name="uid">The entity that is trying to collide with another entity.</param>
|
||||
/// <param name="comp">The event horizon of the former.</param>
|
||||
/// <param name="args">The event arguments.</param>
|
||||
/// <returns>A bool indicating whether the collision prevention has been handled.</return>
|
||||
protected virtual bool PreventCollide(EntityUid uid, EventHorizonComponent comp, ref PreventCollideEvent args)
|
||||
{
|
||||
var otherUid = args.BodyB.Owner;
|
||||
|
||||
// For prediction reasons always want the client to ignore these.
|
||||
if (EntityManager.HasComponent<MapGridComponent>(otherUid) ||
|
||||
EntityManager.HasComponent<SharedGhostComponent>(otherUid))
|
||||
{
|
||||
args.Cancelled = true;
|
||||
return true;
|
||||
}
|
||||
|
||||
// If we can, breach containment
|
||||
// otherwise, check if it's containment and just keep the collision
|
||||
if (EntityManager.HasComponent<SharedContainmentFieldComponent>(otherUid) ||
|
||||
EntityManager.HasComponent<SharedContainmentFieldGeneratorComponent>(otherUid))
|
||||
{
|
||||
if (comp.CanBreachContainment)
|
||||
args.Cancelled = true;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
#endregion EventHandlers
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
namespace Content.Shared.Singularity.EntitySystems;
|
||||
|
||||
/// <summary>
|
||||
/// The entity system primarily responsible for managing <see cref="SharedGravityWellComponent"/>s.
|
||||
/// </summary>
|
||||
public abstract class SharedGravityWellSystem : EntitySystem
|
||||
{}
|
||||
@@ -0,0 +1,385 @@
|
||||
using Robust.Shared.Containers;
|
||||
using Robust.Shared.Physics.Components;
|
||||
using Robust.Shared.Physics.Systems;
|
||||
using Robust.Shared.Serialization;
|
||||
|
||||
using Content.Shared.Radiation.Components;
|
||||
using Content.Shared.Singularity.Components;
|
||||
using Content.Shared.Singularity.Events;
|
||||
|
||||
namespace Content.Shared.Singularity.EntitySystems;
|
||||
|
||||
/// <summary>
|
||||
/// The entity system primarily responsible for managing <see cref="SharedSingularityComponent"/>s.
|
||||
/// </summary>
|
||||
public abstract class SharedSingularitySystem : EntitySystem
|
||||
{
|
||||
#region Dependencies
|
||||
[Dependency] private readonly SharedAppearanceSystem _visualizer = default!;
|
||||
[Dependency] private readonly SharedContainerSystem _containers = default!;
|
||||
[Dependency] private readonly SharedEventHorizonSystem _horizons = default!;
|
||||
[Dependency] private readonly SharedPhysicsSystem _physics = default!;
|
||||
[Dependency] protected readonly IViewVariablesManager Vvm = default!;
|
||||
#endregion Dependencies
|
||||
|
||||
/// <summary>
|
||||
/// The minimum level a singularity can be set to.
|
||||
/// </summary>
|
||||
public const byte MinSingularityLevel = 0;
|
||||
|
||||
/// <summary>
|
||||
/// The maximum level a singularity can be set to.
|
||||
/// </summary>
|
||||
public const byte MaxSingularityLevel = 6;
|
||||
|
||||
/// <summary>
|
||||
/// The amount to scale a singularities distortion shader by when it's in a container.
|
||||
/// This is the inverse of an exponent, not a linear scaling factor.
|
||||
/// ie. n => intensity = intensity ** (1/n)
|
||||
/// </summary>
|
||||
public const float DistortionContainerScaling = 4f;
|
||||
|
||||
|
||||
public override void Initialize()
|
||||
{
|
||||
base.Initialize();
|
||||
|
||||
SubscribeLocalEvent<SharedSingularityComponent, ComponentStartup>(OnSingularityStartup);
|
||||
SubscribeLocalEvent<AppearanceComponent, SingularityLevelChangedEvent>(UpdateAppearance);
|
||||
SubscribeLocalEvent<RadiationSourceComponent, SingularityLevelChangedEvent>(UpdateRadiation);
|
||||
SubscribeLocalEvent<PhysicsComponent, SingularityLevelChangedEvent>(UpdateBody);
|
||||
SubscribeLocalEvent<EventHorizonComponent, SingularityLevelChangedEvent>(UpdateEventHorizon);
|
||||
SubscribeLocalEvent<SingularityDistortionComponent, SingularityLevelChangedEvent>(UpdateDistortion);
|
||||
SubscribeLocalEvent<SingularityDistortionComponent, EntGotInsertedIntoContainerMessage>(UpdateDistortion);
|
||||
SubscribeLocalEvent<SingularityDistortionComponent, EntGotRemovedFromContainerMessage>(UpdateDistortion);
|
||||
|
||||
var vvHandle = Vvm.GetTypeHandler<SharedSingularityComponent>();
|
||||
vvHandle.AddPath(nameof(SharedSingularityComponent.Level), (_, comp) => comp.Level, SetLevel);
|
||||
vvHandle.AddPath(nameof(SharedSingularityComponent.RadsPerLevel), (_, comp) => comp.RadsPerLevel, SetRadsPerLevel);
|
||||
}
|
||||
|
||||
public override void Shutdown()
|
||||
{
|
||||
var vvHandle = Vvm.GetTypeHandler<SharedSingularityComponent>();
|
||||
vvHandle.RemovePath(nameof(SharedSingularityComponent.Level));
|
||||
vvHandle.RemovePath(nameof(SharedSingularityComponent.RadsPerLevel));
|
||||
|
||||
base.Shutdown();
|
||||
}
|
||||
|
||||
#region Getters/Setters
|
||||
|
||||
/// <summary>
|
||||
/// Setter for <see cref="SharedSingularityComponent.Level"/>
|
||||
/// Also sends out an event alerting that the singularities level has changed.
|
||||
/// </summary>
|
||||
/// <param name="uid">The uid of the singularity to change the level of.</param>
|
||||
/// <param name="value">The new level the singularity should have.</param>
|
||||
/// <param name="singularity">The state of the singularity to change the level of.</param>
|
||||
public void SetLevel(EntityUid uid, byte value, SharedSingularityComponent? singularity = null)
|
||||
{
|
||||
if(!Resolve(uid, ref singularity))
|
||||
return;
|
||||
|
||||
value = MathHelper.Clamp(value, MinSingularityLevel, MaxSingularityLevel);
|
||||
var oldValue = singularity.Level;
|
||||
if (oldValue == value)
|
||||
return;
|
||||
|
||||
singularity.Level = value;
|
||||
UpdateSingularityLevel(uid, oldValue, singularity);
|
||||
if(!EntityManager.Deleted(singularity.Owner))
|
||||
EntityManager.Dirty(singularity);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Setter for <see cref="SharedSingularityComponent.RadsPerLevel"/>
|
||||
/// Also updates the radiation output of the singularity according to the new values.
|
||||
/// </summary>
|
||||
/// <param name="uid">The uid of the singularity to change the radioactivity of.</param>
|
||||
/// <param name="value">The new radioactivity the singularity should have.</param>
|
||||
/// <param name="singularity">The state of the singularity to change the radioactivity of.</param>
|
||||
public void SetRadsPerLevel(EntityUid uid, float value, SharedSingularityComponent? singularity = null)
|
||||
{
|
||||
if(!Resolve(uid, ref singularity))
|
||||
return;
|
||||
|
||||
var oldValue = singularity.RadsPerLevel;
|
||||
if (oldValue == value)
|
||||
return;
|
||||
|
||||
singularity.RadsPerLevel = value;
|
||||
UpdateRadiation(uid, singularity);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Alerts the entity hosting the singularity that the level of the singularity has changed.
|
||||
/// Usually follows a SharedSingularitySystem.SetLevel call, but is also used on component startup to sync everything.
|
||||
/// </summary>
|
||||
/// <param name="uid">The uid of the singularity which's level has changed.</param>
|
||||
/// <param name="oldValue">The old level of the singularity. May be equal to <see cref="SharedSingularityComponent.Level"/> if the component is starting.</param>
|
||||
/// <param name="singularity">The state of the singularity which's level has changed.</param>
|
||||
public void UpdateSingularityLevel(EntityUid uid, byte oldValue, SharedSingularityComponent? singularity = null)
|
||||
{
|
||||
if(!Resolve(uid, ref singularity))
|
||||
return;
|
||||
|
||||
RaiseLocalEvent(uid, new SingularityLevelChangedEvent(singularity.Level, oldValue, singularity));
|
||||
if (singularity.Level <= 0)
|
||||
EntityManager.DeleteEntity(singularity.Owner);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Alerts the entity hosting the singularity that the level of the singularity has changed without the level actually changing.
|
||||
/// Used to sync components when the singularity component is added to an entity.
|
||||
/// </summary>
|
||||
/// <param name="uid">The uid of the singularity.</param>
|
||||
/// <param name="singularity">The state of the singularity.</param>
|
||||
public void UpdateSingularityLevel(EntityUid uid, SharedSingularityComponent? singularity = null)
|
||||
{
|
||||
if (Resolve(uid, ref singularity))
|
||||
UpdateSingularityLevel(uid, singularity.Level, singularity);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Updates the amount of radiation the singularity emits to reflect a change in the level or radioactivity per level of the singularity.
|
||||
/// </summary>
|
||||
/// <param name="uid">The uid of the singularity to update the radiation of.</param>
|
||||
/// <param name="singularity">The state of the singularity to update the radiation of.</param>
|
||||
/// <param name="rads">The state of the radioactivity of the singularity to update.</param>
|
||||
private void UpdateRadiation(EntityUid uid, SharedSingularityComponent? singularity = null, RadiationSourceComponent? rads = null)
|
||||
{
|
||||
if(!Resolve(uid, ref singularity, ref rads, logMissing: false))
|
||||
return;
|
||||
rads.Intensity = singularity.Level * singularity.RadsPerLevel;
|
||||
}
|
||||
|
||||
#endregion Getters/Setters
|
||||
|
||||
#region Derivations
|
||||
/// <summary>
|
||||
/// The scaling factor for the size of a singularities gravity well.
|
||||
/// </summary>
|
||||
public const float BaseGravityWellRadius = 2f;
|
||||
|
||||
/// <summary>
|
||||
/// The scaling factor for the base acceleration of a singularities gravity well.
|
||||
/// </summary>
|
||||
public const float BaseGravityWellAcceleration = 10f;
|
||||
|
||||
/// <summary>
|
||||
/// The level at and above which a singularity should be capable of breaching containment.
|
||||
/// </summary>
|
||||
public const byte SingularityBreachThreshold = 5;
|
||||
|
||||
/// <summary>
|
||||
/// Derives the proper gravity well radius for a singularity from its state.
|
||||
/// </summary>
|
||||
/// <param name="singulo">A singularity.</param>
|
||||
/// <returns>The gravity well radius the singularity should have given its state.</returns>
|
||||
public float GravPulseRange(SharedSingularityComponent singulo)
|
||||
=> BaseGravityWellRadius * (singulo.Level + 1);
|
||||
|
||||
/// <summary>
|
||||
/// Derives the proper base gravitational acceleration for a singularity from its state.
|
||||
/// </summary>
|
||||
/// <param name="singulo">A singularity.</param>
|
||||
/// <returns>The base gravitational acceleration the singularity should have given its state.</returns>
|
||||
public (float, float) GravPulseAcceleration(SharedSingularityComponent singulo)
|
||||
=> (BaseGravityWellAcceleration * singulo.Level, 0f);
|
||||
|
||||
/// <summary>
|
||||
/// Derives the proper event horizon radius for a singularity from its state.
|
||||
/// </summary>
|
||||
/// <param name="singulo">A singularity.</param>
|
||||
/// <returns>The event horizon radius the singularity should have given its state.</returns>
|
||||
public float EventHorizonRadius(SharedSingularityComponent singulo)
|
||||
=> (float) singulo.Level - 0.5f;
|
||||
|
||||
/// <summary>
|
||||
/// Derives whether a singularity should be able to breach containment from its state.
|
||||
/// </summary>
|
||||
/// <param name="singulo">A singularity.</param>
|
||||
/// <returns>Whether the singularity should be able to breach containment.</returns>
|
||||
public bool CanBreachContainment(SharedSingularityComponent singulo)
|
||||
=> singulo.Level >= SingularityBreachThreshold;
|
||||
|
||||
/// <summary>
|
||||
/// Derives the proper distortion shader falloff for a singularity from its state.
|
||||
/// </summary>
|
||||
/// <param name="singulo">A singularity.</param>
|
||||
/// <returns>The distortion shader falloff the singularity should have given its state.</returns>
|
||||
public float GetFalloff(float level)
|
||||
{
|
||||
return level switch {
|
||||
0 => 9999f,
|
||||
1 => MathF.Sqrt(6.4f),
|
||||
2 => MathF.Sqrt(7.0f),
|
||||
3 => MathF.Sqrt(8.0f),
|
||||
4 => MathF.Sqrt(10.0f),
|
||||
5 => MathF.Sqrt(12.0f),
|
||||
6 => MathF.Sqrt(12.0f),
|
||||
_ => -1.0f
|
||||
};
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Derives the proper distortion shader intensity for a singularity from its state.
|
||||
/// </summary>
|
||||
/// <param name="singulo">A singularity.</param>
|
||||
/// <returns>The distortion shader intensity the singularity should have given its state.</returns>
|
||||
public float GetIntensity(float level)
|
||||
{
|
||||
return level switch {
|
||||
0 => 0.0f,
|
||||
1 => 3645f,
|
||||
2 => 103680f,
|
||||
3 => 1113920f,
|
||||
4 => 16200000f,
|
||||
5 => 180000000f,
|
||||
6 => 180000000f,
|
||||
_ => -1.0f
|
||||
};
|
||||
}
|
||||
#endregion Derivations
|
||||
|
||||
#region Serialization
|
||||
/// <summary>
|
||||
/// A state wrapper used to sync the singularity between the server and client.
|
||||
/// </summary>
|
||||
[Serializable, NetSerializable]
|
||||
protected sealed class SingularityComponentState : ComponentState
|
||||
{
|
||||
/// <summary>
|
||||
/// The level of the singularity to sync.
|
||||
/// </summary>
|
||||
public readonly byte Level;
|
||||
|
||||
public SingularityComponentState(SharedSingularityComponent singulo)
|
||||
{
|
||||
Level = singulo.Level;
|
||||
}
|
||||
}
|
||||
#endregion Serialization
|
||||
|
||||
#region EventHandlers
|
||||
/// <summary>
|
||||
/// Syncs other components with the state of the singularity via event on startup.
|
||||
/// </summary>
|
||||
/// <param name="uid">The entity that is becoming a singularity.</param>
|
||||
/// <param name="comp">The singularity component that is being added to the entity.</param>
|
||||
/// <param name="args">The event arguments.</param>
|
||||
protected virtual void OnSingularityStartup(EntityUid uid, SharedSingularityComponent comp, ComponentStartup args)
|
||||
{
|
||||
UpdateSingularityLevel(uid, comp);
|
||||
}
|
||||
|
||||
// TODO: Figure out which systems should have control of which coupling.
|
||||
/// <summary>
|
||||
/// Syncs the radius of an event horizon associated with a singularity that just changed levels.
|
||||
/// </summary>
|
||||
/// <param name="uid">The entity that the event horizon and singularity are attached to.</param>
|
||||
/// <param name="comp">The event horizon associated with the singularity.</param>
|
||||
/// <param name="args">The event arguments.</param>
|
||||
private void UpdateEventHorizon(EntityUid uid, EventHorizonComponent comp, SingularityLevelChangedEvent args)
|
||||
{
|
||||
var singulo = args.Singularity;
|
||||
_horizons.SetRadius(uid, EventHorizonRadius(singulo), false, comp);
|
||||
_horizons.SetCanBreachContainment(uid, CanBreachContainment(singulo), false, comp);
|
||||
_horizons.UpdateEventHorizonFixture(uid, eventHorizon: comp);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Updates the distortion shader associated with a singularity when the singuarity changes levels.
|
||||
/// </summary>
|
||||
/// <param name="uid">The uid of the distortion shader.</param>
|
||||
/// <param name="comp">The state of the distortion shader.</param>
|
||||
/// <param name="args">The event arguments.</param>
|
||||
private void UpdateDistortion(EntityUid uid, SingularityDistortionComponent comp, SingularityLevelChangedEvent args)
|
||||
{
|
||||
var newFalloffPower = GetFalloff(args.NewValue);
|
||||
var newIntensity = GetIntensity(args.NewValue);
|
||||
if (_containers.IsEntityInContainer(uid))
|
||||
{
|
||||
var absFalloffPower = MathF.Abs(newFalloffPower);
|
||||
var absIntensity = MathF.Abs(newIntensity);
|
||||
|
||||
var factor = (1f / DistortionContainerScaling) - 1f;
|
||||
newFalloffPower = absFalloffPower > 1f ? newFalloffPower * MathF.Pow(absFalloffPower, factor) : newFalloffPower;
|
||||
newIntensity = absIntensity > 1f ? newIntensity * MathF.Pow(absIntensity, factor) : newIntensity;
|
||||
}
|
||||
|
||||
comp.FalloffPower = newFalloffPower;
|
||||
comp.Intensity = newIntensity;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Updates the distortion shader associated with a singularity when the singuarity is inserted into a container.
|
||||
/// </summary>
|
||||
/// <param name="uid">The uid of the distortion shader.</param>
|
||||
/// <param name="comp">The state of the distortion shader.</param>
|
||||
/// <param name="args">The event arguments.</param>
|
||||
private void UpdateDistortion(EntityUid uid, SingularityDistortionComponent comp, EntGotInsertedIntoContainerMessage args)
|
||||
{
|
||||
var absFalloffPower = MathF.Abs(comp.FalloffPower);
|
||||
var absIntensity = MathF.Abs(comp.Intensity);
|
||||
|
||||
var factor = (1f / DistortionContainerScaling) - 1f;
|
||||
comp.FalloffPower = absFalloffPower > 1 ? comp.FalloffPower * MathF.Pow(absFalloffPower, factor) : comp.FalloffPower;
|
||||
comp.Intensity = absIntensity > 1 ? comp.Intensity * MathF.Pow(absIntensity, factor) : comp.Intensity;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Updates the distortion shader associated with a singularity when the singuarity is removed from a container.
|
||||
/// </summary>
|
||||
/// <param name="uid">The uid of the distortion shader.</param>
|
||||
/// <param name="comp">The state of the distortion shader.</param>
|
||||
/// <param name="args">The event arguments.</param>
|
||||
private void UpdateDistortion(EntityUid uid, SingularityDistortionComponent comp, EntGotRemovedFromContainerMessage args)
|
||||
{
|
||||
var absFalloffPower = MathF.Abs(comp.FalloffPower);
|
||||
var absIntensity = MathF.Abs(comp.Intensity);
|
||||
|
||||
var factor = DistortionContainerScaling - 1;
|
||||
comp.FalloffPower = absFalloffPower > 1 ? comp.FalloffPower * MathF.Pow(absFalloffPower, factor) : comp.FalloffPower;
|
||||
comp.Intensity = absIntensity > 1 ? comp.Intensity * MathF.Pow(absIntensity, factor) : comp.Intensity;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Updates the state of the physics body associated with a singularity when the singualrity changes levels.
|
||||
/// </summary>
|
||||
/// <param name="uid">The entity that the physics body and singularity are attached to.</param>
|
||||
/// <param name="comp">The physics body associated with the singularity.</param>
|
||||
/// <param name="args">The event arguments.</param>
|
||||
private void UpdateBody(EntityUid uid, PhysicsComponent comp, SingularityLevelChangedEvent args)
|
||||
{
|
||||
_physics.SetBodyStatus(comp, (args.NewValue > 1) ? BodyStatus.InAir : BodyStatus.OnGround);
|
||||
if (args.NewValue <= 1 && args.OldValue > 1) // Apparently keeps singularities from getting stuck in the corners of containment fields.
|
||||
_physics.SetLinearVelocity(comp, Vector2.Zero); // No idea how stopping the singularities movement keeps it from getting stuck though.
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Updates the appearance of a singularity when the singularities level changes.
|
||||
/// </summary>
|
||||
/// <param name="uid">The entity that the singularity is attached to.</param>
|
||||
/// <param name="comp">The appearance associated with the singularity.</param>
|
||||
/// <param name="args">The event arguments.</param>
|
||||
private void UpdateAppearance(EntityUid uid, AppearanceComponent comp, SingularityLevelChangedEvent args)
|
||||
{
|
||||
_visualizer.SetData(uid, SingularityVisuals.Level, args.NewValue, comp);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Updates the amount of radiation a singularity emits when the singularities level changes.
|
||||
/// </summary>
|
||||
/// <param name="uid">The entity that the singularity is attached to.</param>
|
||||
/// <param name="comp">The radiation source associated with the singularity.</param>
|
||||
/// <param name="args">The event arguments.</param>
|
||||
private void UpdateRadiation(EntityUid uid, RadiationSourceComponent comp, SingularityLevelChangedEvent args)
|
||||
{
|
||||
UpdateRadiation(uid, args.Singularity, comp);
|
||||
}
|
||||
|
||||
#endregion EventHandlers
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user