# Conflicts: # Content.Server/Antag/AntagSelectionSystem.cs # Content.Server/Changeling/ChangelingRuleSystem.cs # Content.Server/Changeling/ChangelingSystem.Abilities.cs # Content.Server/Doors/Systems/DoorSystem.cs # Content.Server/GameTicking/Rules/NukeopsRuleSystem.cs # Content.Server/GameTicking/Rules/RevolutionaryRuleSystem.cs # Content.Server/GameTicking/Rules/TraitorRuleSystem.cs # Content.Server/GameTicking/Rules/ZombieRuleSystem.cs # Content.Server/Holosign/HolosignSystem.cs # Content.Server/Revenant/EntitySystems/RevenantSystem.Abilities.cs # Content.Server/_White/Cult/GameRule/CultRuleComponent.cs # Content.Server/_White/Cult/GameRule/CultRuleSystem.cs # Content.Server/_White/Cult/Runes/Systems/CultSystem.Rune.cs # Content.Server/_White/Keyhole/KeyholeSystem.cs # Content.Server/_White/MeatyOre/MeatyOreStoreSystem.cs # Content.Shared/Projectiles/SharedProjectileSystem.cs # Content.Shared/Weapons/Melee/SharedMeleeWeaponSystem.cs # Content.Shared/_White/Keyhole/Components/KeyBaseComponent.cs # Resources/Locale/ru-RU/White/stuff.ftl/runes-entities.ftl # Resources/Locale/ru-RU/_white/cult/blood-spear.ftl # Resources/Locale/ru-RU/_white/cult/bolt-barrage.ftl # Resources/Locale/ru-RU/_white/cult/cult.ftl # Resources/Locale/ru-RU/_white/cult/gui.ftl # Resources/Locale/ru-RU/cult/cult-structure.ftl # Resources/Locale/ru-RU/cult/pylon.ftl # Resources/Maps/White/Scoupidia.yml # Resources/Maps/White/Void.yml # Resources/Maps/White/WonderBox.yml # Resources/Prototypes/Actions/types.yml # Resources/Prototypes/Atmospherics/gases.yml # Resources/Prototypes/Catalog/Cargo/cargo_atmospherics.yml # Resources/Prototypes/Catalog/Cargo/cargo_vending.yml # Resources/Prototypes/Catalog/Fills/Lockers/dressers.yml # Resources/Prototypes/Catalog/Fills/Lockers/heads.yml # Resources/Prototypes/Catalog/Fills/Lockers/misc.yml # Resources/Prototypes/Catalog/uplink_catalog.yml # Resources/Prototypes/Entities/Clothing/OuterClothing/armor.yml # Resources/Prototypes/Entities/Objects/Misc/subdermal_implants.yml # Resources/Prototypes/Entities/Objects/Tools/jaws_of_life.yml # Resources/Prototypes/Entities/Objects/Weapons/Melee/sledgehammer.yml # Resources/Prototypes/Entities/Objects/Weapons/Melee/sword.yml # Resources/Prototypes/Entities/Structures/Doors/Airlocks/base_assembly.yml # Resources/Prototypes/Entities/Structures/Doors/Airlocks/base_structureairlocks.yml # Resources/Prototypes/Entities/Structures/Doors/Firelocks/firelock.yml # Resources/Prototypes/Entities/Structures/Doors/Firelocks/frame.yml # Resources/Prototypes/Entities/Structures/Doors/SecretDoor/secret_door.yml # Resources/Prototypes/Entities/Structures/Doors/Windoors/assembly.yml # Resources/Prototypes/Entities/Structures/Doors/Windoors/base_structurewindoors.yml # Resources/Prototypes/Entities/Structures/Furniture/dresser.yml # Resources/Prototypes/Entities/Structures/Lighting/base_lighting.yml # Resources/Prototypes/Entities/Structures/Power/cable_terminal.yml # Resources/Prototypes/Entities/Structures/Walls/grille.yml # Resources/Prototypes/Entities/Structures/Walls/walls.yml # Resources/Prototypes/Entities/Structures/stairs.yml # Resources/Prototypes/_White/Entities/Objects/Misc/books.yml
252 lines
9.3 KiB
C#
252 lines
9.3 KiB
C#
using System.Numerics;
|
|
using Content.Server._White.Other.ChangeThrowForceSystem;
|
|
using Content.Server.Damage.Components;
|
|
using Content.Server.Inventory;
|
|
using Content.Server.Stack;
|
|
using Content.Server.Stunnable;
|
|
using Content.Shared._White.Cult.Systems;
|
|
using Content.Shared._White.MagGloves;
|
|
using Content.Shared.ActionBlocker;
|
|
using Content.Shared.Body.Part;
|
|
using Content.Shared.CombatMode;
|
|
using Content.Shared.Damage.Systems;
|
|
using Content.Shared.Explosion;
|
|
using Content.Shared.Hands.Components;
|
|
using Content.Shared.Hands.EntitySystems;
|
|
using Content.Shared.Input;
|
|
using Content.Shared.Inventory.VirtualItem;
|
|
using Content.Shared.Movement.Pulling.Components;
|
|
using Content.Shared.Movement.Pulling.Events;
|
|
using Content.Shared.Movement.Pulling.Systems;
|
|
using Content.Shared.Stacks;
|
|
using Content.Shared.Throwing;
|
|
using Robust.Shared.GameStates;
|
|
using Robust.Shared.Input.Binding;
|
|
using Robust.Shared.Map;
|
|
using Robust.Shared.Player;
|
|
using Robust.Shared.Timing;
|
|
using Robust.Shared.Utility;
|
|
|
|
namespace Content.Server.Hands.Systems
|
|
{
|
|
public sealed class HandsSystem : SharedHandsSystem
|
|
{
|
|
[Dependency] private readonly IGameTiming _timing = default!;
|
|
[Dependency] private readonly StackSystem _stackSystem = default!;
|
|
[Dependency] private readonly VirtualItemSystem _virtualItemSystem = default!;
|
|
[Dependency] private readonly ActionBlockerSystem _actionBlockerSystem = default!;
|
|
[Dependency] private readonly SharedHandsSystem _handsSystem = default!;
|
|
[Dependency] private readonly SharedTransformSystem _transformSystem = default!;
|
|
[Dependency] private readonly PullingSystem _pullingSystem = default!;
|
|
[Dependency] private readonly ThrowingSystem _throwingSystem = default!;
|
|
[Dependency] private readonly CultItemSystem _cultItem = default!;
|
|
|
|
public override void Initialize()
|
|
{
|
|
base.Initialize();
|
|
|
|
SubscribeLocalEvent<HandsComponent, DisarmedEvent>(OnDisarmed, before: new[] {typeof(StunSystem), typeof(StaminaSystem)});
|
|
|
|
SubscribeLocalEvent<HandsComponent, PullStartedMessage>(HandlePullStarted);
|
|
SubscribeLocalEvent<HandsComponent, PullStoppedMessage>(HandlePullStopped);
|
|
|
|
SubscribeLocalEvent<HandsComponent, BodyPartAddedEvent>(HandleBodyPartAdded);
|
|
SubscribeLocalEvent<HandsComponent, BodyPartRemovedEvent>(HandleBodyPartRemoved);
|
|
|
|
SubscribeLocalEvent<HandsComponent, ComponentGetState>(GetComponentState);
|
|
|
|
SubscribeLocalEvent<HandsComponent, BeforeExplodeEvent>(OnExploded);
|
|
|
|
CommandBinds.Builder
|
|
.Bind(ContentKeyFunctions.ThrowItemInHand, new PointerInputCmdHandler(HandleThrowItem))
|
|
.Register<HandsSystem>();
|
|
}
|
|
|
|
public override void Shutdown()
|
|
{
|
|
base.Shutdown();
|
|
|
|
CommandBinds.Unregister<HandsSystem>();
|
|
}
|
|
|
|
private void GetComponentState(EntityUid uid, HandsComponent hands, ref ComponentGetState args)
|
|
{
|
|
args.State = new HandsComponentState(hands);
|
|
}
|
|
|
|
private void OnExploded(Entity<HandsComponent> ent, ref BeforeExplodeEvent args)
|
|
{
|
|
if (ent.Comp.DisableExplosionRecursion)
|
|
return;
|
|
|
|
foreach (var hand in ent.Comp.Hands.Values)
|
|
{
|
|
if (hand.HeldEntity is { } uid)
|
|
args.Contents.Add(uid);
|
|
}
|
|
}
|
|
|
|
private void OnDisarmed(EntityUid uid, HandsComponent component, DisarmedEvent args)
|
|
{
|
|
if (args.Handled)
|
|
return;
|
|
|
|
if (HasComp<PreventDisarmComponent>(uid))
|
|
return;
|
|
|
|
// Break any pulls
|
|
if (TryComp(uid, out PullerComponent? puller) && TryComp(puller.Pulling, out PullableComponent? pullable))
|
|
_pullingSystem.TryStopPull(puller.Pulling.Value, pullable);
|
|
|
|
if (!_handsSystem.TryDrop(uid, component.ActiveHand!, checkActionBlocker: false))
|
|
return;
|
|
|
|
args.PopupPrefix = "disarm-action-";
|
|
|
|
args.Handled = true; // no shove/stun.
|
|
}
|
|
|
|
private void HandleBodyPartAdded(EntityUid uid, HandsComponent component, ref BodyPartAddedEvent args)
|
|
{
|
|
if (args.Part.Comp.PartType != BodyPartType.Hand)
|
|
return;
|
|
|
|
// If this annoys you, which it should.
|
|
// Ping Smugleaf.
|
|
var location = args.Part.Comp.Symmetry switch
|
|
{
|
|
BodyPartSymmetry.None => HandLocation.Middle,
|
|
BodyPartSymmetry.Left => HandLocation.Left,
|
|
BodyPartSymmetry.Right => HandLocation.Right,
|
|
_ => throw new ArgumentOutOfRangeException(nameof(args.Part.Comp.Symmetry))
|
|
};
|
|
|
|
AddHand(uid, args.Slot, location);
|
|
}
|
|
|
|
private void HandleBodyPartRemoved(EntityUid uid, HandsComponent component, ref BodyPartRemovedEvent args)
|
|
{
|
|
if (args.Part.Comp.PartType != BodyPartType.Hand)
|
|
return;
|
|
|
|
RemoveHand(uid, args.Slot);
|
|
}
|
|
|
|
#region pulling
|
|
|
|
private void HandlePullStarted(EntityUid uid, HandsComponent component, PullStartedMessage args)
|
|
{
|
|
if (args.PullerUid != uid)
|
|
return;
|
|
|
|
if (TryComp<PullerComponent>(args.PullerUid, out var pullerComp) && !pullerComp.NeedsHands)
|
|
return;
|
|
|
|
if (!_virtualItemSystem.TrySpawnVirtualItemInHand(args.PulledUid, uid))
|
|
{
|
|
DebugTools.Assert("Unable to find available hand when starting pulling??");
|
|
}
|
|
}
|
|
|
|
private void HandlePullStopped(EntityUid uid, HandsComponent component, PullStoppedMessage args)
|
|
{
|
|
if (args.PullerUid != uid)
|
|
return;
|
|
|
|
// Try find hand that is doing this pull.
|
|
// and clear it.
|
|
foreach (var hand in component.Hands.Values)
|
|
{
|
|
if (hand.HeldEntity == null
|
|
|| !TryComp(hand.HeldEntity, out VirtualItemComponent? virtualItem)
|
|
|| virtualItem.BlockingEntity != args.PulledUid)
|
|
{
|
|
continue;
|
|
}
|
|
|
|
QueueDel(hand.HeldEntity.Value);
|
|
break;
|
|
}
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region interactions
|
|
|
|
private bool HandleThrowItem(ICommonSession? playerSession, EntityCoordinates coordinates, EntityUid entity)
|
|
{
|
|
if (playerSession?.AttachedEntity is not {Valid: true} player || !Exists(player))
|
|
return false;
|
|
|
|
return ThrowHeldItem(player, coordinates);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Throw the player's currently held item.
|
|
/// </summary>
|
|
public bool ThrowHeldItem(EntityUid player, EntityCoordinates coordinates, float minDistance = 0.1f)
|
|
{
|
|
if (ContainerSystem.IsEntityInContainer(player) ||
|
|
!TryComp(player, out HandsComponent? hands) ||
|
|
hands.ActiveHandEntity is not { } throwEnt ||
|
|
!_actionBlockerSystem.CanThrow(player, throwEnt))
|
|
return false;
|
|
|
|
// WD EDIT START
|
|
if (HasComp<DamageOtherOnHitComponent>(throwEnt) && !_cultItem.CanThrow(player, throwEnt))
|
|
return false;
|
|
// WD EDIT END
|
|
|
|
if (_timing.CurTime < hands.NextThrowTime)
|
|
return false;
|
|
hands.NextThrowTime = _timing.CurTime + hands.ThrowCooldown;
|
|
|
|
if (EntityManager.TryGetComponent(throwEnt, out StackComponent? stack) && stack.Count > 1 && stack.ThrowIndividually)
|
|
{
|
|
var splitStack = _stackSystem.Split(throwEnt, 1, EntityManager.GetComponent<TransformComponent>(player).Coordinates, stack);
|
|
|
|
if (splitStack is not {Valid: true})
|
|
return false;
|
|
|
|
throwEnt = splitStack.Value;
|
|
}
|
|
|
|
var direction = coordinates.ToMapPos(EntityManager, _transformSystem) - Transform(player).WorldPosition;
|
|
if (direction == Vector2.Zero)
|
|
return true;
|
|
|
|
var length = direction.Length();
|
|
var distance = Math.Clamp(length, minDistance, hands.ThrowRange);
|
|
direction *= distance/length;
|
|
|
|
var throwStrength = hands.ThrowForceMultiplier;
|
|
|
|
if (TryComp<ChangeThrowForceComponent>(throwEnt, out var thrownChangeForceComponent))
|
|
{
|
|
var component = EnsureComp<ChangeThrowForceComponent>(player);
|
|
component.ThrowForce = thrownChangeForceComponent.ThrowForce;
|
|
}
|
|
|
|
// Let other systems change the thrown entity (useful for virtual items)
|
|
// or the throw strength.
|
|
var ev = new BeforeThrowEvent(throwEnt, direction, throwStrength, player);
|
|
RaiseLocalEvent(player, ref ev);
|
|
|
|
if (ev.Cancelled)
|
|
return true;
|
|
|
|
// This can grief the above event so we raise it afterwards
|
|
if (IsHolding(player, throwEnt, out _, hands) && !TryDrop(player, throwEnt, handsComp: hands))
|
|
return false;
|
|
|
|
_throwingSystem.TryThrow(ev.ItemUid, ev.Direction, ev.ThrowStrength, ev.PlayerUid);
|
|
|
|
RemComp<ChangeThrowForceComponent>(player);
|
|
|
|
return true;
|
|
}
|
|
|
|
#endregion
|
|
}
|
|
}
|