Files
crystall-punk-14/Content.Shared/Trigger/Systems/TriggerSystem.Interaction.cs

141 lines
4.8 KiB
C#
Raw Permalink Normal View History

using Content.Shared.Examine;
Add trigger-refactor components and systems: Batch 1 (#39391) * Adds the following batch of trigger refactor components and their associated systems: TriggerOnLand: LandEvent TriggerOnExamined: ExaminedEvent TriggerOnUnbuckle: UnbuckledEvent TriggerOnBuckle: BuckledEvent TriggerOnStrap: StrappedEvent TriggerOnUnstrapped: UnstrappedEvent * Removes unnecessary lines from comment * Fix comment formatting, corrects grammar and increases comment clarity. * adds last forgotten edit to comments * Update Content.Shared/Trigger/Systems/TriggerOnStrappedOrBuckledSystem.cs Removes unnecessary comments Co-authored-by: slarticodefast <161409025+slarticodefast@users.noreply.github.com> * Update Content.Shared/Trigger/Components/Triggers/TriggerOnBuckledComponent.cs Increases comment clarity Co-authored-by: slarticodefast <161409025+slarticodefast@users.noreply.github.com> * Update Content.Shared/Trigger/Components/Triggers/TriggerOnExaminedComponent.cs Increases comment clarity Co-authored-by: slarticodefast <161409025+slarticodefast@users.noreply.github.com> * Update Content.Shared/Trigger/Components/Triggers/TriggerOnLandComponent.cs Increases comment clarity Co-authored-by: slarticodefast <161409025+slarticodefast@users.noreply.github.com> * Update Content.Shared/Trigger/Components/Triggers/TriggerOnStrappedComponent.cs Increases comment clarity Co-authored-by: slarticodefast <161409025+slarticodefast@users.noreply.github.com> * Update Content.Shared/Trigger/Components/Triggers/TriggerOnUnbuckledComponent.cs Increases comment clarity Co-authored-by: slarticodefast <161409025+slarticodefast@users.noreply.github.com> * Update Content.Shared/Trigger/Components/Triggers/TriggerOnUnstrappedComponent.cs Increases comment clarity Co-authored-by: slarticodefast <161409025+slarticodefast@users.noreply.github.com> * refactored TriggerOnStrappedOrBuckledSystem.cs removed TriggerOnExaminedSystem.cs and moved it into TriggerSystem.Interaction.cs Changes currently untested, not sure how to make it so modders can change what method they want sending out the appropriate trigger key but want to save progress working on it and get feedback from maintainers * Removed component which already exists as part of TriggerSystem.Interaction.cs * Restores accidentally removed component * Apply suggestions from code review --------- Co-authored-by: slarticodefast <161409025+slarticodefast@users.noreply.github.com>
2025-08-14 17:39:54 +10:00
using Content.Shared.Interaction;
2025-08-03 21:20:37 +02:00
using Content.Shared.Interaction.Events;
using Content.Shared.Item.ItemToggle.Components;
using Content.Shared.Throwing;
2025-08-03 21:20:37 +02:00
using Content.Shared.Trigger.Components.Triggers;
using Content.Shared.Trigger.Components.Effects;
namespace Content.Shared.Trigger.Systems;
public sealed partial class TriggerSystem
{
private void InitializeInteraction()
{
Add trigger-refactor components and systems: Batch 1 (#39391) * Adds the following batch of trigger refactor components and their associated systems: TriggerOnLand: LandEvent TriggerOnExamined: ExaminedEvent TriggerOnUnbuckle: UnbuckledEvent TriggerOnBuckle: BuckledEvent TriggerOnStrap: StrappedEvent TriggerOnUnstrapped: UnstrappedEvent * Removes unnecessary lines from comment * Fix comment formatting, corrects grammar and increases comment clarity. * adds last forgotten edit to comments * Update Content.Shared/Trigger/Systems/TriggerOnStrappedOrBuckledSystem.cs Removes unnecessary comments Co-authored-by: slarticodefast <161409025+slarticodefast@users.noreply.github.com> * Update Content.Shared/Trigger/Components/Triggers/TriggerOnBuckledComponent.cs Increases comment clarity Co-authored-by: slarticodefast <161409025+slarticodefast@users.noreply.github.com> * Update Content.Shared/Trigger/Components/Triggers/TriggerOnExaminedComponent.cs Increases comment clarity Co-authored-by: slarticodefast <161409025+slarticodefast@users.noreply.github.com> * Update Content.Shared/Trigger/Components/Triggers/TriggerOnLandComponent.cs Increases comment clarity Co-authored-by: slarticodefast <161409025+slarticodefast@users.noreply.github.com> * Update Content.Shared/Trigger/Components/Triggers/TriggerOnStrappedComponent.cs Increases comment clarity Co-authored-by: slarticodefast <161409025+slarticodefast@users.noreply.github.com> * Update Content.Shared/Trigger/Components/Triggers/TriggerOnUnbuckledComponent.cs Increases comment clarity Co-authored-by: slarticodefast <161409025+slarticodefast@users.noreply.github.com> * Update Content.Shared/Trigger/Components/Triggers/TriggerOnUnstrappedComponent.cs Increases comment clarity Co-authored-by: slarticodefast <161409025+slarticodefast@users.noreply.github.com> * refactored TriggerOnStrappedOrBuckledSystem.cs removed TriggerOnExaminedSystem.cs and moved it into TriggerSystem.Interaction.cs Changes currently untested, not sure how to make it so modders can change what method they want sending out the appropriate trigger key but want to save progress working on it and get feedback from maintainers * Removed component which already exists as part of TriggerSystem.Interaction.cs * Restores accidentally removed component * Apply suggestions from code review --------- Co-authored-by: slarticodefast <161409025+slarticodefast@users.noreply.github.com>
2025-08-14 17:39:54 +10:00
SubscribeLocalEvent<TriggerOnExaminedComponent, ExaminedEvent>(OnExamined);
2025-08-03 21:20:37 +02:00
SubscribeLocalEvent<TriggerOnActivateComponent, ActivateInWorldEvent>(OnActivate);
SubscribeLocalEvent<TriggerOnUseComponent, UseInHandEvent>(OnUse);
SubscribeLocalEvent<TriggerOnInteractHandComponent, InteractHandEvent>(OnInteractHand);
SubscribeLocalEvent<TriggerOnInteractUsingComponent, InteractUsingEvent>(OnInteractUsing);
SubscribeLocalEvent<TriggerOnThrowComponent, ThrowEvent>(OnThrow);
SubscribeLocalEvent<TriggerOnThrownComponent, ThrownEvent>(OnThrown);
2025-08-03 21:20:37 +02:00
SubscribeLocalEvent<ItemToggleOnTriggerComponent, TriggerEvent>(HandleItemToggleOnTrigger);
SubscribeLocalEvent<AnchorOnTriggerComponent, TriggerEvent>(HandleAnchorOnTrigger);
SubscribeLocalEvent<UseDelayOnTriggerComponent, TriggerEvent>(HandleUseDelayOnTrigger);
}
Add trigger-refactor components and systems: Batch 1 (#39391) * Adds the following batch of trigger refactor components and their associated systems: TriggerOnLand: LandEvent TriggerOnExamined: ExaminedEvent TriggerOnUnbuckle: UnbuckledEvent TriggerOnBuckle: BuckledEvent TriggerOnStrap: StrappedEvent TriggerOnUnstrapped: UnstrappedEvent * Removes unnecessary lines from comment * Fix comment formatting, corrects grammar and increases comment clarity. * adds last forgotten edit to comments * Update Content.Shared/Trigger/Systems/TriggerOnStrappedOrBuckledSystem.cs Removes unnecessary comments Co-authored-by: slarticodefast <161409025+slarticodefast@users.noreply.github.com> * Update Content.Shared/Trigger/Components/Triggers/TriggerOnBuckledComponent.cs Increases comment clarity Co-authored-by: slarticodefast <161409025+slarticodefast@users.noreply.github.com> * Update Content.Shared/Trigger/Components/Triggers/TriggerOnExaminedComponent.cs Increases comment clarity Co-authored-by: slarticodefast <161409025+slarticodefast@users.noreply.github.com> * Update Content.Shared/Trigger/Components/Triggers/TriggerOnLandComponent.cs Increases comment clarity Co-authored-by: slarticodefast <161409025+slarticodefast@users.noreply.github.com> * Update Content.Shared/Trigger/Components/Triggers/TriggerOnStrappedComponent.cs Increases comment clarity Co-authored-by: slarticodefast <161409025+slarticodefast@users.noreply.github.com> * Update Content.Shared/Trigger/Components/Triggers/TriggerOnUnbuckledComponent.cs Increases comment clarity Co-authored-by: slarticodefast <161409025+slarticodefast@users.noreply.github.com> * Update Content.Shared/Trigger/Components/Triggers/TriggerOnUnstrappedComponent.cs Increases comment clarity Co-authored-by: slarticodefast <161409025+slarticodefast@users.noreply.github.com> * refactored TriggerOnStrappedOrBuckledSystem.cs removed TriggerOnExaminedSystem.cs and moved it into TriggerSystem.Interaction.cs Changes currently untested, not sure how to make it so modders can change what method they want sending out the appropriate trigger key but want to save progress working on it and get feedback from maintainers * Removed component which already exists as part of TriggerSystem.Interaction.cs * Restores accidentally removed component * Apply suggestions from code review --------- Co-authored-by: slarticodefast <161409025+slarticodefast@users.noreply.github.com>
2025-08-14 17:39:54 +10:00
private void OnExamined(Entity<TriggerOnExaminedComponent> ent, ref ExaminedEvent args)
{
Trigger(ent.Owner, args.Examiner, ent.Comp.KeyOut);
}
2025-08-03 21:20:37 +02:00
private void OnActivate(Entity<TriggerOnActivateComponent> ent, ref ActivateInWorldEvent args)
{
if (args.Handled)
return;
if (ent.Comp.RequireComplex && !args.Complex)
return;
Trigger(ent.Owner, args.User, ent.Comp.KeyOut);
args.Handled = true;
}
private void OnUse(Entity<TriggerOnUseComponent> ent, ref UseInHandEvent args)
{
if (args.Handled)
return;
Trigger(ent.Owner, args.User, ent.Comp.KeyOut);
args.Handled = true;
}
private void OnInteractHand(Entity<TriggerOnInteractHandComponent> ent, ref InteractHandEvent args)
2025-08-03 21:20:37 +02:00
{
if (args.Handled)
return;
Trigger(ent.Owner, args.User, ent.Comp.KeyOut);
args.Handled = true;
}
private void OnInteractUsing(Entity<TriggerOnInteractUsingComponent> ent, ref InteractUsingEvent args)
{
if (args.Handled)
return;
if (!_whitelist.CheckBoth(args.Used, ent.Comp.Blacklist, ent.Comp.Whitelist))
return;
Trigger(ent.Owner, ent.Comp.TargetUsed ? args.Used : args.User, ent.Comp.KeyOut);
args.Handled = true;
}
private void OnThrow(Entity<TriggerOnThrowComponent> ent, ref ThrowEvent args)
{
Trigger(ent.Owner, args.Thrown, ent.Comp.KeyOut);
}
private void OnThrown(Entity<TriggerOnThrownComponent> ent, ref ThrownEvent args)
{
Trigger(ent.Owner, args.User, ent.Comp.KeyOut);
}
2025-08-03 21:20:37 +02:00
private void HandleItemToggleOnTrigger(Entity<ItemToggleOnTriggerComponent> ent, ref TriggerEvent args)
{
if (args.Key != null && !ent.Comp.KeysIn.Contains(args.Key))
return;
var target = ent.Comp.TargetUser ? args.User : ent.Owner;
if (!TryComp<ItemToggleComponent>(target, out var itemToggle))
return;
var handled = false;
if (itemToggle.Activated && ent.Comp.CanDeactivate)
handled = _itemToggle.TryDeactivate((target.Value, itemToggle), args.User, ent.Comp.Predicted, ent.Comp.ShowPopup);
else if (ent.Comp.CanActivate)
handled = _itemToggle.TryActivate((target.Value, itemToggle), args.User, ent.Comp.Predicted, ent.Comp.ShowPopup);
args.Handled |= handled;
}
private void HandleAnchorOnTrigger(Entity<AnchorOnTriggerComponent> ent, ref TriggerEvent args)
{
if (args.Key != null && !ent.Comp.KeysIn.Contains(args.Key))
return;
var target = ent.Comp.TargetUser ? args.User : ent.Owner;
if (target == null)
return;
var xform = Transform(target.Value);
if (xform.Anchored && ent.Comp.CanUnanchor)
_transform.Unanchor(target.Value, xform);
else if (ent.Comp.CanAnchor)
_transform.AnchorEntity(target.Value, xform);
if (ent.Comp.RemoveOnTrigger)
RemCompDeferred<AnchorOnTriggerComponent>(target.Value);
args.Handled = true;
}
private void HandleUseDelayOnTrigger(Entity<UseDelayOnTriggerComponent> ent, ref TriggerEvent args)
{
if (args.Key != null && !ent.Comp.KeysIn.Contains(args.Key))
return;
var target = ent.Comp.TargetUser ? args.User : ent.Owner;
if (target == null)
return;
args.Handled |= _useDelay.TryResetDelay(target.Value, ent.Comp.CheckDelayed);
}
}