/// <inheritdoc />
 public float GetTreasureChance(Farmer who, FishingRod rod)
 {
     return(this._treasureChance ?? FishHelper.GetRawTreasureChance(who, rod));
 }
 /// <inheritdoc />
 public float GetFishChance(Farmer who)
 {
     return((this._fishChance ?? FishHelper.GetRawFishChance(who))
            .Clamp(ModFishing.Instance.MainConfig.GlobalFishSettings.MinFishChance, ModFishing.Instance.MainConfig.GlobalFishSettings.MaxFishChance)
            .Clamp(0F, 1F)); // Prevent invalid chances
 }
 public static int?GetRandomTrash(Farmer who, string locationName, WaterType waterType, SDate date, Weather weather, int time, int fishingLevel, int?mineLevel) => FishHelper.GetRandomTrash(ModFishing.Instance.Api.GetTrashData(who, locationName, waterType, date, weather, time, fishingLevel, mineLevel));
 public static int?GetRandomTrash(Farmer who) => FishHelper.GetRandomTrash(ModFishing.Instance.Api.GetTrashData(who));
 public static int?GetRandomFish(Farmer who)
 {
     return(FishHelper.GetRandomFish(ModFishing.Instance.Api.GetPossibleFish(who)));
 }
Exemple #6
0
        private void OnPullFromNibble(FishingRod rod, Farmer user)
        {
            // Make sure this rod doesn't get the pullFishFromWater event overridden when it shouldn't be
            this.OverridingCatch.Add(rod);
            ModFishing.Instance.Monitor.Log("Overriding vanilla catch", LogLevel.Trace);

            if (rod == null)
            {
                throw new Exception("Fishing rod is null, please report this");
            }

            if (user == null)
            {
                throw new Exception("User is null, please report this");
            }

            // Get some info about the rod
            int          clearWaterDistance = ModFishing.Instance.Helper.Reflection.GetField <int>(rod, "clearWaterDistance").GetValue();
            GameLocation location           = user.currentLocation;

            int?fish = null;

            // Check if legendary fish are being overridden as well
            if (!ModFishing.Instance.MainConfig.CustomLegendaries)
            {
                // Check if a legendary would be caught
                double baitValue  = rod.attachments[0]?.Price / 10.0 ?? 0.0;
                bool   bubblyZone = false;
                if (!(location.fishSplashPoint is null) && location.fishSplashPoint.Value != Point.Zero)
                {
                    bubblyZone = new Rectangle(location.fishSplashPoint.X * 64, location.fishSplashPoint.Y * 64, 64, 64).Intersects(new Rectangle((int)rod.bobber.X - 80, (int)rod.bobber.Y - 80, 64, 64));
                }

                // NotNull
                SObject normalFish = location.getFish(rod.fishingNibbleAccumulator, rod.attachments[0]?.ParentSheetIndex ?? -1, clearWaterDistance + (bubblyZone ? 1 : 0), user, baitValue + (bubblyZone ? 0.4 : 0.0));

                // If so, select that fish
                if (ModFishing.Instance.Api.IsLegendary(normalFish.ParentSheetIndex))
                {
                    fish = normalFish.ParentSheetIndex;
                }
            }

            // Void mayonnaise
            if (location.Name.Equals("WitchSwamp") && !Game1.MasterPlayer.mailReceived.Contains("henchmanGone") && Game1.random.NextDouble() < 0.25 && !Game1.player.hasItemInInventory(308, 1))
            {
                rod.pullFishFromWater(308, -1, 0, 0, false);
                return;
            }

            // Choose a random fish if one hasn't been chosen yet
            if (fish == null)
            {
                fish = FishHelper.GetRandomFish(user);
            }

            // Check if a fish was chosen
            if (fish == null)
            {
                // Secret note
                if (user.hasMagnifyingGlass && Game1.random.NextDouble() < 0.08)
                {
                    SObject unseenSecretNote = location.tryToCreateUnseenSecretNote(user);
                    if (unseenSecretNote != null)
                    {
                        rod.pullFishFromWater(unseenSecretNote.ParentSheetIndex, -1, 0, 0, false);
                        return;
                    }
                }

                // Trash
                int?trash = FishHelper.GetRandomTrash(user);
                if (trash.HasValue)
                {
                    // Invoke event
                    FishingEventArgs eventArgs = new FishingEventArgs(trash.Value, user, rod);
                    ModFishing.Instance.Api.OnTrashCaught(eventArgs);
                    trash = eventArgs.ParentSheetIndex;

                    ModFishing.Instance.Monitor.Log($"Catching trash: {trash}", LogLevel.Trace);
                    rod.pullFishFromWater(trash.Value, -1, 0, 0, false);
                }
                else
                {
                    ModFishing.Instance.Monitor.Log($"No possible trash found for {location.Name}, using stone instead. This is probably caused by another mod removing trash data.", LogLevel.Warn);
                    rod.pullFishFromWater(Objects.Stone, -1, 0, 0, false);
                }
            }
            else
            {
                // Invoke event
                FishingEventArgs eventArgs = new FishingEventArgs(fish.Value, user, rod);
                ModFishing.Instance.Api.OnBeforeFishCatching(eventArgs);
                fish = eventArgs.ParentSheetIndex;

                // Check if favBait should be set to true (still not sure what this does...)
                SObject fishObject = new SObject(fish.Value, 1);
                if (Math.Abs(fishObject.Scale.X - 1.0) < 0.001)
                {
                    rod.favBait = true;
                }

                // Show hit animation
                rod.hit = true;
                ModFishing.Instance.Monitor.Log($"Catching fish: {fish}", LogLevel.Trace);
                Game1.screenOverlayTempSprites.Add(new TemporaryAnimatedSprite("LooseSprites\\Cursors", new Rectangle(612, 1913, 74, 30), 1500f, 1, 0, Game1.GlobalToLocal(Game1.viewport, rod.bobber.Value + new Vector2(-140f, -160f)), false, false, 1f, 0.005f, Color.White, 4f, 0.075f, 0.0f, 0.0f, true)
                {
                    scaleChangeChange       = -0.005f,
                    motion                  = new Vector2(0.0f, -0.1f),
                    endFunction             = extra => this.StartMinigameEndFunction(rod, user, extra),
                    extraInfoForEndBehavior = fish.Value
                });
                location.localSound("FishHit");
            }
        }