Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

teleporter-WWDP #969

Merged
merged 12 commits into from
Dec 13, 2024
Merged
Show file tree
Hide file tree
Changes from 11 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
using Robust.Shared.Audio;

namespace Content.Server._White.Teleporter;

[RegisterComponent]
public sealed partial class ExperimentalTeleporterComponent : Component
{
[DataField]
public int MinTeleportRange = 3;

[DataField]
public int MaxTeleportRange = 8;

[DataField]
public int EmergencyLength = 4;

[DataField]
public List<int> RandomRotations = new() {90, -90};

[DataField]
public string? TeleportInEffect = "ExperimentalTeleporterInEffect";

[DataField]
public string? TeleportOutEffect = "ExperimentalTeleporterOutEffect";

[DataField]
public SoundSpecifier TeleportSound = new SoundPathSpecifier("/Audio/Backmen/Object/Devices/experimentalsyndicateteleport.ogg");
}
116 changes: 116 additions & 0 deletions Content.Server/Backmen/Teleporter/ExperimentalTeleporterSystem.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
using System.Linq;
using System.Numerics;
using Content.Server.Body.Systems;
using Content.Server.Standing;
using Content.Shared.Backmen.Standing;
using Content.Shared.Charges.Systems;
using Content.Shared.Coordinates.Helpers;
using Content.Shared.Interaction.Events;
using Content.Shared.Maps;
using Content.Shared.Tag;
using Robust.Server.Audio;
using Robust.Server.Containers;
using Robust.Server.GameObjects;
using Robust.Shared.Map;
using Robust.Shared.Map.Components;
using Robust.Shared.Random;

namespace Content.Server._White.Teleporter;
Comment on lines +2 to +19
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Добавьте отсутствующий импорт и исправьте пространство имён

  1. Отсутствует импорт для GhostComponent
  2. Пространство имён Content.Server._White.Teleporter не соответствует структуре остальных файлов в Backmen

Предлагаемые изменения:

+ using Content.Shared.Ghost;
- namespace Content.Server._White.Teleporter;
+ namespace Content.Server.Backmen.Teleporter;
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
using System.Linq;
using System.Numerics;
using Content.Server.Body.Systems;
using Content.Server.Standing;
using Content.Shared.Backmen.Standing;
using Content.Shared.Charges.Systems;
using Content.Shared.Coordinates.Helpers;
using Content.Shared.Interaction.Events;
using Content.Shared.Maps;
using Content.Shared.Tag;
using Robust.Server.Audio;
using Robust.Server.Containers;
using Robust.Server.GameObjects;
using Robust.Shared.Map;
using Robust.Shared.Map.Components;
using Robust.Shared.Random;
namespace Content.Server._White.Teleporter;
using System.Linq;
using System.Numerics;
using Content.Server.Body.Systems;
using Content.Server.Standing;
using Content.Shared.Backmen.Standing;
using Content.Shared.Charges.Systems;
using Content.Shared.Coordinates.Helpers;
using Content.Shared.Ghost;
using Content.Shared.Interaction.Events;
using Content.Shared.Maps;
using Content.Shared.Tag;
using Robust.Server.Audio;
using Robust.Server.Containers;
using Robust.Server.GameObjects;
using Robust.Shared.Map;
using Robust.Shared.Map.Components;
using Robust.Shared.Random;
namespace Content.Server.Backmen.Teleporter;


