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

Телепортация в криокапсулы ссд игроков. #180

Merged
merged 3 commits into from
Jul 12, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
200 changes: 200 additions & 0 deletions Content.Server/_Sunrise/CryoTeleport/CryoTeleportSystem.cs
Original file line number Diff line number Diff line change
@@ -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;

/// <summary>
/// This handles...
/// </summary>
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!;

/// <inheritdoc/>
public override void Initialize()
{
SubscribeLocalEvent<StationInitializedEvent>(OnStationInitialized);
SubscribeLocalEvent<PlayerSpawnCompleteEvent>(OnCompleteSpawn);
// SubscribeLocalEvent<CryoTeleportTargetComponent, BeingGibbedEvent>(OnGibbed);
SubscribeLocalEvent<CryoTeleportTargetComponent, PlayerDetachedEvent>(OnPlayerDetached);
SubscribeLocalEvent<CryoTeleportTargetComponent, PlayerAttachedEvent>(OnPlayerAttached);
}

public override void Update(float delay)
{
var query = AllEntityQuery<CryoTeleportTargetComponent>();
while (query.MoveNext(out var uid, out var comp))
{
// Log.Info($"uid: {uid}, comp: {comp.Station}");

if (comp.Station == null)
continue;

if (!TryComp<StationCryoTeleportComponent>(comp.Station, out var stationCryoTeleportComponent))
continue;

if (comp.ExitTime == null)
continue;

if (_timing.CurTime - comp.ExitTime >= stationCryoTeleportComponent.TransferDelay)
{
if (HasComp<CryostorageContainedComponent>(uid))
continue;

var containedComp = AddComp<CryostorageContainedComponent>(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<StationCryoTeleportComponent>(ev.Station);
}

private void OnCompleteSpawn(PlayerSpawnCompleteEvent ev)
{
if (!TryComp<StationCryoTeleportComponent>(ev.Station, out var cryoTeleportComponent))
return;
if (ev.JobId == null)
return;

if (ev.Player.AttachedEntity == null)
return;

var cryoTeleportTargetComponent = EnsureComp<CryoTeleportTargetComponent>(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<TransformComponent>(uid, out var entityXform))
// return;
//
// if (!TryComp<StationCryoTeleportComponent>(comp.Station, out var stationCryoTeleportComponent))
// return;
//
// // var stationJobsComponent = Comp<StationJobsComponent>(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<StationJobsComponent>(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<StationRecordsComponent>(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<GeneralStationRecord>(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<CryostorageComponent>();
while (query.MoveNext(out var cryoUid, out var cryostorageComponent))
{
if (!TryComp<TransformComponent>(cryoUid, out var cryoTransform))
return null;

if (entityXform.MapUid != cryoTransform.MapUid)
continue;

return cryoUid;
}

return null;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
namespace Content.Server._Sunrise.CryoTeleport;

/// <summary>
/// This is used for...
/// </summary>
[RegisterComponent]
public sealed partial class CryoTeleportTargetComponent : Component
{
[DataField]
public EntityUid? Station;

[DataField]
public TimeSpan? ExitTime;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
using Robust.Shared.Audio;
using Robust.Shared.Network;

namespace Content.Server._Sunrise.CryoTeleport;

/// <summary>
/// This is used for...
/// </summary>
[RegisterComponent]
public sealed partial class StationCryoTeleportComponent : Component
{
[DataField]
public TimeSpan TransferDelay = TimeSpan.FromSeconds(300); // TODO: debug

[DataField]
public string PortalPrototype = "PortalCryo";

[DataField]
public SoundSpecifier TransferSound = new SoundPathSpecifier("/Audio/Effects/teleport_departure.ogg");
}
2 changes: 2 additions & 0 deletions Resources/Locale/ru-RU/_sunrise/cryoteleport/cryoteleport.ftl
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
ent-PortalCryo = { ent-BasePortal }
.desc = { ent-BasePortal.desc }
31 changes: 31 additions & 0 deletions Resources/Prototypes/_Sunrise/CryoTeleport/portal.yml
Original file line number Diff line number Diff line change
@@ -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
Loading