Skip to content

Commit

Permalink
Fixed projectile-only swords' swing trail projectiles not flipping wi…
Browse files Browse the repository at this point in the history
…th the player's swinging animation (#198).
  • Loading branch information
Mirsario committed Sep 7, 2023
1 parent 3d115d3 commit 333dcf0
Showing 1 changed file with 20 additions and 2 deletions.
22 changes: 20 additions & 2 deletions Common/Melee/_Animations/QuickSlashMeleeAnimation.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System;
using Microsoft.Xna.Framework;
using Terraria;
using Terraria.DataStructures;
using TerrariaOverhaul.Common.Charging;
using TerrariaOverhaul.Common.Hooks.Items;
using TerrariaOverhaul.Utilities;
Expand All @@ -11,7 +12,7 @@ namespace TerrariaOverhaul.Common.Melee;
/// Quick swing that lasts 1/2 of the use animation time.
/// Affects gameplay.
/// </summary>
public class QuickSlashMeleeAnimation : MeleeAnimation, ICanDoMeleeDamage
public class QuickSlashMeleeAnimation : MeleeAnimation, ICanDoMeleeDamage, IModifyItemNewProjectile
{
public bool IsAttackFlipped { get; set; }
public bool FlipAttackEachSwing { get; set; }
Expand Down Expand Up @@ -86,7 +87,7 @@ protected override void ApplyAnimation(Item item, Player player)
}
}

public bool CanDoMeleeDamage(Item item, Player player)
bool ICanDoMeleeDamage.CanDoMeleeDamage(Item item, Player player)
{
if (!Enabled) {
return true;
Expand All @@ -96,4 +97,21 @@ public bool CanDoMeleeDamage(Item item, Player player)
// The second half is a cooldown, and the animations reflect that.
return player.itemAnimation >= player.itemAnimationMax / 2;
}

void IModifyItemNewProjectile.ModifyShootProjectile(Player player, Item item, in IModifyItemNewProjectile.Args args, ref IModifyItemNewProjectile.Args result)
{
if (args.Source is EntitySource_ItemUse_WithAmmo
// For horizontally-facing projectiles
&& args.Velocity.Y == 0f
&& args.Velocity.X == player.direction
// That pass rotation direction as AI0
&& args.AI0 == player.direction * player.gravDir
// Whenever the slash animation is flipped
&& item.TryGetGlobalItem(out QuickSlashMeleeAnimation slashAnimation)
&& slashAnimation.IsAttackFlipped
) {
// Flip the rotation direction
result.AI0 = -args.AI0;
}
}
}

0 comments on commit 333dcf0

Please sign in to comment.