Skip to content

Commit

Permalink
Ready
Browse files Browse the repository at this point in the history
  • Loading branch information
FireNameFN committed Nov 10, 2024
1 parent 40950f3 commit c47fb5f
Show file tree
Hide file tree
Showing 5 changed files with 90 additions and 12 deletions.
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 Content.Server/_CorvaxNext/Teleporter/SyndicateTeleporterSystem.cs
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);
}
}
2 changes: 1 addition & 1 deletion Resources/Prototypes/Catalog/uplink_catalog.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2110,7 +2110,7 @@
id: UplinkTeleporter
name: uplink-syndicate-teleporter-name
description: uplink-syndicate-teleporter-desc
icon: { sprite: Objects/Devices/syndicate_teleporter.rsi, state: icon}
icon: { sprite: _CorvaxNext/Objects/Devices/syndicate_teleporter.rsi, state: icon }
productEntity: SyndicateTeleporter
cost:
Telecrystal: 12
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
- type: entity
id: TeleportEffect
noSpawn: true
categories: [ HideSpawnMenu ]
components:
- type: TimedDespawn
lifetime: 0.4
Expand All @@ -10,13 +10,13 @@
layers:
- shader: unshaded
map: ["enum.EffectLayers.Unshaded"]
sprite: Effects/teleport_sparks.rsi
sprite: _CorvaxNext/Effects/teleport_sparks.rsi
state: sparks
- type: EffectVisuals
- type: Tag
tags:
- HideContextMenu
- type: EmitSoundOnSpawn
sound:
path: /Audio/Effects/electrical_short_circuit2.ogg
collection: ShortCircuit
- type: AnimationPlayer
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,12 @@
description: Personal syndicate teleporter.
components:
- type: Sprite
sprite: Objects/Devices/syndicate_teleporter.rsi
sprite: _CorvaxNext/Objects/Devices/syndicate_teleporter.rsi
state: icon
- type: Item
sprite: Objects/Devices/syndicate_teleporter.rsi
- type: SyndicateTeleporter
- type: UseDelay
delay: 0.5
- type: LimitedCharges
charges: 4
maxCharges: 4
- type: AutoRecharge
rechargeDuration: 10
delay: 60
- type: EmitSoundOnUse
sound:
collection: BrokenDevice
Expand Down

0 comments on commit c47fb5f

Please sign in to comment.