Skip to content

Commit

Permalink
Emergency revert for pulling (space-wizards#24923)
Browse files Browse the repository at this point in the history
Revert "Pulling rework (space-wizards#20906)"

This reverts commit 0d8254b.
  • Loading branch information
Jezithyr committed Feb 3, 2024
1 parent 914bab1 commit c15b069
Show file tree
Hide file tree
Showing 53 changed files with 1,358 additions and 763 deletions.
29 changes: 14 additions & 15 deletions Content.Client/Alerts/ClientAlertsSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
using Robust.Client.Player;
using Robust.Shared.Player;
using Robust.Shared.Prototypes;
using Robust.Shared.Timing;

namespace Content.Client.Alerts;

Expand All @@ -13,7 +12,6 @@ public sealed class ClientAlertsSystem : AlertsSystem
{
public AlertOrderPrototype? AlertOrder { get; set; }

[Dependency] private readonly IGameTiming _timing = default!;
[Dependency] private readonly IPlayerManager _playerManager = default!;
[Dependency] private readonly IPrototypeManager _prototypeManager = default!;

Expand Down Expand Up @@ -42,7 +40,7 @@ public IReadOnlyDictionary<AlertKey, AlertState>? ActiveAlerts
{
get
{
var ent = _playerManager.LocalEntity;
var ent = _playerManager.LocalPlayer?.ControlledEntity;
return ent is not null
? GetActiveAlerts(ent.Value)
: null;
Expand All @@ -51,28 +49,29 @@ public IReadOnlyDictionary<AlertKey, AlertState>? ActiveAlerts

protected override void AfterShowAlert(Entity<AlertsComponent> alerts)
{
UpdateHud(alerts);
}
if (_playerManager.LocalPlayer?.ControlledEntity != alerts.Owner)
return;

protected override void AfterClearAlert(Entity<AlertsComponent> alerts)
{
UpdateHud(alerts);
SyncAlerts?.Invoke(this, alerts.Comp.Alerts);
}

private void ClientAlertsHandleState(Entity<AlertsComponent> alerts, ref AfterAutoHandleStateEvent args)
protected override void AfterClearAlert(Entity<AlertsComponent> alertsComponent)
{
UpdateHud(alerts);
if (_playerManager.LocalPlayer?.ControlledEntity != alertsComponent.Owner)
return;

SyncAlerts?.Invoke(this, alertsComponent.Comp.Alerts);
}

private void UpdateHud(Entity<AlertsComponent> entity)
private void ClientAlertsHandleState(EntityUid uid, AlertsComponent component, ref AfterAutoHandleStateEvent args)
{
if (_playerManager.LocalEntity == entity.Owner)
SyncAlerts?.Invoke(this, entity.Comp.Alerts);
if (_playerManager.LocalPlayer?.ControlledEntity == uid)
SyncAlerts?.Invoke(this, component.Alerts);
}

private void OnPlayerAttached(EntityUid uid, AlertsComponent component, LocalPlayerAttachedEvent args)
{
if (_playerManager.LocalEntity != uid)
if (_playerManager.LocalPlayer?.ControlledEntity != uid)
return;

SyncAlerts?.Invoke(this, component.Alerts);
Expand All @@ -82,7 +81,7 @@ protected override void HandleComponentShutdown(EntityUid uid, AlertsComponent c
{
base.HandleComponentShutdown(uid, component, args);

if (_playerManager.LocalEntity != uid)
if (_playerManager.LocalPlayer?.ControlledEntity != uid)
return;

ClearAlerts?.Invoke(this, EventArgs.Empty);
Expand Down
7 changes: 3 additions & 4 deletions Content.Client/Physics/Controllers/MoverController.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
using Content.Shared.Movement.Components;
using Content.Shared.Movement.Pulling.Components;
using Content.Shared.Movement.Systems;
using Robust.Client.GameObjects;
using Content.Shared.Pulling.Components;
using Robust.Client.Physics;
using Robust.Client.Player;
using Robust.Shared.Physics.Components;
Expand All @@ -25,7 +24,7 @@ public override void Initialize()

SubscribeLocalEvent<InputMoverComponent, UpdateIsPredictedEvent>(OnUpdatePredicted);
SubscribeLocalEvent<MovementRelayTargetComponent, UpdateIsPredictedEvent>(OnUpdateRelayTargetPredicted);
SubscribeLocalEvent<PullableComponent, UpdateIsPredictedEvent>(OnUpdatePullablePredicted);
SubscribeLocalEvent<SharedPullableComponent, UpdateIsPredictedEvent>(OnUpdatePullablePredicted);
}

private void OnUpdatePredicted(EntityUid uid, InputMoverComponent component, ref UpdateIsPredictedEvent args)
Expand All @@ -41,7 +40,7 @@ private void OnUpdateRelayTargetPredicted(EntityUid uid, MovementRelayTargetComp
args.IsPredicted = true;
}

private void OnUpdatePullablePredicted(EntityUid uid, PullableComponent component, ref UpdateIsPredictedEvent args)
private void OnUpdatePullablePredicted(EntityUid uid, SharedPullableComponent component, ref UpdateIsPredictedEvent args)
{
// Enable prediction if an entity is being pulled by the player.
// Disable prediction if an entity is being pulled by some non-player entity.
Expand Down
21 changes: 21 additions & 0 deletions Content.Client/Pulling/PullingSystem.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
using Content.Shared.Pulling;
using Content.Shared.Pulling.Components;
using JetBrains.Annotations;
using Robust.Client.Physics;

namespace Content.Client.Pulling
{
[UsedImplicitly]
public sealed class PullingSystem : SharedPullingSystem
{
public override void Initialize()
{
base.Initialize();

UpdatesAfter.Add(typeof(PhysicsSystem));

SubscribeLocalEvent<SharedPullableComponent, PullableMoveMessage>(OnPullableMove);
SubscribeLocalEvent<SharedPullableComponent, PullableStopMovingMessage>(OnPullableStopMove);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
using Content.Shared.Inventory.Events;
using Content.Shared.Item;
using Content.Shared.Movement.Events;
using Content.Shared.Movement.Pulling.Events;
using Content.Shared.Physics.Pull;
using Content.Shared.Throwing;

namespace Content.Client.Replay.Spectator;
Expand Down
2 changes: 1 addition & 1 deletion Content.Client/Throwing/ThrownItemVisualizerSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public override void Initialize()

private void OnAutoHandleState(EntityUid uid, ThrownItemComponent component, ref AfterAutoHandleStateEvent args)
{
if (!TryComp<SpriteComponent>(uid, out var sprite) || !component.Animate)
if (!TryComp<SpriteComponent>(uid, out var sprite))
return;

var animationPlayer = EnsureComp<AnimationPlayerComponent>(uid);
Expand Down
4 changes: 2 additions & 2 deletions Content.IntegrationTests/Tests/Puller/PullerTest.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using Content.Shared.Hands.Components;
using Content.Shared.Movement.Pulling.Components;
using Content.Shared.Prototypes;
using Content.Shared.Pulling.Components;
using Robust.Shared.GameObjects;
using Robust.Shared.Prototypes;

Expand Down Expand Up @@ -29,7 +29,7 @@ await server.WaitAssertion(() =>
{
foreach (var proto in protoManager.EnumeratePrototypes<EntityPrototype>())
{
if (!proto.TryGetComponent(out PullerComponent? puller))
if (!proto.TryGetComponent(out SharedPullerComponent? puller))
continue;
if (!puller.NeedsHands)
Expand Down
8 changes: 4 additions & 4 deletions Content.Server/Alert/Click/StopBeingPulled.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using Content.Shared.ActionBlocker;
using Content.Shared.Alert;
using Content.Shared.Movement.Pulling.Components;
using Content.Shared.Movement.Pulling.Systems;
using Content.Shared.Pulling.Components;
using Content.Shared.Pulling;
using JetBrains.Annotations;

namespace Content.Server.Alert.Click
Expand All @@ -20,9 +20,9 @@ public void AlertClicked(EntityUid player)
if (!entityManager.System<ActionBlockerSystem>().CanInteract(player, null))
return;

if (entityManager.TryGetComponent(player, out PullableComponent? playerPullable))
if (entityManager.TryGetComponent(player, out SharedPullableComponent? playerPullable))
{
entityManager.System<PullingSystem>().TryStopPull(player, playerPullable, user: player);
entityManager.System<SharedPullingSystem>().TryStopPull(playerPullable);
}
}
}
Expand Down
12 changes: 6 additions & 6 deletions Content.Server/Alert/Click/StopPulling.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using Content.Shared.Alert;
using Content.Shared.Movement.Pulling.Components;
using Content.Shared.Movement.Pulling.Systems;
using Content.Shared.Pulling;
using Content.Shared.Pulling.Components;
using JetBrains.Annotations;

namespace Content.Server.Alert.Click
Expand All @@ -15,12 +15,12 @@ public sealed partial class StopPulling : IAlertClick
public void AlertClicked(EntityUid player)
{
var entManager = IoCManager.Resolve<IEntityManager>();
var ps = entManager.System<PullingSystem>();

if (entManager.TryGetComponent(player, out PullerComponent? puller) &&
entManager.TryGetComponent(puller.Pulling, out PullableComponent? pullableComp))
var ps = entManager.System<SharedPullingSystem>();
var playerTarget = ps.GetPulled(player);
if (playerTarget != default && entManager.TryGetComponent(playerTarget, out SharedPullableComponent? playerPullable))
{
ps.TryStopPull(puller.Pulling.Value, pullableComp, user: player);
ps.TryStopPull(playerPullable);
}
}
}
Expand Down
7 changes: 3 additions & 4 deletions Content.Server/Electrocution/ElectrocutionSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
using Content.Shared.Maps;
using Content.Shared.Mobs;
using Content.Shared.Popups;
using Content.Shared.Pulling.Components;
using Content.Shared.Speech.EntitySystems;
using Content.Shared.StatusEffect;
using Content.Shared.Stunnable;
Expand All @@ -31,8 +32,6 @@
using Robust.Shared.Player;
using Robust.Shared.Prototypes;
using Robust.Shared.Random;
using PullableComponent = Content.Shared.Movement.Pulling.Components.PullableComponent;
using PullerComponent = Content.Shared.Movement.Pulling.Components.PullerComponent;

namespace Content.Server.Electrocution;

Expand Down Expand Up @@ -466,14 +465,14 @@ private void GetChainedElectrocutionTargetsRecurse(
all.Add((entity, depth));
visited.Add(entity);

if (TryComp<PullableComponent>(entity, out var pullable) &&
if (TryComp<SharedPullableComponent>(entity, out var pullable) &&
pullable.Puller is { Valid: true } pullerId &&
!visited.Contains(pullerId))
{
GetChainedElectrocutionTargetsRecurse(pullerId, depth + 1, visited, all);
}

if (TryComp<PullerComponent>(entity, out var puller) &&
if (TryComp<SharedPullerComponent>(entity, out var puller) &&
puller.Pulling is { Valid: true } pullingId &&
!visited.Contains(pullingId))
{
Expand Down
23 changes: 11 additions & 12 deletions Content.Server/Hands/Systems/HandsSystem.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System.Numerics;
using Content.Server.Inventory;
using Content.Server.Pulling;
using Content.Server.Stack;
using Content.Server.Stunnable;
using Content.Shared.ActionBlocker;
Expand All @@ -10,9 +11,8 @@
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.Physics.Pull;
using Content.Shared.Pulling.Components;
using Content.Shared.Stacks;
using Content.Shared.Throwing;
using Robust.Shared.GameStates;
Expand Down Expand Up @@ -88,8 +88,9 @@ private void OnDisarmed(EntityUid uid, HandsComponent component, DisarmedEvent a
return;

// Break any pulls
if (TryComp(uid, out PullerComponent? puller) && TryComp(puller.Pulling, out PullableComponent? pullable))
_pullingSystem.TryStopPull(puller.Pulling.Value, pullable);
if (TryComp(uid, out SharedPullerComponent? puller) && puller.Pulling is EntityUid pulled &&
TryComp(pulled, out SharedPullableComponent? pullable))
_pullingSystem.TryStopPull(pullable);

if (!_handsSystem.TryDrop(uid, component.ActiveHand!, null, checkActionBlocker: false))
return;
Expand Down Expand Up @@ -127,21 +128,21 @@ private void HandleBodyPartRemoved(EntityUid uid, HandsComponent component, ref

private void HandlePullStarted(EntityUid uid, HandsComponent component, PullStartedMessage args)
{
if (args.PullerUid != uid)
if (args.Puller.Owner != uid)
return;

if (TryComp<PullerComponent>(args.PullerUid, out var pullerComp) && !pullerComp.NeedsHands)
if (TryComp<SharedPullerComponent>(args.Puller.Owner, out var pullerComp) && !pullerComp.NeedsHands)
return;

if (!_virtualItemSystem.TrySpawnVirtualItemInHand(args.PulledUid, uid))
if (!_virtualItemSystem.TrySpawnVirtualItemInHand(args.Pulled.Owner, uid))
{
DebugTools.Assert("Unable to find available hand when starting pulling??");
}
}

private void HandlePullStopped(EntityUid uid, HandsComponent component, PullStoppedMessage args)
{
if (args.PullerUid != uid)
if (args.Puller.Owner != uid)
return;

// Try find hand that is doing this pull.
Expand All @@ -150,10 +151,8 @@ private void HandlePullStopped(EntityUid uid, HandsComponent component, PullStop
{
if (hand.HeldEntity == null
|| !TryComp(hand.HeldEntity, out VirtualItemComponent? virtualItem)
|| virtualItem.BlockingEntity != args.PulledUid)
{
|| virtualItem.BlockingEntity != args.Pulled.Owner)
continue;
}

QueueDel(hand.HeldEntity.Value);
break;
Expand Down
5 changes: 2 additions & 3 deletions Content.Server/NPC/HTN/Preconditions/PulledPrecondition.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using Content.Shared.Pulling;
using PullingSystem = Content.Shared.Movement.Pulling.Systems.PullingSystem;

namespace Content.Server.NPC.HTN.Preconditions;

Expand All @@ -8,14 +7,14 @@ namespace Content.Server.NPC.HTN.Preconditions;
/// </summary>
public sealed partial class PulledPrecondition : HTNPrecondition
{
private PullingSystem _pulling = default!;
private SharedPullingSystem _pulling = default!;

[ViewVariables(VVAccess.ReadWrite)] [DataField("isPulled")] public bool IsPulled = true;

public override void Initialize(IEntitySystemManager sysManager)
{
base.Initialize(sysManager);
_pulling = sysManager.GetEntitySystem<PullingSystem>();
_pulling = sysManager.GetEntitySystem<SharedPullingSystem>();
}

public override bool IsMet(NPCBlackboard blackboard)
Expand Down
15 changes: 8 additions & 7 deletions Content.Server/Objectives/Systems/StealConditionSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,11 @@
using Robust.Shared.Containers;
using Robust.Shared.Prototypes;
using Robust.Shared.Random;
using Content.Shared.Pulling.Components;
using Content.Shared.Objectives;
using Content.Shared.Mind.Components;
using Content.Shared.Mobs.Systems;
using Content.Shared.Mobs.Components;
using Content.Shared.Movement.Pulling.Components;

namespace Content.Server.Objectives.Systems;

Expand Down Expand Up @@ -99,19 +100,19 @@ private float GetProgress(MindComponent mind, StealConditionComponent condition)
var count = 0;

//check pulling object
if (TryComp<PullerComponent>(mind.OwnedEntity, out var pull)) //TO DO: to make the code prettier? don't like the repetition
if (TryComp<SharedPullerComponent>(mind.OwnedEntity, out var pull)) //TO DO: to make the code prettier? don't like the repetition
{
var pulledEntity = pull.Pulling;
if (pulledEntity != null)
var pullid = pull.Pulling;
if (pullid != null)
{
// check if this is the item
if (CheckStealTarget(pulledEntity.Value, condition)) count++;
if (CheckStealTarget(pullid.Value, condition)) count++;

//we don't check the inventories of sentient entity
if (!HasComp<MindContainerComponent>(pulledEntity))
if (!TryComp<MindContainerComponent>(pullid, out var pullMind))
{
// if it is a container check its contents
if (_containerQuery.TryGetComponent(pulledEntity, out var containerManager))
if (_containerQuery.TryGetComponent(pullid, out var containerManager))
stack.Push(containerManager);
}
}
Expand Down
Loading

0 comments on commit c15b069

Please sign in to comment.