2023-04-27 20:49:41 +06:00
|
|
|
|
using System.Linq;
|
|
|
|
|
|
using Content.Server.Chat.Managers;
|
Tesla (#21124)
* upload all textures
finished easiest part - TeslaGenerator
* Added Tesla energy logic
* add lightning pulse priority
* work
* optimise lightning arc system
* now tesla moving to LightningTarget entity and consume it
* some audio work
add airlock and computers to the LightningTarget
* add nice visual and explosions
add crashing to game
* rsi meta fix
* disabling explosions (crashing server)
I'll get back to that problem later.
* adding important admin logging
* a little bit of cleaning and documentation
* Persistent attempts to fix the server crashing on explosions. Accidental cleaning of everything I see.
* now the tesla incinerates everything it touches except the containment field.
* colliders work
* fix falling tesla on ground after being exploded
* add consume sound, add spawn and collapses sound
* added TeslaGenerator to cargo trading console
* add all tesla part to cargo trading console
* Tesla coils: Turn on and off, get energy from lightning, give energy to the grid.
* tesla coil is ready
* tesla grounding rod is ready
* clean up
* clean up 2
* grounding rods now working without power
* add LightningResistance parameter for LightningTarget Component
* add chaotic teleport
* eletrocution remove?
* deltanedas fix pack
* more fixes
* FIXES
* FIIIXEEES
* The "Grounding Rod" component is removed, and replaced with "LightiningSparking", which is responsible for changing the visuals when hit by lightning. Duplicate code from the coil is removed.
* ops
* fix
* nah, is escaped anyway
* increase tesla collider size
* keron bb
* try fix test?
* fix
* bruh
* check turn off sus comp
* prototype cleaning
* FIIX
* return and fix sus component
* fix tesla eating lightnings, now mini tesla is electrocuted
* commented some issues
* remove linq sorting
fix jumping system
minor fixes
* fix second Linq
* fix tesla colliders! Yeah, it works
* fix componentregistration
* Just retests
* not fix
* FIX TESLA
* fixes
* store targets
* back
* make dictionary of hashsets
* some sloth fixes
* stump
* playtest balance energy generation, return to unpotimized (but working) lightning shoot
* parity
* work on
* some new fix, some new bug (chasingComponent not chasing)
* comment
* fix ChasingWalkSystem
* fix collider tesla problem
* revert old unoptimized shoot lightning
* new fix pack
---------
Co-authored-by: metalgearsloth <comedian_vs_clown@hotmail.com>
2023-12-28 16:11:50 +03:00
|
|
|
|
using Content.Server.ParticleAccelerator.Components;
|
2022-08-05 00:22:37 -04:00
|
|
|
|
using Content.Server.Singularity.Components;
|
2023-04-27 20:49:41 +06:00
|
|
|
|
using Content.Shared.Coordinates;
|
2022-08-05 00:22:37 -04:00
|
|
|
|
using Content.Shared.Singularity.Components;
|
2022-09-14 17:26:26 +10:00
|
|
|
|
using Robust.Shared.Physics.Events;
|
2022-08-05 00:22:37 -04:00
|
|
|
|
|
|
|
|
|
|
namespace Content.Server.Singularity.EntitySystems;
|
|
|
|
|
|
|
|
|
|
|
|
public sealed class SingularityGeneratorSystem : EntitySystem
|
|
|
|
|
|
{
|
2023-06-07 23:25:59 -07:00
|
|
|
|
#region Dependencies
|
2022-12-19 18:47:15 -08:00
|
|
|
|
[Dependency] private readonly IViewVariablesManager _vvm = default!;
|
2023-04-27 20:49:41 +06:00
|
|
|
|
[Dependency] private readonly IEntityManager _entityManager = default!;
|
|
|
|
|
|
[Dependency] private readonly IChatManager _chatManager = default!;
|
2023-06-07 23:25:59 -07:00
|
|
|
|
#endregion Dependencies
|
2022-12-19 18:47:15 -08:00
|
|
|
|
|
2022-08-05 00:22:37 -04:00
|
|
|
|
public override void Initialize()
|
|
|
|
|
|
{
|
|
|
|
|
|
base.Initialize();
|
|
|
|
|
|
|
|
|
|
|
|
SubscribeLocalEvent<ParticleProjectileComponent, StartCollideEvent>(HandleParticleCollide);
|
2022-12-19 18:47:15 -08:00
|
|
|
|
|
|
|
|
|
|
var vvHandle = _vvm.GetTypeHandler<SingularityGeneratorComponent>();
|
|
|
|
|
|
vvHandle.AddPath(nameof(SingularityGeneratorComponent.Power), (_, comp) => comp.Power, SetPower);
|
|
|
|
|
|
vvHandle.AddPath(nameof(SingularityGeneratorComponent.Threshold), (_, comp) => comp.Threshold, SetThreshold);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public override void Shutdown()
|
|
|
|
|
|
{
|
|
|
|
|
|
var vvHandle = _vvm.GetTypeHandler<SingularityGeneratorComponent>();
|
|
|
|
|
|
vvHandle.RemovePath(nameof(SingularityGeneratorComponent.Power));
|
|
|
|
|
|
vvHandle.RemovePath(nameof(SingularityGeneratorComponent.Threshold));
|
|
|
|
|
|
|
|
|
|
|
|
base.Shutdown();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Handles what happens when a singularity generator passes its power threshold.
|
|
|
|
|
|
/// Default behavior is to reset the singularities power level and spawn a singularity.
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="uid">The uid of the singularity generator.</param>
|
|
|
|
|
|
/// <param name="comp">The state of the singularity generator.</param>
|
|
|
|
|
|
private void OnPassThreshold(EntityUid uid, SingularityGeneratorComponent? comp)
|
|
|
|
|
|
{
|
2023-06-07 23:25:59 -07:00
|
|
|
|
if (!Resolve(uid, ref comp))
|
2022-12-19 18:47:15 -08:00
|
|
|
|
return;
|
|
|
|
|
|
|
2023-06-07 23:25:59 -07:00
|
|
|
|
SetPower(uid, 0, comp);
|
2023-04-27 20:49:41 +06:00
|
|
|
|
#region Logging
|
|
|
|
|
|
var fieldComp = _entityManager.EntityQuery<ContainmentFieldComponent>();
|
|
|
|
|
|
if (!fieldComp.Any())
|
|
|
|
|
|
{
|
|
|
|
|
|
_chatManager.SendAdminAnnouncement(Loc.GetString("admin-chatalert-singularity-no-fields",
|
|
|
|
|
|
("singularity", ToPrettyString(uid))));
|
|
|
|
|
|
}
|
|
|
|
|
|
foreach (var singComp in fieldComp)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (!singComp.Owner.ToCoordinates().InRange(_entityManager, uid.ToCoordinates(), 7))
|
|
|
|
|
|
{
|
|
|
|
|
|
_chatManager.SendAdminAnnouncement(Loc.GetString("admin-chatalert-singularity-no-fields",
|
|
|
|
|
|
("singularity", ToPrettyString(uid))));
|
|
|
|
|
|
break;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
#endregion Logging
|
2023-06-07 23:25:59 -07:00
|
|
|
|
EntityManager.SpawnEntity(comp.SpawnPrototype, Transform(uid).Coordinates);
|
2022-12-19 18:47:15 -08:00
|
|
|
|
}
|
|
|
|
|
|
|
2023-06-07 23:25:59 -07:00
|
|
|
|
#region Getters/Setters
|
2022-12-19 18:47:15 -08:00
|
|
|
|
/// <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>
|
2023-06-07 23:25:59 -07:00
|
|
|
|
public void SetPower(EntityUid uid, float value, SingularityGeneratorComponent? comp = null)
|
2022-12-19 18:47:15 -08:00
|
|
|
|
{
|
2023-06-07 23:25:59 -07:00
|
|
|
|
if (!Resolve(uid, ref comp))
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
2022-12-19 18:47:15 -08:00
|
|
|
|
var oldValue = comp.Power;
|
|
|
|
|
|
if (value == oldValue)
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
|
|
comp.Power = value;
|
|
|
|
|
|
if (comp.Power >= comp.Threshold && oldValue < comp.Threshold)
|
2023-06-07 23:25:59 -07:00
|
|
|
|
OnPassThreshold(uid, comp);
|
2022-12-19 18:47:15 -08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Setter for <see cref="SingularityGeneratorComponent.Threshold"/>
|
|
|
|
|
|
/// If the singularity generator has passed its new threshold it also spawns a singularity.
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="comp">The singularity generator component.</param>
|
|
|
|
|
|
/// <param name="value">The new threshold power level for the generator component to have.</param>
|
2023-06-07 23:25:59 -07:00
|
|
|
|
public void SetThreshold(EntityUid uid, float value, SingularityGeneratorComponent? comp = null)
|
2022-12-19 18:47:15 -08:00
|
|
|
|
{
|
2023-06-07 23:25:59 -07:00
|
|
|
|
if (!Resolve(uid, ref comp))
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
2022-12-19 18:47:15 -08:00
|
|
|
|
var oldValue = comp.Threshold;
|
|
|
|
|
|
if (value == comp.Threshold)
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
|
|
comp.Power = value;
|
|
|
|
|
|
if (comp.Power >= comp.Threshold && comp.Power < oldValue)
|
2023-06-07 23:25:59 -07:00
|
|
|
|
OnPassThreshold(uid, comp);
|
2022-08-05 00:22:37 -04:00
|
|
|
|
}
|
2023-06-07 23:25:59 -07:00
|
|
|
|
#endregion Getters/Setters
|
2022-08-05 00:22:37 -04:00
|
|
|
|
|
2023-06-07 23:25:59 -07:00
|
|
|
|
#region Event Handlers
|
2022-12-19 18:47:15 -08:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Handles PA Particles colliding with a singularity generator.
|
|
|
|
|
|
/// Adds the power from the particles to the generator.
|
|
|
|
|
|
/// TODO: Desnowflake this.
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="uid">The uid of the PA particles have collided with.</param>
|
|
|
|
|
|
/// <param name="component">The state of the PA particles.</param>
|
|
|
|
|
|
/// <param name="args">The state of the beginning of the collision.</param>
|
2022-09-14 17:26:26 +10:00
|
|
|
|
private void HandleParticleCollide(EntityUid uid, ParticleProjectileComponent component, ref StartCollideEvent args)
|
2022-08-05 00:22:37 -04:00
|
|
|
|
{
|
2023-06-07 23:25:59 -07:00
|
|
|
|
if (EntityManager.TryGetComponent<SingularityGeneratorComponent>(args.OtherEntity, out var singularityGeneratorComponent))
|
2022-08-05 00:22:37 -04:00
|
|
|
|
{
|
2022-12-20 15:54:56 -08:00
|
|
|
|
SetPower(
|
2023-06-07 23:25:59 -07:00
|
|
|
|
args.OtherEntity,
|
2022-12-20 15:54:56 -08:00
|
|
|
|
singularityGeneratorComponent.Power + component.State switch
|
2023-06-07 23:25:59 -07:00
|
|
|
|
{
|
|
|
|
|
|
ParticleAcceleratorPowerState.Standby => 0,
|
|
|
|
|
|
ParticleAcceleratorPowerState.Level0 => 1,
|
|
|
|
|
|
ParticleAcceleratorPowerState.Level1 => 2,
|
|
|
|
|
|
ParticleAcceleratorPowerState.Level2 => 4,
|
|
|
|
|
|
ParticleAcceleratorPowerState.Level3 => 8,
|
|
|
|
|
|
_ => 0
|
|
|
|
|
|
},
|
|
|
|
|
|
singularityGeneratorComponent
|
|
|
|
|
|
);
|
2022-08-05 00:22:37 -04:00
|
|
|
|
EntityManager.QueueDeleteEntity(uid);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2023-06-07 23:25:59 -07:00
|
|
|
|
#endregion Event Handlers
|
2022-08-05 00:22:37 -04:00
|
|
|
|
}
|