public sealed class ExperimentalTeleporterSystem : EntitySystem
{
[Dependency] private readonly TransformSystem _transform = default!;
[Dependency] private readonly BodySystem _bodySystem = default!;
[Dependency] private readonly MapSystem _mapSystem = default!;
[Dependency] private readonly IEntityManager _entManager = default!;
[Dependency] private readonly AudioSystem _audio = default!;
[Dependency] private readonly ContainerSystem _containerSystem = default!;
[Dependency] private readonly IRobustRandom _random = default!;
[Dependency] private readonly SharedLayingDownSystem _layingDown = default!;
[Dependency] private readonly SharedChargesSystem _charges = default!;
[Dependency] private readonly TagSystem _tag = default!;

public override void Initialize()
{
base.Initialize();
SubscribeLocalEvent<ExperimentalTeleporterComponent, UseInHandEvent>(OnUse);
}

private void OnUse(EntityUid uid, ExperimentalTeleporterComponent component, UseInHandEvent args)
{
if (_charges.IsEmpty(uid)
|| !TryComp<TransformComponent>(args.User, out var xform)
|| (_containerSystem.IsEntityInContainer(args.User)
&& !_containerSystem.TryRemoveFromContainer(args.User)))
return;

var oldCoords = xform.Coordinates;
var range = _random.Next(component.MinTeleportRange, component.MaxTeleportRange);
var offset = xform.LocalRotation.ToWorldVec().Normalized();
var direction = xform.LocalRotation.GetDir().ToVec();
var newOffset = offset + direction * range;

var coords = xform.Coordinates.Offset(newOffset).SnapToGrid(EntityManager);

Teleport(args.User, uid, component, coords, oldCoords);

if (!TryCheckWall(coords)
|| EmergencyTeleportation(args.User, uid, component, xform, oldCoords, newOffset)
|| HasComp<GhostComponent>(args.User))

Check failure on line 59 in Content.Server/Backmen/Teleporter/ExperimentalTeleporterSystem.cs

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest)

The type or namespace name 'GhostComponent' could not be found (are you missing a using directive or an assembly reference?)

Check failure on line 59 in Content.Server/Backmen/Teleporter/ExperimentalTeleporterSystem.cs

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest)

The type or namespace name 'GhostComponent' could not be found (are you missing a using directive or an assembly reference?)

Check failure on line 59 in Content.Server/Backmen/Teleporter/ExperimentalTeleporterSystem.cs

View workflow job for this annotation

GitHub Actions / YAML Linter

The type or namespace name 'GhostComponent' could not be found (are you missing a using directive or an assembly reference?)

Check failure on line 59 in Content.Server/Backmen/Teleporter/ExperimentalTeleporterSystem.cs

View workflow job for this annotation

GitHub Actions / YAML Linter

The type or namespace name 'GhostComponent' could not be found (are you missing a using directive or an assembly reference?)

Check failure on line 59 in Content.Server/Backmen/Teleporter/ExperimentalTeleporterSystem.cs

View workflow job for this annotation

GitHub Actions / Test Packaging

The type or namespace name 'GhostComponent' could not be found (are you missing a using directive or an assembly reference?)

Check failure on line 59 in Content.Server/Backmen/Teleporter/ExperimentalTeleporterSystem.cs

View workflow job for this annotation

GitHub Actions / Test Packaging

The type or namespace name 'GhostComponent' could not be found (are you missing a using directive or an assembly reference?)

Check failure on line 59 in Content.Server/Backmen/Teleporter/ExperimentalTeleporterSystem.cs

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest)

The type or namespace name 'GhostComponent' could not be found (are you missing a using directive or an assembly reference?)

Check failure on line 59 in Content.Server/Backmen/Teleporter/ExperimentalTeleporterSystem.cs

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest)

The type or namespace name 'GhostComponent' could not be found (are you missing a using directive or an assembly reference?)
return;

_bodySystem.GibBody(args.User, true, splatModifier: 3F);
}

private bool EmergencyTeleportation(EntityUid uid, EntityUid teleporterUid, ExperimentalTeleporterComponent component, TransformComponent xform, EntityCoordinates oldCoords, Vector2 offset)
{
var newOffset = offset + VectorRandomDirection(component, offset, component.EmergencyLength);
var coords = xform.Coordinates.Offset(newOffset).SnapToGrid(EntityManager);

if (_charges.IsEmpty(teleporterUid))
return false;

Teleport(uid, teleporterUid, component, coords, oldCoords);

return !TryCheckWall(coords);
}
Comment on lines +66 to +77
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Предотвратите возможность бесконечной рекурсии

Метод EmergencyTeleportation может вызвать бесконечную рекурсию через Teleport, который может снова вызвать EmergencyTeleportation. Рекомендуется:

  1. Добавить максимальное количество попыток телепортации
  2. Передавать счётчик попыток через параметры
  3. Добавить проверку на максимальное количество попыток

Предлагаемые изменения:

+ private const int MaxEmergencyAttempts = 3;

