GatherableSystem.Projectile.cs 923 B

123456789101112131415161718192021222324252627282930
  1. using Content.Server.Gatherable.Components;
  2. using Content.Shared.Projectiles;
  3. using Robust.Shared.Physics.Events;
  4. namespace Content.Server.Gatherable;
  5. public sealed partial class GatherableSystem
  6. {
  7. private void InitializeProjectile()
  8. {
  9. SubscribeLocalEvent<GatheringProjectileComponent, StartCollideEvent>(OnProjectileCollide);
  10. }
  11. private void OnProjectileCollide(Entity<GatheringProjectileComponent> gathering, ref StartCollideEvent args)
  12. {
  13. if (!args.OtherFixture.Hard ||
  14. args.OurFixtureId != SharedProjectileSystem.ProjectileFixture ||
  15. gathering.Comp.Amount <= 0 ||
  16. !TryComp<GatherableComponent>(args.OtherEntity, out var gatherable))
  17. {
  18. return;
  19. }
  20. Gather(args.OtherEntity, gathering, gatherable);
  21. gathering.Comp.Amount--;
  22. if (gathering.Comp.Amount <= 0)
  23. QueueDel(gathering);
  24. }
  25. }