Melee rebalancing (#17520)
This commit is contained in:
@@ -30,21 +30,22 @@ public sealed partial class MeleeWeaponSystem
|
||||
if (localPos == Vector2.Zero || animation == null)
|
||||
return;
|
||||
|
||||
if (!TryComp<TransformComponent>(user, out var userXform) || userXform.MapID == MapId.Nullspace)
|
||||
if (!_xformQuery.TryGetComponent(user, out var userXform) || userXform.MapID == MapId.Nullspace)
|
||||
return;
|
||||
|
||||
var animationUid = Spawn(animation, userXform.Coordinates);
|
||||
|
||||
if (!TryComp<SpriteComponent>(animationUid, out var sprite)
|
||||
|| !TryComp<WeaponArcVisualsComponent>(animationUid, out var arcComponent))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
sprite.NoRotation = true;
|
||||
sprite.Rotation = localPos.ToWorldAngle();
|
||||
var distance = Math.Clamp(localPos.Length() / 2f, 0.2f, 1f);
|
||||
|
||||
var xformQuery = GetEntityQuery<TransformComponent>();
|
||||
var xform = xformQuery.GetComponent(animationUid);
|
||||
var xform = _xformQuery.GetComponent(animationUid);
|
||||
|
||||
switch (arcComponent.Animation)
|
||||
{
|
||||
@@ -61,10 +62,10 @@ public sealed partial class MeleeWeaponSystem
|
||||
_animation.Play(animationUid, GetFadeAnimation(sprite, 0.05f, 0.15f), FadeAnimationKey);
|
||||
break;
|
||||
case WeaponArcAnimation.None:
|
||||
var (mapPos, mapRot) = TransformSystem.GetWorldPositionRotation(userXform, xformQuery);
|
||||
var (mapPos, mapRot) = TransformSystem.GetWorldPositionRotation(userXform);
|
||||
TransformSystem.AttachToGridOrMap(animationUid, xform);
|
||||
var worldPos = mapPos + (mapRot - userXform.LocalRotation).RotateVec(localPos);
|
||||
var newLocalPos = TransformSystem.GetInvWorldMatrix(xform.ParentUid, xformQuery).Transform(worldPos);
|
||||
var newLocalPos = TransformSystem.GetInvWorldMatrix(xform.ParentUid).Transform(worldPos);
|
||||
TransformSystem.SetLocalPositionNoLerp(xform, newLocalPos);
|
||||
if (arcComponent.Fadeout)
|
||||
_animation.Play(animationUid, GetFadeAnimation(sprite, 0f, 0.15f), FadeAnimationKey);
|
||||
|
||||
@@ -26,29 +26,23 @@ public sealed partial class MeleeWeaponSystem : SharedMeleeWeaponSystem
|
||||
[Dependency] private readonly IEyeManager _eyeManager = default!;
|
||||
[Dependency] private readonly IGameTiming _timing = default!;
|
||||
[Dependency] private readonly IInputManager _inputManager = default!;
|
||||
[Dependency] private readonly IOverlayManager _overlayManager = default!;
|
||||
[Dependency] private readonly IPlayerManager _player = default!;
|
||||
[Dependency] private readonly IPrototypeManager _protoManager = default!;
|
||||
[Dependency] private readonly IStateManager _stateManager = default!;
|
||||
[Dependency] private readonly AnimationPlayerSystem _animation = default!;
|
||||
[Dependency] private readonly InputSystem _inputSystem = default!;
|
||||
|
||||
private EntityQuery<TransformComponent> _xformQuery;
|
||||
|
||||
private const string MeleeLungeKey = "melee-lunge";
|
||||
|
||||
public override void Initialize()
|
||||
{
|
||||
base.Initialize();
|
||||
_overlayManager.AddOverlay(new MeleeWindupOverlay(EntityManager, _timing, _player, _protoManager));
|
||||
_xformQuery = GetEntityQuery<TransformComponent>();
|
||||
SubscribeNetworkEvent<MeleeLungeEvent>(OnMeleeLunge);
|
||||
UpdatesOutsidePrediction = true;
|
||||
}
|
||||
|
||||
public override void Shutdown()
|
||||
{
|
||||
base.Shutdown();
|
||||
_overlayManager.RemoveOverlay<MeleeWindupOverlay>();
|
||||
}
|
||||
|
||||
public override void Update(float frameTime)
|
||||
{
|
||||
base.Update(frameTime);
|
||||
@@ -69,56 +63,63 @@ public sealed partial class MeleeWeaponSystem : SharedMeleeWeaponSystem
|
||||
if (!CombatMode.IsInCombatMode(entity) || !Blocker.CanAttack(entity))
|
||||
{
|
||||
weapon.Attacking = false;
|
||||
if (weapon.WindUpStart != null)
|
||||
{
|
||||
EntityManager.RaisePredictiveEvent(new StopHeavyAttackEvent(weaponUid));
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
var useDown = _inputSystem.CmdStates.GetState(EngineKeyFunctions.Use);
|
||||
var altDown = _inputSystem.CmdStates.GetState(EngineKeyFunctions.UseSecondary);
|
||||
|
||||
if (useDown != BoundKeyState.Down && altDown != BoundKeyState.Down)
|
||||
{
|
||||
if (weapon.Attacking)
|
||||
{
|
||||
RaisePredictiveEvent(new StopAttackEvent(weaponUid));
|
||||
}
|
||||
}
|
||||
|
||||
if (weapon.Attacking || weapon.NextAttack > Timing.CurTime)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
// TODO using targeted actions while combat mode is enabled should NOT trigger attacks.
|
||||
|
||||
var useDown = _inputSystem.CmdStates.GetState(EngineKeyFunctions.Use);
|
||||
var altDown = _inputSystem.CmdStates.GetState(EngineKeyFunctions.UseSecondary);
|
||||
var currentTime = Timing.CurTime;
|
||||
// TODO: Need to make alt-fire melee its own component I guess?
|
||||
// Melee and guns share a lot in the middle but share virtually nothing at the start and end so
|
||||
// it's kinda tricky.
|
||||
// I think as long as we make secondaries their own component it's probably fine
|
||||
// as long as guncomp has an alt-use key then it shouldn't be too much of a PITA to deal with.
|
||||
if (HasComp<GunComponent>(weaponUid))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
var mousePos = _eyeManager.ScreenToMap(_inputManager.MouseScreenPosition);
|
||||
|
||||
if (mousePos.MapId == MapId.Nullspace)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
EntityCoordinates coordinates;
|
||||
|
||||
if (MapManager.TryFindGridAt(mousePos, out var gridUid, out _))
|
||||
{
|
||||
coordinates = EntityCoordinates.FromMap(gridUid, mousePos, TransformSystem, EntityManager);
|
||||
}
|
||||
else
|
||||
{
|
||||
coordinates = EntityCoordinates.FromMap(MapManager.GetMapEntityId(mousePos.MapId), mousePos, TransformSystem, EntityManager);
|
||||
}
|
||||
|
||||
// Heavy attack.
|
||||
if (altDown == BoundKeyState.Down)
|
||||
{
|
||||
// TODO: Need to make alt-fire melee its own component I guess?
|
||||
// Melee and guns share a lot in the middle but share virtually nothing at the start and end so
|
||||
// it's kinda tricky.
|
||||
// I think as long as we make secondaries their own component it's probably fine
|
||||
// as long as guncomp has an alt-use key then it shouldn't be too much of a PITA to deal with.
|
||||
if (HasComp<GunComponent>(weaponUid))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
// We did the click to end the attack but haven't pulled the key up.
|
||||
if (weapon.Attacking)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
// If it's an unarmed attack then do a disarm
|
||||
if (weapon.AltDisarm && weaponUid == entity)
|
||||
{
|
||||
EntityUid? target = null;
|
||||
|
||||
var mousePos = _eyeManager.ScreenToMap(_inputManager.MouseScreenPosition);
|
||||
EntityCoordinates coordinates;
|
||||
|
||||
if (MapManager.TryFindGridAt(mousePos, out var gridUid, out _))
|
||||
{
|
||||
coordinates = EntityCoordinates.FromMap(gridUid, mousePos, TransformSystem, EntityManager);
|
||||
}
|
||||
else
|
||||
{
|
||||
coordinates = EntityCoordinates.FromMap(MapManager.GetMapEntityId(mousePos.MapId), mousePos, TransformSystem, EntityManager);
|
||||
}
|
||||
|
||||
if (_stateManager.CurrentState is GameplayStateBase screen)
|
||||
{
|
||||
target = screen.GetClickedEntity(mousePos);
|
||||
@@ -128,52 +129,13 @@ public sealed partial class MeleeWeaponSystem : SharedMeleeWeaponSystem
|
||||
return;
|
||||
}
|
||||
|
||||
// Otherwise do heavy attack.
|
||||
|
||||
// Start a windup
|
||||
if (weapon.WindUpStart == null)
|
||||
{
|
||||
EntityManager.RaisePredictiveEvent(new StartHeavyAttackEvent(weaponUid));
|
||||
weapon.WindUpStart = currentTime;
|
||||
}
|
||||
|
||||
// Try to do a heavy attack.
|
||||
if (useDown == BoundKeyState.Down)
|
||||
{
|
||||
var mousePos = _eyeManager.ScreenToMap(_inputManager.MouseScreenPosition);
|
||||
EntityCoordinates coordinates;
|
||||
|
||||
// Bro why would I want a ternary here
|
||||
// ReSharper disable once ConvertIfStatementToConditionalTernaryExpression
|
||||
if (MapManager.TryFindGridAt(mousePos, out var gridUid, out _))
|
||||
{
|
||||
coordinates = EntityCoordinates.FromMap(gridUid, mousePos, TransformSystem, EntityManager);
|
||||
}
|
||||
else
|
||||
{
|
||||
coordinates = EntityCoordinates.FromMap(MapManager.GetMapEntityId(mousePos.MapId), mousePos, TransformSystem, EntityManager);
|
||||
}
|
||||
|
||||
ClientHeavyAttack(entity, coordinates, weaponUid, weapon);
|
||||
}
|
||||
|
||||
ClientHeavyAttack(entity, coordinates, weaponUid, weapon);
|
||||
return;
|
||||
}
|
||||
|
||||
if (weapon.WindUpStart != null)
|
||||
{
|
||||
EntityManager.RaisePredictiveEvent(new StopHeavyAttackEvent(weaponUid));
|
||||
}
|
||||
|
||||
// Light attack
|
||||
if (useDown == BoundKeyState.Down)
|
||||
{
|
||||
if (weapon.Attacking || weapon.NextAttack > Timing.CurTime)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
var mousePos = _eyeManager.ScreenToMap(_inputManager.MouseScreenPosition);
|
||||
var attackerPos = Transform(entity).MapPosition;
|
||||
|
||||
if (mousePos.MapId != attackerPos.MapId ||
|
||||
@@ -182,34 +144,14 @@ public sealed partial class MeleeWeaponSystem : SharedMeleeWeaponSystem
|
||||
return;
|
||||
}
|
||||
|
||||
EntityCoordinates coordinates;
|
||||
|
||||
// Bro why would I want a ternary here
|
||||
// ReSharper disable once ConvertIfStatementToConditionalTernaryExpression
|
||||
if (MapManager.TryFindGridAt(mousePos, out var gridUid, out _))
|
||||
{
|
||||
coordinates = EntityCoordinates.FromMap(gridUid, mousePos, TransformSystem, EntityManager);
|
||||
}
|
||||
else
|
||||
{
|
||||
coordinates = EntityCoordinates.FromMap(MapManager.GetMapEntityId(mousePos.MapId), mousePos, TransformSystem, EntityManager);
|
||||
}
|
||||
|
||||
EntityUid? target = null;
|
||||
|
||||
// TODO: UI Refactor update I assume
|
||||
if (_stateManager.CurrentState is GameplayStateBase screen)
|
||||
{
|
||||
target = screen.GetClickedEntity(mousePos);
|
||||
}
|
||||
|
||||
RaisePredictiveEvent(new LightAttackEvent(target, weaponUid, coordinates));
|
||||
return;
|
||||
}
|
||||
|
||||
if (weapon.Attacking)
|
||||
{
|
||||
RaisePredictiveEvent(new StopAttackEvent(weaponUid));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -263,7 +205,7 @@ public sealed partial class MeleeWeaponSystem : SharedMeleeWeaponSystem
|
||||
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) ||
|
||||
if (!_xformQuery.TryGetComponent(user, out var userXform) ||
|
||||
!Timing.IsFirstTimePredicted)
|
||||
{
|
||||
return;
|
||||
@@ -284,14 +226,6 @@ public sealed partial class MeleeWeaponSystem : SharedMeleeWeaponSystem
|
||||
RaisePredictiveEvent(new HeavyAttackEvent(meleeUid, entities.GetRange(0, Math.Min(MaxTargets, entities.Count)), coordinates));
|
||||
}
|
||||
|
||||
protected override void Popup(string message, EntityUid? uid, EntityUid? user)
|
||||
{
|
||||
if (!Timing.IsFirstTimePredicted || uid == null)
|
||||
return;
|
||||
|
||||
PopupSystem.PopupEntity(message, uid.Value);
|
||||
}
|
||||
|
||||
private void OnMeleeLunge(MeleeLungeEvent ev)
|
||||
{
|
||||
// Entity might not have been sent by PVS.
|
||||
|
||||
@@ -1,146 +0,0 @@
|
||||
using System.Numerics;
|
||||
using Content.Shared.Weapons.Melee;
|
||||
using Robust.Client.GameObjects;
|
||||
using Robust.Client.Graphics;
|
||||
using Robust.Client.Player;
|
||||
using Robust.Shared.Enums;
|
||||
using Robust.Shared.Prototypes;
|
||||
using Robust.Shared.Timing;
|
||||
using Robust.Shared.Utility;
|
||||
|
||||
namespace Content.Client.Weapons.Melee;
|
||||
|
||||
public sealed class MeleeWindupOverlay : Overlay
|
||||
{
|
||||
private readonly IEntityManager _entManager;
|
||||
private readonly IGameTiming _timing;
|
||||
private readonly IPlayerManager _player;
|
||||
private readonly SharedMeleeWeaponSystem _melee;
|
||||
private readonly SharedTransformSystem _transform;
|
||||
|
||||
public override OverlaySpace Space => OverlaySpace.WorldSpaceBelowFOV;
|
||||
|
||||
private readonly Texture _texture;
|
||||
private readonly ShaderInstance _shader;
|
||||
|
||||
public MeleeWindupOverlay(IEntityManager entManager, IGameTiming timing, IPlayerManager playerManager, IPrototypeManager protoManager)
|
||||
{
|
||||
_entManager = entManager;
|
||||
_timing = timing;
|
||||
_player = playerManager;
|
||||
_melee = _entManager.EntitySysManager.GetEntitySystem<SharedMeleeWeaponSystem>();
|
||||
_transform = _entManager.EntitySysManager.GetEntitySystem<SharedTransformSystem>();
|
||||
var sprite = new SpriteSpecifier.Rsi(new ("/Textures/Interface/Misc/progress_bar.rsi"), "icon");
|
||||
_texture = _entManager.EntitySysManager.GetEntitySystem<SpriteSystem>().Frame0(sprite);
|
||||
_shader = protoManager.Index<ShaderPrototype>("unshaded").Instance();
|
||||
}
|
||||
|
||||
protected override void Draw(in OverlayDrawArgs args)
|
||||
{
|
||||
var owner = _player.LocalPlayer?.ControlledEntity;
|
||||
|
||||
if (!_entManager.TryGetComponent<TransformComponent>(owner, out var ownerXform) ||
|
||||
ownerXform.MapID != args.MapId)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (!_melee.TryGetWeapon(owner.Value, out var meleeUid, out var comp))
|
||||
return;
|
||||
|
||||
var handle = args.WorldHandle;
|
||||
var rotation = args.Viewport.Eye?.Rotation ?? Angle.Zero;
|
||||
var spriteQuery = _entManager.GetEntityQuery<SpriteComponent>();
|
||||
var xformQuery = _entManager.GetEntityQuery<TransformComponent>();
|
||||
|
||||
// If you use the display UI scale then need to set max(1f, displayscale) because 0 is valid.
|
||||
const float scale = 1f;
|
||||
var scaleMatrix = Matrix3.CreateScale(new Vector2(scale, scale));
|
||||
var rotationMatrix = Matrix3.CreateRotation(-rotation);
|
||||
handle.UseShader(_shader);
|
||||
var currentTime = _timing.CurTime;
|
||||
|
||||
if (comp.WindUpStart == null ||
|
||||
comp.Attacking)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (!xformQuery.TryGetComponent(meleeUid, out var xform) ||
|
||||
xform.MapID != args.MapId)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
var worldPosition = _transform.GetWorldPosition(xform);
|
||||
var worldMatrix = Matrix3.CreateTranslation(worldPosition);
|
||||
Matrix3.Multiply(scaleMatrix, worldMatrix, out var scaledWorld);
|
||||
Matrix3.Multiply(rotationMatrix, scaledWorld, out var matty);
|
||||
|
||||
handle.SetTransform(matty);
|
||||
var offset = -_texture.Height / scale;
|
||||
|
||||
// Use the sprite itself if we know its bounds. This means short or tall sprites don't get overlapped
|
||||
// by the bar.
|
||||
float yOffset;
|
||||
if (spriteQuery.TryGetComponent(meleeUid, out var sprite))
|
||||
{
|
||||
yOffset = -sprite.Bounds.Height / 2f - 0.05f;
|
||||
}
|
||||
else
|
||||
{
|
||||
yOffset = -0.5f;
|
||||
}
|
||||
|
||||
// Position above the entity (we've already applied the matrix transform to the entity itself)
|
||||
// Offset by the texture size for every do_after we have.
|
||||
var position = new Vector2(-_texture.Width / 2f / EyeManager.PixelsPerMeter,
|
||||
yOffset / scale + offset / EyeManager.PixelsPerMeter * scale);
|
||||
|
||||
// Draw the underlying bar texture
|
||||
handle.DrawTexture(_texture, position);
|
||||
|
||||
// Draw the items overlapping the texture
|
||||
const float startX = 2f;
|
||||
const float endX = 22f;
|
||||
|
||||
// Area marking where to release
|
||||
var releaseWidth = 2f * SharedMeleeWeaponSystem.GracePeriod / (float) _melee.GetWindupTime(meleeUid, owner.Value, comp).TotalSeconds * EyeManager.PixelsPerMeter;
|
||||
const float releaseMiddle = (endX - startX) / 2f + startX;
|
||||
|
||||
var releaseBox = new Box2(new Vector2(releaseMiddle - releaseWidth / 2f, 3f) / EyeManager.PixelsPerMeter,
|
||||
new Vector2(releaseMiddle + releaseWidth / 2f, 4f) / EyeManager.PixelsPerMeter);
|
||||
|
||||
releaseBox = releaseBox.Translated(position);
|
||||
handle.DrawRect(releaseBox, Color.LimeGreen);
|
||||
|
||||
// Wraps around back to 0
|
||||
var totalDuration = _melee.GetWindupTime(meleeUid, owner.Value, comp).TotalSeconds * 2;
|
||||
|
||||
var elapsed = (currentTime - comp.WindUpStart.Value).TotalSeconds % (2 * totalDuration);
|
||||
var value = elapsed / totalDuration;
|
||||
|
||||
if (value > 1)
|
||||
{
|
||||
value = 2 - value;
|
||||
}
|
||||
|
||||
var fraction = (float) value;
|
||||
|
||||
var xPos = (endX - startX) * fraction + startX;
|
||||
|
||||
// In pixels
|
||||
const float width = 2f;
|
||||
// If we hit the end we won't draw half the box so we need to subtract the end pos from it
|
||||
var endPos = xPos + width / 2f;
|
||||
|
||||
var box = new Box2(new Vector2(Math.Max(startX, endPos - width), 3f) / EyeManager.PixelsPerMeter,
|
||||
new Vector2(Math.Min(endX, endPos), 4f) / EyeManager.PixelsPerMeter);
|
||||
|
||||
box = box.Translated(position);
|
||||
handle.DrawRect(box, Color.White);
|
||||
|
||||
handle.UseShader(null);
|
||||
handle.SetTransform(Matrix3.Identity);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user