ParticleAcceleratorSystem.Emitter.cs 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. using Content.Server.ParticleAccelerator.Components;
  2. using Content.Server.Singularity.Components;
  3. using Content.Shared.Projectiles;
  4. using Content.Shared.Singularity.Components;
  5. using Robust.Shared.Physics.Components;
  6. namespace Content.Server.ParticleAccelerator.EntitySystems;
  7. public sealed partial class ParticleAcceleratorSystem
  8. {
  9. private void FireEmitter(EntityUid uid, ParticleAcceleratorPowerState strength, ParticleAcceleratorEmitterComponent? emitter = null)
  10. {
  11. if (!Resolve(uid, ref emitter))
  12. return;
  13. var xformQuery = GetEntityQuery<TransformComponent>();
  14. if (!xformQuery.TryGetComponent(uid, out var xform))
  15. {
  16. Log.Error("ParticleAccelerator attempted to emit a particle without (having) a transform from which to base its initial position and orientation.");
  17. return;
  18. }
  19. var emitted = Spawn(emitter.EmittedPrototype, xform.Coordinates);
  20. if (xformQuery.TryGetComponent(emitted, out var particleXform))
  21. _transformSystem.SetLocalRotation(emitted, xform.LocalRotation, particleXform);
  22. if (TryComp<PhysicsComponent>(emitted, out var particlePhys))
  23. {
  24. var angle = _transformSystem.GetWorldRotation(uid, xformQuery);
  25. _physicsSystem.SetBodyStatus(emitted, particlePhys, BodyStatus.InAir);
  26. var velocity = angle.ToWorldVec() * 20f;
  27. if (TryComp<PhysicsComponent>(uid, out var phys))
  28. velocity += phys.LinearVelocity; // Inherit velocity from parent so if the clown has strapped a dozen engines to departures we don't outpace the particles.
  29. _physicsSystem.SetLinearVelocity(emitted, velocity, body: particlePhys);
  30. }
  31. if (TryComp<ProjectileComponent>(emitted, out var proj))
  32. _projectileSystem.SetShooter(emitted, proj, uid);
  33. if (TryComp<SinguloFoodComponent>(emitted, out var food))
  34. {
  35. // TODO: Unhardcode this.
  36. food.Energy = strength switch
  37. {
  38. ParticleAcceleratorPowerState.Standby => 0,
  39. ParticleAcceleratorPowerState.Level0 => 1,
  40. ParticleAcceleratorPowerState.Level1 => 2,
  41. ParticleAcceleratorPowerState.Level2 => 3,
  42. ParticleAcceleratorPowerState.Level3 => 6,
  43. _ => 0,
  44. } * 10;
  45. }
  46. if (TryComp<ParticleProjectileComponent>(emitted, out var particle))
  47. particle.State = strength;
  48. _appearanceSystem.SetData(emitted, ParticleAcceleratorVisuals.VisualState, strength);
  49. }
  50. }