From 5e29678befa63eae079bef606dddd573d5ffc58f Mon Sep 17 00:00:00 2001 From: pxc1984 Date: Sun, 7 Jul 2024 17:16:47 +0300 Subject: [PATCH 1/3] =?UTF-8?q?=D0=94=D0=BE=D0=B1=D0=B0=D0=B2=D0=B8=D0=BB?= =?UTF-8?q?=20=D0=B0=D0=B2=D1=82=D0=BE=D0=BA=D1=80=D0=B8=D0=BE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: JDtrimble --- .../CryoTeleport/CryoTeleportSystem.cs | 200 ++++++++++++++++++ .../CryoTeleportTargetComponent.cs | 14 ++ .../StationCryoTeleportComponent.cs | 20 ++ .../_sunrise/cryoteleport/cryoteleport.ftl | 2 + .../_Sunrise/CryoTeleport/portal.yml | 31 +++ 5 files changed, 267 insertions(+) create mode 100644 Content.Server/_Sunrise/CryoTeleport/CryoTeleportSystem.cs create mode 100644 Content.Server/_Sunrise/CryoTeleport/CryoTeleportTargetComponent.cs create mode 100644 Content.Server/_Sunrise/CryoTeleport/StationCryoTeleportComponent.cs create mode 100644 Resources/Locale/ru-RU/_sunrise/cryoteleport/cryoteleport.ftl create mode 100644 Resources/Prototypes/_Sunrise/CryoTeleport/portal.yml diff --git a/Content.Server/_Sunrise/CryoTeleport/CryoTeleportSystem.cs b/Content.Server/_Sunrise/CryoTeleport/CryoTeleportSystem.cs new file mode 100644 index 00000000000..0b0bac11efb --- /dev/null +++ b/Content.Server/_Sunrise/CryoTeleport/CryoTeleportSystem.cs @@ -0,0 +1,200 @@ +using System.Globalization; +using Content.Server.Bed.Cryostorage; +using Content.Server.Body.Components; +using Content.Server.Chat.Systems; +using Content.Server.Database; +using Content.Server.GameTicking; +using Content.Server.Objectives.Components; +using Content.Server.Station.Components; +using Content.Server.Station.Systems; +using Content.Server.StationRecords; +using Content.Server.StationRecords.Systems; +using Content.Shared.Bed.Cryostorage; +using Content.Shared.Mind; +using Content.Shared.Mobs; +using Content.Shared.Objectives.Systems; +using Content.Shared.StationRecords; +using FastAccessors; +using Robust.Shared.Audio.Systems; +using Robust.Shared.Player; +using Robust.Shared.Timing; + +namespace Content.Server._Sunrise.CryoTeleport; + +/// +/// This handles... +/// +public sealed class CryoTeleportSystem : EntitySystem +{ + [Dependency] private readonly StationSystem _station = default!; + [Dependency] private readonly StationJobsSystem _stationJobs = default!; + [Dependency] private readonly CryostorageSystem _cryostorage = default!; + [Dependency] private readonly SharedObjectivesSystem _objectives = default!; + [Dependency] private readonly SharedMindSystem _mind = default!; + [Dependency] private readonly SharedAudioSystem _audio = default!; + [Dependency] private readonly ChatSystem _chat = default!; + [Dependency] private readonly StationRecordsSystem _stationRecords = default!; + [Dependency] private readonly IEntityManager _entity = default!; + [Dependency] private readonly IGameTiming _timing = default!; + + /// + public override void Initialize() + { + SubscribeLocalEvent(OnStationInitialized); + SubscribeLocalEvent(OnCompleteSpawn); + // SubscribeLocalEvent(OnGibbed); + SubscribeLocalEvent(OnPlayerDetached); + SubscribeLocalEvent(OnPlayerAttached); + } + + public override void Update(float delay) + { + var query = AllEntityQuery(); + while (query.MoveNext(out var uid, out var comp)) + { + // Log.Info($"uid: {uid}, comp: {comp.Station}"); + + if (comp.Station == null) + continue; + + if (!TryComp(comp.Station, out var stationCryoTeleportComponent)) + continue; + + if (comp.ExitTime == null) + continue; + + if (_timing.CurTime - comp.ExitTime >= stationCryoTeleportComponent.TransferDelay) + { + if (HasComp(uid)) + continue; + + var containedComp = AddComp(uid); + + containedComp.Cryostorage = FindCryo(comp.Station.Value, Transform(uid)); + containedComp.GracePeriodEndTime = _timing.CurTime; + + _mind.TryGetMind(uid, out var _, out var mindComponent); + + if (mindComponent == null) + continue; + + _entity.SpawnEntity(stationCryoTeleportComponent.PortalPrototype, Transform(uid).Coordinates); + _audio.PlayPvs(stationCryoTeleportComponent.TransferSound, Transform(uid).Coordinates); + + _cryostorage.HandleEnterCryostorage((uid, containedComp), mindComponent.UserId); + } + } + } + + private void OnStationInitialized(StationInitializedEvent ev) + { + // if (FindCryo(ev.Station, Transform(ev.Station)) == null) + // return; // Ни одного крио на станции + EnsureComp(ev.Station); + } + + private void OnCompleteSpawn(PlayerSpawnCompleteEvent ev) + { + if (!TryComp(ev.Station, out var cryoTeleportComponent)) + return; + if (ev.JobId == null) + return; + + if (ev.Player.AttachedEntity == null) + return; + + var cryoTeleportTargetComponent = EnsureComp(ev.Player.AttachedEntity.Value); + cryoTeleportTargetComponent.Station = ev.Station; + } + + private void OnPlayerDetached(EntityUid uid, CryoTeleportTargetComponent comp, PlayerDetachedEvent ev) + { + comp.ExitTime = _timing.CurTime; + } + + private void OnPlayerAttached(EntityUid uid, CryoTeleportTargetComponent comp, PlayerAttachedEvent ev) + { + comp.ExitTime = null; + } + + // private void OnGibbed(EntityUid uid, CryoTeleportTargetComponent comp, BeingGibbedEvent ev) + // { + // if (comp.Station == null) + // return; + // + // if (!TryComp(uid, out var entityXform)) + // return; + // + // if (!TryComp(comp.Station, out var stationCryoTeleportComponent)) + // return; + // + // // var stationJobsComponent = Comp(comp.Station.Value); + // _mind.TryGetMind(uid, out var mindId, out var mindComp); + // + // if (mindComp == null) + // { + // Log.Error($"mindComp null"); + // return; + // } + // + // if (mindComp.UserId == null) + // return; + // + // foreach (var uniqueStation in _station.GetStationsSet()) + // { + // if (!TryComp(uniqueStation, out var stationJobs)) + // continue; + // + // if (!_stationJobs.TryGetPlayerJobs(uniqueStation, mindComp.UserId.Value, out var jobs, stationJobs)) + // continue; + // + // foreach (var job in jobs) + // { + // _stationJobs.TryAdjustJobSlot(uniqueStation, job, 1, clamp: true); + // } + // + // _stationJobs.TryRemovePlayerJobs(uniqueStation, mindComp.UserId.Value, stationJobs); + // } + // + // if (!TryComp(comp.Station, out var stationRecords)) + // return; + // + // var jobName = Loc.GetString("earlyleave-cryo-job-unknown"); + // var recordId = _stationRecords.GetRecordByName(comp.Station.Value, Name(uid)); + // if (recordId != null) + // { + // var key = new StationRecordKey(recordId.Value, comp.Station.Value); + // if (_stationRecords.TryGetRecord(key, out var entry, stationRecords)) + // jobName = entry.JobTitle; + // + // _stationRecords.RemoveRecord(key, stationRecords); + // } + // + // _chat.DispatchStationAnnouncement(comp.Station.Value, + // Loc.GetString( + // "earlyleave-cryo-announcement", + // ("character", Name(uid)), + // ("job", CultureInfo.CurrentCulture.TextInfo.ToTitleCase(jobName)) + // ), + // Loc.GetString("earlyleave-cryo-sender"), + // playDefault: false + // ); + // } + + private EntityUid? FindCryo(EntityUid station, TransformComponent entityXform) + { + var query = AllEntityQuery(); + while (query.MoveNext(out var cryoUid, out var cryostorageComponent)) + { + if (!TryComp(cryoUid, out var cryoTransform)) + return null; + + if (entityXform.MapUid != cryoTransform.MapUid) + continue; + + return cryoUid; + } + + return null; + } +} diff --git a/Content.Server/_Sunrise/CryoTeleport/CryoTeleportTargetComponent.cs b/Content.Server/_Sunrise/CryoTeleport/CryoTeleportTargetComponent.cs new file mode 100644 index 00000000000..da45879c06b --- /dev/null +++ b/Content.Server/_Sunrise/CryoTeleport/CryoTeleportTargetComponent.cs @@ -0,0 +1,14 @@ +namespace Content.Server._Sunrise.CryoTeleport; + +/// +/// This is used for... +/// +[RegisterComponent] +public sealed partial class CryoTeleportTargetComponent : Component +{ + [DataField] + public EntityUid? Station; + + [DataField] + public TimeSpan? ExitTime; +} diff --git a/Content.Server/_Sunrise/CryoTeleport/StationCryoTeleportComponent.cs b/Content.Server/_Sunrise/CryoTeleport/StationCryoTeleportComponent.cs new file mode 100644 index 00000000000..4b4835876ed --- /dev/null +++ b/Content.Server/_Sunrise/CryoTeleport/StationCryoTeleportComponent.cs @@ -0,0 +1,20 @@ +using Robust.Shared.Audio; +using Robust.Shared.Network; + +namespace Content.Server._Sunrise.CryoTeleport; + +/// +/// This is used for... +/// +[RegisterComponent] +public sealed partial class StationCryoTeleportComponent : Component +{ + [DataField] + public TimeSpan TransferDelay = TimeSpan.FromSeconds(10); // TODO: debug + + [DataField] + public string PortalPrototype = "PortalCryo"; + + [DataField] + public SoundSpecifier TransferSound = new SoundPathSpecifier("/Audio/Effects/teleport_departure.ogg"); +} diff --git a/Resources/Locale/ru-RU/_sunrise/cryoteleport/cryoteleport.ftl b/Resources/Locale/ru-RU/_sunrise/cryoteleport/cryoteleport.ftl new file mode 100644 index 00000000000..a45aef3cfcb --- /dev/null +++ b/Resources/Locale/ru-RU/_sunrise/cryoteleport/cryoteleport.ftl @@ -0,0 +1,2 @@ +ent-PortalCryo = { ent-BasePortal } + .desc = { ent-BasePortal.desc } diff --git a/Resources/Prototypes/_Sunrise/CryoTeleport/portal.yml b/Resources/Prototypes/_Sunrise/CryoTeleport/portal.yml new file mode 100644 index 00000000000..42169639ef0 --- /dev/null +++ b/Resources/Prototypes/_Sunrise/CryoTeleport/portal.yml @@ -0,0 +1,31 @@ +- type: entity + id: PortalCryo + components: + - type: Transform + anchored: False + - type: InteractionOutline + - type: Clickable + - type: Physics + bodyType: Static + - type: Sprite + sprite: /Textures/Effects/portal.rsi + layers: + - state: portal-blue + - type: Fixtures + fixtures: + portalFixture: + shape: + !type:PhysShapeAabb + bounds: "-0.25,-0.48,0.25,0.48" + mask: + - FullTileMask + layer: + - WallLayer + hard: false + - type: PointLight + color: SkyBlue + radius: 3 + energy: 1 + netsync: false + - type: TimedDespawn + lifetime: 2 From de2a3a17a362e8d72398b03e5f3088f962e978a7 Mon Sep 17 00:00:00 2001 From: JDtrimble Date: Sun, 7 Jul 2024 18:05:12 +0300 Subject: [PATCH 2/3] release fix Signed-off-by: JDtrimble --- Content.Server/_Sunrise/CryoTeleport/CryoTeleportSystem.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Content.Server/_Sunrise/CryoTeleport/CryoTeleportSystem.cs b/Content.Server/_Sunrise/CryoTeleport/CryoTeleportSystem.cs index 0b0bac11efb..e7c6ceda217 100644 --- a/Content.Server/_Sunrise/CryoTeleport/CryoTeleportSystem.cs +++ b/Content.Server/_Sunrise/CryoTeleport/CryoTeleportSystem.cs @@ -88,8 +88,8 @@ public override void Update(float delay) private void OnStationInitialized(StationInitializedEvent ev) { - // if (FindCryo(ev.Station, Transform(ev.Station)) == null) - // return; // Ни одного крио на станции + if (FindCryo(ev.Station, Transform(ev.Station)) == null) + return; // Ни одного крио на станции EnsureComp(ev.Station); } From 248fe7795e5deeeb1d5d6855142fc181b837c5b6 Mon Sep 17 00:00:00 2001 From: Vigers Ray <60344369+VigersRay@users.noreply.github.com> Date: Fri, 12 Jul 2024 01:41:24 +0300 Subject: [PATCH 3/3] Update StationCryoTeleportComponent.cs --- .../_Sunrise/CryoTeleport/StationCryoTeleportComponent.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Content.Server/_Sunrise/CryoTeleport/StationCryoTeleportComponent.cs b/Content.Server/_Sunrise/CryoTeleport/StationCryoTeleportComponent.cs index 4b4835876ed..c1429f1f606 100644 --- a/Content.Server/_Sunrise/CryoTeleport/StationCryoTeleportComponent.cs +++ b/Content.Server/_Sunrise/CryoTeleport/StationCryoTeleportComponent.cs @@ -10,7 +10,7 @@ namespace Content.Server._Sunrise.CryoTeleport; public sealed partial class StationCryoTeleportComponent : Component { [DataField] - public TimeSpan TransferDelay = TimeSpan.FromSeconds(10); // TODO: debug + public TimeSpan TransferDelay = TimeSpan.FromSeconds(300); // TODO: debug [DataField] public string PortalPrototype = "PortalCryo";