Files
OldThink/Content.Server/_Amour/InteractionPanel/InteractionPanelSystem.cs

160 lines
5.9 KiB
C#
Raw Normal View History

2024-02-23 18:52:03 +03:00
using System.Linq;
2024-02-24 20:54:20 +03:00
using Content.Server.Access.Systems;
2024-02-23 18:52:03 +03:00
using Content.Server.Chat.Systems;
using Content.Server.EUI;
2024-02-20 14:28:01 +03:00
using Content.Shared._Amour.Hole;
2024-02-23 18:52:03 +03:00
using Content.Shared._Amour.InteractionPanel;
using Content.Shared.Emoting;
2024-02-24 20:54:20 +03:00
using Content.Shared.Humanoid;
using Content.Shared.Mind;
2024-02-23 18:52:03 +03:00
using Content.Shared.Random.Helpers;
2024-02-20 14:28:01 +03:00
using Content.Shared.Verbs;
2024-02-23 18:52:03 +03:00
using Robust.Server.Audio;
2024-02-20 14:28:01 +03:00
using Robust.Server.Player;
2024-02-23 18:52:03 +03:00
using Robust.Shared.Audio;
2024-02-24 20:54:20 +03:00
using Robust.Shared.Enums;
2024-02-23 18:52:03 +03:00
using Robust.Shared.Prototypes;
using Robust.Shared.Random;
using Robust.Shared.Timing;
2024-02-20 14:28:01 +03:00
namespace Content.Server._Amour.InteractionPanel;
public sealed class InteractionPanelSystem : EntitySystem
{
[Dependency] private readonly EuiManager _eui = default!;
[Dependency] private readonly IPlayerManager _playerManager = default!;
2024-02-23 18:52:03 +03:00
[Dependency] private readonly IPrototypeManager _prototypeManager = default!;
[Dependency] private readonly IGameTiming _gameTiming = default!;
[Dependency] private readonly ChatSystem _chatSystem = default!;
[Dependency] private readonly AudioSystem _audioSystem = default!;
[Dependency] private readonly IRobustRandom _robustRandom = default!;
2024-02-24 20:54:20 +03:00
[Dependency] private readonly IdCardSystem _cardSystem = default!;
2024-02-23 18:52:03 +03:00
2024-02-20 14:28:01 +03:00
public override void Initialize()
{
2024-02-23 18:52:03 +03:00
SubscribeLocalEvent<InteractionPanelComponent,GetVerbsEvent<Verb>>(OnVerb);
SubscribeLocalEvent<InteractionPanelComponent,ComponentInit>(OnInit);
2024-02-20 14:28:01 +03:00
}
2024-02-23 18:52:03 +03:00
private void OnInit(EntityUid uid, InteractionPanelComponent component, ComponentInit args)
{
component.Timeout = _gameTiming.CurTime;
2024-02-24 20:54:20 +03:00
component.EndTime = _gameTiming.CurTime;
2024-02-23 18:52:03 +03:00
}
private void OnVerb(EntityUid uid, InteractionPanelComponent component, GetVerbsEvent<Verb> args)
2024-02-20 14:28:01 +03:00
{
args.Verbs.Add(new Verb()
{
2024-02-23 18:52:03 +03:00
Text = "Open funny panel",
Act = () => OpenPanel(args.User,args.User,uid)
2024-02-20 14:28:01 +03:00
});
}
2024-02-23 18:52:03 +03:00
public void OpenPanel(EntityUid panelOpener, Entity<InteractionPanelComponent?> user,
Entity<InteractionPanelComponent?> target)
{
if(!Resolve(user,ref user.Comp) || !Resolve(target,ref target.Comp)
|| !_playerManager.TryGetSessionByEntity(panelOpener, out var session))
return;
_eui.OpenEui(new InteractionPanelEui(
new Entity<InteractionPanelComponent>(user,user.Comp),
new Entity<InteractionPanelComponent>(target,target.Comp)),
session);
}
public void Interact(Entity<InteractionPanelComponent?> user,
Entity<InteractionPanelComponent?> target, ProtoId<InteractionPrototype> protoId)
{
//TODO: Пиздец... пиздец.... пиздец....
if( !Resolve(user,ref user.Comp)
|| !Resolve(target,ref target.Comp)
|| user.Comp.IsActive || user.Comp.IsBlocked
|| target.Comp.IsActive || target.Comp.IsBlocked
2024-02-24 20:54:20 +03:00
|| user.Comp.Timeout > _gameTiming.CurTime
|| target.Comp.Timeout > _gameTiming.CurTime
2024-02-23 18:52:03 +03:00
|| !_prototypeManager.TryIndex(protoId, out var prototype)
|| !prototype.Checks.All(check => check.IsAvailable(user!,target!,EntityManager)))
return;
user.Comp.Timeout = _gameTiming.CurTime + prototype.Timeout;
2024-02-24 20:54:20 +03:00
user.Comp.EndTime = _gameTiming.CurTime + prototype.EndTime;
2024-02-23 18:52:03 +03:00
user.Comp.IsActive = true;
user.Comp.CurrentAction = protoId;
user.Comp.CurrentPartner = new Entity<InteractionPanelComponent>(target,target.Comp);
if(prototype.BeginningMessages.Count > 0)
2024-02-24 20:54:20 +03:00
{
_chatSystem.TrySendInGameICMessage(user,
ParseMessage(target,_robustRandom.Pick(prototype.BeginningMessages)),
InGameICChatType.Emote,
false);
}
2024-02-23 18:52:03 +03:00
if (prototype.BeginningSound is not null)
_audioSystem.PlayPvs(prototype.BeginningSound, user);
RaiseLocalEvent(user,new InteractionBeginningEvent(protoId,user!,target!));
}
2024-02-24 20:54:20 +03:00
private string GetName(EntityUid target)
{
if(!TryComp<MindComponent>(target,out var mind) || mind.CharacterName is null)
return MetaData(target).EntityName;
return mind.CharacterName;
}
private Gender GetGender(EntityUid target)
{
if (!TryComp<HumanoidAppearanceComponent>(target, out var humanoidAppearanceComponent))
return Gender.Male;
return humanoidAppearanceComponent.Gender;
}
private string ParseMessage(EntityUid target, string message)
{
return Loc.GetString(message,
("target", GetName(target)), ("gender", GetGender(target)));
}
2024-02-23 18:52:03 +03:00
public override void Update(float frameTime)
{
base.Update(frameTime);
var query = EntityQueryEnumerator<InteractionPanelComponent>();
while (query.MoveNext(out var uid, out var component))
{
2024-02-24 20:54:20 +03:00
if(component.EndTime > _gameTiming.CurTime || !component.IsActive)
2024-02-23 18:52:03 +03:00
continue;
if (component.CurrentPartner is null)
{
continue;
}
if (_prototypeManager.TryIndex(component.CurrentAction, out var prototype))
{
2024-02-24 20:54:20 +03:00
if (prototype.EndingMessages.Count > 0)
{
_chatSystem.TrySendInGameICMessage(uid,
ParseMessage(component.CurrentPartner.Value,
_robustRandom.Pick(prototype.EndingMessages)),
InGameICChatType.Emote,
false);
}
2024-02-23 18:52:03 +03:00
if (prototype.EndingSound is not null)
_audioSystem.PlayPvs(prototype.EndingSound, uid);
}
component.IsActive = false;
RaiseLocalEvent(uid, new InteractionEndingEvent(component.CurrentAction,
new Entity<InteractionPanelComponent>(uid,component),
component.CurrentPartner.Value));
}
}
2024-02-20 14:28:01 +03:00
}