- add: interaction part 2
This commit is contained in:
@@ -1,7 +1,17 @@
|
||||
using Content.Server.EUI;
|
||||
using System.Linq;
|
||||
using Content.Server.Chat.Systems;
|
||||
using Content.Server.EUI;
|
||||
using Content.Shared._Amour.Hole;
|
||||
using Content.Shared._Amour.InteractionPanel;
|
||||
using Content.Shared.Emoting;
|
||||
using Content.Shared.Random.Helpers;
|
||||
using Content.Shared.Verbs;
|
||||
using Robust.Server.Audio;
|
||||
using Robust.Server.Player;
|
||||
using Robust.Shared.Audio;
|
||||
using Robust.Shared.Prototypes;
|
||||
using Robust.Shared.Random;
|
||||
using Robust.Shared.Timing;
|
||||
|
||||
namespace Content.Server._Amour.InteractionPanel;
|
||||
|
||||
@@ -9,19 +19,100 @@ public sealed class InteractionPanelSystem : EntitySystem
|
||||
{
|
||||
[Dependency] private readonly EuiManager _eui = default!;
|
||||
[Dependency] private readonly IPlayerManager _playerManager = default!;
|
||||
[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!;
|
||||
|
||||
public override void Initialize()
|
||||
{
|
||||
SubscribeLocalEvent<HoleContainerComponent,GetVerbsEvent<Verb>>(OnVerb);
|
||||
SubscribeLocalEvent<InteractionPanelComponent,GetVerbsEvent<Verb>>(OnVerb);
|
||||
SubscribeLocalEvent<InteractionPanelComponent,ComponentInit>(OnInit);
|
||||
}
|
||||
|
||||
private void OnVerb(EntityUid uid, HoleContainerComponent component, GetVerbsEvent<Verb> args)
|
||||
private void OnInit(EntityUid uid, InteractionPanelComponent component, ComponentInit args)
|
||||
{
|
||||
component.Timeout = _gameTiming.CurTime;
|
||||
}
|
||||
|
||||
private void OnVerb(EntityUid uid, InteractionPanelComponent component, GetVerbsEvent<Verb> args)
|
||||
{
|
||||
if(!_playerManager.TryGetSessionByEntity(uid, out var session))
|
||||
return;
|
||||
args.Verbs.Add(new Verb()
|
||||
{
|
||||
Text = "MEOW",
|
||||
Act = () => _eui.OpenEui(new InteractionPanelEui(), session)
|
||||
Text = "Open funny panel",
|
||||
Act = () => OpenPanel(args.User,args.User,uid)
|
||||
});
|
||||
}
|
||||
|
||||
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
|
||||
|| !_prototypeManager.TryIndex(protoId, out var prototype)
|
||||
|| !prototype.Checks.All(check => check.IsAvailable(user!,target!,EntityManager)))
|
||||
return;
|
||||
|
||||
user.Comp.Timeout = _gameTiming.CurTime + prototype.Timeout;
|
||||
user.Comp.IsActive = true;
|
||||
user.Comp.CurrentAction = protoId;
|
||||
user.Comp.CurrentPartner = new Entity<InteractionPanelComponent>(target,target.Comp);
|
||||
|
||||
if(prototype.BeginningMessages.Count > 0)
|
||||
_chatSystem.TrySendInGameICMessage(user,_robustRandom.Pick(prototype.BeginningMessages),InGameICChatType.Emote,false);
|
||||
|
||||
if (prototype.BeginningSound is not null)
|
||||
_audioSystem.PlayPvs(prototype.BeginningSound, user);
|
||||
|
||||
|
||||
RaiseLocalEvent(user,new InteractionBeginningEvent(protoId,user!,target!));
|
||||
}
|
||||
|
||||
public override void Update(float frameTime)
|
||||
{
|
||||
base.Update(frameTime);
|
||||
var query = EntityQueryEnumerator<InteractionPanelComponent>();
|
||||
while (query.MoveNext(out var uid, out var component))
|
||||
{
|
||||
if(component.Timeout > _gameTiming.CurTime || !component.IsActive)
|
||||
continue;
|
||||
|
||||
if (component.CurrentPartner is null)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
if (_prototypeManager.TryIndex(component.CurrentAction, out var prototype))
|
||||
{
|
||||
if(prototype.EndingMessages.Count > 0)
|
||||
_chatSystem.TrySendInGameICMessage(uid,_robustRandom.Pick(prototype.EndingMessages),InGameICChatType.Emote,false);
|
||||
|
||||
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));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user