Converts the particle accelerator over to ECS + misc (#17075)

Co-authored-by: metalgearsloth <31366439+metalgearsloth@users.noreply.github.com>
This commit is contained in:
TemporalOroboros
2023-06-07 23:25:59 -07:00
committed by GitHub
parent a3137cc0f0
commit d71b6c84e5
61 changed files with 1293 additions and 1169 deletions

View File

@@ -7,9 +7,9 @@ namespace Content.Server.Singularity.EntitySystems;
public sealed class SingularityGeneratorSystem : EntitySystem
{
#region Dependencies
#region Dependencies
[Dependency] private readonly IViewVariablesManager _vvm = default!;
#endregion Dependencies
#endregion Dependencies
public override void Initialize()
{
@@ -40,29 +40,32 @@ public sealed class SingularityGeneratorSystem : EntitySystem
/// <param name="comp">The state of the singularity generator.</param>
private void OnPassThreshold(EntityUid uid, SingularityGeneratorComponent? comp)
{
if(!Resolve(uid, ref comp))
if (!Resolve(uid, ref comp))
return;
SetPower(comp, 0);
EntityManager.SpawnEntity(comp.SpawnPrototype, Transform(comp.Owner).Coordinates);
SetPower(uid, 0, comp);
EntityManager.SpawnEntity(comp.SpawnPrototype, Transform(uid).Coordinates);
}
#region Getters/Setters
#region Getters/Setters
/// <summary>
/// Setter for <see cref="SingularityGeneratorComponent.Power"/>
/// If the singularity generator passes its threshold it also spawns a singularity.
/// </summary>
/// <param name="comp">The singularity generator component.</param>
/// <param name="value">The new power level for the generator component to have.</param>
public void SetPower(SingularityGeneratorComponent comp, float value)
public void SetPower(EntityUid uid, float value, SingularityGeneratorComponent? comp = null)
{
if (!Resolve(uid, ref comp))
return;
var oldValue = comp.Power;
if (value == oldValue)
return;
comp.Power = value;
if (comp.Power >= comp.Threshold && oldValue < comp.Threshold)
OnPassThreshold(comp.Owner, comp);
OnPassThreshold(uid, comp);
}
/// <summary>
@@ -71,48 +74,22 @@ public sealed class SingularityGeneratorSystem : EntitySystem
/// </summary>
/// <param name="comp">The singularity generator component.</param>
/// <param name="value">The new threshold power level for the generator component to have.</param>
public void SetThreshold(SingularityGeneratorComponent comp, float value)
public void SetThreshold(EntityUid uid, float value, SingularityGeneratorComponent? comp = null)
{
if (!Resolve(uid, ref comp))
return;
var oldValue = comp.Threshold;
if (value == comp.Threshold)
return;
comp.Power = value;
if (comp.Power >= comp.Threshold && comp.Power < oldValue)
OnPassThreshold(comp.Owner, comp);
}
#region VV
/// <summary>
/// VV setter for <see cref="SingularityGeneratorComponent.Power"/>
/// If the singularity generator passes its threshold it also spawns a singularity.
/// </summary>
/// <param name="uid">The entity hosting the singularity generator that is being modified.</param>
/// <param name="value">The value of the new power level the singularity generator should have.</param>
/// <param name="comp">The singularity generator to change the power level of.</param>
public void SetPower(EntityUid uid, float value, SingularityGeneratorComponent? comp)
{
if(!Resolve(uid, ref comp))
return;
SetPower(comp, value);
OnPassThreshold(uid, comp);
}
#endregion Getters/Setters
/// <summary>
/// VV setter for <see cref="SingularityGeneratorComponent.Threshold"/>
/// If the singularity generator has passed its new threshold it also spawns a singularity.
/// </summary>
/// <param name="uid">The entity hosting the singularity generator that is being modified.</param>
/// <param name="value">The value of the new threshold power level the singularity generator should have.</param>
/// <param name="comp">The singularity generator to change the threshold power level of.</param>
public void SetThreshold(EntityUid uid, float value, SingularityGeneratorComponent? comp)
{
if(!Resolve(uid, ref comp))
return;
SetThreshold(comp, value);
}
#endregion VV
#endregion Getters/Setters
#region Event Handlers
#region Event Handlers
/// <summary>
/// Handles PA Particles colliding with a singularity generator.
/// Adds the power from the particles to the generator.
@@ -123,21 +100,23 @@ 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 singularityGeneratorComponent))
{
SetPower(
singularityGeneratorComponent,
args.OtherEntity,
singularityGeneratorComponent.Power + component.State switch
{
ParticleAcceleratorPowerState.Standby => 0,
ParticleAcceleratorPowerState.Level0 => 1,
ParticleAcceleratorPowerState.Level1 => 2,
ParticleAcceleratorPowerState.Level2 => 4,
ParticleAcceleratorPowerState.Level3 => 8,
_ => 0
});
{
ParticleAcceleratorPowerState.Standby => 0,
ParticleAcceleratorPowerState.Level0 => 1,
ParticleAcceleratorPowerState.Level1 => 2,
ParticleAcceleratorPowerState.Level2 => 4,
ParticleAcceleratorPowerState.Level3 => 8,
_ => 0
},
singularityGeneratorComponent
);
EntityManager.QueueDeleteEntity(uid);
}
}
#endregion Event Handlers
#endregion Event Handlers
}