Melee refactor (#10897)

Co-authored-by: metalgearsloth <metalgearsloth@gmail.com>
This commit is contained in:
metalgearsloth
2022-09-29 15:51:59 +10:00
committed by GitHub
parent c583b7b361
commit f51248ecaa
140 changed files with 2440 additions and 1824 deletions

View File

@@ -1,53 +0,0 @@
using Robust.Client.GameObjects;
using Robust.Shared.GameObjects;
using Robust.Shared.IoC;
using Robust.Shared.Maths;
namespace Content.Client.Weapons.Melee.Components
{
[RegisterComponent]
public sealed class MeleeLungeComponent : Component
{
private const float ResetTime = 0.3f;
private const float BaseOffset = 0.25f;
private Angle _angle;
private float _time;
public void SetData(Angle angle)
{
_angle = angle;
_time = 0;
}
public void Update(float frameTime)
{
_time += frameTime;
var offset = Vector2.Zero;
var deleteSelf = false;
if (_time > ResetTime)
{
deleteSelf = true;
}
else
{
offset = _angle.RotateVec((0, -BaseOffset));
offset *= (ResetTime - _time) / ResetTime;
}
var entMan = IoCManager.Resolve<IEntityManager>();
if (entMan.TryGetComponent(Owner, out ISpriteComponent? spriteComponent))
{
spriteComponent.Offset = offset;
}
if (deleteSelf)
{
entMan.RemoveComponent<MeleeLungeComponent>(Owner);
}
}
}
}

View File

@@ -1,79 +0,0 @@
using Content.Shared.Weapons.Melee;
using Robust.Client.GameObjects;
using Robust.Client.Graphics;
using Robust.Shared.GameObjects;
using Robust.Shared.IoC;
using Robust.Shared.Maths;
namespace Content.Client.Weapons.Melee.Components
{
[RegisterComponent]
public sealed class MeleeWeaponArcAnimationComponent : Component
{
[Dependency] private readonly IEntityManager _entMan = default!;
private MeleeWeaponAnimationPrototype? _meleeWeaponAnimation;
private float _timer;
private SpriteComponent? _sprite;
private Angle _baseAngle;
protected override void Initialize()
{
base.Initialize();
_sprite = _entMan.GetComponent<SpriteComponent>(Owner);
}
public void SetData(MeleeWeaponAnimationPrototype prototype, Angle baseAngle, EntityUid attacker, bool followAttacker = true)
{
_meleeWeaponAnimation = prototype;
_sprite?.AddLayer(new RSI.StateId(prototype.State));
_baseAngle = baseAngle;
if(followAttacker)
_entMan.GetComponent<TransformComponent>(Owner).AttachParent(attacker);
}
internal void Update(float frameTime)
{
if (_meleeWeaponAnimation == null)
{
return;
}
_timer += frameTime;
var (r, g, b, a) =
Vector4.Clamp(_meleeWeaponAnimation.Color + _meleeWeaponAnimation.ColorDelta * _timer, Vector4.Zero, Vector4.One);
if (_sprite != null)
{
_sprite.Color = new Color(r, g, b, a);
}
var transform = _entMan.GetComponent<TransformComponent>(Owner);
switch (_meleeWeaponAnimation.ArcType)
{
case WeaponArcType.Slash:
var angle = Angle.FromDegrees(_meleeWeaponAnimation.Width)/2;
transform.WorldRotation = _baseAngle + Angle.Lerp(-angle, angle, (float) (_timer / _meleeWeaponAnimation.Length.TotalSeconds));
break;
case WeaponArcType.Poke:
transform.WorldRotation = _baseAngle;
if (_sprite != null)
{
_sprite.Offset -= (0, _meleeWeaponAnimation.Speed * frameTime);
}
break;
}
if (_meleeWeaponAnimation.Length.TotalSeconds <= _timer)
{
_entMan.DeleteEntity(Owner);
}
}
}
}

View File

@@ -0,0 +1,18 @@
namespace Content.Client.Weapons.Melee.Components;
/// <summary>
/// Used for melee attack animations. Typically just has a fadeout.
/// </summary>
[RegisterComponent]
public sealed class WeaponArcVisualsComponent : Component
{
[ViewVariables, DataField("animation")]
public WeaponArcAnimation Animation = WeaponArcAnimation.None;
}
public enum WeaponArcAnimation : byte
{
None,
Thrust,
Slash,
}