- private bool EmergencyTeleportation(EntityUid uid, EntityUid teleporterUid, ExperimentalTeleporterComponent component, TransformComponent xform, EntityCoordinates oldCoords, Vector2 offset)
+ private bool EmergencyTeleportation(EntityUid uid, EntityUid teleporterUid, ExperimentalTeleporterComponent component, TransformComponent xform, EntityCoordinates oldCoords, Vector2 offset, int attempts = 0)
 {
+    if (attempts >= MaxEmergencyAttempts)
+        return false;
+
     var newOffset = offset + VectorRandomDirection(component, offset, component.EmergencyLength);
     // ... rest of the method
 }

Committable suggestion skipped: line range outside the PR's diff.


private void Teleport(EntityUid uid, EntityUid teleporterUid, ExperimentalTeleporterComponent component, EntityCoordinates coords, EntityCoordinates oldCoords)
{
PlaySoundAndEffects(component, coords, oldCoords);

_layingDown.LieDownInRange(uid, coords);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Исправьте ошибку: метод 'LieDownInRange' отсутствует в 'LayingDownSystem'

Статический анализ выявил, что метод LieDownInRange не определён в LayingDownSystem. Проверьте правильность вызова метода или замените его на существующий метод для укладывания персонажа.

🧰 Tools
🪛 GitHub Check: YAML Linter

[failure] 80-80:
'LayingDownSystem' does not contain a definition for 'LieDownInRange' and no accessible extension method 'LieDownInRange' accepting a first argument of type 'LayingDownSystem' could be found (are you missing a using directive or an assembly reference?)


[failure] 80-80:
'LayingDownSystem' does not contain a definition for 'LieDownInRange' and no accessible extension method 'LieDownInRange' accepting a first argument of type 'LayingDownSystem' could be found (are you missing a using directive or an assembly reference?)

🪛 GitHub Check: build (ubuntu-latest)

[failure] 80-80:
'LayingDownSystem' does not contain a definition for 'LieDownInRange' and no accessible extension method 'LieDownInRange' accepting a first argument of type 'LayingDownSystem' could be found (are you missing a using directive or an assembly reference?)


[failure] 80-80:
'LayingDownSystem' does not contain a definition for 'LieDownInRange' and no accessible extension method 'LieDownInRange' accepting a first argument of type 'LayingDownSystem' could be found (are you missing a using directive or an assembly reference?)

🪛 GitHub Check: Test Packaging

[failure] 80-80:
'LayingDownSystem' does not contain a definition for 'LieDownInRange' and no accessible extension method 'LieDownInRange' accepting a first argument of type 'LayingDownSystem' could be found (are you missing a using directive or an assembly reference?)


[failure] 80-80:
'LayingDownSystem' does not contain a definition for 'LieDownInRange' and no accessible extension method 'LieDownInRange' accepting a first argument of type 'LayingDownSystem' could be found (are you missing a using directive or an assembly reference?)

_transform.SetCoordinates(uid, coords);

_charges.UseCharge(teleporterUid);
}

private void PlaySoundAndEffects(ExperimentalTeleporterComponent component, EntityCoordinates coords, EntityCoordinates oldCoords)
{
_audio.PlayPvs(component.TeleportSound, coords);
_audio.PlayPvs(component.TeleportSound, oldCoords);

_entManager.SpawnEntity(component.TeleportInEffect, coords);
_entManager.SpawnEntity(component.TeleportOutEffect, oldCoords);
}

private bool TryCheckWall(EntityCoordinates coords)
{
if (!coords.TryGetTileRef(out var tile)
|| !TryComp<MapGridComponent>(tile.Value.GridUid, out var mapGridComponent))
return false;

var anchoredEntities = _mapSystem.GetAnchoredEntities(tile.Value.GridUid, mapGridComponent, coords);

return anchoredEntities.Any(x => _tag.HasTag(x, "Wall"));
}

