From 803bde708d2806f6d080ab62b95437b2baff8f32 Mon Sep 17 00:00:00 2001 From: IbanPlay <56191483+IbanPlay@users.noreply.github.com> Date: Sun, 26 Jun 2022 00:11:11 +0200 Subject: [PATCH] Accounting for gravity flip GRAHHHH --- Items/Weapons/Melee/Cnidarian.cs | 7 ++-- Items/Weapons/Ranged/ReedBlowgun.cs | 8 ++--- Projectiles/Ranged/PressurizedBubbleStream.cs | 4 +-- .../Rogue/FishboneBoomerangProjectile.cs | 4 +-- Utilities/PlayerUtils.cs | 36 +++++++++++++++++++ 5 files changed, 48 insertions(+), 11 deletions(-) diff --git a/Items/Weapons/Melee/Cnidarian.cs b/Items/Weapons/Melee/Cnidarian.cs index 5516cb1739..60eeb20d2f 100644 --- a/Items/Weapons/Melee/Cnidarian.cs +++ b/Items/Weapons/Melee/Cnidarian.cs @@ -82,7 +82,8 @@ namespace CalamityMod.Items.Weapons.Melee player.ChangeDir(-1); } - CalamityUtils.CleanHoldStyle(player, player.compositeFrontArm.rotation + MathHelper.PiOver2, player.GetFrontHandPosition(player.compositeFrontArm.stretch, player.compositeFrontArm.rotation).Floor(), new Vector2(42, 34), new Vector2(-15, 11)); + + CalamityUtils.CleanHoldStyle(player, player.compositeFrontArm.rotation + MathHelper.PiOver2 * player.gravDir, player.GetFrontHandPositionImproved(player.compositeFrontArm), new Vector2(42, 34), new Vector2(-15, 11)); } @@ -108,8 +109,8 @@ namespace CalamityMod.Items.Weapons.Melee armPointingDirection = -MathHelper.Pi + MathHelper.PiOver4 * Utils.GetLerpValue(-MathHelper.Pi, -MathHelper.PiOver4, armPointingDirection, true); } - player.SetCompositeArmBack(true, Player.CompositeArmStretchAmount.Full, armPointingDirection - MathHelper.PiOver2); - player.SetCompositeArmFront(true, Player.CompositeArmStretchAmount.Full, armPointingDirection - MathHelper.PiOver2); + player.SetCompositeArmBack(true, Player.CompositeArmStretchAmount.Full, armPointingDirection * player.gravDir - MathHelper.PiOver2); + player.SetCompositeArmFront(true, Player.CompositeArmStretchAmount.Full, armPointingDirection * player.gravDir - MathHelper.PiOver2); } public override void HoldStyle(Player player, Rectangle heldItemFrame) diff --git a/Items/Weapons/Ranged/ReedBlowgun.cs b/Items/Weapons/Ranged/ReedBlowgun.cs index 165b4cd7f1..6c6048ef6f 100644 --- a/Items/Weapons/Ranged/ReedBlowgun.cs +++ b/Items/Weapons/Ranged/ReedBlowgun.cs @@ -55,7 +55,7 @@ namespace CalamityMod.Items.Weapons.Ranged velocity = velocity.RotatedByRandom(0.01f); } - public static Vector2 getPlayerMouth(Player player) => player.MountedCenter - 5f * Vector2.UnitY + Vector2.UnitX * 6f * player.direction; + public static Vector2 getPlayerMouth(Player player) => player.MountedCenter - 5f * Vector2.UnitY * player.gravDir + Vector2.UnitX * 6f * player.direction; public static Vector2 getPlayerShoulder(Player player) => player.MountedCenter - Vector2.UnitX * 4f * player.direction; public void SetItemInHand(Player player, Rectangle heldItemFrame) @@ -73,7 +73,7 @@ namespace CalamityMod.Items.Weapons.Ranged Vector2 playerMouth = getPlayerMouth(player); Vector2 playerToCursor = (player.Calamity().mouseWorld - playerMouth).SafeNormalize(Vector2.UnitX); - float pointingDirection = (playerToCursor.ToRotation() + MathHelper.PiOver4 / 3f * player.direction); + float pointingDirection = (playerToCursor.ToRotation() + MathHelper.PiOver4 / 3f * player.direction * player.gravDir); CalamityUtils.CleanHoldStyle(player, pointingDirection, playerMouth, new Vector2(50, 18), new Vector2(-23, 6)); } @@ -91,9 +91,9 @@ namespace CalamityMod.Items.Weapons.Ranged float frontArmDirection = (playerMouth + mouthToCursor * 25f - getPlayerShoulder(player)).ToRotation(); if (frontArm) - player.SetCompositeArmFront(true, Player.CompositeArmStretchAmount.Full, frontArmDirection - MathHelper.PiOver2); + player.SetCompositeArmFront(true, Player.CompositeArmStretchAmount.Full, frontArmDirection * player.gravDir - MathHelper.PiOver2); - player.SetCompositeArmBack(true, Player.CompositeArmStretchAmount.Full, backArmDirection - MathHelper.PiOver2); + player.SetCompositeArmBack(true, Player.CompositeArmStretchAmount.Full, backArmDirection * player.gravDir - MathHelper.PiOver2); } public override void HoldStyle(Player player, Rectangle heldItemFrame) diff --git a/Projectiles/Ranged/PressurizedBubbleStream.cs b/Projectiles/Ranged/PressurizedBubbleStream.cs index fdec0d1e3f..4cca79aa66 100644 --- a/Projectiles/Ranged/PressurizedBubbleStream.cs +++ b/Projectiles/Ranged/PressurizedBubbleStream.cs @@ -52,12 +52,12 @@ namespace CalamityMod.Projectiles.Ranged if (ChargingUp) { - float bubbleRotation = Owner.itemRotation - MathHelper.PiOver4 / 3f * Owner.direction; + float bubbleRotation = Owner.itemRotation - MathHelper.PiOver4 / 3f * Owner.direction * Owner.gravDir; if (Owner.direction < 0) bubbleRotation += MathHelper.Pi; - Vector2 bubblePosition = ReedBlowgun.getPlayerMouth(Owner) + (bubbleRotation + MathHelper.PiOver4 / 15f * Owner.direction).ToRotationVector2() * 48f; + Vector2 bubblePosition = ReedBlowgun.getPlayerMouth(Owner) + (bubbleRotation + MathHelper.PiOver4 / 15f * Owner.direction * Owner.gravDir).ToRotationVector2() * 48f; Projectile.Center = bubblePosition; Projectile.velocity = Vector2.UnitX.RotatedBy(bubbleRotation) * Projectile.velocity.Length(); diff --git a/Projectiles/Rogue/FishboneBoomerangProjectile.cs b/Projectiles/Rogue/FishboneBoomerangProjectile.cs index c1339a3a1d..4cd6efc108 100644 --- a/Projectiles/Rogue/FishboneBoomerangProjectile.cs +++ b/Projectiles/Rogue/FishboneBoomerangProjectile.cs @@ -70,8 +70,8 @@ namespace CalamityMod.Projectiles.Rogue Owner.heldProj = Projectile.whoAmI; - Projectile.Center = Owner.MountedCenter + Vector2.UnitY.RotatedBy(armRotation) * -40f; - Projectile.rotation = -MathHelper.PiOver2 + armRotation; + Projectile.Center = Owner.MountedCenter + Vector2.UnitY.RotatedBy(armRotation * Owner.gravDir) * -40f * Owner.gravDir; + Projectile.rotation = (-MathHelper.PiOver2 + armRotation) * Owner.gravDir; Owner.SetCompositeArmFront(true, Player.CompositeArmStretchAmount.Full, MathHelper.Pi + armRotation); diff --git a/Utilities/PlayerUtils.cs b/Utilities/PlayerUtils.cs index 56bebcf620..2c555078f1 100644 --- a/Utilities/PlayerUtils.cs +++ b/Utilities/PlayerUtils.cs @@ -11,6 +11,7 @@ using Terraria.ModLoader; using Microsoft.Xna.Framework.Graphics; using Microsoft.Xna.Framework; using static Terraria.ModLoader.ModContent; +using static Terraria.Player; namespace CalamityMod { @@ -488,6 +489,39 @@ namespace CalamityMod #endregion #region Arms Control + + /// + /// The exact same thing as Player.GetFrontHandPosition() except it properly accounts for gravity swaps instead of requiring the coders to do it manually afterwards. + /// Additionally, it simply takes in the arm data instead of asking for the rotation and stretch separately. + /// + public static Vector2 GetFrontHandPositionImproved(this Player player, CompositeArmData arm) + { + Vector2 position = player.GetFrontHandPosition(arm.stretch, arm.rotation * player.gravDir).Floor(); + + if (player.gravDir == -1f) + { + position.Y = player.position.Y + (float)player.height + (player.position.Y - position.Y); + } + + return position; + } + + /// + /// The exact same thing as Player.GetBackHandPosition() except it properly accounts for gravity swaps instead of requiring the coders to do it manually afterwards. + /// Additionally, it simply takes in the arm data instead of asking for the rotation and stretch separately. + /// + public static Vector2 GetBackHandPositionImproved(this Player player, CompositeArmData arm) + { + Vector2 position = player.GetBackHandPosition(arm.stretch, arm.rotation * player.gravDir).Floor(); + + if (player.gravDir == -1f) + { + position.Y = player.position.Y + (float)player.height + (player.position.Y - position.Y); + } + + return position; + } + /// /// Properly sets the player's held item rotation and position by doing the annoying math for you, since vanilla decided to be wholly inconsistent about it! /// This all assumes the player is facing right. All the flip stuff is automatically handled in here @@ -508,6 +542,8 @@ namespace CalamityMod Vector2 origin = rotationOriginFromCenter.Value; //Flip the origin's X position, since the sprite will be flipped if the player faces left. origin.X *= player.direction; + //Additionally, flip the origin's Y position in case the player is in reverse gravity. + origin.Y *= player.gravDir; player.itemRotation = desiredRotation;