Predict blocking examine + fix blocking breaking persistence (#36619)
* Predict blocking examine No idea why this was blocked. * Fix blocking * remove nullcheck that made no sense * predict popups --------- Co-authored-by: slarticodefast <161409025+slarticodefast@users.noreply.github.com>
This commit is contained in:
@@ -13,13 +13,9 @@ using Content.Shared.Physics;
|
|||||||
using Content.Shared.Popups;
|
using Content.Shared.Popups;
|
||||||
using Content.Shared.Toggleable;
|
using Content.Shared.Toggleable;
|
||||||
using Content.Shared.Verbs;
|
using Content.Shared.Verbs;
|
||||||
using Robust.Shared.Network;
|
|
||||||
using Robust.Shared.Physics;
|
using Robust.Shared.Physics;
|
||||||
using Robust.Shared.Physics.Components;
|
using Robust.Shared.Physics.Components;
|
||||||
using Robust.Shared.Physics.Systems;
|
using Robust.Shared.Physics.Systems;
|
||||||
using Robust.Shared.Player;
|
|
||||||
using Robust.Shared.Prototypes;
|
|
||||||
using Robust.Shared.Timing;
|
|
||||||
using Robust.Shared.Utility;
|
using Robust.Shared.Utility;
|
||||||
|
|
||||||
namespace Content.Shared.Blocking;
|
namespace Content.Shared.Blocking;
|
||||||
@@ -35,8 +31,6 @@ public sealed partial class BlockingSystem : EntitySystem
|
|||||||
[Dependency] private readonly EntityLookupSystem _lookup = default!;
|
[Dependency] private readonly EntityLookupSystem _lookup = default!;
|
||||||
[Dependency] private readonly SharedPhysicsSystem _physics = default!;
|
[Dependency] private readonly SharedPhysicsSystem _physics = default!;
|
||||||
[Dependency] private readonly ExamineSystemShared _examine = default!;
|
[Dependency] private readonly ExamineSystemShared _examine = default!;
|
||||||
[Dependency] private readonly INetManager _net = default!;
|
|
||||||
[Dependency] private readonly IGameTiming _gameTiming = default!;
|
|
||||||
|
|
||||||
public override void Initialize()
|
public override void Initialize()
|
||||||
{
|
{
|
||||||
@@ -156,61 +150,53 @@ public sealed partial class BlockingSystem : EntitySystem
|
|||||||
var msgUser = Loc.GetString("action-popup-blocking-user", ("shield", shieldName));
|
var msgUser = Loc.GetString("action-popup-blocking-user", ("shield", shieldName));
|
||||||
var msgOther = Loc.GetString("action-popup-blocking-other", ("blockerName", blockerName), ("shield", shieldName));
|
var msgOther = Loc.GetString("action-popup-blocking-other", ("blockerName", blockerName), ("shield", shieldName));
|
||||||
|
|
||||||
if (component.BlockingToggleAction != null)
|
//Don't allow someone to block if they're not parented to a grid
|
||||||
|
if (xform.GridUid != xform.ParentUid)
|
||||||
{
|
{
|
||||||
//Don't allow someone to block if they're not parented to a grid
|
CantBlockError(user);
|
||||||
if (xform.GridUid != xform.ParentUid)
|
return false;
|
||||||
{
|
}
|
||||||
CantBlockError(user);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Don't allow someone to block if they're not holding the shield
|
// Don't allow someone to block if they're not holding the shield
|
||||||
if(!_handsSystem.IsHolding(user, item, out _))
|
if (!_handsSystem.IsHolding(user, item, out _))
|
||||||
{
|
{
|
||||||
CantBlockError(user);
|
CantBlockError(user);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
//Don't allow someone to block if someone else is on the same tile
|
//Don't allow someone to block if someone else is on the same tile
|
||||||
var playerTileRef = xform.Coordinates.GetTileRef();
|
var playerTileRef = xform.Coordinates.GetTileRef();
|
||||||
if (playerTileRef != null)
|
if (playerTileRef != null)
|
||||||
|
{
|
||||||
|
var intersecting = _lookup.GetLocalEntitiesIntersecting(playerTileRef.Value, 0f);
|
||||||
|
var mobQuery = GetEntityQuery<MobStateComponent>();
|
||||||
|
foreach (var uid in intersecting)
|
||||||
{
|
{
|
||||||
var intersecting = _lookup.GetLocalEntitiesIntersecting(playerTileRef.Value, 0f);
|
if (uid != user && mobQuery.HasComponent(uid))
|
||||||
var mobQuery = GetEntityQuery<MobStateComponent>();
|
|
||||||
foreach (var uid in intersecting)
|
|
||||||
{
|
{
|
||||||
if (uid != user && mobQuery.HasComponent(uid))
|
TooCloseError(user);
|
||||||
{
|
return false;
|
||||||
TooCloseError(user);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//Don't allow someone to block if they're somehow not anchored.
|
|
||||||
_transformSystem.AnchorEntity(user, xform);
|
|
||||||
if (!xform.Anchored)
|
|
||||||
{
|
|
||||||
CantBlockError(user);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
_actionsSystem.SetToggled(component.BlockingToggleActionEntity, true);
|
|
||||||
if (_gameTiming.IsFirstTimePredicted)
|
|
||||||
{
|
|
||||||
_popupSystem.PopupEntity(msgOther, user, Filter.PvsExcept(user), true);
|
|
||||||
if(_gameTiming.InPrediction)
|
|
||||||
_popupSystem.PopupEntity(msgUser, user, user);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//Don't allow someone to block if they're somehow not anchored.
|
||||||
|
_transformSystem.AnchorEntity(user, xform);
|
||||||
|
if (!xform.Anchored)
|
||||||
|
{
|
||||||
|
CantBlockError(user);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
_actionsSystem.SetToggled(component.BlockingToggleActionEntity, true);
|
||||||
|
_popupSystem.PopupPredicted(msgUser, msgOther, user, user);
|
||||||
|
|
||||||
if (TryComp<PhysicsComponent>(user, out var physicsComponent))
|
if (TryComp<PhysicsComponent>(user, out var physicsComponent))
|
||||||
{
|
{
|
||||||
_fixtureSystem.TryCreateFixture(user,
|
_fixtureSystem.TryCreateFixture(user,
|
||||||
component.Shape,
|
component.Shape,
|
||||||
BlockingComponent.BlockFixtureID,
|
BlockingComponent.BlockFixtureID,
|
||||||
hard: true,
|
hard: true,
|
||||||
collisionLayer: (int) CollisionGroup.WallLayer,
|
collisionLayer: (int)CollisionGroup.WallLayer,
|
||||||
body: physicsComponent);
|
body: physicsComponent);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -223,13 +209,13 @@ public sealed partial class BlockingSystem : EntitySystem
|
|||||||
private void CantBlockError(EntityUid user)
|
private void CantBlockError(EntityUid user)
|
||||||
{
|
{
|
||||||
var msgError = Loc.GetString("action-popup-blocking-user-cant-block");
|
var msgError = Loc.GetString("action-popup-blocking-user-cant-block");
|
||||||
_popupSystem.PopupEntity(msgError, user, user);
|
_popupSystem.PopupClient(msgError, user, user);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void TooCloseError(EntityUid user)
|
private void TooCloseError(EntityUid user)
|
||||||
{
|
{
|
||||||
var msgError = Loc.GetString("action-popup-blocking-user-too-close");
|
var msgError = Loc.GetString("action-popup-blocking-user-too-close");
|
||||||
_popupSystem.PopupEntity(msgError, user, user);
|
_popupSystem.PopupClient(msgError, user, user);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -255,8 +241,7 @@ public sealed partial class BlockingSystem : EntitySystem
|
|||||||
//If the component blocking toggle isn't null, grab the users SharedBlockingUserComponent and PhysicsComponent
|
//If the component blocking toggle isn't null, grab the users SharedBlockingUserComponent and PhysicsComponent
|
||||||
//then toggle the action to false, unanchor the user, remove the hard fixture
|
//then toggle the action to false, unanchor the user, remove the hard fixture
|
||||||
//and set the users bodytype back to their original type
|
//and set the users bodytype back to their original type
|
||||||
if (component.BlockingToggleAction != null && TryComp<BlockingUserComponent>(user, out var blockingUserComponent)
|
if (TryComp<BlockingUserComponent>(user, out var blockingUserComponent) && TryComp<PhysicsComponent>(user, out var physicsComponent))
|
||||||
&& TryComp<PhysicsComponent>(user, out var physicsComponent))
|
|
||||||
{
|
{
|
||||||
if (xform.Anchored)
|
if (xform.Anchored)
|
||||||
_transformSystem.Unanchor(user, xform);
|
_transformSystem.Unanchor(user, xform);
|
||||||
@@ -264,12 +249,7 @@ public sealed partial class BlockingSystem : EntitySystem
|
|||||||
_actionsSystem.SetToggled(component.BlockingToggleActionEntity, false);
|
_actionsSystem.SetToggled(component.BlockingToggleActionEntity, false);
|
||||||
_fixtureSystem.DestroyFixture(user, BlockingComponent.BlockFixtureID, body: physicsComponent);
|
_fixtureSystem.DestroyFixture(user, BlockingComponent.BlockFixtureID, body: physicsComponent);
|
||||||
_physics.SetBodyType(user, blockingUserComponent.OriginalBodyType, body: physicsComponent);
|
_physics.SetBodyType(user, blockingUserComponent.OriginalBodyType, body: physicsComponent);
|
||||||
if (_gameTiming.IsFirstTimePredicted)
|
_popupSystem.PopupPredicted(msgUser, msgOther, user, user);
|
||||||
{
|
|
||||||
_popupSystem.PopupEntity(msgOther, user, Filter.PvsExcept(user), true);
|
|
||||||
if(_gameTiming.InPrediction)
|
|
||||||
_popupSystem.PopupEntity(msgUser, user, user);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
component.IsBlocking = false;
|
component.IsBlocking = false;
|
||||||
@@ -313,7 +293,7 @@ public sealed partial class BlockingSystem : EntitySystem
|
|||||||
|
|
||||||
private void OnVerbExamine(EntityUid uid, BlockingComponent component, GetVerbsEvent<ExamineVerb> args)
|
private void OnVerbExamine(EntityUid uid, BlockingComponent component, GetVerbsEvent<ExamineVerb> args)
|
||||||
{
|
{
|
||||||
if (!args.CanInteract || !args.CanAccess || !_net.IsServer)
|
if (!args.CanInteract || !args.CanAccess)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
var fraction = component.IsBlocking ? component.ActiveBlockFraction : component.PassiveBlockFraction;
|
var fraction = component.IsBlocking ? component.ActiveBlockFraction : component.PassiveBlockFraction;
|
||||||
|
|||||||
@@ -16,13 +16,13 @@ public sealed partial class BlockingComponent : Component
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// The entity that's blocking
|
/// The entity that's blocking
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[ViewVariables, AutoNetworkedField]
|
[DataField, AutoNetworkedField]
|
||||||
public EntityUid? User;
|
public EntityUid? User;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Is it currently blocking?
|
/// Is it currently blocking?
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[ViewVariables, AutoNetworkedField]
|
[DataField, AutoNetworkedField]
|
||||||
public bool IsBlocking;
|
public bool IsBlocking;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -33,7 +33,7 @@ public sealed partial class BlockingComponent : Component
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// The shape of the blocking fixture that will be dynamically spawned
|
/// The shape of the blocking fixture that will be dynamically spawned
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[DataField("shape"), ViewVariables(VVAccess.ReadWrite)]
|
[DataField]
|
||||||
public IPhysShape Shape = new PhysShapeCircle(0.5f);
|
public IPhysShape Shape = new PhysShapeCircle(0.5f);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -48,8 +48,8 @@ public sealed partial class BlockingComponent : Component
|
|||||||
[DataField("activeBlockModifier", required: true)]
|
[DataField("activeBlockModifier", required: true)]
|
||||||
public DamageModifierSet ActiveBlockDamageModifier = default!;
|
public DamageModifierSet ActiveBlockDamageModifier = default!;
|
||||||
|
|
||||||
[DataField("blockingToggleAction", customTypeSerializer: typeof(PrototypeIdSerializer<EntityPrototype>))]
|
[DataField]
|
||||||
public string BlockingToggleAction = "ActionToggleBlock";
|
public EntProtoId BlockingToggleAction = "ActionToggleBlock";
|
||||||
|
|
||||||
[DataField, AutoNetworkedField]
|
[DataField, AutoNetworkedField]
|
||||||
public EntityUid? BlockingToggleActionEntity;
|
public EntityUid? BlockingToggleActionEntity;
|
||||||
@@ -57,7 +57,7 @@ public sealed partial class BlockingComponent : Component
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// The sound to be played when you get hit while actively blocking
|
/// The sound to be played when you get hit while actively blocking
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[DataField("blockSound")] public SoundSpecifier BlockSound =
|
[DataField] public SoundSpecifier BlockSound =
|
||||||
new SoundPathSpecifier("/Audio/Weapons/block_metal1.ogg")
|
new SoundPathSpecifier("/Audio/Weapons/block_metal1.ogg")
|
||||||
{
|
{
|
||||||
Params = AudioParams.Default.WithVariation(0.25f)
|
Params = AudioParams.Default.WithVariation(0.25f)
|
||||||
@@ -67,13 +67,13 @@ public sealed partial class BlockingComponent : Component
|
|||||||
/// Fraction of original damage shield will take instead of user
|
/// Fraction of original damage shield will take instead of user
|
||||||
/// when not blocking
|
/// when not blocking
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[DataField("passiveBlockFraction"), ViewVariables(VVAccess.ReadWrite)]
|
[DataField]
|
||||||
public float PassiveBlockFraction = 0.5f;
|
public float PassiveBlockFraction = 0.5f;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Fraction of original damage shield will take instead of user
|
/// Fraction of original damage shield will take instead of user
|
||||||
/// when blocking
|
/// when blocking
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[DataField("activeBlockFraction"), ViewVariables(VVAccess.ReadWrite)]
|
[DataField]
|
||||||
public float ActiveBlockFraction = 1.0f;
|
public float ActiveBlockFraction = 1.0f;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user