1
0

ConstructionPlacementHijack.cs 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. using System.Linq;
  2. using Content.Shared.Construction.Prototypes;
  3. using Robust.Client.Placement;
  4. using Robust.Client.Utility;
  5. using Robust.Shared.Map;
  6. namespace Content.Client.Construction
  7. {
  8. public sealed class ConstructionPlacementHijack : PlacementHijack
  9. {
  10. private readonly ConstructionSystem _constructionSystem;
  11. private readonly ConstructionPrototype? _prototype;
  12. public override bool CanRotate { get; }
  13. public ConstructionPlacementHijack(ConstructionSystem constructionSystem, ConstructionPrototype? prototype)
  14. {
  15. _constructionSystem = constructionSystem;
  16. _prototype = prototype;
  17. CanRotate = prototype?.CanRotate ?? true;
  18. }
  19. /// <inheritdoc />
  20. public override bool HijackPlacementRequest(EntityCoordinates coordinates)
  21. {
  22. if (_prototype != null)
  23. {
  24. var dir = Manager.Direction;
  25. _constructionSystem.SpawnGhost(_prototype, coordinates, dir);
  26. }
  27. return true;
  28. }
  29. /// <inheritdoc />
  30. public override bool HijackDeletion(EntityUid entity)
  31. {
  32. if (IoCManager.Resolve<IEntityManager>().HasComponent<ConstructionGhostComponent>(entity))
  33. {
  34. _constructionSystem.ClearGhost(entity.GetHashCode());
  35. }
  36. return true;
  37. }
  38. /// <inheritdoc />
  39. public override void StartHijack(PlacementManager manager)
  40. {
  41. base.StartHijack(manager);
  42. manager.CurrentTextures = _prototype?.Layers.Select(sprite => sprite.DirFrame0()).ToList();
  43. }
  44. }
  45. }