private Vector2 VectorRandomDirection(ExperimentalTeleporterComponent component, Vector2 offset, int length)
{
if (component.RandomRotations.Count == 0)
return Vector2.Zero;

var randomRotation = _random.Next(0, component.RandomRotations.Count);
return Angle.FromDegrees(component.RandomRotations[randomRotation]).RotateVec(offset.Normalized() * length);
}
}
15 changes: 15 additions & 0 deletions Content.Shared/Backmen/Standing/SharedLayingDownSystem.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Diagnostics.CodeAnalysis;
using System.Linq;
using Content.Shared.Backmen.CCVar;
using Content.Shared.Backmen.Targeting;
using Content.Shared.Body.Components;
Expand Down Expand Up @@ -27,6 +28,7 @@
using Robust.Shared.Configuration;
using Robust.Shared.Containers;
using Robust.Shared.Input.Binding;
using Robust.Shared.Map;
using Robust.Shared.Map.Components;
using Robust.Shared.Network;
using Robust.Shared.Physics;
Expand Down Expand Up @@ -55,6 +57,7 @@ public abstract class SharedLayingDownSystem : EntitySystem
[Dependency] private readonly DamageableSystem _damageable = default!;
[Dependency] private readonly SharedAudioSystem _audioSystem = default!;
[Dependency] private readonly IGameTiming _timing = default!;
[Dependency] private readonly EntityLookupSystem _lookup = default!;

[Dependency] private readonly IConfigurationManager _config = default!;

Expand Down Expand Up @@ -356,6 +359,18 @@ standingState.CurrentState is not StandingState.Standing ||
_standing.Down(uid, true, behavior != DropHeldItemsBehavior.NoDrop, standingState: standingState);
return true;
}

// WWDP
public void LieDownInRange(EntityUid uid, EntityCoordinates coords, float range = 0.4f)
KayzelW marked this conversation as resolved.
Show resolved Hide resolved
{
var ents = new HashSet<Entity<LayingDownComponent>>();
_lookup.GetEntitiesInRange(coords, range, ents);

foreach (var ent in ents.Where(ent => ent.Owner != uid))
{
TryLieDown(ent, behavior: DropHeldItemsBehavior.DropIfStanding);
}
}
Comment on lines +363 to +373
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Требуются улучшения в методе LieDownInRange

Рекомендуемые изменения для повышения надежности и производительности:

  1. Добавить проверку на null для сервиса _lookup
  2. Добавить валидацию параметра range (должен быть положительным)
  3. Рассмотреть возможность использования пула объектов для HashSet
 public void LieDownInRange(EntityUid uid, EntityCoordinates coords, float range = 0.4f)
 {
+    if (range <= 0)
+        return;
+
+    if (!Resolve(uid, ref _lookup))
+        return;
+
     var ents = new HashSet<Entity<LayingDownComponent>>();
     _lookup.GetEntitiesInRange(coords, range, ents);

     foreach (var ent in ents.Where(ent => ent.Owner != uid))
     {
         TryLieDown(ent, behavior: DropHeldItemsBehavior.DropIfStanding);
     }
 }

Committable suggestion skipped: line range outside the PR's diff.

🧰 Tools
🪛 GitHub Check: build (ubuntu-latest)

[failure] 361-361:
The type or namespace name 'EntityCoordinates' could not be found (are you missing a using directive or an assembly reference?)


[failure] 361-361:
The type or namespace name 'EntityCoordinates' could not be found (are you missing a using directive or an assembly reference?)

🪛 GitHub Check: YAML Linter

[failure] 361-361:
The type or namespace name 'EntityCoordinates' could not be found (are you missing a using directive or an assembly reference?)


[failure] 361-361:
The type or namespace name 'EntityCoordinates' could not be found (are you missing a using directive or an assembly reference?)

🪛 GitHub Check: Test Packaging

[failure] 361-361:
The type or namespace name 'EntityCoordinates' could not be found (are you missing a using directive or an assembly reference?)


[failure] 361-361:
The type or namespace name 'EntityCoordinates' could not be found (are you missing a using directive or an assembly reference?)

}

[Serializable, NetSerializable]
Expand Down
4 changes: 4 additions & 0 deletions Resources/Audio/Backmen/Object/Devices/attributions.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
- files: ["experimentalsyndicateteleport.ogg"]
license: "CC-BY-NC-SA-4.0"
copyright: "Taken from White Dream"
source: "https://github.com/frosty-dev/ss14-core/blob/master/Resources/Audio/White/Devices/expsyndicateteleport.ogg"
Comment on lines +1 to +4
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codebase verification

Источник звукового файла недоступен!

Ссылка на исходный файл возвращает ошибку 404, что указывает на его отсутствие в указанном репозитории. Необходимо:

  • Обновить ссылку на актуальный источник файла
  • Убедиться, что использование файла соответствует условиям лицензии CC-BY-NC-SA-4.0
  • Рассмотреть возможность поиска файла в архивных версиях репозитория или связаться с авторами White Dream для получения корректной ссылки
