using Content.Shared._DV.Grappling.Components;
using Content.Shared.Interaction.Events;
using Content.Shared.Movement.Events;
using Content.Shared.Standing;
namespace Content.Shared._DV.Grappling.EntitySystems;
///
/// Shared logic for grapplers.
/// Enables some prediction of events and updates.
///
public abstract partial class SharedGrapplingSystem : EntitySystem
{
public override void Initialize()
{
base.Initialize();
SubscribeLocalEvent(OnCanMoveQuery);
SubscribeLocalEvent(OnAttemptAttack);
SubscribeLocalEvent(OnGrappledStand);
SubscribeLocalEvent(OnGrappleCanMoveQuery);
}
///
/// Handles when a grappler attempts to move.
/// Potentially disallows movement of the grappler when they are grappling a target.
///
/// The grappling entity.
/// Args for the event.
private void OnCanMoveQuery(Entity grappler, ref UpdateCanMoveEvent args)
{
if (grappler.Comp.CanMoveWhileGrappling)
return; // This entity can always move.
if (grappler.Comp.ActiveVictim.HasValue)
args.Cancel(); // Can't move while grappling
}
///
/// Handles when a grappled target attempts to stand and blocks it.
///
/// Grappled entity attempting to stand.
/// Args for the event.
private void OnGrappledStand(Entity grappled, ref StandAttemptEvent args)
{
args.Cancel(); // Can't stand while being grappled
}
///
/// Handles when a grappled target attempts to move and blocks it.
///
/// Grappled entity attempting to move.
/// Args for the event.
private void OnGrappleCanMoveQuery(Entity grappled, ref UpdateCanMoveEvent args)
{
args.Cancel(); // Can't move while grappled
}
///
/// Handles when a grappler attempts to attack an entity.
/// If they have an active victim, they will not be able to attack because their body
/// is currently being used in the grapple.
///
/// Grappler attempting to attack an entity.
/// Args for the event.
private void OnAttemptAttack(Entity grappler, ref AttackAttemptEvent args)
{
if (grappler.Comp.ActiveVictim.HasValue)
args.Cancel(); // You cannot attack while grappling
}
}