Fix melee animation exception (#12806)

This commit is contained in:
Leon Friedrich
2022-11-30 14:40:57 +13:00
committed by GitHub
parent 4f6ead57bf
commit 5f964f02b7

View File

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