2023-05-04 13:43:03 +06:00
|
|
|
|
using System.Linq;
|
|
|
|
|
|
using System.Threading.Tasks;
|
2024-03-27 21:23:18 +07:00
|
|
|
|
using Content.Server.Popups;
|
2023-05-04 13:43:03 +06:00
|
|
|
|
using Content.Shared.Hands.EntitySystems;
|
|
|
|
|
|
using Content.Shared.Interaction;
|
|
|
|
|
|
using Content.Shared.Tag;
|
|
|
|
|
|
using Content.Shared.Verbs;
|
2024-01-28 18:37:24 +07:00
|
|
|
|
using Content.Shared._White.Jukebox;
|
2024-03-27 21:23:18 +07:00
|
|
|
|
using Content.Shared.Popups;
|
|
|
|
|
|
using Robust.Server.Containers;
|
2023-05-04 13:43:03 +06:00
|
|
|
|
using Robust.Shared.Containers;
|
|
|
|
|
|
using Robust.Shared.GameStates;
|
|
|
|
|
|
using Robust.Shared.Utility;
|
|
|
|
|
|
|
2024-01-28 18:18:54 +07:00
|
|
|
|
namespace Content.Server._White.Jukebox;
|
2023-05-04 13:43:03 +06:00
|
|
|
|
|
|
|
|
|
|
public sealed class TapeCreatorSystem : EntitySystem
|
|
|
|
|
|
{
|
|
|
|
|
|
[Dependency] private readonly ServerJukeboxSongsSyncManager _songsSyncManager = default!;
|
2024-03-27 21:23:18 +07:00
|
|
|
|
[Dependency] private readonly PopupSystem _popup = default!;
|
|
|
|
|
|
[Dependency] private readonly ContainerSystem _container = default!;
|
|
|
|
|
|
[Dependency] private readonly SharedHandsSystem _hands = default!;
|
|
|
|
|
|
[Dependency] private readonly TagSystem _tag = default!;
|
2023-05-04 13:43:03 +06:00
|
|
|
|
|
2024-03-27 21:23:18 +07:00
|
|
|
|
private const string TapeCreatorContainerName = "tape_creator_container";
|
2023-05-04 13:43:03 +06:00
|
|
|
|
|
|
|
|
|
|
public override void Initialize()
|
|
|
|
|
|
{
|
|
|
|
|
|
base.Initialize();
|
|
|
|
|
|
SubscribeNetworkEvent<JukeboxSongUploadRequest>(OnSongUploaded);
|
|
|
|
|
|
SubscribeLocalEvent<TapeCreatorComponent, ComponentInit>(OnComponentInit);
|
|
|
|
|
|
SubscribeLocalEvent<TapeCreatorComponent, InteractUsingEvent>(OnInteract);
|
|
|
|
|
|
SubscribeLocalEvent<TapeCreatorComponent, GetVerbsEvent<Verb>>(OnTapeCreatorGetVerb);
|
|
|
|
|
|
SubscribeLocalEvent<TapeCreatorComponent, ComponentGetState>(OnTapeCreatorStateChanged);
|
|
|
|
|
|
SubscribeLocalEvent<TapeComponent, ComponentGetState>(OnTapeStateChanged);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void OnTapeCreatorGetVerb(EntityUid uid, TapeCreatorComponent component, GetVerbsEvent<Verb> ev)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (component.Recording) return;
|
|
|
|
|
|
if (ev.Hands == null) return;
|
|
|
|
|
|
if (component.TapeContainer.ContainedEntities.Count == 0) return;
|
|
|
|
|
|
|
2024-03-27 21:23:18 +07:00
|
|
|
|
var removeTapeVerb = new Verb
|
2023-05-04 13:43:03 +06:00
|
|
|
|
{
|
|
|
|
|
|
Text = "Вытащить касету",
|
|
|
|
|
|
Priority = 10000,
|
|
|
|
|
|
Icon = new SpriteSpecifier.Texture(new ResPath("/Textures/Interface/VerbIcons/remove_tape.png")),
|
|
|
|
|
|
Act = () =>
|
|
|
|
|
|
{
|
|
|
|
|
|
var tapes = component.TapeContainer.ContainedEntities.ToList();
|
2024-03-27 21:23:18 +07:00
|
|
|
|
_container.EmptyContainer(component.TapeContainer, true);
|
2023-05-04 13:43:03 +06:00
|
|
|
|
|
|
|
|
|
|
foreach (var tape in tapes)
|
|
|
|
|
|
{
|
2024-03-27 21:23:18 +07:00
|
|
|
|
_hands.PickupOrDrop(ev.User, tape);
|
2023-05-04 13:43:03 +06:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
component.InsertedTape = null;
|
2024-03-27 21:23:18 +07:00
|
|
|
|
Dirty(uid, component);
|
2023-05-04 13:43:03 +06:00
|
|
|
|
}
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
ev.Verbs.Add(removeTapeVerb);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void OnTapeStateChanged(EntityUid uid, TapeComponent component, ref ComponentGetState args)
|
|
|
|
|
|
{
|
2024-03-27 21:23:18 +07:00
|
|
|
|
args.State = new TapeComponentState
|
2023-05-04 13:43:03 +06:00
|
|
|
|
{
|
|
|
|
|
|
Songs = component.Songs
|
|
|
|
|
|
};
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void OnTapeCreatorStateChanged(EntityUid uid, TapeCreatorComponent component, ref ComponentGetState args)
|
|
|
|
|
|
{
|
|
|
|
|
|
args.State = new TapeCreatorComponentState
|
|
|
|
|
|
{
|
|
|
|
|
|
Recording = component.Recording,
|
|
|
|
|
|
CoinBalance = component.CoinBalance,
|
|
|
|
|
|
InsertedTape = component.InsertedTape
|
|
|
|
|
|
};
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void OnComponentInit(EntityUid uid, TapeCreatorComponent component, ComponentInit args)
|
|
|
|
|
|
{
|
2024-03-27 21:23:18 +07:00
|
|
|
|
component.TapeContainer = _container.EnsureContainer<Container>(uid, TapeCreatorContainerName);
|
2023-05-04 13:43:03 +06:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void OnInteract(EntityUid uid, TapeCreatorComponent component, InteractUsingEvent args)
|
|
|
|
|
|
{
|
2024-03-27 21:23:18 +07:00
|
|
|
|
if (component.Recording)
|
|
|
|
|
|
{
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
2023-05-04 13:43:03 +06:00
|
|
|
|
|
2024-03-27 21:23:18 +07:00
|
|
|
|
if (HasComp<TapeComponent>(args.Used))
|
2023-05-04 13:43:03 +06:00
|
|
|
|
{
|
|
|
|
|
|
var containedEntities = component.TapeContainer.ContainedEntities;
|
|
|
|
|
|
|
|
|
|
|
|
if (containedEntities.Count > 1)
|
|
|
|
|
|
{
|
2024-03-27 21:23:18 +07:00
|
|
|
|
var removedTapes = _container.EmptyContainer(component.TapeContainer, true).ToList();
|
|
|
|
|
|
_container.Insert(args.Used, component.TapeContainer);
|
2023-05-04 13:43:03 +06:00
|
|
|
|
|
|
|
|
|
|
foreach (var tapes in removedTapes)
|
|
|
|
|
|
{
|
2024-03-27 21:23:18 +07:00
|
|
|
|
_hands.PickupOrDrop(args.User, tapes);
|
2023-05-04 13:43:03 +06:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
2024-03-27 21:23:18 +07:00
|
|
|
|
_container.Insert(args.Used, component.TapeContainer);
|
2023-05-04 13:43:03 +06:00
|
|
|
|
}
|
|
|
|
|
|
|
2024-03-27 21:23:18 +07:00
|
|
|
|
component.InsertedTape = GetNetEntity(args.Used);
|
|
|
|
|
|
Dirty(uid, component);
|
2023-05-04 13:43:03 +06:00
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2024-03-27 21:23:18 +07:00
|
|
|
|
if (_tag.HasTag(args.Used, "TapeRecorderCoin"))
|
2023-05-04 13:43:03 +06:00
|
|
|
|
{
|
|
|
|
|
|
Del(args.Used);
|
|
|
|
|
|
component.CoinBalance += 1;
|
2024-03-27 21:23:18 +07:00
|
|
|
|
Dirty(uid, component);
|
2023-05-04 13:43:03 +06:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void OnSongUploaded(JukeboxSongUploadRequest ev)
|
|
|
|
|
|
{
|
2024-03-27 21:23:18 +07:00
|
|
|
|
var tapeCreator = GetEntity(ev.TapeCreatorUid);
|
|
|
|
|
|
if (!TryComp<TapeCreatorComponent>(tapeCreator, out var tapeCreatorComponent))
|
|
|
|
|
|
{
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
2023-05-04 13:43:03 +06:00
|
|
|
|
|
|
|
|
|
|
if (!tapeCreatorComponent.InsertedTape.HasValue || tapeCreatorComponent.CoinBalance <= 0)
|
|
|
|
|
|
{
|
2024-03-27 21:23:18 +07:00
|
|
|
|
_popup.PopupEntity("Т# %ак@ э*^о сdf{ал б2я~b? Запись была прервана.", tapeCreator);
|
2023-05-04 13:43:03 +06:00
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
tapeCreatorComponent.CoinBalance -= 1;
|
|
|
|
|
|
tapeCreatorComponent.Recording = true;
|
|
|
|
|
|
|
2024-03-27 21:23:18 +07:00
|
|
|
|
var insertedTape = GetEntity(tapeCreatorComponent.InsertedTape.Value);
|
|
|
|
|
|
var tapeComponent = Comp<TapeComponent>(insertedTape);
|
2023-05-04 13:43:03 +06:00
|
|
|
|
var songData = _songsSyncManager.SyncSongData(ev.SongName, ev.SongBytes);
|
|
|
|
|
|
|
2024-03-27 21:23:18 +07:00
|
|
|
|
var song = new JukeboxSong
|
2023-05-04 13:43:03 +06:00
|
|
|
|
{
|
2024-03-27 21:23:18 +07:00
|
|
|
|
SongName = songData.SongName,
|
|
|
|
|
|
SongPath = songData.Path
|
2023-05-04 13:43:03 +06:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
tapeComponent.Songs.Add(song);
|
2024-03-27 21:23:18 +07:00
|
|
|
|
|
2024-01-13 12:24:00 +03:00
|
|
|
|
DirtyEntity(GetEntity(ev.TapeCreatorUid));
|
2024-03-27 21:23:18 +07:00
|
|
|
|
Dirty(insertedTape, tapeComponent);
|
2023-05-04 13:43:03 +06:00
|
|
|
|
|
2024-08-01 07:08:29 +03:00
|
|
|
|
Record(tapeCreator, tapeCreatorComponent, _popup, _container);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void Record(
|
|
|
|
|
|
EntityUid uid,
|
|
|
|
|
|
TapeCreatorComponent component,
|
|
|
|
|
|
SharedPopupSystem popupSystem,
|
|
|
|
|
|
SharedContainerSystem containerSystem)
|
|
|
|
|
|
{
|
|
|
|
|
|
containerSystem.EmptyContainer(component.TapeContainer, force: true);
|
|
|
|
|
|
|
|
|
|
|
|
component.Recording = false;
|
|
|
|
|
|
component.InsertedTape = null;
|
|
|
|
|
|
|
|
|
|
|
|
popupSystem.PopupEntity("Запись мозговой активности завершена", uid);
|
|
|
|
|
|
Dirty(uid, component);
|
2023-05-04 13:43:03 +06:00
|
|
|
|
}
|
2024-07-31 07:20:33 +03:00
|
|
|
|
}
|