LogSystem.cs 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. using Content.Server.Botany.Components;
  2. using Content.Server.Kitchen.Components;
  3. using Content.Shared.Hands.EntitySystems;
  4. using Content.Shared.Interaction;
  5. using Content.Shared.Random;
  6. using Robust.Shared.Containers;
  7. namespace Content.Server.Botany.Systems;
  8. public sealed class LogSystem : EntitySystem
  9. {
  10. [Dependency] private readonly SharedHandsSystem _handsSystem = default!;
  11. [Dependency] private readonly SharedContainerSystem _containerSystem = default!;
  12. [Dependency] private readonly RandomHelperSystem _randomHelper = default!;
  13. public override void Initialize()
  14. {
  15. base.Initialize();
  16. SubscribeLocalEvent<LogComponent, InteractUsingEvent>(OnInteractUsing);
  17. }
  18. private void OnInteractUsing(EntityUid uid, LogComponent component, InteractUsingEvent args)
  19. {
  20. if (!HasComp<SharpComponent>(args.Used))
  21. return;
  22. // if in some container, try pick up, else just drop to world
  23. var inContainer = _containerSystem.IsEntityInContainer(uid);
  24. var pos = Transform(uid).Coordinates;
  25. for (var i = 0; i < component.SpawnCount; i++)
  26. {
  27. var plank = Spawn(component.SpawnedPrototype, pos);
  28. if (inContainer)
  29. _handsSystem.PickupOrDrop(args.User, plank);
  30. else
  31. {
  32. var xform = Transform(plank);
  33. _containerSystem.AttachParentToContainerOrGrid((plank, xform));
  34. xform.LocalRotation = 0;
  35. _randomHelper.RandomOffset(plank, 0.25f);
  36. }
  37. }
  38. QueueDel(uid);
  39. args.Handled = true;
  40. }
  41. }