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:
parent
b9a0894d7c
commit
4a89446e03
|
|
@ -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;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,8 +1,10 @@
|
|||
using Content.Shared.Audio;
|
||||
using Content.Shared.Buckle.Components;
|
||||
using Content.Shared.Damage;
|
||||
using Content.Shared.Damage.Prototypes;
|
||||
using Content.Shared.Hands.EntitySystems;
|
||||
using Robust.Shared.Audio;
|
||||
using Robust.Shared.Containers;
|
||||
using Robust.Shared.Player;
|
||||
using Robust.Shared.Prototypes;
|
||||
|
||||
|
|
@ -21,12 +23,30 @@ public sealed class BlockingUserSystem : EntitySystem
|
|||
SubscribeLocalEvent<BlockingUserComponent, DamageChangedEvent>(OnDamageChanged);
|
||||
SubscribeLocalEvent<BlockingUserComponent, DamageModifyEvent>(OnUserDamageModified);
|
||||
|
||||
SubscribeLocalEvent<BlockingUserComponent, EntParentChangedMessage>(OnParentChanged);
|
||||
SubscribeLocalEvent<BlockingUserComponent, ContainerGettingInsertedAttemptEvent>(OnInsertAttempt);
|
||||
SubscribeLocalEvent<BlockingUserComponent, AnchorStateChangedEvent>(OnAnchorChanged);
|
||||
}
|
||||
|
||||
private void OnParentChanged(EntityUid uid, BlockingUserComponent component, ref EntParentChangedMessage args)
|
||||
{
|
||||
if (TryComp<BlockingComponent>(component.BlockingItem, out var blockComp) && blockComp.IsBlocking)
|
||||
{
|
||||
_blockingSystem.StopBlocking(component.BlockingItem.Value, blockComp, uid);
|
||||
}
|
||||
}
|
||||
|
||||
private void OnInsertAttempt(EntityUid uid, BlockingUserComponent component, ContainerGettingInsertedAttemptEvent args)
|
||||
{
|
||||
if (TryComp<BlockingComponent>(component.BlockingItem, out var blockComp) && blockComp.IsBlocking)
|
||||
{
|
||||
_blockingSystem.StopBlocking(component.BlockingItem.Value, blockComp, uid);
|
||||
}
|
||||
}
|
||||
|
||||
private void OnAnchorChanged(EntityUid uid, BlockingUserComponent component, ref AnchorStateChangedEvent args)
|
||||
{
|
||||
if (!args.Anchored)
|
||||
if (args.Anchored)
|
||||
return;
|
||||
|
||||
if (TryComp<BlockingComponent>(component.BlockingItem, out var blockComp) && blockComp.IsBlocking)
|
||||
|
|
|
|||
|
|
@ -7,4 +7,4 @@ action-popup-blocking-disabling-user = You lower your {$shield}!
|
|||
action-popup-blocking-other = {CAPITALIZE(THE($blockerName))} raises {POSS-ADJ($blockerName)} {$shield}!
|
||||
action-popup-blocking-disabling-other = {CAPITALIZE(THE($blockerName))} lowers {POSS-ADJ($blockerName)} {$shield}!
|
||||
|
||||
action-popup-blocking-user-cant-block = The gravity here prevents you from blocking.
|
||||
action-popup-blocking-user-cant-block = You tried to raise your shield, but it was no use.
|
||||
|
|
|
|||
Loading…
Reference in New Issue