- fix: more fixes for interactions
This commit is contained in:
@@ -1,14 +1,18 @@
|
||||
using System.Linq;
|
||||
using Content.Server.Access.Systems;
|
||||
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.Humanoid;
|
||||
using Content.Shared.Mind;
|
||||
using Content.Shared.Random.Helpers;
|
||||
using Content.Shared.Verbs;
|
||||
using Robust.Server.Audio;
|
||||
using Robust.Server.Player;
|
||||
using Robust.Shared.Audio;
|
||||
using Robust.Shared.Enums;
|
||||
using Robust.Shared.Prototypes;
|
||||
using Robust.Shared.Random;
|
||||
using Robust.Shared.Timing;
|
||||
@@ -24,6 +28,7 @@ public sealed class InteractionPanelSystem : EntitySystem
|
||||
[Dependency] private readonly ChatSystem _chatSystem = default!;
|
||||
[Dependency] private readonly AudioSystem _audioSystem = default!;
|
||||
[Dependency] private readonly IRobustRandom _robustRandom = default!;
|
||||
[Dependency] private readonly IdCardSystem _cardSystem = default!;
|
||||
|
||||
public override void Initialize()
|
||||
{
|
||||
@@ -34,6 +39,7 @@ public sealed class InteractionPanelSystem : EntitySystem
|
||||
private void OnInit(EntityUid uid, InteractionPanelComponent component, ComponentInit args)
|
||||
{
|
||||
component.Timeout = _gameTiming.CurTime;
|
||||
component.EndTime = _gameTiming.CurTime;
|
||||
}
|
||||
|
||||
private void OnVerb(EntityUid uid, InteractionPanelComponent component, GetVerbsEvent<Verb> args)
|
||||
@@ -66,32 +72,61 @@ public sealed class InteractionPanelSystem : EntitySystem
|
||||
|| !Resolve(target,ref target.Comp)
|
||||
|| user.Comp.IsActive || user.Comp.IsBlocked
|
||||
|| target.Comp.IsActive || target.Comp.IsBlocked
|
||||
|| user.Comp.Timeout > _gameTiming.CurTime
|
||||
|| target.Comp.Timeout > _gameTiming.CurTime
|
||||
|| !_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.EndTime = _gameTiming.CurTime + prototype.EndTime;
|
||||
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);
|
||||
{
|
||||
_chatSystem.TrySendInGameICMessage(user,
|
||||
ParseMessage(target,_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!));
|
||||
}
|
||||
|
||||
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)));
|
||||
}
|
||||
|
||||
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)
|
||||
if(component.EndTime > _gameTiming.CurTime || !component.IsActive)
|
||||
continue;
|
||||
|
||||
if (component.CurrentPartner is null)
|
||||
@@ -101,8 +136,14 @@ public sealed class InteractionPanelSystem : EntitySystem
|
||||
|
||||
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.EndingMessages.Count > 0)
|
||||
{
|
||||
_chatSystem.TrySendInGameICMessage(uid,
|
||||
ParseMessage(component.CurrentPartner.Value,
|
||||
_robustRandom.Pick(prototype.EndingMessages)),
|
||||
InGameICChatType.Emote,
|
||||
false);
|
||||
}
|
||||
|
||||
if (prototype.EndingSound is not null)
|
||||
_audioSystem.PlayPvs(prototype.EndingSound, uid);
|
||||
|
||||
Reference in New Issue
Block a user