2022-07-09 13:46:11 +10:00
|
|
|
using Content.Server.Projectiles;
|
2021-06-09 22:19:39 +02:00
|
|
|
using Content.Server.Singularity.Components;
|
2022-12-24 23:28:21 -05:00
|
|
|
using Content.Shared.Projectiles;
|
2021-06-09 22:19:39 +02:00
|
|
|
using Content.Shared.Singularity.Components;
|
2022-09-14 17:26:26 +10:00
|
|
|
using Robust.Shared.Physics.Components;
|
2023-01-15 15:38:59 +11:00
|
|
|
using Robust.Shared.Physics.Systems;
|
2021-02-18 20:45:45 -08:00
|
|
|
using Robust.Shared.Timing;
|
2020-10-28 19:19:47 +01:00
|
|
|
|
2021-06-09 22:19:39 +02:00
|
|
|
namespace Content.Server.ParticleAccelerator.Components
|
2020-10-28 19:19:47 +01:00
|
|
|
{
|
|
|
|
|
[RegisterComponent]
|
2022-02-16 00:23:23 -07:00
|
|
|
public sealed class ParticleProjectileComponent : Component
|
2020-10-28 19:19:47 +01:00
|
|
|
{
|
2021-12-08 17:32:32 +01:00
|
|
|
[Dependency] private readonly IEntityManager _entMan = default!;
|
|
|
|
|
|
2021-07-21 22:26:18 +10:00
|
|
|
public ParticleAcceleratorPowerState State;
|
2020-10-28 19:19:47 +01:00
|
|
|
|
2021-12-05 18:09:01 +01:00
|
|
|
public void Fire(ParticleAcceleratorPowerState state, Angle angle, EntityUid firer)
|
2020-10-28 19:19:47 +01:00
|
|
|
{
|
2021-07-21 22:26:18 +10:00
|
|
|
State = state;
|
2020-10-28 19:19:47 +01:00
|
|
|
|
2023-01-15 15:38:59 +11:00
|
|
|
if (!_entMan.TryGetComponent<PhysicsComponent>(Owner, out var physicsComponent))
|
2020-10-28 19:19:47 +01:00
|
|
|
{
|
|
|
|
|
Logger.Error("ParticleProjectile tried firing, but it was spawned without a CollidableComponent");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2023-01-15 15:38:59 +11:00
|
|
|
var physics = _entMan.System<SharedPhysicsSystem>();
|
|
|
|
|
physics.SetBodyStatus(physicsComponent, BodyStatus.InAir);
|
|
|
|
|
|
|
|
|
|
if (!_entMan.TryGetComponent<ProjectileComponent>(Owner, out var projectileComponent))
|
2020-10-28 19:19:47 +01:00
|
|
|
{
|
|
|
|
|
Logger.Error("ParticleProjectile tried firing, but it was spawned without a ProjectileComponent");
|
|
|
|
|
return;
|
|
|
|
|
}
|
2022-07-09 13:46:11 +10:00
|
|
|
|
|
|
|
|
_entMan.EntitySysManager.GetEntitySystem<ProjectileSystem>().SetShooter(projectileComponent, firer);
|
2020-10-28 19:19:47 +01:00
|
|
|
|
2023-01-15 15:38:59 +11:00
|
|
|
if (!_entMan.TryGetComponent<SinguloFoodComponent>(Owner, out var singuloFoodComponent))
|
2021-05-28 10:44:13 +01:00
|
|
|
{
|
|
|
|
|
Logger.Error("ParticleProjectile tried firing, but it was spawned without a SinguloFoodComponent");
|
|
|
|
|
return;
|
|
|
|
|
}
|
2021-07-21 22:26:18 +10:00
|
|
|
var multiplier = State switch
|
2021-05-28 10:44:13 +01:00
|
|
|
{
|
|
|
|
|
ParticleAcceleratorPowerState.Standby => 0,
|
|
|
|
|
ParticleAcceleratorPowerState.Level0 => 1,
|
|
|
|
|
ParticleAcceleratorPowerState.Level1 => 3,
|
|
|
|
|
ParticleAcceleratorPowerState.Level2 => 6,
|
|
|
|
|
ParticleAcceleratorPowerState.Level3 => 10,
|
|
|
|
|
_ => 0
|
|
|
|
|
};
|
|
|
|
|
singuloFoodComponent.Energy = 10 * multiplier;
|
|
|
|
|
|
2022-07-27 04:22:49 +12:00
|
|
|
if (_entMan.TryGetComponent(Owner, out AppearanceComponent? appearance))
|
2020-10-28 19:19:47 +01:00
|
|
|
{
|
2022-07-27 04:22:49 +12:00
|
|
|
appearance.SetData(ParticleAcceleratorVisuals.VisualState, state);
|
2020-10-28 19:19:47 +01:00
|
|
|
}
|
|
|
|
|
|
2023-01-15 15:38:59 +11:00
|
|
|
physics.SetLinearVelocity(Owner, angle.ToWorldVec() * 20f, body: physicsComponent);
|
2020-10-28 19:19:47 +01:00
|
|
|
|
2021-12-08 17:32:32 +01:00
|
|
|
_entMan.GetComponent<TransformComponent>(Owner).LocalRotation = angle;
|
|
|
|
|
Timer.Spawn(3000, () => _entMan.DeleteEntity(Owner));
|
2020-10-28 19:19:47 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|