This commit is contained in:
BIGZi0348
2025-02-23 22:36:27 +03:00
parent 43d5033ae7
commit cff08e0550
4 changed files with 40 additions and 36 deletions

View File

@@ -30,14 +30,14 @@ public sealed partial class InteractionPanelWindow : DefaultWindow
public void AddButton(InteractionEntry entry)
{
if(!_prototypeManager.TryIndex<InteractionPrototype>(entry.Prototype, out var prototype)
if (!_prototypeManager.TryIndex<InteractionPrototype>(entry.Prototype, out var prototype)
|| !_prototypeManager.TryIndex(prototype.Group, out var groupPrototype))
return;
if (!Groups.TryGetValue(prototype.Group, out var box))
return;
if(DisCheckbox.Pressed && !entry.Enabled)
if (DisCheckbox.Pressed && !entry.Enabled)
return;
var btn = new InteractionPanelButton();
@@ -59,7 +59,7 @@ public sealed partial class InteractionPanelWindow : DefaultWindow
var box = new BoxContainer();
Interactions.AddChild(box);
box.Orientation = BoxContainer.LayoutOrientation.Vertical;
Groups.Add(prototype.ID,Interactions.ChildCount - 1);
Groups.Add(prototype.ID, Interactions.ChildCount - 1);
}
var messageUser = new FormattedMessage();

View File

@@ -40,11 +40,11 @@ public sealed class InteractionPanelSystem : EntitySystem
public override void Initialize()
{
SubscribeLocalEvent<InteractionPanelComponent,GetVerbsEvent<Verb>>(OnVerb);
SubscribeLocalEvent<InteractionPanelComponent,ComponentInit>(OnInit);
SubscribeLocalEvent<InteractionPanelComponent,PanelDoAfterEvent>(OnPanel);
SubscribeLocalEvent<InteractionPanelComponent,ChangeDirectionAttemptEvent>(OnCancelable);
SubscribeLocalEvent<InteractionPanelComponent,UpdateCanMoveEvent>(OnCancelable);
SubscribeLocalEvent<InteractionPanelComponent, GetVerbsEvent<Verb>>(OnVerb);
SubscribeLocalEvent<InteractionPanelComponent, ComponentInit>(OnInit);
SubscribeLocalEvent<InteractionPanelComponent, PanelDoAfterEvent>(OnPanel);
SubscribeLocalEvent<InteractionPanelComponent, ChangeDirectionAttemptEvent>(OnCancelable);
SubscribeLocalEvent<InteractionPanelComponent, UpdateCanMoveEvent>(OnCancelable);
}
private void OnCancelable(EntityUid uid, InteractionPanelComponent component, CancellableEntityEventArgs args)
@@ -58,12 +58,12 @@ public sealed class InteractionPanelSystem : EntitySystem
private void OnPanel(EntityUid uid, InteractionPanelComponent component, PanelDoAfterEvent args)
{
component.IsBlocked = false;
if(args.Cancelled
if (args.Cancelled
|| !_prototypeManager.TryIndex<InteractionPrototype>(args.Prototype, out var prototype)
|| !TryComp<InteractionPanelComponent>(args.Target, out var targetInteractionPanelComponent))
return;
Interact(new Entity<InteractionPanelComponent>(uid,component),new Entity<InteractionPanelComponent>(args.Target.Value,targetInteractionPanelComponent),prototype,false);
Interact(new Entity<InteractionPanelComponent>(uid, component), new Entity<InteractionPanelComponent>(args.Target.Value, targetInteractionPanelComponent), prototype, false);
}
private void OnInit(EntityUid uid, InteractionPanelComponent component, ComponentInit args)
@@ -84,14 +84,14 @@ public sealed class InteractionPanelSystem : EntitySystem
args.Verbs.Add(new Verb()
{
Text = Loc.GetString("interaction-open"),
Act = () => OpenPanel(args.User,args.User,uid)
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)
if (!Resolve(user, ref user.Comp) || !Resolve(target, ref target.Comp)
|| !_playerManager.TryGetSessionByEntity(panelOpener, out var session))
return;
@@ -99,8 +99,8 @@ public sealed class InteractionPanelSystem : EntitySystem
return;
_eui.OpenEui(new InteractionPanelEui(
new Entity<InteractionPanelComponent>(user,user.Comp),
new Entity<InteractionPanelComponent>(target,target.Comp)),
new Entity<InteractionPanelComponent>(user, user.Comp),
new Entity<InteractionPanelComponent>(target, target.Comp)),
session);
}
@@ -108,8 +108,8 @@ public sealed class InteractionPanelSystem : EntitySystem
Entity<InteractionPanelComponent?> target, ProtoId<InteractionPrototype> protoId)
{
//TODO: Пиздец... пиздец.... пиздец....
if( !Resolve(user,ref user.Comp)
|| !Resolve(target,ref target.Comp)
if (!Resolve(user, ref user.Comp)
|| !Resolve(target, ref target.Comp)
|| user.Comp.IsActive || user.Comp.IsBlocked
|| target.Comp.IsActive || target.Comp.IsBlocked
|| user.Comp.Timeout > _gameTiming.CurTime
@@ -120,28 +120,28 @@ public sealed class InteractionPanelSystem : EntitySystem
if (!_mobStateSystem.IsAlive(user) || !_mobStateSystem.IsAlive(target))
return;
if(!Check(user!,target!,prototype, out var check))
if (!Check(user!, target!, prototype, out var check))
{
if(_playerManager.TryGetSessionByEntity(user,out var session) || session is null)
if (_playerManager.TryGetSessionByEntity(user, out var session) || session is null)
return;
var message = ParseMessage(target, $"interaction-fail-{check.GetType().Name.ToLower()}");
_chatManager.ChatMessageToOne(ChatChannel.Emotes,message,message,EntityUid.Invalid,false,session.Channel);
_chatManager.ChatMessageToOne(ChatChannel.Emotes, message, message, EntityUid.Invalid, false, session.Channel);
return;
}
if (prototype.BeginningTimeout == TimeSpan.Zero)
{
Interact(user!,target!,prototype);
Interact(user!, target!, prototype);
return;
}
user.Comp.IsBlocked = true;
if(prototype.PreBeginMessages.Count > 0)
if (prototype.PreBeginMessages.Count > 0)
{
_chatSystem.TrySendInGameICMessage(user,
ParseMessage(target,_robustRandom.Pick(prototype.PreBeginMessages)),
ParseMessage(target, _robustRandom.Pick(prototype.PreBeginMessages)),
InGameICChatType.Emote,
false);
}
@@ -150,7 +150,7 @@ public sealed class InteractionPanelSystem : EntitySystem
EntityManager,
user,
prototype.BeginningTimeout,
new PanelDoAfterEvent(prototype.ID),user,target
new PanelDoAfterEvent(prototype.ID), user, target
)
{
BreakOnDamage = true,
@@ -162,13 +162,13 @@ public sealed class InteractionPanelSystem : EntitySystem
private void Interact(Entity<InteractionPanelComponent> user,
Entity<InteractionPanelComponent> target, InteractionPrototype prototype, bool hasChecked = true)
{
if(!hasChecked && !Check(user,target,prototype, out var check))
if (!hasChecked && !Check(user, target, prototype, out var check))
{
if(_playerManager.TryGetSessionByEntity(user,out var session) || session is null)
if (_playerManager.TryGetSessionByEntity(user, out var session) || session is null)
return;
var message = ParseMessage(target, $"interaction-fail-{check.GetType().Name.ToLower()}");
_chatManager.ChatMessageToOne(ChatChannel.Emotes,message,message,EntityUid.Invalid,false,session.Channel);
_chatManager.ChatMessageToOne(ChatChannel.Emotes, message, message, EntityUid.Invalid, false, session.Channel);
return;
}
@@ -177,12 +177,12 @@ public sealed class InteractionPanelSystem : EntitySystem
user.Comp.EndTime = _gameTiming.CurTime + prototype.EndTime;
user.Comp.IsActive = true;
user.Comp.CurrentAction = prototype.ID;
user.Comp.CurrentPartner = new Entity<InteractionPanelComponent>(target,target.Comp);
user.Comp.CurrentPartner = new Entity<InteractionPanelComponent>(target, target.Comp);
if(prototype.BeginningMessages.Count > 0)
if (prototype.BeginningMessages.Count > 0)
{
_chatSystem.TrySendInGameICMessage(user,
ParseMessage(target,_robustRandom.Pick(prototype.BeginningMessages)),
ParseMessage(target, _robustRandom.Pick(prototype.BeginningMessages)),
InGameICChatType.Emote,
false);
}
@@ -192,18 +192,18 @@ public sealed class InteractionPanelSystem : EntitySystem
foreach (var action in prototype.BeginningActions)
{
action.Run(user!,target!,EntityManager);
action.Run(user!, target!, EntityManager);
}
_actionBlockerSystem.UpdateCanMove(user);
_actionBlockerSystem.UpdateCanMove(target);
RaiseLocalEvent(user,new InteractionBeginningEvent(prototype.ID,user,target));
RaiseLocalEvent(user, new InteractionBeginningEvent(prototype.ID, user, target));
}
private string GetName(EntityUid target)
{
if(!TryComp<MindComponent>(target,out var mind) || mind.CharacterName is null)
if (!TryComp<MindComponent>(target, out var mind) || mind.CharacterName is null)
return MetaData(target).EntityName;
return mind.CharacterName;
@@ -224,7 +224,7 @@ public sealed class InteractionPanelSystem : EntitySystem
}
public bool Check(Entity<InteractionPanelComponent> user,
Entity<InteractionPanelComponent> target, InteractionPrototype prototype,[NotNullWhen(false)] out IInteractionCheck? check)
Entity<InteractionPanelComponent> target, InteractionPrototype prototype, [NotNullWhen(false)] out IInteractionCheck? check)
{
check = null;
foreach (var checkout in prototype.Checks.Where(check => !check.IsAvailable(user!, target!, EntityManager)))
@@ -243,7 +243,7 @@ public sealed class InteractionPanelSystem : EntitySystem
while (query.MoveNext(out var uid, out var component))
{
if(component.EndTime > _gameTiming.CurTime || !component.IsActive)
if (component.EndTime > _gameTiming.CurTime || !component.IsActive)
continue;
if (component.CurrentPartner is null)
@@ -270,7 +270,7 @@ public sealed class InteractionPanelSystem : EntitySystem
foreach (var action in prototype.EndingActions)
{
action.Run(user,component.CurrentPartner.Value,EntityManager);
action.Run(user, component.CurrentPartner.Value, EntityManager);
}
}

View File

@@ -9,6 +9,10 @@ public sealed class HasSmallDistance : IInteractionCheck
{
var transformSystem = entityManager.System<SharedTransformSystem>();
if (!entityManager.HasComponent<TransformComponent>(user) ||
!entityManager.HasComponent<TransformComponent>(target))
return false;
if (_range <= 0)
return true;

View File

@@ -3,5 +3,5 @@ namespace Content.Shared._Amour.InteractionPanel.Checks;
public interface IInteractionCheck
{
public bool IsAvailable(Entity<InteractionPanelComponent> user,
Entity<InteractionPanelComponent> target,IEntityManager entityManager);
Entity<InteractionPanelComponent> target, IEntityManager entityManager);
}