Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feature] Grab / Захват #23

Draft
wants to merge 5 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Content.Server/Alert/Click/StopPulling.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public void AlertClicked(EntityUid player)
if (entManager.TryGetComponent(player, out PullerComponent? puller) &&
entManager.TryGetComponent(puller.Pulling, out PullableComponent? pullableComp))
{
ps.TryStopPull(puller.Pulling.Value, pullableComp, user: player);
ps.TryLowerGrabStage(puller.Pulling.Value, player, true); // WD EDIT
}
}
}
Expand Down
13 changes: 12 additions & 1 deletion Content.Server/Body/Systems/RespiratorSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
using Content.Shared.Damage;
using Content.Shared.Database;
using Content.Shared.Mobs.Systems;
using Content.Shared.Movement.Pulling.Components;
using Content.Shared.Movement.Pulling.Systems;
using JetBrains.Annotations;
using Robust.Shared.Timing;

Expand Down Expand Up @@ -50,6 +52,15 @@ private void OnUnpaused(Entity<RespiratorComponent> ent, ref EntityUnpausedEvent
ent.Comp.NextUpdate += args.PausedTime;
}

// WD EDIT START
public bool CanBreathe(EntityUid uid)
{
if (TryComp<PullableComponent>(uid, out var pullable) && pullable.GrabStage == GrabStage.Suffocate)
return false;
return true;
}
// WD EDIT END

public override void Update(float frameTime)
{
base.Update(frameTime);
Expand Down Expand Up @@ -82,7 +93,7 @@ public override void Update(float frameTime)
}
}

