Lag compensation for wide attacks (#15877)
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
using System.Linq;
|
||||
using Content.Client.Gameplay;
|
||||
using Content.Shared.CombatMode;
|
||||
using Content.Shared.Hands.Components;
|
||||
@@ -142,7 +143,7 @@ public sealed partial class MeleeWeaponSystem : SharedMeleeWeaponSystem
|
||||
coordinates = EntityCoordinates.FromMap(MapManager.GetMapEntityId(mousePos.MapId), mousePos, _transform, EntityManager);
|
||||
}
|
||||
|
||||
EntityManager.RaisePredictiveEvent(new HeavyAttackEvent(weaponUid, coordinates));
|
||||
ClientHeavyAttack(entity, coordinates, weaponUid, weapon);
|
||||
}
|
||||
|
||||
return;
|
||||
@@ -244,6 +245,31 @@ public sealed partial class MeleeWeaponSystem : SharedMeleeWeaponSystem
|
||||
return true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Raises a heavy attack event with the relevant attacked entities.
|
||||
/// This is to avoid lag effecting the client's perspective too much.
|
||||
/// </summary>
|
||||
private void ClientHeavyAttack(EntityUid user, EntityCoordinates coordinates, EntityUid meleeUid, MeleeWeaponComponent component)
|
||||
{
|
||||
// Only run on first prediction to avoid the potential raycast entities changing.
|
||||
if (!TryComp<TransformComponent>(user, out var userXform) || !Timing.IsFirstTimePredicted)
|
||||
return;
|
||||
|
||||
var targetMap = coordinates.ToMap(EntityManager, _transform);
|
||||
|
||||
if (targetMap.MapId != userXform.MapID)
|
||||
return;
|
||||
|
||||
var userPos = _transform.GetWorldPosition(userXform);
|
||||
var direction = targetMap.Position - userPos;
|
||||
var distance = Math.Min(component.Range, direction.Length);
|
||||
|
||||
// This should really be improved. GetEntitiesInArc uses pos instead of bounding boxes.
|
||||
// Server will validate it with InRangeUnobstructed.
|
||||
var entities = ArcRayCast(userPos, direction.ToWorldAngle(), component.Angle, distance, userXform.MapID, user);
|
||||
RaisePredictiveEvent(new HeavyAttackEvent(meleeUid, entities.ToList(), coordinates));
|
||||
}
|
||||
|
||||
protected override void Popup(string message, EntityUid? uid, EntityUid? user)
|
||||
{
|
||||
if (!Timing.IsFirstTimePredicted || uid == null)
|
||||
|
||||
Reference in New Issue
Block a user