Fix melee animation exception (#12806)
This commit is contained in:
parent
4f6ead57bf
commit
5f964f02b7
|
|
@ -125,47 +125,42 @@ public sealed partial class MeleeWeaponSystem
|
|||
_animation.Stop(user, MeleeLungeKey);
|
||||
_animation.Play(user, lunge, MeleeLungeKey);
|
||||
|
||||
// Clientside entity to spawn
|
||||
if (animation != null)
|
||||
if (localPos == Vector2.Zero || animation == null)
|
||||
return;
|
||||
|
||||
if (!TryComp<TransformComponent>(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);
|
||||
|
||||
switch (arcComponent.Animation)
|
||||
{
|
||||
if (!TryComp<TransformComponent>(user, out var userXform))
|
||||
return;
|
||||
|
||||
var coords = userXform.Coordinates;
|
||||
var animationUid = Spawn(animation, coords);
|
||||
|
||||
if (localPos != Vector2.Zero && TryComp<SpriteComponent>(animationUid, out var sprite))
|
||||
{
|
||||
if (TryComp<WeaponArcVisualsComponent>(animationUid, out var arcComponent))
|
||||
{
|
||||
sprite.NoRotation = true;
|
||||
sprite.Rotation = localPos.ToWorldAngle();
|
||||
|
||||
var distance = Math.Clamp(localPos.Length / 2f, 0.2f, 1f);
|
||||
|
||||
switch (arcComponent.Animation)
|
||||
{
|
||||
case WeaponArcAnimation.Slash:
|
||||
_animation.Play(animationUid, GetSlashAnimation(sprite, angle), SlashAnimationKey);
|
||||
if (arcComponent.Fadeout)
|
||||
_animation.Play(animationUid, GetFadeAnimation(sprite, 0.065f, 0.065f + 0.05f), FadeAnimationKey);
|
||||
break;
|
||||
case WeaponArcAnimation.Thrust:
|
||||
_animation.Play(animationUid, GetThrustAnimation(sprite, distance), ThrustAnimationKey);
|
||||
if (arcComponent.Fadeout)
|
||||
_animation.Play(animationUid, GetFadeAnimation(sprite, 0.05f, 0.15f), FadeAnimationKey);
|
||||
break;
|
||||
case WeaponArcAnimation.None:
|
||||
var mapPos = userXform.WorldPosition;
|
||||
var xform = Transform(animationUid);
|
||||
xform.AttachToGridOrMap();
|
||||
xform.WorldPosition = mapPos + (userXform.WorldRotation - userXform.LocalRotation).RotateVec(localPos);
|
||||
if (arcComponent.Fadeout)
|
||||
_animation.Play(animationUid, GetFadeAnimation(sprite, 0f, 0.15f), FadeAnimationKey);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
case WeaponArcAnimation.Slash:
|
||||
_animation.Play(animationUid, GetSlashAnimation(sprite, angle), SlashAnimationKey);
|
||||
if (arcComponent.Fadeout)
|
||||
_animation.Play(animationUid, GetFadeAnimation(sprite, 0.065f, 0.065f + 0.05f), FadeAnimationKey);
|
||||
break;
|
||||
case WeaponArcAnimation.Thrust:
|
||||
_animation.Play(animationUid, GetThrustAnimation(sprite, distance), ThrustAnimationKey);
|
||||
if (arcComponent.Fadeout)
|
||||
_animation.Play(animationUid, GetFadeAnimation(sprite, 0.05f, 0.15f), FadeAnimationKey);
|
||||
break;
|
||||
case WeaponArcAnimation.None:
|
||||
var mapPos = userXform.WorldPosition;
|
||||
var xform = Transform(animationUid);
|
||||
xform.AttachToGridOrMap();
|
||||
xform.WorldPosition = mapPos + (userXform.WorldRotation - userXform.LocalRotation).RotateVec(localPos);
|
||||
if (arcComponent.Fadeout)
|
||||
_animation.Play(animationUid, GetFadeAnimation(sprite, 0f, 0.15f), FadeAnimationKey);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue