forked from space-syndicate/space-station-14
-
Notifications
You must be signed in to change notification settings - Fork 43
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
40950f3
commit c47fb5f
Showing
5 changed files
with
90 additions
and
12 deletions.
There are no files selected for viewing
11 changes: 11 additions & 0 deletions
11
Content.Server/_CorvaxNext/Teleporter/SyndicateTeleporterComponent.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
namespace Content.Server._CorvaxNext.Teleporter; | ||
|
||
[RegisterComponent] | ||
public sealed partial class SyndicateTeleporterComponent : Component | ||
{ | ||
[DataField] | ||
public float TeleportationRangeStart = 4; | ||
|
||
[DataField] | ||
public int TeleportationRangeLength = 4; | ||
} |
73 changes: 73 additions & 0 deletions
73
Content.Server/_CorvaxNext/Teleporter/SyndicateTeleporterSystem.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
using Content.Shared.Body.Systems; | ||
using Content.Shared.Coordinates.Helpers; | ||
using Content.Shared.Interaction.Events; | ||
using Content.Shared.Maps; | ||
using Content.Shared.Physics; | ||
using Content.Shared.Random.Helpers; | ||
using Robust.Shared.Map; | ||
using Robust.Shared.Prototypes; | ||
using Robust.Shared.Random; | ||
|
||
namespace Content.Server._CorvaxNext.Teleporter; | ||
|
||
public sealed class SyndicateTeleporterSystem : EntitySystem | ||
{ | ||
[Dependency] private readonly SharedTransformSystem _transform = default!; | ||
[Dependency] private readonly IMapManager _map = default!; | ||
[Dependency] private readonly TurfSystem _turf = default!; | ||
[Dependency] private readonly SharedBodySystem _body = default!; | ||
[Dependency] private readonly IRobustRandom _random = default!; | ||
|
||
[ValidatePrototypeId<EntityPrototype>] | ||
private const string TeleportEffectPrototype = "TeleportEffect"; | ||
|
||
public override void Initialize() | ||
{ | ||
SubscribeLocalEvent<SyndicateTeleporterComponent, UseInHandEvent>(OnUseInHand); | ||
} | ||
|
||
private void OnUseInHand(EntityUid entity, SyndicateTeleporterComponent teleproter, UseInHandEvent e) | ||
{ | ||
if (e.Handled) | ||
return; | ||
|
||
var transform = Transform(e.User); | ||
|
||
var direction = transform.LocalRotation.ToWorldVec().Normalized(); | ||
|
||
List<EntityCoordinates> safeCoordinates = []; | ||
|
||
for (var i = 0; i <= teleproter.TeleportationRangeLength; i++) | ||
{ | ||
var offset = (teleproter.TeleportationRangeStart + i) * direction; | ||
|
||
var coordinates = transform.Coordinates.Offset(offset).SnapToGrid(EntityManager, _map); | ||
|
||
var tile = coordinates.GetTileRef(EntityManager, _map); | ||
|
||
if (tile is not null && _turf.IsTileBlocked(tile.Value, CollisionGroup.MobMask)) | ||
continue; | ||
|
||
safeCoordinates.Add(coordinates); | ||
} | ||
|
||
EntityCoordinates resultCoordinates; | ||
|
||
if (safeCoordinates.Count < 1) | ||
{ | ||
var offset = (teleproter.TeleportationRangeStart + _random.NextFloat(teleproter.TeleportationRangeLength)) * direction; | ||
|
||
resultCoordinates = transform.Coordinates.Offset(offset); | ||
} | ||
else | ||
resultCoordinates = _random.Pick(safeCoordinates); | ||
|
||
Spawn(TeleportEffectPrototype, transform.Coordinates); | ||
Spawn(TeleportEffectPrototype, resultCoordinates); | ||
|
||
_transform.SetCoordinates(e.User, resultCoordinates); | ||
|
||
if (safeCoordinates.Count < 1) | ||
_body.GibBody(e.User, true); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters