57 lines
1.9 KiB
C#
57 lines
1.9 KiB
C#
using Content.Server.Administration.Logs;
|
|
using Content.Server.Singularity.Components;
|
|
using Content.Server.Tesla.Components;
|
|
using Content.Shared.Database;
|
|
using Content.Shared.Singularity.Components;
|
|
using Content.Shared.Mind.Components;
|
|
using Content.Shared.Tag;
|
|
using Robust.Shared.Physics.Events;
|
|
using Content.Server.Lightning.Components;
|
|
using Robust.Server.Audio;
|
|
using Content.Server.Singularity.Events;
|
|
|
|
namespace Content.Server.Tesla.EntitySystems;
|
|
|
|
/// <summary>
|
|
/// A component that tracks an entity's saturation level from absorbing other creatures by touch, and spawns new entities when the saturation limit is reached.
|
|
/// </summary>
|
|
public sealed partial class TeslaEnergyBallSystem : EntitySystem // DeltaV - Change to partial
|
|
{
|
|
[Dependency] private readonly AudioSystem _audio = default!;
|
|
|
|
public override void Initialize()
|
|
{
|
|
base.Initialize();
|
|
|
|
SubscribeLocalEvent<TeslaEnergyBallComponent, EntityConsumedByEventHorizonEvent>(OnConsumed);
|
|
}
|
|
|
|
private void OnConsumed(Entity<TeslaEnergyBallComponent> tesla, ref EntityConsumedByEventHorizonEvent args)
|
|
{
|
|
Spawn(tesla.Comp.ConsumeEffectProto, Transform(args.Entity).Coordinates);
|
|
if (TryComp<SinguloFoodComponent>(args.Entity, out var singuloFood))
|
|
{
|
|
AdjustEnergy(tesla, tesla.Comp, singuloFood.Energy);
|
|
} else
|
|
{
|
|
AdjustEnergy(tesla, tesla.Comp, tesla.Comp.ConsumeStuffEnergy);
|
|
}
|
|
}
|
|
|
|
public void AdjustEnergy(EntityUid uid, TeslaEnergyBallComponent component, float delta)
|
|
{
|
|
component.Energy += delta;
|
|
|
|
if (component.Energy > component.NeedEnergyToSpawn)
|
|
{
|
|
component.Energy -= component.NeedEnergyToSpawn;
|
|
Spawn(component.SpawnProto, Transform(uid).Coordinates);
|
|
}
|
|
if (component.Energy < component.EnergyToDespawn)
|
|
{
|
|
_audio.PlayPvs(component.SoundCollapse, uid);
|
|
QueueDel(uid);
|
|
}
|
|
}
|
|
}
|