* Converted all SnapGridPositionChangedEvent subscriptions to AnchorStateChangedEvent. * Fixes power tests with new anchored requirements. * Moved AnchorableComponent into construction. AnchorableComponent now uses Transform.Anchored. * Fixed bug with nodes, power works again. * Adds lifetime stages to Component. * Update Engine to v0.4.70.
79 lines
2.4 KiB
C#
79 lines
2.4 KiB
C#
using Content.Shared.Weapons.Melee;
|
|
using Robust.Client.GameObjects;
|
|
using Robust.Client.Graphics;
|
|
using Robust.Shared.GameObjects;
|
|
using Robust.Shared.Maths;
|
|
|
|
namespace Content.Client.Weapons.Melee.Components
|
|
{
|
|
[RegisterComponent]
|
|
public sealed class MeleeWeaponArcAnimationComponent : Component
|
|
{
|
|
public override string Name => "MeleeWeaponArcAnimation";
|
|
|
|
private MeleeWeaponAnimationPrototype? _meleeWeaponAnimation;
|
|
|
|
private float _timer;
|
|
private SpriteComponent? _sprite;
|
|
private Angle _baseAngle;
|
|
|
|
protected override void Initialize()
|
|
{
|
|
base.Initialize();
|
|
|
|
_sprite = Owner.GetComponent<SpriteComponent>();
|
|
}
|
|
|
|
public void SetData(MeleeWeaponAnimationPrototype prototype, Angle baseAngle, IEntity attacker, bool followAttacker = true)
|
|
{
|
|
_meleeWeaponAnimation = prototype;
|
|
_sprite?.AddLayer(new RSI.StateId(prototype.State));
|
|
_baseAngle = baseAngle;
|
|
if(followAttacker)
|
|
Owner.Transform.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);
|
|
}
|
|
|
|
switch (_meleeWeaponAnimation.ArcType)
|
|
{
|
|
case WeaponArcType.Slash:
|
|
var angle = Angle.FromDegrees(_meleeWeaponAnimation.Width)/2;
|
|
Owner.Transform.WorldRotation =
|
|
_baseAngle + Angle.Lerp(-angle, angle, (float) (_timer / _meleeWeaponAnimation.Length.TotalSeconds));
|
|
break;
|
|
|
|
case WeaponArcType.Poke:
|
|
Owner.Transform.WorldRotation = _baseAngle;
|
|
|
|
if (_sprite != null)
|
|
{
|
|
_sprite.Offset -= (0, _meleeWeaponAnimation.Speed * frameTime);
|
|
}
|
|
break;
|
|
}
|
|
|
|
|
|
if (_meleeWeaponAnimation.Length.TotalSeconds <= _timer)
|
|
{
|
|
Owner.Delete();
|
|
}
|
|
}
|
|
}
|
|
}
|