if (respirator.Saturation < respirator.SuffocationThreshold)
if (respirator.Saturation < respirator.SuffocationThreshold || !CanBreathe(uid)) // WD EDIT
{
if (_gameTiming.CurTime >= respirator.LastGaspPopupTime + respirator.GaspPopupCooldown)
{
Expand Down
28 changes: 27 additions & 1 deletion Content.Server/Hands/Systems/HandsSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using Content.Shared.Body.Part;
using Content.Shared.CombatMode;
using Content.Shared.Explosion;
using Content.Shared.Hands;
using Content.Shared.Hands.Components;
using Content.Shared.Hands.EntitySystems;
using Content.Shared.Input;
Expand Down Expand Up @@ -88,7 +89,7 @@ private void OnDisarmed(EntityUid uid, HandsComponent component, DisarmedEvent a

// Break any pulls
if (TryComp(uid, out PullerComponent? puller) && TryComp(puller.Pulling, out PullableComponent? pullable))
_pullingSystem.TryStopPull(puller.Pulling.Value, pullable);
_pullingSystem.TryStopPull(puller.Pulling.Value, pullable, ignoreGrab: true); // WD EDIT

if (!_handsSystem.TryDrop(uid, component.ActiveHand!, null, checkActionBlocker: false))
return;
Expand Down Expand Up @@ -168,6 +169,20 @@ private bool HandleThrowItem(ICommonSession? playerSession, EntityCoordinates co
if (playerSession?.AttachedEntity is not {Valid: true} player || !Exists(player))
return false;

// WD EDIT START
if (TryGetActiveItem(player, out var item) && TryComp<VirtualItemComponent>(item, out var virtComp))
{
var userEv = new VirtualItemDropAttemptEvent(virtComp.BlockingEntity, player, item.Value, true);
RaiseLocalEvent(player, userEv);

var targEv = new VirtualItemDropAttemptEvent(virtComp.BlockingEntity, player, item.Value, true);
RaiseLocalEvent(virtComp.BlockingEntity, targEv);

if (userEv.Cancelled || targEv.Cancelled)
return false;
}
// WD EDIT END

return ThrowHeldItem(player, coordinates);
}

Expand Down Expand Up @@ -211,6 +226,17 @@ hands.ActiveHandEntity is not { } throwEnt ||
var ev = new BeforeThrowEvent(throwEnt, direction, throwStrength, player);
RaiseLocalEvent(player, ref ev);

// WD EDIT START
if (TryComp<VirtualItemComponent>(throwEnt, out var virt))
{
var userEv = new VirtualItemThrownEvent(virt.BlockingEntity, player, throwEnt, direction);
RaiseLocalEvent(player, userEv);

var targEv = new VirtualItemThrownEvent(virt.BlockingEntity, player, throwEnt, direction);
RaiseLocalEvent(virt.BlockingEntity, targEv);
}
// WD EDIT END

if (ev.Cancelled)
return true;

Expand Down
2 changes: 1 addition & 1 deletion Content.Server/Implants/SubdermalImplantSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ private void OnScramImplant(EntityUid uid, SubdermalImplantComponent component,
// We need stop the user from being pulled so they don't just get "attached" with whoever is pulling them.
// This can for example happen when the user is cuffed and being pulled.
if (TryComp<PullableComponent>(ent, out var pull) && _pullingSystem.IsPulled(ent, pull))
_pullingSystem.TryStopPull(ent, pull);
_pullingSystem.TryStopPull(ent, pull, ignoreGrab: true); // WD EDIT

var xform = Transform(ent);
var targetCoords = SelectRandomTileInRange(xform, implant.TeleportRadius);
Expand Down
2 changes: 1 addition & 1 deletion Content.Shared/Administration/AdminFrozenSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ private void OnStartup(EntityUid uid, AdminFrozenComponent component, ComponentS
{
if (TryComp<PullableComponent>(uid, out var pullable))
{
_pulling.TryStopPull(uid, pullable);
_pulling.TryStopPull(uid, pullable, ignoreGrab: true); // WD EDIT
}

UpdateCanMove(uid, component, args);
Expand Down
5 changes: 5 additions & 0 deletions Content.Shared/CombatMode/SharedCombatModeSystem.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
using Content.Shared.Actions;
using Content.Shared.MouseRotator;
using Content.Shared.Movement.Components;
using Content.Shared.Movement.Pulling.Components;
using Content.Shared.Movement.Pulling.Systems;
using Content.Shared.Popups;
using Robust.Shared.Network;
using Robust.Shared.Timing;
Expand Down Expand Up @@ -75,6 +77,9 @@ public virtual void SetInCombatMode(EntityUid entity, bool value, CombatModeComp
if (component.IsInCombatMode == value)
return;

if (value && TryComp<PullableComponent>(entity, out var pullable) && pullable.GrabStage != GrabStage.No) // WD EDIT
return;

component.IsInCombatMode = value;
Dirty(entity, component);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ private void OnAnchorComplete(EntityUid uid, AnchorableComponent component, TryA

if (TryComp<PullableComponent>(uid, out var pullable) && pullable.Puller != null)
{
_pulling.TryStopPull(uid, pullable);
_pulling.TryStopPull(uid, pullable, ignoreGrab: true); // WD EDIT
}

// TODO: Anchoring snaps rn anyway!
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,27 @@ private void SwapHandsPressed(ICommonSession? session)
private bool DropPressed(ICommonSession? session, EntityCoordinates coords, EntityUid netEntity)
{
if (TryComp(session?.AttachedEntity, out HandsComponent? hands) && hands.ActiveHand != null)
TryDrop(session.AttachedEntity.Value, hands.ActiveHand, coords, handsComp: hands);
{
// WD EDIT START
if (session != null)
{
var ent = session.AttachedEntity.Value;

if (TryGetActiveItem(ent, out var item) && TryComp<VirtualItemComponent>(item, out var virtComp))
{
var userEv = new VirtualItemDropAttemptEvent(virtComp.BlockingEntity, ent, item.Value, false);
RaiseLocalEvent(ent, userEv);

var targEv = new VirtualItemDropAttemptEvent(virtComp.BlockingEntity, ent, item.Value, false);
RaiseLocalEvent(virtComp.BlockingEntity, targEv);

if (userEv.Cancelled || targEv.Cancelled)
return false;
}
TryDrop(ent, hands.ActiveHand, coords, handsComp: hands);
}
}
// WD EDIT END

// always send to server.
return false;
Expand Down
39 changes: 39 additions & 0 deletions Content.Shared/Hands/EntitySystems/SharedHandsSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,45 @@ public bool TryGetEmptyHand(EntityUid uid, [NotNullWhen(true)] out Hand? emptyHa
return false;
}

// WD EDIT START
public bool TryGetActiveHand(Entity<HandsComponent?> entity, [NotNullWhen(true)] out Hand? hand)
{
if (!Resolve(entity, ref entity.Comp, false))
{
hand = null;
return false;
}

hand = entity.Comp.ActiveHand;
return hand != null;
}

public bool TryGetActiveItem(Entity<HandsComponent?> entity, [NotNullWhen(true)] out EntityUid? item)
{
if (!TryGetActiveHand(entity, out var hand))
{
item = null;
return false;
}

item = hand.HeldEntity;
return item != null;
}

public Hand? GetActiveHand(Entity<HandsComponent?> entity)
{
if (!Resolve(entity, ref entity.Comp))
return null;

return entity.Comp.ActiveHand;
}

public EntityUid? GetActiveItem(Entity<HandsComponent?> entity)
{
return GetActiveHand(entity)?.HeldEntity;
}
// WD EDIT END

/// <summary>
/// Enumerate over hands, starting with the currently active hand.
/// </summary>
Expand Down
45 changes: 44 additions & 1 deletion Content.Shared/Hands/HandEvents.cs
Original file line number Diff line number Diff line change
Expand Up @@ -148,14 +148,57 @@ public sealed class VirtualItemDeletedEvent : EntityEventArgs
{
public EntityUid BlockingEntity;
public EntityUid User;
public EntityUid VirtualItem; // WD EDIT

public VirtualItemDeletedEvent(EntityUid blockingEntity, EntityUid user)
public VirtualItemDeletedEvent(EntityUid blockingEntity, EntityUid user, EntityUid virtualItem) // WD EDIT
{
BlockingEntity = blockingEntity;
User = user;
VirtualItem = virtualItem; // WD EDIT
}
}

// WD EDIT START
/// <summary>
/// Raised directed on both the blocking entity and user when
/// a virtual hand item is thrown (at least attempted to).
/// </summary>
public sealed class VirtualItemThrownEvent : EntityEventArgs
{
public EntityUid BlockingEntity;
public EntityUid User;
public EntityUid VirtualItem;
public Vector2 Direction;
public VirtualItemThrownEvent(EntityUid blockingEntity, EntityUid user, EntityUid virtualItem, Vector2 direction)
{
BlockingEntity = blockingEntity;
User = user;
VirtualItem = virtualItem;
Direction = direction;
}
}

/// <summary>
/// Raised directed on both the blocking entity and user when
/// user tries to drop it by keybind.
/// Cancellable.
/// </summary>
public sealed class VirtualItemDropAttemptEvent : CancellableEntityEventArgs
{
public EntityUid BlockingEntity;
public EntityUid User;
public EntityUid VirtualItem;
public bool Throw;
public VirtualItemDropAttemptEvent(EntityUid blockingEntity, EntityUid user, EntityUid virtualItem, bool thrown)
{
BlockingEntity = blockingEntity;
User = user;
VirtualItem = virtualItem;
Throw = thrown;
}
}
// WD EDIT END

/// <summary>
/// Raised when putting an entity into a hand slot
/// </summary>
Expand Down
52 changes: 44 additions & 8 deletions Content.Shared/Inventory/VirtualItem/SharedVirtualItemSystem.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
using System.Diagnostics.CodeAnalysis;
using Content.Shared.Hands;
using Content.Shared.Hands.Components;
using Content.Shared.Hands.EntitySystems;
using Content.Shared.Interaction;
using Content.Shared.Inventory.Events;
using Content.Shared.Item;
using Content.Shared.Popups;
using Robust.Shared.Containers;
using Robust.Shared.Network;
using Robust.Shared.Prototypes;
Expand All @@ -29,6 +31,7 @@ public abstract class SharedVirtualItemSystem : EntitySystem
[Dependency] private readonly SharedItemSystem _itemSystem = default!;
[Dependency] private readonly InventorySystem _inventorySystem = default!;
[Dependency] private readonly SharedHandsSystem _handsSystem = default!;
[Dependency] private readonly SharedPopupSystem _popup = default!; // WD EDIT

[ValidatePrototypeId<EntityPrototype>]
private const string VirtualItem = "VirtualItem";
Expand Down Expand Up @@ -76,20 +79,53 @@ private void OnBeforeRangedInteract(Entity<VirtualItemComponent> ent, ref Before
/// </summary>
/// <param name="blockingEnt">The entity we will make a virtual entity copy of</param>
/// <param name="user">The entity that we want to insert the virtual entity</param>
public bool TrySpawnVirtualItemInHand(EntityUid blockingEnt, EntityUid user)
public bool TrySpawnVirtualItemInHand(EntityUid blockingEnt, EntityUid user, bool dropOthers = false) // WD EDIT
{
return TrySpawnVirtualItemInHand(blockingEnt, user, out _);
return TrySpawnVirtualItemInHand(blockingEnt, user, out _, dropOthers); // WD EDIT
}

// WD EDIT START
/// <inheritdoc cref="TrySpawnVirtualItemInHand(Robust.Shared.GameObjects.EntityUid,Robust.Shared.GameObjects.EntityUid)"/>
public bool TrySpawnVirtualItemInHand(EntityUid blockingEnt, EntityUid user, [NotNullWhen(true)] out EntityUid? virtualItem)
public bool TrySpawnVirtualItemInHand(EntityUid blockingEnt, EntityUid user, [NotNullWhen(true)] out EntityUid? virtualItem, bool dropOthers = false, Hand? empty = null)
{
if (!TrySpawnVirtualItem(blockingEnt, user, out virtualItem) || !_handsSystem.TryGetEmptyHand(user, out var hand))
virtualItem = null;
if (empty == null && !_handsSystem.TryGetEmptyHand(user, out empty))
{
if (!dropOthers)
return false;

foreach (var hand in _handsSystem.EnumerateHands(user))
{
if (hand.HeldEntity is not { } held)
continue;

if (held == blockingEnt)
continue;

if (HasComp<VirtualItemComponent>(held))
continue;

if (!_handsSystem.TryDrop(user, hand))
continue;

if (!TerminatingOrDeleted(held))
_popup.PopupClient(Loc.GetString("virtual-item-dropped-other", ("dropped", held)), user, user);

empty = hand;
break;
}
}

if (empty == null)
return false;

if (!TrySpawnVirtualItem(blockingEnt, user, out virtualItem))
return false;

_handsSystem.DoPickup(user, hand, virtualItem.Value);
_handsSystem.DoPickup(user, empty, virtualItem.Value);
return true;
}
// WD EDIT END

/// <summary>
/// Scan the user's hands until we find the virtual entity, if the
Expand Down Expand Up @@ -188,7 +224,7 @@ public bool TrySpawnVirtualItem(EntityUid blockingEnt, EntityUid user, [NotNullW

var pos = Transform(user).Coordinates;
virtualItem = Spawn(VirtualItem, pos);
var virtualItemComp = Comp<VirtualItemComponent>(virtualItem.Value);
var virtualItemComp = EnsureComp<VirtualItemComponent>(virtualItem.Value); // WD EDIT
virtualItemComp.BlockingEntity = blockingEnt;
Dirty(virtualItem.Value, virtualItemComp);
return true;
Expand All @@ -199,10 +235,10 @@ public bool TrySpawnVirtualItem(EntityUid blockingEnt, EntityUid user, [NotNullW
/// </summary>
public void DeleteVirtualItem(Entity<VirtualItemComponent> item, EntityUid user)
{
var userEv = new VirtualItemDeletedEvent(item.Comp.BlockingEntity, user);
var userEv = new VirtualItemDeletedEvent(item.Comp.BlockingEntity, user, item.Owner); // WD EDIT
RaiseLocalEvent(user, userEv);

var targEv = new VirtualItemDeletedEvent(item.Comp.BlockingEntity, user);
var targEv = new VirtualItemDeletedEvent(item.Comp.BlockingEntity, user, item.Owner); // WD EDIT
RaiseLocalEvent(item.Comp.BlockingEntity, targEv);

if (TerminatingOrDeleted(item))
Expand Down
Loading
Loading