using System; using System.Collections.Generic; using System.Linq; using CalamityMod.Events; using CalamityMod.Items.Accessories; using CalamityMod.Items.Accessories.Vanity; using CalamityMod.Items.Fishing; using CalamityMod.Items.Fishing.AstralCatches; using CalamityMod.Items.Fishing.BrimstoneCragCatches; using CalamityMod.Items.Fishing.FishingRods; using CalamityMod.Items.Fishing.SulphurCatches; using CalamityMod.Items.Fishing.SunkenSeaCatches; using CalamityMod.Items.Materials; using CalamityMod.Items.Pets; using CalamityMod.Items.Placeables.Abyss; using CalamityMod.Items.Placeables.FurnitureDriftwood; using CalamityMod.Items.SummonItems; using CalamityMod.Items.Tools.ClimateChange; using CalamityMod.Items.Weapons.Magic; using CalamityMod.Items.Weapons.Melee; using CalamityMod.Items.Weapons.Ranged; using CalamityMod.Items.Weapons.Rogue; using CalamityMod.Items.Weapons.Summon; using CalamityMod.NPCs; using CalamityMod.NPCs.OldDuke; using CalamityMod.Particles; using CalamityMod.World; using Microsoft.Xna.Framework; using Terraria; using Terraria.DataStructures; using Terraria.ID; using Terraria.Localization; using Terraria.ModLoader; namespace CalamityMod.CalPlayer { public partial class CalamityPlayer : ModPlayer { #region Modify Fishing Attempt public override void ModifyFishingAttempt(ref FishingAttempt attempt) { if (enchantedPearl) { // If the player fails to roll a crate naturally and has Enchanted Pearl, reroll // Stacking with existing probability, it should increase chances by 15% (12.5% with Crate Potion) if (!attempt.crate) attempt.crate = Main.rand.NextBool(6); // If the player does get a crate (can be from the reroll above), give it increased chances of being rarer if (attempt.crate) { int uncommonRate = Math.Clamp(240 / attempt.fishingLevel, 3, 240); // Iron/Mythril (originally 300) attempt.uncommon = Main.rand.NextBool(uncommonRate); // These roll result bools are individually stored for the rarifying visuals int rareRate = Math.Clamp(840 / attempt.fishingLevel, 4, 840); // Biome (originally 1050) bool rareRoll = Main.rand.NextBool(rareRate); attempt.rare = rareRoll; int veryRareRate = Math.Clamp(1800 / attempt.fishingLevel, 5, 1800); // Golden/Titanium (originally 2250) bool veryRareRoll = Main.rand.NextBool(veryRareRate); attempt.veryrare = veryRareRoll; Vector2 basePos = new Vector2(attempt.X * 16f, attempt.Y * 16f); if (rareRoll || veryRareRoll) { for (int i = 0; i < 8; i++) { Vector2 position = basePos + Vector2.UnitX * Main.rand.NextFloat(-16f, 16f); Vector2 velocity = (Vector2.UnitY * Main.rand.NextFloat(-12f, -9f)).RotatedByRandom(MathHelper.ToRadians(18f)); float scale = Main.rand.NextFloat(0.5f, 1.5f); CritSpark spark = new(position, velocity, Color.White, Main.hslToRgb(Main.rand.NextFloat(), 1f, 0.5f), scale, 36, 0.2f, scale * 2f); GeneralParticleHandler.SpawnParticle(spark); } } for (int i = 0; i < 6; i++) { Vector2 position = basePos + Vector2.UnitX * Main.rand.NextFloat(-16f, 16f); Vector2 velocity = (Vector2.UnitY * Main.rand.NextFloat(-3f, -0.5f)).RotatedByRandom(MathHelper.ToRadians(12f)); PearlParticle pearl = new(position, velocity, false, 24, Main.rand.NextFloat(0.5f, 1f), Main.hslToRgb(Main.rand.NextFloat(), 1f, (rareRoll || veryRareRoll) ? 0.75f : 1f)); GeneralParticleHandler.SpawnParticle(pearl); } } } } #endregion public override bool? CanConsumeBait(Item bait) { if (bait.type == ModContent.ItemType()) return true; return null; } #region Catch Fish public override void CatchFish(FishingAttempt attempt, ref int itemDrop, ref int npcSpawn, ref AdvancedPopupRequest sonar, ref Vector2 sonarPosition) { // If vanilla catches an enemy, just immediately cancel if (npcSpawn > 0) return; int bait = attempt.playerFishingConditions.BaitItemType; int power = attempt.fishingLevel; int questFish = attempt.questFish; int poolSize = attempt.waterTilesCount; bool lava = attempt.inLava; bool honey = attempt.inHoney; bool sky = attempt.heightLevel == 0; bool surface = attempt.heightLevel == 1; bool underground = attempt.heightLevel == 2; bool cavern = attempt.heightLevel == 3; bool underworld = attempt.heightLevel == 4; // Custom rate; increased by Enchanted Pearl bool grabBagFish = attempt.uncommon && Main.rand.Next(100) < (enchantedPearl ? 30 : 15); // Set up for allowing fishing in the Sulphurous Sea Point point = Player.Center.ToTileCoordinates(); bool canSulphurFish = false; if (Abyss.AtLeftSideOfWorld) { if (point.X < 380) canSulphurFish = true; } else { if (point.X > Main.maxTilesX - 380) canSulphurFish = true; } if (ZoneAbyss || ZoneSulphur) canSulphurFish = true; // Fishing in lava overrides the rest of logic if (lava) { // Don't do anything if you can't fish in lava if (!attempt.CanFishInLava) return; if (ZoneCalamity) { // Crates have highest priority if (attempt.crate && attempt.rare) itemDrop = Main.hardMode ? ModContent.ItemType() : ModContent.ItemType(); else if (attempt.legendary) itemDrop = ModContent.ItemType(); else if (attempt.veryrare) itemDrop = ModContent.ItemType(); else if (DownedBossSystem.downedProvidence && ((attempt.rare && Main.rand.NextBool(2)) || (attempt.uncommon && Main.rand.NextBool(4)))) itemDrop = ModContent.ItemType(); // Quest fish hover around this priority else if (questFish == ModContent.ItemType() && attempt.uncommon) itemDrop = ModContent.ItemType(); else if (questFish == ModContent.ItemType() && attempt.uncommon) itemDrop = ModContent.ItemType(); else if (questFish == ModContent.ItemType() && attempt.uncommon) itemDrop = ModContent.ItemType(); else if (attempt.rare) { List uncommonCatches = new List() { ModContent.ItemType(), ModContent.ItemType() }; itemDrop = uncommonCatches[Main.rand.Next(uncommonCatches.Count)]; } // Lava fish usually don't have plentiful catches but we can be more lenient else itemDrop = ModContent.ItemType(); } if (ZoneBasaltGully) { itemDrop = ModContent.ItemType(); } return; } // Honey also overrides logic but we have nothing to catch from honey... for now if (honey) return; // Old Duke spawn if (canSulphurFish && bait == ModContent.ItemType() && !BossRushEvent.BossRushActive) { if (!Main.projectile.Any(x => x.active && x.aiStyle == ProjAIStyleID.Bobber && x.ai[1] != 0 && x.localAI[1] == ModContent.NPCType() * -1)) npcSpawn = ModContent.NPCType(); itemDrop = -1; sonar.Text = ""; return; } if (attempt.playerFishingConditions.PoleItemType == ModContent.ItemType()) { if (Main.rand.NextBool(5)) { itemDrop = ModContent.ItemType(); return; } if (Main.rand.NextBool(15)) { itemDrop = ModContent.ItemType(); return; } if (Main.rand.NextBool(50)) { switch (Main.rand.Next(3)) { case 0: itemDrop = ModContent.ItemType(); return; case 1: itemDrop = ModContent.ItemType(); return; case 2: itemDrop = ModContent.ItemType(); return; } return; } } // Ignore catches if it's junk if (itemDrop == ItemID.OldShoe || itemDrop == ItemID.FishingSeaweed || itemDrop == ItemID.TinCan || itemDrop == ItemID.JojaCola) return; if (attempt.crate) { // This can override Golden/Titanium Crates, but so do vanilla biome crates // Those are still obtainable if the catch is very rare/legendary but not rare (fishing oddities) if (attempt.rare) { if (ZoneAstral) itemDrop = Main.hardMode ? ModContent.ItemType() : ModContent.ItemType(); if (ZoneSunkenSea) itemDrop = Main.hardMode ? ModContent.ItemType() : ModContent.ItemType(); if (canSulphurFish) itemDrop = Main.hardMode ? ModContent.ItemType() : ModContent.ItemType(); } return; } // Ignore all top priority legendary vanilla catches List keepCatchList = new List() { ItemID.CombatBook, ItemID.DreadoftheRedSea, ItemID.FrogLeg, ItemID.BalloonPufferfish, ItemID.ZephyrFish }; if (keepCatchList.Contains(itemDrop)) return; // Add top priorities of our own if (DownedBossSystem.downedLeviathan && attempt.legendary && poolSize > 1000 && !Main.rand.NextBool(3)) { itemDrop = ModContent.ItemType(); return; } //Rare abyss catches are replaced with abyss chest items post-skeletron if (NPC.downedBoss3 && (ZoneAbyssLayer2 || ZoneAbyssLayer3 || ZoneAbyssLayer4) && attempt.rare) { switch (Main.rand.Next(10)) { case 0: itemDrop = ModContent.ItemType(); return; case 1: itemDrop = ModContent.ItemType(); return; case 2: itemDrop = ModContent.ItemType(); return; case 3: itemDrop = ModContent.ItemType(); return; case 4: itemDrop = ModContent.ItemType(); return; case 5: itemDrop = ModContent.ItemType(); return; case 6: itemDrop = ModContent.ItemType(); return; case 7: itemDrop = ModContent.ItemType(); return; case 8: itemDrop = ModContent.ItemType(); return; case 9: itemDrop = ModContent.ItemType(); return; } } // Quest fish if (sky && questFish == ModContent.ItemType() && attempt.uncommon) itemDrop = ModContent.ItemType(); if (Player.ZoneSnow && questFish == ModContent.ItemType() && attempt.uncommon) itemDrop = ModContent.ItemType(); if (grabBagFish) { if (surface && Main.bloodMoon) itemDrop = ModContent.ItemType(); else if (surface && Main.dayTime) itemDrop = ModContent.ItemType(); else if (cavern) itemDrop = ModContent.ItemType(); if (Main.hardMode && sky) itemDrop = ModContent.ItemType(); } // Increased chance of Enchanted Starfish if you don't have maximum mana if (surface && !Main.dayTime) // Surface { int chance = (Player.ConsumedManaCrystals >= Player.ManaCrystalMax) ? 20 : 5; if (attempt.uncommon && Main.rand.NextBool(chance)) itemDrop = ModContent.ItemType(); if (attempt.uncommon && Main.rand.NextBool(10)) itemDrop = ModContent.ItemType(); } if (ZoneAstral) { if (attempt.legendary) { int legendaryCatch = Utils.SelectRandom(Main.rand, new int[] { ModContent.ItemType(), ModContent.ItemType(), ModContent.ItemType() }); itemDrop = legendaryCatch; } else if (attempt.veryrare) itemDrop = ModContent.ItemType(); else if (attempt.uncommon || attempt.rare) { int uncommonCatch = Utils.SelectRandom(Main.rand, new int[] { ModContent.ItemType(), ModContent.ItemType() }); itemDrop = uncommonCatch; } else itemDrop = ModContent.ItemType(); return; } if (ZoneSunkenSea) { // If the player is overlapping with the desert, split the catches if (Player.ZoneDesert && Main.rand.NextBool()) return; int commonCatch = ModContent.ItemType(); if (ZonePolypForest) commonCatch = ModContent.ItemType(); else if (ZoneGleamingBurrows) commonCatch = ModContent.ItemType(); else if (ZoneTimelessShores) commonCatch = ModContent.ItemType(); if (attempt.legendary) { List legendaryCatches = [ ModContent.ItemType() ]; legendaryCatches.AddWithCondition(ModContent.ItemType(), Main.hardMode); itemDrop = legendaryCatches[Main.rand.Next(legendaryCatches.Count)]; } else if (attempt.veryrare) { List veryRareCatches = [ ModContent.ItemType() ]; veryRareCatches.AddWithCondition(ModContent.ItemType(), DownedBossSystem.downedDesertScourge); veryRareCatches.AddWithCondition(ModContent.ItemType(), DownedBossSystem.downedDesertScourge); itemDrop = veryRareCatches[Main.rand.Next(veryRareCatches.Count)]; } // Quest fish hover around this priority else if (questFish == ModContent.ItemType() && attempt.uncommon) itemDrop = ModContent.ItemType(); else if (questFish == ModContent.ItemType() && attempt.uncommon) itemDrop = ModContent.ItemType(); else if (questFish == ModContent.ItemType() && attempt.uncommon) itemDrop = ModContent.ItemType(); else if (attempt.uncommon || attempt.rare) itemDrop = ModContent.ItemType(); else if (Main.rand.NextBool()) // 50% chance the common fish is replaced with driftwood itemDrop = ModContent.ItemType(); else itemDrop = commonCatch; return; } // There is no complete fishing pool here, so most of it is vanilla default if (canSulphurFish) { if (attempt.legendary) { itemDrop = ModContent.ItemType(); } else if (attempt.common && Main.rand.NextBool()) itemDrop = ModContent.ItemType(); } } #endregion #region Get Fishing Level public override void GetFishingLevel(Item fishingRod, Item bait, ref float fishingLevel) { // Note: This is calculated after equipments (Rod, Bait, Potions, etc) and before modifications (Chum Buckets, Luck) if ((ZoneAstral || ZoneAbyss || ZoneSulphur) && bait.type == ModContent.ItemType()) fishingLevel = fishingLevel * ArcturusAstroidean.FishingPowerBiomeMult; if (Player.ZoneSnow && fishingRod.type == ModContent.ItemType()) fishingLevel = fishingLevel * VerstaltiteFishingRod.FishingPowerBiomeMult; if (Player.ZoneSkyHeight && fishingRod.type == ModContent.ItemType()) fishingLevel = fishingLevel * HeronRod.FishingPowerBiomeMult; // Rage bait gives free sonar effect if (bait.type == ModContent.ItemType()) Player.sonarPotion = true; // Prevent the player from fishing if they have the Bloodworm if (bait.type == ModContent.ItemType()) { Point point = Player.Center.ToTileCoordinates(); bool canSulphurFish = false; if (Abyss.AtLeftSideOfWorld) { if (point.X < 380) canSulphurFish = true; } else { if (point.X > Main.maxTilesX - 380) canSulphurFish = true; } if (ZoneAbyss || ZoneSulphur) canSulphurFish = true; Item item = Player.HeldItem; if (!canSulphurFish || item.fishingPole <= 0 || item.holdStyle != 1) fishingLevel = -1; // Set Fisherman's Pocket Guide to display "Warning!" with Bloodworm as bait // This runs only while there is a fishing bobber; logic with no fishing bobber is handled in the ModifyDisplayParameters hook in the separate class below Player.displayedFishingInfo = Language.GetTextValue("GameUI.FishingWarning"); } } #endregion #region Modify Caught Fish public override void ModifyCaughtFish(Item fish) { // Increases yeild of driftwood from the Sunken Sea // ~7% chance that yeild is very high so that exhaustive fishing can allow for enough driftwood to make large builds if (fish.type == ModContent.ItemType()) fish.stack = ((Main.rand.NextBool(14) ? 20 : 1) * Main.rand.Next(8, 20 + 1)); // Increases the yield of potion ingredient fish with Alluring Bait if (alluringBait) { List fishList = new List() { ItemID.FlarefinKoi, ItemID.Obsidifish, ItemID.ArmoredCavefish, ItemID.Stinkfish, ItemID.SpecularFish, ItemID.ChaosFish, ItemID.VariegatedLardfish, ItemID.DoubleCod, ItemID.FrostMinnow, ItemID.Ebonkoi, ItemID.CrimsonTigerfish, ItemID.Hemopiranha, ItemID.PrincessFish, ItemID.Prismite, ItemID.Damselfish, ModContent.ItemType(), ModContent.ItemType(), ModContent.ItemType(), ModContent.ItemType(), }; if (fishList.Contains(fish.type)) fish.stack += Main.rand.Next(1, 3 + 1); } if (fish.type == ModContent.ItemType()) fish.stack = Main.rand.Next(1, 6); } #endregion } public class BloodwormFishPowerWarning : GlobalInfoDisplay { // Set Fisherman's Pocket Guide to display "Warning!" with Bloodworm as bait // This runs only while there is no fishing bobber; logic with a fishing bobber is handled in the GetFishingLevel hook above public override void ModifyDisplayParameters(InfoDisplay currentDisplay, ref string displayValue, ref string displayName, ref Color displayColor, ref Color displayShadowColor) { if (currentDisplay == InfoDisplay.FishFinder) { foreach (Projectile p in Main.ActiveProjectiles) { if (p.owner == Main.myPlayer && p.bobber) return; } if (Main.LocalPlayer.GetFishingConditions().BaitItemType == ModContent.ItemType()) displayValue = Language.GetTextValue("GameUI.FishingWarning"); } } } }