Example #1
0
        public static float GetRawTreasureChance(SFarmer who, FishingRod rod)
        {
            ConfigMain.ConfigGlobalTreasure config = ModFishing.Instance.MainConfig.GlobalTreasureSettings;

            // Calculate chance
            float chance = config.TreasureChance;

            chance += who.LuckLevel * config.TreasureLuckLevelEffect;
            chance += (float)Game1.dailyLuck * config.TreasureDailyLuckEffect;
            chance += config.TreasureStreakEffect * ModFishing.Instance.Api.GetStreak(who);
            if (rod.getBaitAttachmentIndex() == 703)
            {
                chance += config.TreasureBaitEffect;
            }
            if (rod.getBobberAttachmentIndex() == 693)
            {
                chance += config.TreasureBobberEffect;
            }
            if (who.professions.Contains(9))
            {
                chance += config.TreasureChance;
            }

            return(Math.Min(chance, config.MaxTreasureChance));
        }
Example #2
0
        public static void StartMinigameEndFunction(FishingRod rod, int extra)
        {
            ModFishing.INSTANCE.Monitor.Log("Overriding fishing minigame", LogLevel.Trace);
            ConfigMain config   = ModFishing.INSTANCE.Config;
            SFarmer    lastUser = ModFishing.INSTANCE.Helper.Reflection.GetPrivateValue <SFarmer>(rod, "lastUser");
            Vector2    bobber   = ModFishing.INSTANCE.Helper.Reflection.GetPrivateValue <Vector2>(rod, "bobber");

            rod.isReeling = true;
            rod.hit       = false;
            switch (lastUser.FacingDirection)
            {
            case 1:
                lastUser.FarmerSprite.setCurrentSingleFrame(48, 32000, false, false);
                break;

            case 3:
                lastUser.FarmerSprite.setCurrentSingleFrame(48, 32000, false, true);
                break;
            }
            lastUser.FarmerSprite.pauseForSingleAnimation = true;

            int clearWaterDistance = FishingRod.distanceToLand((int)(bobber.X / (double)Game1.tileSize - 1.0), (int)(bobber.Y / (double)Game1.tileSize - 1.0), lastUser.currentLocation);

            FishingRodOverrides.ClearWaterDistances[lastUser] = clearWaterDistance;
            float num = 1f * (clearWaterDistance / 5f) * (Game1.random.Next(1 + Math.Min(10, lastUser.FishingLevel) / 2, 6) / 5f);

            if (rod.favBait)
            {
                num *= 1.2f;
            }
            float fishSize = Math.Max(0.0f, Math.Min(1f, num * (float)(1.0 + Game1.random.Next(-10, 10) / 100.0)));
            bool  treasure = false;

            double treasureChance = config.TreasureChance + lastUser.LuckLevel * config.TreasureLuckLevelEffect + (rod.getBaitAttachmentIndex() == 703 ? config.TreasureBaitEffect : 0.0) + (rod.getBobberAttachmentIndex() == 693 ? config.TreasureBobberEffect : 0.0) + Game1.dailyLuck * config.TreasureDailyLuckEffect + (lastUser.professions.Contains(9) ? config.TreasureChance : 0.0) + config.TreasureStreakEffect * FishHelper.GetStreak(lastUser);

            treasureChance = Math.Min(treasureChance, config.MaxTreasureChance);
            if (!Game1.isFestival() && lastUser.fishCaught != null && lastUser.fishCaught.Count > 1 && Game1.random.NextDouble() < treasureChance)
            {
                treasure = true;
            }

            // Override caught fish
            bool legendary = FishHelper.IsLegendary(extra);

            if (!config.UseVanillaFish && (!config.VanillaLegendaries || !legendary))
            {
                int origExtra = extra;
                extra = FishHelper.GetRandomFish(clearWaterDistance);
                if (FishHelper.IsTrash(extra))
                {
                    if (false) // TODO: Replace this with code relating to a config option that determines the chance you'll get fish/trash
                    {
#pragma warning disable CS0162 // Unreachable code detected
                        Game1.showGlobalMessage("No valid fish to catch! Giving junk instead.");
                        StardewValley.Object o = new StardewValley.Object(extra, 1, false, -1, 0);
                        rod.pullFishFromWater(extra, -1, 0, 0, false, false);
                        return;

#pragma warning restore CS0162 // Unreachable code detected
                    }
                    else
                    {
                        ModFishing.INSTANCE.Monitor.Log("No valid fish to catch! Using original fish instead.", LogLevel.Warn);
                        extra = origExtra;
                    }
                }
            }

            // Show custom bobber bar
            Game1.activeClickableMenu = new CustomBobberBar(lastUser, extra, fishSize, treasure, rod.attachments[1] != null ? rod.attachments[1].ParentSheetIndex : -1, clearWaterDistance);
        }