From 20ecf6392cc7897ec7fcb5fc93c03b622e9ebaa6 Mon Sep 17 00:00:00 2001 From: Altixal <73398287+Altixal@users.noreply.github.com> Date: Sat, 24 May 2025 07:09:00 +0700 Subject: [PATCH] :fishing_pole_and_fish: (2/2) --- ILEditing/ILChangesLoading.cs | 2 + ILEditing/VanillaStupidityFixingILChanges.cs | 54 ++++++++++++++ ...ods.CalamityMod.Projectiles.Typeless.hjson | 1 + Projectiles/Typeless/VictideBobber.cs | 71 +++++++++++++++++++ Projectiles/Typeless/VictideSeaSnail.cs | 35 +++++---- 5 files changed, 151 insertions(+), 12 deletions(-) create mode 100644 Projectiles/Typeless/VictideBobber.cs diff --git a/ILEditing/ILChangesLoading.cs b/ILEditing/ILChangesLoading.cs index fcf29214a6..11c01a64a2 100644 --- a/ILEditing/ILChangesLoading.cs +++ b/ILEditing/ILChangesLoading.cs @@ -200,6 +200,8 @@ namespace CalamityMod.ILEditing On_NPC.SlimeRainSpawns += PreventBossSlimeRainSpawns; On_ShimmerTransforms.IsItemTransformLocked += AdjustShimmerRequirements; On_Projectile.AI_015_Flails += FlailsNoLongerAffectedByPlayerVelocity; + IL_Projectile.AI_061_FishingBobber += WhitelistVictideBobber; + On_Player.ItemCheck_CheckFishingBobbers += PreventVictideBobberFromJamming; IL_Projectile.CanExplodeTile += MakeMeteoriteExplodable; IL_Main.UpdateWindyDayState += MakeWindyDayMusicPlayLessOften; diff --git a/ILEditing/VanillaStupidityFixingILChanges.cs b/ILEditing/VanillaStupidityFixingILChanges.cs index a7c1ac0020..17165d6ec0 100644 --- a/ILEditing/VanillaStupidityFixingILChanges.cs +++ b/ILEditing/VanillaStupidityFixingILChanges.cs @@ -8,6 +8,7 @@ using CalamityMod.Items.TreasureBags.MiscGrabBags; using CalamityMod.NPCs.AcidRain; using CalamityMod.NPCs.NormalNPCs; using CalamityMod.NPCs.TownNPCs; +using CalamityMod.Projectiles.Typeless; using CalamityMod.Walls; using Microsoft.Xna.Framework; using Mono.Cecil.Cil; @@ -295,6 +296,59 @@ namespace CalamityMod.ILEditing } #endregion + #region Allow Victide Bobber to Exist + private static void WhitelistVictideBobber(ILContext il) + { + var cursor = new ILCursor(il); + + // Find the label which skips the "flag = true" that kills the projectile + ILLabel flagStorage = null; + if (!cursor.TryGotoNext(MoveType.After, x => x.MatchBeq(out flagStorage))) + { + LogFailure("Allow Victide Bobber to Exist", "Failed to properly navigate label to direct to"); + return; + } + + // Properly perform the skip if the projectile type is the Victide Bobber + cursor.Emit(OpCodes.Ldarg_0); + cursor.Emit(OpCodes.Ldfld, typeof(Projectile).GetField("type")); + cursor.Emit(OpCodes.Ldc_I4, ModContent.ProjectileType()); + cursor.Emit(OpCodes.Beq_S, flagStorage); + } + #endregion + + #region Prevent Victide Bobber from Jammming + private static bool PreventVictideBobberFromJamming(On_Player.orig_ItemCheck_CheckFishingBobbers orig, Player self, bool canUse) + { + // Run through the original stuff + canUse = orig(self, canUse); + + int bobberCount = 0; + foreach (Projectile proj in Main.ActiveProjectiles) + { + if (proj.active && proj.owner == self.whoAmI && proj.bobber) + { + bobberCount++; + if (proj.type == ModContent.ProjectileType()) + { + // Go back to casting if there's nothing loaded + if (proj.ai[1] == 0f) + proj.ai[0] = 0f; + + // Allow you to still use the fishing rod + canUse = true; + } + } + } + + // Unless.. you have a bobber already that's NOT Victide, then back to disabling + if (canUse && bobberCount > 1) + canUse = false; + + return canUse; + } + #endregion + #region Fix Chlorophyte Crystal Attacking Where it Shouldn't // TODO -- Finish this #endregion Fix Chlorophyte Crystal Attacking Where it Shouldn't diff --git a/Localization/en-US/Mods.CalamityMod.Projectiles.Typeless.hjson b/Localization/en-US/Mods.CalamityMod.Projectiles.Typeless.hjson index bde4722fe7..ba9749f9f7 100644 --- a/Localization/en-US/Mods.CalamityMod.Projectiles.Typeless.hjson +++ b/Localization/en-US/Mods.CalamityMod.Projectiles.Typeless.hjson @@ -146,6 +146,7 @@ TransformerAura.DisplayName: Transformer Aura TransformerBlob.DisplayName: Transformer Shard UrsaSlash.DisplayName: Ursa Slash VerstaltiteBobber.DisplayName: Verstaltite Bobber +VictideBobber.DisplayName: Victide Bobber VictideSeaSnail.DisplayName: Sea Snail VoidFieldGenerator.DisplayName: Void Field Generator WarbannerDamage.DisplayName: The Unmatched Power of the Sun diff --git a/Projectiles/Typeless/VictideBobber.cs b/Projectiles/Typeless/VictideBobber.cs new file mode 100644 index 0000000000..df392340a8 --- /dev/null +++ b/Projectiles/Typeless/VictideBobber.cs @@ -0,0 +1,71 @@ +using Microsoft.Xna.Framework; +using CalamityMod.Items; +using Terraria; +using Terraria.ID; +using Terraria.Localization; +using Terraria.ModLoader; + +namespace CalamityMod.Projectiles.Typeless +{ + public class VictideBobber : ModProjectile, ILocalizedModType + { + public new string LocalizationCategory => "Projectiles.Typeless"; + public override string Texture => "CalamityMod/Projectiles/Summon/CnidarianJellyfishOnTheString"; + + public Player Owner => Main.player[Projectile.owner]; + public ref float ParentProjectile => ref Projectile.ai[2]; + public Projectile Parent => Main.projectile[(int)ParentProjectile]; + + public override void SetDefaults() + { + Projectile.width = Projectile.height = 20; + Projectile.aiStyle = ProjAIStyleID.Bobber; + Projectile.bobber = true; + } + + public override bool PreAI() + { + // Snap if the snail is shelled, or just nowhere to be found + if (!Parent.active || Parent == null || Parent.frame < 6) + { + Projectile.Kill(); + return false; + } + return true; + } + + public override void AI() + { + // Automatic reeling + if (Projectile.ai[1] < 0f) + { + Projectile.ai[0] = 1f; + Projectile.ai[1] = Projectile.localAI[1]; + Projectile.localAI[0] = 1f; + Projectile.localAI[1] = 0f; + } + } + + // Anchor the bobber to the parent projectile, since the default is bound to the player + // Yes. This method is obsolete. No, there is no other way and I won't make another IL edit to remedy this fact. - Iris + public override void ModifyFishingLine(ref Vector2 lineOriginOffset, ref Color lineColor) + { + Vector2 originalPos = Owner.MountedCenter + Vector2.UnitY * (Owner.gfxOffY - (Owner.gravDir == -1 ? 12f : 0f)); + + if (Parent.active) + lineOriginOffset = Parent.Center - originalPos + Vector2.UnitY * 10f; + + // How this is a thing is beyond me + if (Owner.direction == -1) + lineOriginOffset += Vector2.UnitX * (Parent.Center.X < Owner.Center.X ? 48f : -54f); + + lineColor = Color.Cyan; + } + + public override bool PreDrawExtras() + { + Lighting.AddLight(Projectile.Center, 0f, 0.2f, 0.2f); + return true; + } + } +} diff --git a/Projectiles/Typeless/VictideSeaSnail.cs b/Projectiles/Typeless/VictideSeaSnail.cs index ea5367f2ba..e3c9229482 100644 --- a/Projectiles/Typeless/VictideSeaSnail.cs +++ b/Projectiles/Typeless/VictideSeaSnail.cs @@ -1,5 +1,6 @@ using System; using CalamityMod.CalPlayer; +using CalamityMod.Items.Weapons.Summon; using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Graphics; using Terraria; @@ -22,8 +23,9 @@ namespace CalamityMod.Projectiles.Typeless public Player Owner => Main.player[Projectile.owner]; public CalamityPlayer ModdedOwner => Owner.Calamity(); - public bool StandingStill => Owner.velocity.Length() == 0 && !Owner.mount.Active && !Collision.DrownCollision(Owner.position, Owner.width, Owner.height, Owner.gravDir); - public bool CanPeekOut => PlayerStandStillTimer >= PeekCooldown || Projectile.frame > 0; + + // Extra requirements so you don't break the bobber, or snail, or how would you fish underwater?? + public bool StandingStill => Owner.velocity.Length() == 0 && !Owner.pulley && !Owner.mount.Active && !Collision.DrownCollision(Owner.position, Owner.width, Owner.height, Owner.gravDir); public override void SetStaticDefaults() { @@ -99,8 +101,7 @@ namespace CalamityMod.Projectiles.Typeless Projectile.velocity.Y = collide.Value ? MathF.Sin(CollisionTimer * 0.05f) * 0.25f : 0f; } - if (CanPeekOut) - Projectile.rotation = Projectile.rotation.AngleTowards(0, MathHelper.PiOver4 * 0.14f); + Projectile.rotation = Projectile.rotation.AngleTowards(0, MathHelper.PiOver4 * 0.14f); if (CollisionTimer > 0f) { @@ -167,17 +168,19 @@ namespace CalamityMod.Projectiles.Typeless // This means you can't just AFK with the fishing rod held if (Owner.itemAnimation > 0 && Owner.ActiveItem().fishingPole > 0) PlayerFishingTimer = 600f; + else + PlayerFishingTimer = Math.Max(PlayerFishingTimer -1f, 0f); // Automatically casts bobbers one at a time - // This casts to your cursor at the speed of the pole - /*int bobberType = ModContent.ProjectileType(); - if (Owner.ownedProjectileCounts[bobberType] < 1 && Projectile.owner == Main.myPlayer) + // This casts the same way the pole does to prevent position variance + int bobberType = ModContent.ProjectileType(); + if (Owner.ownedProjectileCounts[bobberType] < 1 && Owner.ActiveItem().fishingPole > 0 && Projectile.owner == Main.myPlayer && PlayerFishingTimer > 0f) { SoundEngine.PlaySound(SoundID.Item1, Projectile.Center); - Vector2 velocity = Projectile.SafeDirectionTo(Main.MouseWorld) * Owner.ActiveItem().shootSpeed; - Projectile.NewProjectile(Projectile.GetSource_FromThis(), Projectile.Center, velocity, bobberType, 0, 0f, Projectile.owner); - }*/ + Vector2 velocity = Owner.SafeDirectionTo(Main.MouseWorld) * Owner.ActiveItem().shootSpeed; + Projectile.NewProjectile(Projectile.GetSource_FromThis(), Projectile.Center, velocity, bobberType, 0, 0f, Projectile.owner, ai2: Projectile.whoAmI); + } } } @@ -230,7 +233,7 @@ namespace CalamityMod.Projectiles.Typeless public override bool OnTileCollide(Vector2 oldVelocity) { - //Touches the ground + // Touches the ground if (oldVelocity.Y >= 0) CollisionTimer = 1f; return false; @@ -240,11 +243,19 @@ namespace CalamityMod.Projectiles.Typeless { Texture2D tex = Terraria.GameContent.TextureAssets.Projectile[Type].Value; Rectangle frame = tex.Frame(1, Main.projFrames[Type], 0, Projectile.frame); + bool CanPeekOut = PlayerStandStillTimer >= PeekCooldown || Projectile.frame > 0; Vector2 origin = !CanPeekOut ? new Vector2(15, 23) : frame.Size() * 0.5f; - //Look at the player's direction + // Look at the player's direction SpriteEffects flip = Owner.direction < 0 ? SpriteEffects.FlipHorizontally : SpriteEffects.None; Main.EntitySpriteDraw(tex, Projectile.Center + Vector2.UnitY * 2f - Main.screenPosition, frame, lightColor, Projectile.rotation, origin, Projectile.scale, flip); + + // Fisbing Rod,,. + if (Owner.ownedProjectileCounts[ModContent.ProjectileType()] > 0) + { + Texture2D rod = Terraria.GameContent.TextureAssets.Item[ModContent.ItemType()].Value; + Main.EntitySpriteDraw(rod, Projectile.Center - Main.screenPosition + Vector2.UnitX * Owner.direction * 30f, null, lightColor, 0f, rod.Size() * 0.5f, Projectile.scale, flip); + } return false; } }