Fixes Blocking bugs (#9424)

* Fixes Riot shield bugs

* Removes redundant check and extra parenthesis

* Requested changes

* Prevent block with another shield if already blocking.
This commit is contained in:
keronshb
2022-07-10 21:50:09 -04:00
committed by GitHub
parent b9a0894d7c
commit 4a89446e03
3 changed files with 64 additions and 5 deletions

View File

@@ -1,11 +1,14 @@
using Content.Shared.Actions;
using Content.Shared.Actions.ActionTypes;
using Content.Shared.Buckle.Components;
using Content.Shared.Hands;
using Content.Shared.Hands.EntitySystems;
using Content.Shared.IdentityManagement;
using Content.Shared.Physics;
using Content.Shared.Popups;
using Content.Shared.Toggleable;
using Robust.Shared.Containers;
using Robust.Shared.Map;
using Robust.Shared.Physics;
using Robust.Shared.Physics.Dynamics;
using Robust.Shared.Player;
@@ -21,6 +24,8 @@ public sealed class BlockingSystem : EntitySystem
[Dependency] private readonly FixtureSystem _fixtureSystem = default!;
[Dependency] private readonly SharedHandsSystem _handsSystem = default!;
[Dependency] private readonly SharedPopupSystem _popupSystem = default!;
[Dependency] private readonly IMapManager _mapManager = default!;
[Dependency] private readonly SharedContainerSystem _containerSystem = default!;
public override void Initialize()
{
@@ -71,6 +76,17 @@ public sealed class BlockingSystem : EntitySystem
if(args.Handled)
return;
foreach (var shield in _handsSystem.EnumerateHeld(args.Performer))
{
if (shield == uid)
continue;
if (TryComp<BlockingComponent>(shield, out var otherBlockComp) && otherBlockComp.IsBlocking)
{
CantBlockError(args.Performer);
return;
}
}
if (component.IsBlocking)
StopBlocking(uid, component, args.Performer);
else
@@ -112,11 +128,16 @@ public sealed class BlockingSystem : EntitySystem
if (component.BlockingToggleAction != null)
{
if (_containerSystem.IsEntityInContainer(user) || !_mapManager.TryFindGridAt(xform.MapPosition, out var grid))
{
CantBlockError(user);
return false;
}
_transformSystem.AnchorEntity(xform);
if (!xform.Anchored)
{
var msgError = Loc.GetString("action-popup-blocking-user-cant-block");
_popupSystem.PopupEntity(msgError, user, Filter.Entities(user));
CantBlockError(user);
return false;
}
_actionsSystem.SetToggled(component.BlockingToggleAction, true);
@@ -141,6 +162,12 @@ public sealed class BlockingSystem : EntitySystem
return true;
}
private void CantBlockError(EntityUid user)
{
var msgError = Loc.GetString("action-popup-blocking-user-cant-block");
_popupSystem.PopupEntity(msgError, user, Filter.Entities(user));
}
/// <summary>
/// Called where you want the user to stop blocking.
/// </summary>
@@ -166,7 +193,9 @@ public sealed class BlockingSystem : EntitySystem
if (component.BlockingToggleAction != null && TryComp<BlockingUserComponent>(user, out var blockingUserComponent)
&& TryComp<PhysicsComponent>(user, out var physicsComponent))
{
_transformSystem.Unanchor(xform);
if (xform.Anchored)
_transformSystem.Unanchor(xform);
_actionsSystem.SetToggled(component.BlockingToggleAction, false);
_fixtureSystem.DestroyFixture(physicsComponent, BlockingComponent.BlockFixtureID);
physicsComponent.BodyType = blockingUserComponent.OriginalBodyType;
@@ -181,6 +210,7 @@ public sealed class BlockingSystem : EntitySystem
/// <summary>
/// Called where you want someone to stop blocking and to remove the <see cref="BlockingUserComponent"/> from them
/// Won't remove the <see cref="BlockingUserComponent"/> if they're holding another blocking item
/// </summary>
/// <param name="uid"> The item the component is attached to</param>
/// <param name="component"> The <see cref="BlockingComponent"/> </param>
@@ -190,6 +220,15 @@ public sealed class BlockingSystem : EntitySystem
if (component.IsBlocking)
StopBlocking(uid, component, user);
foreach (var shield in _handsSystem.EnumerateHeld(user))
{
if (HasComp<BlockingComponent>(shield) && TryComp<BlockingUserComponent>(user, out var blockingUserComponent))
{
blockingUserComponent.BlockingItem = shield;
return;
}
}
RemComp<BlockingUserComponent>(user);
component.User = null;
}