🔗 Analysis chain

Проверить доступность источника звукового файла!

Атрибуция корректно указана, но необходимо убедиться в актуальности ссылки на исходный файл и соответствии условиям лицензии CC-BY-NC-SA-4.0.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify source file availability and license compliance

# Check if source URL is accessible
curl -I "https://github.com/frosty-dev/ss14-core/blob/master/Resources/Audio/White/Devices/expsyndicateteleport.ogg"

# Verify local file exists
fd "experimentalsyndicateteleport.ogg" Resources/Audio/Backmen/Object/Devices/

Length of output: 5069

🧰 Tools
🪛 yamllint (1.35.1)

[error] 4-4: no new line character at the end of file

(new-line-at-end-of-file)

Binary file not shown.
3 changes: 3 additions & 0 deletions Resources/Locale/en-US/_backmen/store/uplink-catalog.ftl
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
uplink-betrayal-knife-name = Experimental syndicate teleporter
uplink-betrayal-knife-desc = Syndicate teleporter, when used, moves 3-8 meters forward. In case of teleportation into a wall, uses emergency teleportation. Has 4 charge.

Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
ent-ExperimentalSyndicateTeleporter = экспериментальный телепортер синдиката
.desc = Телепортер синдиката, при использовании перемещает на 3-8 метров вперед. В случае телепортации в стену, использует экстренную телепортацию. Имеет 4 заряда и автоматически заряжается.
3 changes: 3 additions & 0 deletions Resources/Locale/ru-RU/_backmen/store/uplink-catalog.ftl
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
uplink-experimental-syndicate-teleporter-name = Экспериментальный телепортер синдиката
uplink-experimental-syndicate-teleporter-desc = Телепортер синдиката, при использовании перемещает на 3-8 метров вперед. В случае телепортации в стену, использует экстренную телепортацию. Имеет 4 заряда и автоматически заряжается.

9 changes: 9 additions & 0 deletions Resources/Prototypes/_Backmen/Catalog/uplink_catalog.yml
Original file line number Diff line number Diff line change
Expand Up @@ -164,3 +164,12 @@
categories:
- UplinkPointless

- type: listing
id: UplinkExperimentalSyndicateTeleporter
name: uplink-experimental-syndicate-teleporter-name
description: uplink-experimental-syndicate-teleporter-desc
productEntity: ExperimentalSyndicateTeleporter
cost:
Telecrystal: 10
categories:
- UplinkDeception
39 changes: 39 additions & 0 deletions Resources/Prototypes/_Backmen/Entities/Effects/effects.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
- type: entity
id: ExperimentalTeleporterInEffect
name: experimental syndicate teleporter in effect
components:
- type: TimedDespawn
lifetime: 0.6
- type: EvaporationSparkle
- type: Transform
noRot: true
anchored: true
- type: Sprite
layers:
- sprite: /Textures/Backmen/Objects/Devices/experimentalsyndicateteleporter.rsi
state: in
shader: unshaded
netsync: false
drawdepth: Effects
- type: PointLight
color: "#008DFE"

- type: entity
id: ExperimentalTeleporterOutEffect
name: experimental syndicate teleporter out effect
components:
- type: TimedDespawn
lifetime: 0.6
- type: EvaporationSparkle
- type: Transform
noRot: true
anchored: true
- type: Sprite
layers:
- sprite: /Textures/Backmen/Objects/Devices/experimentalsyndicateteleporter.rsi
state: out
shader: unshaded
netsync: false
drawdepth: Effects
- type: PointLight
color: "#008DFE"
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
- type: entity
id: ExperimentalSyndicateTeleporter
parent: BaseItem
name: experimental syndicate teleporter
description: Syndicate teleporter, when used, moves 3-8 meters forward. In case of teleportation into a wall, uses emergency teleportation. Has 4 charge.
components:
- type: Sprite
sprite: /Textures/Backmen/Objects/Devices/experimentalsyndicateteleporter.rsi
layers:
- state: icon
- type: ExperimentalTeleporter
- type: LimitedCharges
maxCharges: 4
charges: 4
- type: AutoRecharge
rechargeDuration: 10
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Loading