Example #1
0
 public static void Before_checkForAction(CrabPot __instance, Farmer who, bool justCheckingForActivity)
 {
     if (__instance.tileIndexToShow == 714 && !justCheckingForActivity && __instance.heldObject.Value != null)
     {
         QuestEssentialsMod.QuestApi.CheckForQuestComplete(new FishMessage(who, __instance.heldObject.Value));
     }
 }
Example #2
0
        private bool CheckForAction(Farmer farmer, CrabPot pot, CrabNetStats stats)
        {
            if (!this.CanAfford(farmer, this.CostPerCheck, stats))
            {
                return(false);
            }

            if (pot.tileIndexToShow == 714)
            {
                if (farmer.IsMainPlayer && !this.AddItemToInventory(pot.heldObject.Value, farmer, Game1.getFarm()))
                {
                    Game1.addHUDMessage(new HUDMessage("Inventory Full", Color.Red, 3500f));
                    return(false);
                }
                Dictionary <int, string> dictionary = this.Helper.Content.Load <Dictionary <int, string> >("Data\\Fish", ContentSource.GameContent);
                if (this.GetFishSize(pot.heldObject.Value.ParentSheetIndex, out int minSize, out int maxSize))
                {
                    farmer.caughtFish(pot.heldObject.Value.ParentSheetIndex, Game1.random.Next(minSize, maxSize + 1));
                }
                pot.readyForHarvest.Value = false;
                pot.heldObject.Value      = null;
                pot.tileIndexToShow       = 710;
                pot.bait.Value            = null;
                farmer.gainExperience(1, 5);

                return(true);
            }
            return(false);
        }
Example #3
0
        private void UpdateObjectInfoList(GameLocation loc)
        {
            this.ObjectInfoList.RemoveAll(soi => soi.Location == loc);

            foreach (KeyValuePair <Vector2, StardewValley.Object> o in loc.Objects)
            {
                if (o.Value is CrabPot)
                {
                    CrabPot currentCrabPot = (CrabPot)o.Value;
                    var     soi            = new StardewObjectInfo();
                    soi.Coordinate = o.Key * Game1.tileSize + new Vector2(Game1.tileSize / 2, Game1.tileSize / 2);
                    soi.Location   = loc;
                    if (currentCrabPot.readyForHarvest)
                    {
                        soi.NeedAction = true;
                    }

                    // if player is luremaster, crab pots dont need bait
                    if (currentCrabPot.bait == null && !Game1.player.professions.Contains(11))
                    {
                        soi.NeedAction = true;
                    }

                    this.ObjectInfoList.Add(soi);
                }
            }
        }
Example #4
0
        private bool CheckForAction(Farmer farmer, CrabPot pot, CrabNetStats stats)
        {
            if (!this.CanAfford(farmer, this.CostPerCheck, stats))
            {
                return(false);
            }

            if (pot.tileIndexToShow == 714)
            {
                if (farmer.IsMainPlayer && !this.AddItemToInventory(pot.heldObject.Value, farmer, Game1.getFarm()))
                {
                    Game1.addHUDMessage(new HUDMessage("Inventory Full", Color.Red, 3500f));
                    return(false);
                }
                Dictionary <int, string> dictionary = this.Helper.Content.Load <Dictionary <int, string> >("Data\\Fish", ContentSource.GameContent);
                if (dictionary.ContainsKey(pot.heldObject.Value.ParentSheetIndex))
                {
                    string[] strArray = dictionary[pot.heldObject.Value.ParentSheetIndex].Split('/');
                    int      minValue = strArray.Length > 5 ? Convert.ToInt32(strArray[5]) : 1;
                    int      num      = strArray.Length > 5 ? Convert.ToInt32(strArray[6]) : 10;
                    farmer.caughtFish(pot.heldObject.Value.ParentSheetIndex, Game1.random.Next(minValue, num + 1));
                }
                pot.readyForHarvest.Value = false;
                pot.heldObject.Value      = null;
                pot.tileIndexToShow       = 710;
                pot.bait.Value            = null;
                farmer.gainExperience(1, 5);

                return(true);
            }
            return(false);
        }
Example #5
0
 public static bool Prefix(CrabPot __instance, GameLocation location)
 {
     try
     {
         PrefixData = new DayUpdateParameters(__instance);
         if (__instance.IsCombinedMachine())
         {
             if (CurrentlyModifying.Contains(__instance) || !ModEntry.UserConfig.ShouldModifyProcessingSpeed(__instance))
             {
                 return(true);
             }
             else
             {
                 return(false);
             }
         }
         else
         {
             return(true);
         }
     }
     catch (Exception ex)
     {
         ModEntry.Logger.Log(string.Format("Unhandled Error in {0}.{1}:\n{2}", nameof(CrabPot_DayUpdatePatch), nameof(Prefix), ex), LogLevel.Error);
         return(true);
     }
 }
Example #6
0
        /// <summary>Patch to draw weapons in Luremaster crabpots.</summary>
        private static bool CrabPotDrawPrefix(ref CrabPot __instance, ref float ___yBob, ref Vector2 ___shake, SpriteBatch spriteBatch, int x, int y)
        {
            try
            {
                if (!__instance.readyForHarvest.Value || __instance.heldObject.Value == null || !__instance.heldObject.Value.ParentSheetIndex.AnyOf(14, 51))
                {
                    return(true);                    // run original logic
                }
                ___yBob = (float)(Math.Sin(Game1.currentGameTime.TotalGameTime.TotalMilliseconds / 500.0 + (x * 64)) * 8.0 + 8.0);
                if (___yBob <= 0.001f)
                {
                    Game1.currentLocation.temporarySprites.Add(new TemporaryAnimatedSprite(Path.Combine("TileSheets", "animations"), new Rectangle(0, 0, 64, 64), 150f, 8, 0, __instance.directionOffset.Value + new Vector2(x * 64f + 4f, y * 64f + 32f), flicker: false, Game1.random.NextDouble() < 0.5, 0.001f, 0.01f, Color.White, 0.75f, 0.003f, 0f, 0f));
                }

                _ = Game1.currentLocation.Map.GetLayer("Buildings").Tiles[x, y];
                spriteBatch.Draw(Game1.objectSpriteSheet, Game1.GlobalToLocal(Game1.viewport, __instance.directionOffset.Value + new Vector2(x * 64f, y * 64f + ___yBob)) + ___shake, Game1.getSourceRectForStandardTileSheet(Game1.objectSpriteSheet, __instance.tileIndexToShow, 16, 16), Color.White, 0f, Vector2.Zero, 4f, SpriteEffects.None, (y * 64 + __instance.directionOffset.Value.Y + (x % 4)) / 10000f);
                spriteBatch.Draw(Game1.mouseCursors, Game1.GlobalToLocal(Game1.viewport, __instance.directionOffset.Value + new Vector2(x * 64f + 4f, y * 64f + 48f)) + ___shake, new Rectangle(Game1.currentLocation.waterAnimationIndex * 64, 2112 + ((x + y) % 2 != 0 ? (!Game1.currentLocation.waterTileFlip ? 128 : 0) : (Game1.currentLocation.waterTileFlip ? 128 : 0)), 56, 16 + (int)___yBob), Game1.currentLocation.waterColor.Value, 0f, Vector2.Zero, 1f, SpriteEffects.None, (y * 64 + __instance.directionOffset.Value.Y + (x % 4)) / 9999f);
                var yOffset = 4f * (float)Math.Round(Math.Sin(Game1.currentGameTime.TotalGameTime.TotalMilliseconds / 250.0), 2);
                spriteBatch.Draw(Game1.mouseCursors, Game1.GlobalToLocal(Game1.viewport, __instance.directionOffset.Value + new Vector2(x * 64f - 8f, (y * 64f - 96f - 16f) + yOffset)), new Rectangle(141, 465, 20, 24), Color.White * 0.75f, 0f, Vector2.Zero, 4f, SpriteEffects.None, (y + 1) * 64 / 10000f + 1E-06f + __instance.TileLocation.X / 10000f);
                spriteBatch.Draw(Tool.weaponsTexture, Game1.GlobalToLocal(Game1.viewport, __instance.directionOffset.Value + new Vector2(x * 64f + 32f, (y * 64f - 64f - 8f) + yOffset)), Game1.getSourceRectForStandardTileSheet(Tool.weaponsTexture, __instance.heldObject.Value.ParentSheetIndex, 16, 16), Color.White * 0.75f, 0f, new Vector2(8f, 8f), 4f, SpriteEffects.None, (y + 1) * 64 / 10000f + 1E-05f + __instance.TileLocation.X / 10000f);
                return(false);                // don't run original logic
            }
            catch (Exception ex)
            {
                Monitor.Log($"Failed in {nameof(CrabPotDrawPrefix)}:\n{ex}");
                return(true);                // default to original logic
            }
        }
Example #7
0
        public static bool TryGetProcessingInterval(this CrabPot Item, out double Power, out double IntervalDecimalHours, out int IntervalMinutes)
        {
            if (Item.TryGetCombinedQuantity(out int Quantity))
            {
                Power = ModEntry.UserConfig.ComputeProcessingPower(Quantity);

                IntervalDecimalHours = MinutesElapsedPatch.CrabPotHoursPerDay / Power;
                IntervalMinutes      = (int)(IntervalDecimalHours * MinutesElapsedPatch.MinutesPerHour);

                //  Round the minutes up to the nearest multiple of 10
                if (IntervalMinutes % 10 != 0)
                {
                    IntervalMinutes     += 10 - IntervalMinutes % 10;
                    IntervalDecimalHours = IntervalMinutes * 1.0 / MinutesElapsedPatch.MinutesPerHour;
                }

                return(true);
            }
            else
            {
                Power = 1.0;
                IntervalDecimalHours = -1;
                IntervalMinutes      = -1;
                return(false);
            }
        }
 private static void Postfix(CrabPot __instance, bool justCheckingForActivity, SObject?__state)
 {
     if (!justCheckingForActivity && __state is not null && __instance.bait.Value is null)
     {
         __instance.bait.Value = __state;
     }
 }
Example #9
0
                public SVObject Retrieve(IntPoint?tileLocation)
                {
                    SVObject result;

                    if (tileLocation is null)
                    {
                        result = Color.HasValue ? new ColoredObject(ParentSheetIndex, 1, Color.Value) : new SVObject(ParentSheetIndex, 1);
                    }
                    else
                    {
                        if (!BigCraftable && ParentSheetIndex == CrabPotID)
                        {
                            result = new CrabPot(new Vector2(tileLocation.Value.X, tileLocation.Value.Y));
                        }
                        else
                        {
                            result = new SVObject(new Vector2(tileLocation.Value.X, tileLocation.Value.Y), ParentSheetIndex, 1);
                        }
                    }

                    result.Name = Name;
                    result.bigCraftable.Value  = BigCraftable;
                    result.showNextIndex.Value = ShowNextIndex;
                    if (result is ColoredObject colored)
                    {
                        colored.ColorSameIndexAsParentSheetIndex = ColorSameIndexAsParentSheetIndex;
                    }
                    return(result);
                }
Example #10
0
 public static void Postfix(CrabPot __instance, bool __result, Farmer who, bool probe)
 {
     if (!Config.EnableMod || probe || !__result)
     {
         return;
     }
     who.currentLocation.playSound("dropItemInWater");
 }
Example #11
0
        private bool PerformObjectDropInAction(SObject dropIn, Farmer farmer, CrabPot pot)
        {
            if (pot.bait.Value != null || farmer.professions.Contains(11))
            {
                return(false);
            }

            pot.bait.Value = dropIn;

            return(true);
        }
 private static void Prefix(CrabPot __instance, bool justCheckingForActivity, out SObject?__state)
 {
     if (!justCheckingForActivity && ModEntry.Config.CrabPotTrashDoesNotEatBait && __instance.heldObject.Value?.IsTrashItem() == true)
     {
         __state = __instance.bait.Value;
     }
     else
     {
         __state = null;
     }
 }
Example #13
0
        /*********
        ** Private methods
        *********/
        /// <summary>Get whether an object is a machine with 'fast processing' enabled.</summary>
        /// <param name="context">The cheat context.</param>
        /// <param name="obj">The machine to check.</param>
        private bool IsFastMachine(CheatContext context, SObject obj)
        {
            // quick initial check
            bool mayBeMachine = obj != null && (obj.bigCraftable.Value || obj is CrabPot);

            if (!mayBeMachine)
            {
                return(false);
            }

            // specific check
            ModConfig config = context.Config;

            return(obj switch
            {
                Cask _ => config.FastCask,
                CrabPot _ => config.FastCrabPot,
                WoodChipper _ => config.FastWoodChipper,
                _ => obj.name switch
                {
                    "Bee House" => config.FastBeeHouse,
                    "Bone Mill" => config.FastBoneMill,
                    "Charcoal Kiln" => config.FastCharcoalKiln,
                    "Cheese Press" => config.FastCheesePress,
                    "Coffee Maker" => config.FastCoffeeMaker,
                    "Crystalarium" => config.FastCrystalarium,
                    "Deconstructor" => config.FastDeconstructor,
                    "Furnace" => config.FastFurnace,
                    "Geode Crusher" => config.FastGeodeCrusher,
                    "Heavy Tapper" => config.FastTapper,
                    "Incubator" => config.FastIncubator,
                    "Keg" => config.FastKeg,
                    "Lightning Rod" => config.FastLightningRod,
                    "Loom" => config.FastLoom,
                    "Mayonnaise Machine" => config.FastMayonnaiseMachine,
                    "Mushroom Box" => config.FastMushroomBox,
                    "Oil Maker" => config.FastOilMaker,
                    "Ostrich Incubator" => config.FastOstrichIncubator,
                    "Preserves Jar" => config.FastPreservesJar,
                    "Recycling Machine" => config.FastRecyclingMachine,
                    "Seed Maker" => config.FastSeedMaker,
                    "Slime Egg-Press" => config.FastSlimeEggPress,
                    "Slime Incubator" => config.FastSlimeIncubator,
                    "Soda Machine" => config.FastSodaMachine,
                    "Solar Panel" => config.FastSolarPanel,
                    "Statue Of Endless Fortune" => config.FastStatueOfEndlessFortune,
                    "Statue Of Perfection" => config.FastStatueOfPerfection,
                    "Statue Of True Perfection" => config.FastStatueOfTruePerfection,
                    "Tapper" => config.FastTapper,
                    "Worm Bin" => config.FastWormBin,
                    _ => false
                }
            });
Example #14
0
            public static bool Prefix(CrabPot __instance, SpriteBatch spriteBatch, int x, int y, float alpha, ref float ___yBob, Vector2 ___shake)
            {
                if (!Config.EnableMod || (__instance.heldObject.Value == null && !__instance.readyForHarvest.Value && __instance.bait.Value == null))
                {
                    return(true);
                }
                ___yBob = (float)(Math.Sin(Game1.currentGameTime.TotalGameTime.TotalMilliseconds / 500.0 + x * 64) * 8.0 + 8.0);
                int tileIndexToShow = (int)((___yBob - 1) / 5);

                if (__instance.heldObject.Value is not null || __instance.readyForHarvest.Value)
                {
                    tileIndexToShow = 2;
                    ___yBob        /= 2;
                }
Example #15
0
        internal static void InvokeDayUpdate(CrabPot instance, GameLocation location)
        {
            if (instance == null)
            {
                return;
            }

            try
            {
                CurrentlyModifying.Add(instance);
                instance.DayUpdate(location);
            }
            finally { CurrentlyModifying.Remove(instance); }
        }
Example #16
0
        private int DeterminePotQuality(CrabPot pot)
        {
            // if it is magic bait, done before trash check so it's never wasted
            if (pot.bait != null && pot.bait.Value != null && pot.bait.Value.ParentSheetIndex == 908)
            {
                // give the crab pot a rainbow shell
                pot.heldObject.Value = new StardewObject(394, 1, false, -1, 0);
            }

            // item is trash
            if (pot.heldObject.Value.ParentSheetIndex >= 168 && pot.heldObject.Value.ParentSheetIndex < 173)
            {
                return(0);
            }

            Farmer farmer = Game1.getFarmer(pot.owner);

            if (farmer == null)
            {
                return(0);
            }

            if (IsLuremaster(farmer) || IsMariner(farmer))
            {
                return(4);
            }

            int multiplier = 1;

            // if it is wild bait
            if (pot.bait != null && pot.bait.Value != null && pot.bait.Value.ParentSheetIndex == 774)
            {
                multiplier = 2;
            }

            // foraging formula
            if (Game1.random.NextDouble() < farmer.FishingLevel / 30f * multiplier)
            {
                return(2);
            }
            else if (Game1.random.NextDouble() < farmer.FishingLevel / 15f * multiplier)
            {
                return(1);
            }
            else
            {
                return(0);
            }
        }
Example #17
0
        private static int DeterminePotQuality(CrabPot pot)
        {
            // if it is magic bait, done before trash check so it's never wasted
            if (pot.bait.Value != null && pot.UsesMagicBait())
            {
                // give the crab pot a rainbow shell
                pot.heldObject.Value = new StardewObject(394, 1, false, -1, 0);
            }

            // item is trash
            if (pot.heldObject.Value.ParentSheetIndex >= 168 && pot.heldObject.Value.ParentSheetIndex < 173)
            {
                return(0);
            }

            Farmer farmer = Game1.getFarmer(pot.owner.Value) ?? Game1.MasterPlayer; // set to host if owner somehow doesn't exist

            if (farmer.IsLuremaster() || farmer.IsMariner())
            {
                return(4);
            }

            int multiplier = 1;

            // if it is wild bait
            if (pot.bait.Value != null && pot.UsesWildBait())
            {
                multiplier = 2;
            }

            // foraging formula
            if (Game1.random.NextDouble() < farmer.FishingLevel / 30f * multiplier)
            {
                return(2);
            }
            else if (Game1.random.NextDouble() < farmer.FishingLevel / 15f * multiplier)
            {
                return(1);
            }
            else
            {
                return(0);
            }
        }
Example #18
0
 public static void Postfix(CrabPot __instance, GameLocation location)
 {
     try
     {
         //  Check if the output item was just set
         if (PrefixData != null && PrefixData.CrabPot == __instance && PrefixData.PreviousHeldObject == null && PrefixData.CurrentHeldObject != null)
         {
             //  Modify the output quantity based on the combined machine's processing power
             if (__instance.IsCombinedMachine() && ModEntry.UserConfig.ShouldModifyInputsAndOutputs(__instance) && __instance.TryGetCombinedQuantity(out int CombinedQuantity))
             {
                 double Power           = ModEntry.UserConfig.ComputeProcessingPower(CombinedQuantity);
                 double DesiredNewValue = PrefixData.CurrentHeldObjectQuantity * Power;
                 int    RoundedNewValue = RNGHelpers.WeightedRound(DesiredNewValue);
                 __instance.heldObject.Value.Stack = RoundedNewValue;
                 ModEntry.LogTrace(CombinedQuantity, PrefixData.CrabPot, PrefixData.CrabPot.TileLocation, "HeldObject.Stack", PrefixData.CurrentHeldObjectQuantity,
                                   DesiredNewValue, RoundedNewValue, Power);
             }
         }
     }
     catch (Exception ex)
     {
         ModEntry.Logger.Log(string.Format("Unhandled Error in {0}.{1}:\n{2}", nameof(CrabPot_DayUpdatePatch), nameof(Postfix), ex), LogLevel.Error);
     }
 }
Example #19
0
 public CrabPotState(CrabPot pot) : base(pot)
 {
     bait = (pot.bait != null);
 }
Example #20
0
 public static bool UsesMagnetBait(this CrabPot pot)
 {
     return(pot?.bait.Value is not null && pot.bait.Value.ParentSheetIndex == 703);
 }
Example #21
0
        private void IterateOverCrabPots()
        {
            // reset this each time invoked, it is a flag to determine if uncompleted work is due to inventory or money.
            this.InventoryAndChestFull = false;
            CrabNetStats stats = new CrabNetStats();

            foreach (GameLocation location in Game1.locations)
            {
                if (location.IsOutdoors)
                {
                    foreach (SObject obj in location.Objects.Values)
                    {
                        if (obj.Name == "Crab Pot")
                        {
                            stats.NumTotal++;

                            if (!this.Free && !this.CanAfford(Game1.player, this.CostPerCheck, stats) && !this.AllowFreebies)
                            {
                                this.Monitor.Log("Couldn't afford to check.", LogLevel.Trace);
                                stats.NotChecked++;
                                continue;
                            }

                            stats.NumChecked++;
                            stats.RunningTotal += this.CostPerCheck;

                            CrabPot pot = (CrabPot)obj;

                            if (pot.heldObject.Value != null && pot.heldObject.Value.Category != -21)
                            {
                                if (!this.Free && !this.CanAfford(Game1.player, this.CostPerEmpty, stats) && !this.AllowFreebies)
                                {
                                    this.Monitor.Log("Couldn't afford to empty.", LogLevel.Trace);
                                    stats.NotEmptied++;
                                    continue;
                                }

                                if (this.CheckForAction(Game1.player, pot, stats))
                                {
                                    stats.NumEmptied++;
                                    stats.RunningTotal += this.CostPerEmpty;
                                }
                            }
                            else
                            {
                                stats.NothingToRetrieve++;
                            }

                            if (pot.bait.Value == null && pot.heldObject.Value == null && !Game1.player.professions.Contains(11))
                            {
                                SObject b = new SObject(this.BaitChoice, 1);

                                if (!this.Free && !this.CanAfford(Game1.player, this.BaitCost, stats) && !this.AllowFreebies && this.ChargeForBait)
                                {
                                    this.Monitor.Log("Couldn't afford to bait.", LogLevel.Trace);
                                    stats.NotBaited++;
                                    continue;
                                }

                                if (this.PerformObjectDropInAction(b, Game1.player, pot))
                                {
                                    stats.NumBaited++;
                                    if (this.ChargeForBait)
                                    {
                                        stats.RunningTotal += this.BaitCost;
                                    }
                                }
                            }
                            else
                            {
                                stats.NothingToBait++;
                            }
                        }
                    }
                }
            }

            int totalCost = (stats.NumChecked * this.CostPerCheck);

            totalCost += (stats.NumEmptied * this.CostPerEmpty);
            if (this.ChargeForBait)
            {
                totalCost += (this.BaitCost * stats.NumBaited);
            }
            if (this.Free)
            {
                totalCost = 0;
            }

            if (this.LoggingEnabled)
            {
                this.Monitor.Log($"CrabNet checked {stats.NumChecked} pots. You used {stats.NumBaited} bait to reset.", LogLevel.Trace);
                if (!this.Free)
                {
                    this.Monitor.Log($"Total cost was {totalCost}g. Checks: {stats.NumChecked * this.CostPerCheck}, Emptied: {stats.NumEmptied * this.CostPerEmpty}, Bait: {stats.NumBaited * this.BaitCost}", LogLevel.Trace);
                }
            }

            if (!this.Free)
            {
                Game1.player.Money = Math.Max(0, Game1.player.Money + (-1 * totalCost));
            }

            if (this.EnableMessages)
            {
                this.ShowMessage(stats, totalCost);
            }
        }
Example #22
0
        public static bool performToolAction_prefix(Tool t, GameLocation location, ref CrabPot __instance)
        {
            // when pickaxe used on placed crab pot with no catch, and the inventory can accept a crab pot, the crab pot is
            // automatically moved to the inventory (not dropped into the environment then picked up by player) and the bait is
            // added back into the inventory (either a bait stack in rod or inventory)
            if (t is Pickaxe && !__instance.readyForHarvest)
            {
                Farmer who         = Game1.player;
                bool   baitRemoved = false;

                if (__instance.bait.Value != null)
                {
                    // Restore bait to stack or rod (inverse of improved baiting action)
                    // Prefer adding to the rod
                    Item   baitInPot = __instance.bait.Value;
                    string baitName  = baitInPot.Name;
                    foreach (FishingRod rod in who.items.Where(item => item is FishingRod && item.attachmentSlots() > 0))
                    {
                        Item baitSlot = rod.attachments[0] ?? new StardewValley.Object();
                        // TODO: make the bait from crab pot add to the fishing rod bait slot even if it is empty
                        if (baitSlot.Category == BaitCategory && baitSlot.Stack > 0 && baitSlot.Name == baitInPot.Name)
                        {
                            __instance.bait.Value = null;
                            baitSlot.Stack++;
                            ModEntry.EMonitor?.Log($"Added {baitName} to rod {rod.Name}");
                            baitRemoved = true;
                            break;
                        }
                    }

                    if (!baitRemoved)
                    {
                        // Didn't find a suitable rod
                        if (who.addItemToInventoryBool(baitInPot))
                        {
                            __instance.bait.Value = null;
                            baitRemoved           = true;
                            ModEntry.EMonitor?.Log($"Added {baitName} to inventory");
                        }
                        else
                        {
                            //who.dropItem(__instance.bait.Value);
                            //__instance.bait.Value = null;
                            //ModEntry.EMonitor?.Log($"Dropping {baitName} at player's feet");
                            ModEntry.EMonitor?.Log($"No space for {baitName}");
                            Game1.showRedMessage(Game1.content.LoadString("Strings\\StringsFromCSFiles:Crop.cs.588"));
                            return(false);
                        }
                    }
                }

                if (baitRemoved)
                {
                    Game1.playSound("coin");
                }

                if (who.addItemToInventoryBool(__instance.getOne(), false))
                {
                    // ripped from CrabPot::checkForAction
                    if (who.isMoving())
                    {
                        Game1.haltAfterCheck = false;
                    }
                    if (!baitRemoved)
                    {
                        // play sound if no bait removed but the pot was removed
                        Game1.playSound("coin");
                    }
                    Game1.currentLocation.objects.Remove(__instance.tileLocation);
                }
                else
                {
                    Game1.showRedMessage(Game1.content.LoadString("Strings\\StringsFromCSFiles:Crop.cs.588"));
                }

                return(false);
            }

            // Some other tool, let base Object handle it
            return(true);
        }
Example #23
0
        private static bool dayUpdatePrefix(GameLocation location, ref CrabPot __instance)
        {
            // A strange issue was occuring where new numbers wouldn't be regenerated (the previos crabpot id was used) causing all crab pots to have the same object in it. This was the only way I could find to fix that from happening
            System.Threading.Thread.Sleep(250);

            // Check if the current crabpot has bait and requires it and doesn't already have an item to be collected
            if ((__instance.bait.Value == null && Config.RequiresBait) || __instance.heldObject.Value != null)
            {
                if (Config.EnablePassiveTrash)
                {
                    List <int> possiblePassiveTrash = new List <int>();

                    if (Config.WhatCanBeFoundAsPassiveTrash.Count() == 0)
                    {
                        possiblePassiveTrash.Add(168);
                        possiblePassiveTrash.Add(169);
                        possiblePassiveTrash.Add(170);
                        possiblePassiveTrash.Add(171);
                        possiblePassiveTrash.Add(172);
                    }
                    else
                    {
                        foreach (var item in Config.WhatCanBeFoundAsPassiveTrash)
                        {
                            for (int i = 0; i < item.Value; i++)
                            {
                                possiblePassiveTrash.Add(item.Key);
                            }
                        }
                    }

                    int percentChanceForPassiveTrash = Config.PercentChanceForPassiveTrash;

                    // Ensure the percent value is between 0 and 100
                    percentChanceForPassiveTrash = Math.Max(0, percentChanceForPassiveTrash);
                    percentChanceForPassiveTrash = Math.Min(100, percentChanceForPassiveTrash);

                    // Generate a random number to see if trash should be given (+1 to start with 1 instead of 0)
                    int randomValue = new Random().Next(100) + 1;

                    // If the percentage chance for trash is higher than the generated number, give them trash
                    if (percentChanceForPassiveTrash >= randomValue && percentChanceForPassiveTrash != 0)
                    {
                        int id = new Random().Next(possiblePassiveTrash.Count());
                        __instance.heldObject.Value = new StardewValley.Object(possiblePassiveTrash[id], 1, false, -1, 0);
                    }
                }

                return(false);
            }

            __instance.tileIndexToShow       = 714;
            __instance.readyForHarvest.Value = true;

            List <int> possibleItems = new List <int>();
            List <int> possibleTrash = new List <int>();

            // Get a list of possible stuff to find in the crabpot
            if (location is Beach)
            {
                if (Config.WhatCanBeFoundInOcean.Count() == 0)
                {
                    possibleItems.Add(715);
                    possibleItems.Add(327);
                    possibleItems.Add(717);
                    possibleItems.Add(718);
                    possibleItems.Add(719);
                    possibleItems.Add(720);
                    possibleItems.Add(723);
                }
                else
                {
                    foreach (var item in Config.WhatCanBeFoundInOcean)
                    {
                        for (int i = 0; i < item.Value; i++)
                        {
                            possibleItems.Add(item.Key);
                        }
                    }
                }

                if (Config.WhatCanBeFoundInOcean_AsTrash.Count() == 0)
                {
                    possibleTrash.Add(168);
                    possibleTrash.Add(169);
                    possibleTrash.Add(170);
                    possibleTrash.Add(171);
                    possibleTrash.Add(172);
                }
                else
                {
                    foreach (var item in Config.WhatCanBeFoundInOcean_AsTrash)
                    {
                        for (int i = 0; i < item.Value; i++)
                        {
                            possibleTrash.Add(item.Key);
                        }
                    }
                }
            }

            else if (location is Farm)
            {
                if (Config.WhatCanBeFoundInFarmLand.Count() == 0)
                {
                    possibleItems.Add(716);
                    possibleItems.Add(721);
                    possibleItems.Add(722);
                }
                else
                {
                    foreach (var item in Config.WhatCanBeFoundInFarmLand)
                    {
                        for (int i = 0; i < item.Value; i++)
                        {
                            possibleItems.Add(item.Key);
                        }
                    }
                }

                if (Config.WhatCanBeFoundInFarmLand_AsTrash.Count() == 0)
                {
                    possibleTrash.Add(168);
                    possibleTrash.Add(169);
                    possibleTrash.Add(170);
                    possibleTrash.Add(171);
                    possibleTrash.Add(172);
                }
                else
                {
                    foreach (var item in Config.WhatCanBeFoundInFarmLand_AsTrash)
                    {
                        for (int i = 0; i < item.Value; i++)
                        {
                            possibleTrash.Add(item.Key);
                        }
                    }
                }
            }

            else if (location is Forest)
            {
                if (Config.WhatCanBeFoundInCindersapForest.Count() == 0)
                {
                    possibleItems.Add(716);
                    possibleItems.Add(721);
                    possibleItems.Add(722);
                }
                else
                {
                    foreach (var item in Config.WhatCanBeFoundInCindersapForest)
                    {
                        for (int i = 0; i < item.Value; i++)
                        {
                            possibleItems.Add(item.Key);
                        }
                    }
                }

                if (Config.WhatCanBeFoundInCindersapForest_AsTrash.Count() == 0)
                {
                    possibleTrash.Add(168);
                    possibleTrash.Add(169);
                    possibleTrash.Add(170);
                    possibleTrash.Add(171);
                    possibleTrash.Add(172);
                }
                else
                {
                    foreach (var item in Config.WhatCanBeFoundInCindersapForest_AsTrash)
                    {
                        for (int i = 0; i < item.Value; i++)
                        {
                            possibleTrash.Add(item.Key);
                        }
                    }
                }
            }

            else if (location is Mountain)
            {
                if (Config.WhatCanBeFoundInMountainsLake.Count() == 0)
                {
                    possibleItems.Add(716);
                    possibleItems.Add(721);
                    possibleItems.Add(722);
                }
                else
                {
                    foreach (var item in Config.WhatCanBeFoundInMountainsLake)
                    {
                        for (int i = 0; i < item.Value; i++)
                        {
                            possibleItems.Add(item.Key);
                        }
                    }
                }

                if (Config.WhatCanBeFoundInMountainsLake_AsTrash.Count() == 0)
                {
                    possibleTrash.Add(168);
                    possibleTrash.Add(169);
                    possibleTrash.Add(170);
                    possibleTrash.Add(171);
                    possibleTrash.Add(172);
                }
                else
                {
                    foreach (var item in Config.WhatCanBeFoundInMountainsLake_AsTrash)
                    {
                        for (int i = 0; i < item.Value; i++)
                        {
                            possibleTrash.Add(item.Key);
                        }
                    }
                }
            }

            else if (location is Town)
            {
                if (Config.WhatCanBeFoundInTown.Count() == 0)
                {
                    possibleItems.Add(716);
                    possibleItems.Add(721);
                    possibleItems.Add(722);
                }
                else
                {
                    foreach (var item in Config.WhatCanBeFoundInTown)
                    {
                        for (int i = 0; i < item.Value; i++)
                        {
                            possibleItems.Add(item.Key);
                        }
                    }
                }

                if (Config.WhatCanBeFoundInTown_AsTrash.Count() == 0)
                {
                    possibleTrash.Add(168);
                    possibleTrash.Add(169);
                    possibleTrash.Add(170);
                    possibleTrash.Add(171);
                    possibleTrash.Add(172);
                }
                else
                {
                    foreach (var item in Config.WhatCanBeFoundInTown_AsTrash)
                    {
                        for (int i = 0; i < item.Value; i++)
                        {
                            possibleTrash.Add(item.Key);
                        }
                    }
                }
            }

            else if (location is MineShaft mine20 && mine20.mineLevel == 20)
            {
                if (Config.WhatCanBeFoundInMines_Layer20.Count() == 0)
                {
                    possibleItems.Add(716);
                    possibleItems.Add(721);
                    possibleItems.Add(722);
                }
                else
                {
                    foreach (var item in Config.WhatCanBeFoundInMines_Layer20)
                    {
                        for (int i = 0; i < item.Value; i++)
                        {
                            possibleItems.Add(item.Key);
                        }
                    }
                }

                if (Config.WhatCanBeFoundInMines_Layer20_AsTrash.Count() == 0)
                {
                    possibleTrash.Add(168);
                    possibleTrash.Add(169);
                    possibleTrash.Add(170);
                    possibleTrash.Add(171);
                    possibleTrash.Add(172);
                }
                else
                {
                    foreach (var item in Config.WhatCanBeFoundInMines_Layer20_AsTrash)
                    {
                        for (int i = 0; i < item.Value; i++)
                        {
                            possibleTrash.Add(item.Key);
                        }
                    }
                }
            }
Example #24
0
        private void Display_RenderedWorld(object sender, RenderedWorldEventArgs e)
        {
            if (Game1.activeClickableMenu == null)
            {
                GameLocation CurrentLocation = Game1.player.currentLocation;

                bool IsHoveringPlacedObject = CurrentLocation.Objects.TryGetValue(HoveredTile, out SObject HoveredObject);
                if (IsHoveringPlacedObject)
                {
                    if (UserConfig.DrawToolTip)
                    {
                        //  Draw a tooltip that shows how many of the machine were combined, and its total combined processing power
                        //  Such as: "Quantity: 5\nPower: 465%"
                        if (HoveredObject.TryGetCombinedQuantity(out int CombinedQuantity))
                        {
                            Cask    Cask        = HoveredObject as Cask;
                            bool    IsCask      = Cask != null;
                            CrabPot CrabPot     = HoveredObject as CrabPot;
                            bool    IsCrabPot   = CrabPot != null;
                            bool    IsScarecrow = HoveredObject.IsScarecrow();

                            bool HasHeldObject = HoveredObject.heldObject?.Value != null;

                            float UIScaleFactor = Game1.options.zoomLevel / Game1.options.uiScale;

                            SpriteFont DefaultFont          = Game1.dialogueFont;
                            int        Padding              = 25;
                            int        MarginBetweenColumns = 10;
                            int        MarginBetweenRows    = 5;
                            float      LabelTextScale       = 0.75f;
                            float      ValueTextScale       = 1.0f;

                            bool ShowDurationInfo = UserConfig.ToolTipShowDuration && UserConfig.ShouldModifyProcessingSpeed(HoveredObject);
                            bool ShowQuantityInfo = UserConfig.ToolTipShowQuantity && UserConfig.ShouldModifyInputsAndOutputs(HoveredObject);

                            //  Compute row headers
                            List <string> RowHeaders = new List <string>()
                            {
                                Helper.Translation.Get("ToolTipQuantityLabel"), Helper.Translation.Get("ToolTipPowerLabel")
                            };
                            if (ShowDurationInfo)
                            {
                                if (IsCask)
                                {
                                    //RowHeaders.Add(Helper.Translation.Get("ToolTipCaskAgingRateLabel"));
                                    if (HasHeldObject)
                                    {
                                        RowHeaders.Add(Helper.Translation.Get("ToolTipCaskDaysUntilIridiumLabel"));
                                    }
                                }
                                else if (IsCrabPot)
                                {
                                    RowHeaders.Add(Helper.Translation.Get("ToolTipCrabPotProcessingIntervalLabel"));
                                }
                                else
                                {
                                    if (HasHeldObject)
                                    {
                                        RowHeaders.Add(Helper.Translation.Get("ToolTipMinutesRemainingLabel"));
                                    }
                                }
                            }
                            if (ShowQuantityInfo)
                            {
                                if (HasHeldObject && HoveredObject.HasModifiedOutput())
                                {
                                    RowHeaders.Add(Helper.Translation.Get("ToolTipProducedQuantityLabel"));
                                }
                            }
                            if (IsScarecrow)
                            {
                                RowHeaders.Add(Helper.Translation.Get("ToolTipScarecrowRadiusLabel"));
                            }
                            List <Vector2> RowHeaderSizes = RowHeaders.Select(x => DefaultFont.MeasureString(x) * LabelTextScale).ToList();

                            double ProcessingPower          = UserConfig.ComputeProcessingPower(CombinedQuantity) * 100.0;
                            string FormattedProcessingPower = string.Format("{0}%", ProcessingPower.ToString("0.#"));

                            //  Compute row values
                            List <string> RowValues = new List <string>()
                            {
                                CombinedQuantity.ToString(), FormattedProcessingPower
                            };
                            if (ShowDurationInfo)
                            {
                                if (IsCask)
                                {
                                    //RowValues.Add(Cask.agingRate.Value.ToString("0.##"));
                                    if (HasHeldObject)
                                    {
                                        RowValues.Add(Math.Ceiling(Cask.daysToMature.Value / Cask.agingRate.Value).ToString("0.##"));
                                    }
                                }
                                else if (IsCrabPot)
                                {
                                    CrabPot.TryGetProcessingInterval(out double Power, out double IntervalHours, out int IntervalMinutes);
                                    RowValues.Add(IntervalMinutes.ToString());
                                }
                                else
                                {
                                    if (HasHeldObject)
                                    {
                                        RowValues.Add(HoveredObject.MinutesUntilReady.ToString("0.##"));
                                    }
                                }
                            }
                            if (ShowQuantityInfo)
                            {
                                if (HasHeldObject && HoveredObject.HasModifiedOutput())
                                {
                                    RowValues.Add(HoveredObject.heldObject.Value.Stack.ToString());
                                }
                            }
                            if (IsScarecrow)
                            {
                                //  Subtract 1 because the game internally counts the scarecrow's occupied tile as part of its radius, but users usually would be confused by that
                                //  So a typical user expects radius=8 for a regular scarecrow, even though the game does its calculations with radius=9
                                int OriginalRadius = HoveredObject.GetScarecrowBaseRadius() - 1;
                                int AlteredRadius  = HoveredObject.GetScarecrowRadius() - 1;
                                //RowValues.Add(string.Format("{0}-->{1}", OriginalRadius, AlteredRadius));
                                RowValues.Add(AlteredRadius.ToString());
                            }
                            List <Vector2> RowValueSizes = RowValues.Select(x => DrawHelpers.MeasureStringWithSpecialNumbers(x, ValueTextScale, 0.0f)).ToList();

                            //  Measure the tooltip
                            List <int> RowHeights = new List <int>();
                            for (int i = 0; i < RowHeaders.Count; i++)
                            {
                                RowHeights.Add((int)Math.Max(RowHeaderSizes[i].Y, RowValueSizes[i].Y));
                            }

                            List <int> ColumnWidths = new List <int> {
                                (int)RowHeaderSizes.Max(x => x.X),
                                (int)RowValueSizes.Max(x => x.X)
                            };

                            int   ToolTipTopWidth = Padding + ColumnWidths.Sum() + (ColumnWidths.Count - 1) * MarginBetweenColumns + Padding;
                            int   ToolTipHeight   = Padding + RowHeights.Sum() + (RowHeights.Count - 1) * MarginBetweenRows + Padding;
                            Point ToolTipTopleft  = DrawHelpers.GetTopleftPosition(new Point(ToolTipTopWidth, ToolTipHeight),
                                                                                   new Point((int)((MouseScreenPosition.X + UserConfig.ToolTipOffset.X) / UIScaleFactor), (int)((MouseScreenPosition.Y + UserConfig.ToolTipOffset.Y) / UIScaleFactor)), 100);

                            //  Draw tooltip background
                            DrawHelpers.DrawBox(e.SpriteBatch, new Rectangle(ToolTipTopleft.X, ToolTipTopleft.Y, ToolTipTopWidth, ToolTipHeight));

                            //  Draw each row's header and value
                            int CurrentY = ToolTipTopleft.Y + Padding;
                            for (int i = 0; i < RowHeights.Count; i++)
                            {
                                int CurrentRowHeight = RowHeights[i];

                                //  Draw the row header
                                Vector2 RowHeaderPosition = new Vector2(
                                    ToolTipTopleft.X + Padding + ColumnWidths[0] - RowHeaderSizes[i].X,
                                    CurrentY + (RowHeights[i] - RowHeaderSizes[i].Y) / 2.0f
                                    );
                                e.SpriteBatch.DrawString(DefaultFont, RowHeaders[i], RowHeaderPosition, Color.Black, 0.0f, Vector2.Zero, LabelTextScale, SpriteEffects.None, 1.0f);

                                //  Draw the row value
                                Vector2 RowValuePosition = new Vector2(
                                    ToolTipTopleft.X + Padding + ColumnWidths[0] + MarginBetweenColumns,
                                    CurrentY + (RowHeights[i] - RowValueSizes[i].Y) / 2.0f
                                    );
                                DrawHelpers.DrawStringWithSpecialNumbers(e.SpriteBatch, RowValuePosition, RowValues[i], ValueTextScale, Color.White);

                                CurrentY += CurrentRowHeight + MarginBetweenRows;
                            }
                        }
                    }
                }
            }
        }
Example #25
0
 public static void CrabPot_Postfix(CrabPot __instance, Item __result)
 {
     Postfix(__instance as SObject, __result);
 }
Example #26
0
        private static bool dayUpdatePrefix(GameLocation location, ref CrabPot __instance)
        {
            // Check if the current crabpot has bait and requires it and doesn't already have an item to be collected
            if ((__instance.bait.Value == null && Config.RequiresBait) || __instance.heldObject.Value != null)
            {
                if (Config.EnablePassiveTrash)
                {
                    List <int> possiblePassiveTrash = new List <int>();

                    if (Config.WhatCanBeFoundAsPassiveTrash.Count() == 0)
                    {
                        possiblePassiveTrash.Add(168);
                        possiblePassiveTrash.Add(169);
                        possiblePassiveTrash.Add(170);
                        possiblePassiveTrash.Add(171);
                        possiblePassiveTrash.Add(172);
                    }
                    else
                    {
                        foreach (var item in Config.WhatCanBeFoundAsPassiveTrash)
                        {
                            for (int i = 0; i < item.Value; i++)
                            {
                                possiblePassiveTrash.Add(item.Key);
                            }
                        }
                    }

                    int percentChanceForPassiveTrash = Config.PercentChanceForPassiveTrash;

                    // Ensure the percent value is between 0 and 100
                    percentChanceForPassiveTrash = Math.Max(0, percentChanceForPassiveTrash);
                    percentChanceForPassiveTrash = Math.Min(100, percentChanceForPassiveTrash);

                    // Generate a random number to see if trash should be given (+1 to start with 1 instead of 0)
                    int randomValue = ModEntry.random.Next(100) + 1;

                    // If the percentage chance for trash is higher than the generated number, give them trash
                    if (percentChanceForPassiveTrash >= randomValue && percentChanceForPassiveTrash != 0)
                    {
                        int id = ModEntry.random.Next(possiblePassiveTrash.Count());
                        __instance.heldObject.Value = new StardewValley.Object(possiblePassiveTrash[id], 1, false, -1, 0);

                        ModMonitor.Log($"Crabpot contains item id: {__instance.heldObject.Value.ParentSheetIndex}", LogLevel.Trace);
                    }
                    else
                    {
                        ModMonitor.Log($"Crabpot contains item id: [null]", LogLevel.Trace);
                    }
                }

                return(false);
            }

            __instance.tileIndexToShow       = 714;
            __instance.readyForHarvest.Value = true;

            Dictionary <int, int> possibleItems = new Dictionary <int, int>();
            Dictionary <int, int> possibleTrash = new Dictionary <int, int>();

            // Get a list of possible stuff to find in the crabpot
            if (location is Beach)
            {
                if (Config.Beach.WhatCanBeFound.Count() == 0 && Config.AllWater.WhatCanBeFound.Count() == 0)
                {
                    possibleItems.Add(715, 1);
                    possibleItems.Add(327, 1);
                    possibleItems.Add(717, 1);
                    possibleItems.Add(718, 1);
                    possibleItems.Add(719, 1);
                    possibleItems.Add(720, 1);
                    possibleItems.Add(723, 1);
                }
                else
                {
                    foreach (var item in Config.Beach.WhatCanBeFound)
                    {
                        for (int i = 0; i < item.Chance; i++)
                        {
                            if (!possibleItems.ContainsKey(item.Id))
                            {
                                possibleItems.Add(item.Id, item.Quantity);
                            }
                        }
                    }

                    foreach (var item in Config.AllWater.WhatCanBeFound)
                    {
                        for (int i = 0; i < item.Chance; i++)
                        {
                            if (!possibleItems.ContainsKey(item.Id))
                            {
                                possibleItems.Add(item.Id, item.Quantity);
                            }
                        }
                    }
                }

                if (Config.Beach.WhatTrashCanBeFound.Count() == 0 && Config.AllWater.WhatTrashCanBeFound.Count() == 0)
                {
                    possibleTrash.Add(168, 1);
                    possibleTrash.Add(169, 1);
                    possibleTrash.Add(170, 1);
                    possibleTrash.Add(171, 1);
                    possibleTrash.Add(172, 1);
                }
                else
                {
                    foreach (var item in Config.Beach.WhatTrashCanBeFound)
                    {
                        for (int i = 0; i < item.Chance; i++)
                        {
                            if (!possibleTrash.ContainsKey(item.Id))
                            {
                                possibleTrash.Add(item.Id, item.Quantity);
                            }
                        }
                    }

                    foreach (var item in Config.AllWater.WhatTrashCanBeFound)
                    {
                        for (int i = 0; i < item.Chance; i++)
                        {
                            if (!possibleTrash.ContainsKey(item.Id))
                            {
                                possibleTrash.Add(item.Id, item.Quantity);
                            }
                        }
                    }
                }
            }

            else if (location is Farm)
            {
                if (Config.FarmLand.WhatCanBeFound.Count() == 0 && Config.AllWater.WhatCanBeFound.Count() == 0)
                {
                    possibleItems.Add(716, 1);
                    possibleItems.Add(721, 1);
                    possibleItems.Add(722, 1);
                }
                else
                {
                    foreach (var item in Config.FarmLand.WhatCanBeFound)
                    {
                        for (int i = 0; i < item.Chance; i++)
                        {
                            if (!possibleItems.ContainsKey(item.Id))
                            {
                                possibleItems.Add(item.Id, item.Quantity);
                            }
                        }
                    }

                    foreach (var item in Config.AllWater.WhatCanBeFound)
                    {
                        for (int i = 0; i < item.Chance; i++)
                        {
                            if (!possibleItems.ContainsKey(item.Id))
                            {
                                possibleItems.Add(item.Id, item.Quantity);
                            }
                        }
                    }
                }

                if (Config.FarmLand.WhatTrashCanBeFound.Count() == 0 && Config.AllWater.WhatTrashCanBeFound.Count() == 0)
                {
                    possibleTrash.Add(168, 1);
                    possibleTrash.Add(169, 1);
                    possibleTrash.Add(170, 1);
                    possibleTrash.Add(171, 1);
                    possibleTrash.Add(172, 1);
                }
                else
                {
                    foreach (var item in Config.FarmLand.WhatTrashCanBeFound)
                    {
                        for (int i = 0; i < item.Chance; i++)
                        {
                            if (!possibleTrash.ContainsKey(item.Id))
                            {
                                possibleTrash.Add(item.Id, item.Quantity);
                            }
                        }
                    }

                    foreach (var item in Config.AllWater.WhatTrashCanBeFound)
                    {
                        for (int i = 0; i < item.Chance; i++)
                        {
                            if (!possibleTrash.ContainsKey(item.Id))
                            {
                                possibleTrash.Add(item.Id, item.Quantity);
                            }
                        }
                    }
                }
            }

            else if (location is Forest)
            {
                if (Config.CindersapForest.WhatCanBeFound.Count() == 0 && Config.AllWater.WhatCanBeFound.Count() == 0)
                {
                    possibleItems.Add(716, 1);
                    possibleItems.Add(721, 1);
                    possibleItems.Add(722, 1);
                }
                else
                {
                    foreach (var item in Config.CindersapForest.WhatCanBeFound)
                    {
                        for (int i = 0; i < item.Chance; i++)
                        {
                            if (!possibleItems.ContainsKey(item.Id))
                            {
                                possibleItems.Add(item.Id, item.Quantity);
                            }
                        }
                    }

                    foreach (var item in Config.AllWater.WhatCanBeFound)
                    {
                        for (int i = 0; i < item.Chance; i++)
                        {
                            if (!possibleItems.ContainsKey(item.Id))
                            {
                                possibleItems.Add(item.Id, item.Quantity);
                            }
                        }
                    }
                }

                if (Config.CindersapForest.WhatTrashCanBeFound.Count() == 0 && Config.AllWater.WhatTrashCanBeFound.Count() == 0)
                {
                    possibleTrash.Add(168, 1);
                    possibleTrash.Add(169, 1);
                    possibleTrash.Add(170, 1);
                    possibleTrash.Add(171, 1);
                    possibleTrash.Add(172, 1);
                }
                else
                {
                    foreach (var item in Config.CindersapForest.WhatTrashCanBeFound)
                    {
                        for (int i = 0; i < item.Chance; i++)
                        {
                            if (!possibleTrash.ContainsKey(item.Id))
                            {
                                possibleTrash.Add(item.Id, item.Quantity);
                            }
                        }
                    }

                    foreach (var item in Config.AllWater.WhatTrashCanBeFound)
                    {
                        for (int i = 0; i < item.Chance; i++)
                        {
                            if (!possibleTrash.ContainsKey(item.Id))
                            {
                                possibleTrash.Add(item.Id, item.Quantity);
                            }
                        }
                    }
                }
            }

            else if (location is Mountain)
            {
                if (Config.MountainsLake.WhatCanBeFound.Count() == 0 && Config.AllWater.WhatCanBeFound.Count() == 0)
                {
                    possibleItems.Add(716, 1);
                    possibleItems.Add(721, 1);
                    possibleItems.Add(722, 1);
                }
                else
                {
                    foreach (var item in Config.MountainsLake.WhatCanBeFound)
                    {
                        for (int i = 0; i < item.Chance; i++)
                        {
                            if (!possibleItems.ContainsKey(item.Id))
                            {
                                possibleItems.Add(item.Id, item.Quantity);
                            }
                        }
                    }

                    foreach (var item in Config.AllWater.WhatCanBeFound)
                    {
                        for (int i = 0; i < item.Chance; i++)
                        {
                            if (!possibleItems.ContainsKey(item.Id))
                            {
                                possibleItems.Add(item.Id, item.Quantity);
                            }
                        }
                    }
                }

                if (Config.MountainsLake.WhatTrashCanBeFound.Count() == 0 && Config.AllWater.WhatTrashCanBeFound.Count() == 0)
                {
                    possibleTrash.Add(168, 1);
                    possibleTrash.Add(169, 1);
                    possibleTrash.Add(170, 1);
                    possibleTrash.Add(171, 1);
                    possibleTrash.Add(172, 1);
                }
                else
                {
                    foreach (var item in Config.MountainsLake.WhatTrashCanBeFound)
                    {
                        for (int i = 0; i < item.Chance; i++)
                        {
                            if (!possibleTrash.ContainsKey(item.Id))
                            {
                                possibleTrash.Add(item.Id, item.Quantity);
                            }
                        }
                    }

                    foreach (var item in Config.AllWater.WhatTrashCanBeFound)
                    {
                        for (int i = 0; i < item.Chance; i++)
                        {
                            if (!possibleTrash.ContainsKey(item.Id))
                            {
                                possibleTrash.Add(item.Id, item.Quantity);
                            }
                        }
                    }
                }
            }

            else if (location is Town)
            {
                if (Config.Town.WhatCanBeFound.Count() == 0 && Config.AllWater.WhatCanBeFound.Count() == 0)
                {
                    possibleItems.Add(716, 1);
                    possibleItems.Add(721, 1);
                    possibleItems.Add(722, 1);
                }
                else
                {
                    foreach (var item in Config.Town.WhatCanBeFound)
                    {
                        for (int i = 0; i < item.Chance; i++)
                        {
                            if (!possibleItems.ContainsKey(item.Id))
                            {
                                possibleItems.Add(item.Id, item.Quantity);
                            }
                        }
                    }

                    foreach (var item in Config.AllWater.WhatCanBeFound)
                    {
                        for (int i = 0; i < item.Chance; i++)
                        {
                            if (!possibleItems.ContainsKey(item.Id))
                            {
                                possibleItems.Add(item.Id, item.Quantity);
                            }
                        }
                    }
                }

                if (Config.Town.WhatTrashCanBeFound.Count() == 0 && Config.AllWater.WhatTrashCanBeFound.Count() == 0)
                {
                    possibleTrash.Add(168, 1);
                    possibleTrash.Add(169, 1);
                    possibleTrash.Add(170, 1);
                    possibleTrash.Add(171, 1);
                    possibleTrash.Add(172, 1);
                }
                else
                {
                    foreach (var item in Config.Town.WhatTrashCanBeFound)
                    {
                        for (int i = 0; i < item.Chance; i++)
                        {
                            if (!possibleTrash.ContainsKey(item.Id))
                            {
                                possibleTrash.Add(item.Id, item.Quantity);
                            }
                        }
                    }

                    foreach (var item in Config.AllWater.WhatTrashCanBeFound)
                    {
                        for (int i = 0; i < item.Chance; i++)
                        {
                            if (!possibleTrash.ContainsKey(item.Id))
                            {
                                possibleTrash.Add(item.Id, item.Quantity);
                            }
                        }
                    }
                }
            }

            else if (location is MineShaft mine20 && mine20.mineLevel == 20)
            {
                if (Config.Mines_Layer20.WhatCanBeFound.Count() == 0 && Config.AllWater.WhatCanBeFound.Count() == 0)
                {
                    possibleItems.Add(716, 1);
                    possibleItems.Add(721, 1);
                    possibleItems.Add(722, 1);
                }
                else
                {
                    foreach (var item in Config.Mines_Layer20.WhatCanBeFound)
                    {
                        for (int i = 0; i < item.Chance; i++)
                        {
                            if (!possibleItems.ContainsKey(item.Id))
                            {
                                possibleItems.Add(item.Id, item.Quantity);
                            }
                        }
                    }

                    foreach (var item in Config.AllWater.WhatCanBeFound)
                    {
                        for (int i = 0; i < item.Chance; i++)
                        {
                            if (!possibleItems.ContainsKey(item.Id))
                            {
                                possibleItems.Add(item.Id, item.Quantity);
                            }
                        }
                    }
                }

                if (Config.Mines_Layer20.WhatTrashCanBeFound.Count() == 0 && Config.AllWater.WhatTrashCanBeFound.Count() == 0)
                {
                    possibleTrash.Add(168, 1);
                    possibleTrash.Add(169, 1);
                    possibleTrash.Add(170, 1);
                    possibleTrash.Add(171, 1);
                    possibleTrash.Add(172, 1);
                }
                else
                {
                    foreach (var item in Config.Mines_Layer20.WhatTrashCanBeFound)
                    {
                        for (int i = 0; i < item.Chance; i++)
                        {
                            if (!possibleTrash.ContainsKey(item.Id))
                            {
                                possibleTrash.Add(item.Id, item.Quantity);
                            }
                        }
                    }

                    foreach (var item in Config.AllWater.WhatTrashCanBeFound)
                    {
                        for (int i = 0; i < item.Chance; i++)
                        {
                            if (!possibleTrash.ContainsKey(item.Id))
                            {
                                possibleTrash.Add(item.Id, item.Quantity);
                            }
                        }
                    }
                }
            }
Example #27
0
        private static void UpdatePot(CrabPotCatch @catch, CrabPot pot)
        {
            // Check for the Mariner and Luremaster professions.
            var  owner      = Game1.getFarmer(pot.owner.Value);
            bool luremaster = owner != null && owner.professions.Contains(11);
            bool mariner    = (owner != null && owner.professions.Contains(10)) ||
                              (pot.owner.Value == 0L && Game1.player.professions.Contains(11));

            // Don't proceed unless the pot is baited or Luremaster applies.
            if (pot.bait.Value == null && !luremaster)
            {
                return;
            }

            // The game stops here if the pot has an item, but we must continue.

            // Set the pot as ready for harvest. This is probably redundant.
            pot.tileIndexToShow       = 714;
            pot.readyForHarvest.Value = true;

            // Seed the RNG.
            Random random = new ((int)Game1.stats.DaysPlayed +
                                 (int)Game1.uniqueIDForThisGame / 2 +
                                 (int)pot.TileLocation.X * 1000 +
                                 (int)pot.TileLocation.Y);

            // Maybe catch trash.
            double trashChance = 0.2 + @catch.ExtraTrashChance;

            if (!mariner && !(random.NextDouble() > trashChance))
            {
                pot.heldObject.Value = new SObject(random.Next(168, 173), 1);
                return;
            }

            // Search for a suitable fish.
            var fishes = Helper.Content.Load <Dictionary <int, string> > ("Data\\Fish",
                                                                          ContentSource.GameContent);
            List <int> candidates = new ();

            foreach (var fish in fishes)
            {
                string[] fields = fish.Value.Split('/');

                // Must be a Crab Pot fish.
                if (!fish.Value.Contains("trap"))
                {
                    continue;
                }

                // Must be the right catch type.
                if (fields[4] == (@catch.OceanCatches ? "freshwater" : "ocean"))
                {
                    continue;
                }

                // Mariners get all fish with equal chance.
                if (mariner)
                {
                    candidates.Add(fish.Key);
                    continue;
                }

                // Roll for getting the fish immediately.
                double chance = Convert.ToDouble(fields[2]);
                if (random.NextDouble() < chance)
                {
                    pot.heldObject.Value = new SObject(fish.Key, 1);
                    return;
                }
            }

            // Fall back to a random selection of the candidates.
            if (candidates.Count == 0)
            {
                candidates.AddRange(new int[] { 168, 169, 170, 171, 172 });
            }
            pot.heldObject.Value = new SObject(candidates[random.Next(candidates.Count)], 1);
        }
        /// <summary>Patch for Trapper fish quality + Luremaster bait mechanics + Conservationist trash collection mechanics.</summary>
        private static bool CrabPotDayUpdatePrefix(ref CrabPot __instance, GameLocation location)
        {
            try
            {
                var who = Game1.getFarmer(__instance.owner.Value);
                if (__instance.bait.Value == null && !Utility.SpecificPlayerHasProfession("Conservationist", who) || __instance.heldObject.Value != null)
                {
                    return(false);                    // don't run original logic
                }
                __instance.tileIndexToShow       = 714;
                __instance.readyForHarvest.Value = true;

                var r            = new Random((int)Game1.stats.DaysPlayed + (int)Game1.uniqueIDForThisGame / 2 + (int)__instance.TileLocation.X * 1000 + (int)__instance.TileLocation.Y);
                var locationData = Game1.content.Load <Dictionary <string, string> >(Path.Combine("Data", "Locations"));
                var fishData     = Game1.content.Load <Dictionary <int, string> >(Path.Combine("Data", "Fish"));
                var whichFish    = -1;
                if (__instance.bait.Value != null)
                {
                    if (Utility.SpecificPlayerHasProfession("Luremaster", who))
                    {
                        if (Utility.IsUsingMagnet(__instance))
                        {
                            whichFish = 14;
                            //whichFish = Utility.ChoosePirateTreasure(r, who);
                        }
                        else if (Game1.random.NextDouble() < (Utility.IsUsingMagicBait(__instance) ? 0.25 : 0.1))
                        {
                            var rawFishData             = Utility.IsUsingMagicBait(__instance) ? Utility.GetRawFishDataForAllSeasons(location, locationData) : Utility.GetRawFishDataForThisSeason(location, locationData);
                            var rawFishDataWithLocation = Utility.GetRawFishDataWithLocation(rawFishData);
                            whichFish = Utility.ChooseFish(__instance, fishData, rawFishDataWithLocation, location, r);
                            if (whichFish < 0)
                            {
                                whichFish = Utility.ChooseTrapFish(__instance, fishData, location, r, isLuremaster: true);
                            }
                        }
                        else
                        {
                            whichFish = Utility.ChooseTrapFish(__instance, fishData, location, r, isLuremaster: true);
                        }
                    }
                    else
                    {
                        whichFish = Utility.ChooseTrapFish(__instance, fishData, location, r, isLuremaster: false);
                    }
                }

                if (whichFish.AnyOf(14, 51, 516, 517, 518, 519, 527, 529, 530, 531, 532, 533, 534))
                {
                    var equipment = new SObject(whichFish, 1);
                    __instance.heldObject.Value = equipment;
                    return(false);                    // don't run original logic
                }

                var fishQuality = 0;
                if (whichFish < 0)
                {
                    if (__instance.bait.Value != null || Utility.SpecificPlayerHasProfession("Conservationist", who))
                    {
                        whichFish = Utility.GetTrash(r);
                    }
                }
                else
                {
                    fishQuality = Utility.GetTrapFishQuality(whichFish, who, r, __instance, Utility.SpecificPlayerHasProfession("Luremaster", who));
                }

                var fishQuantity = Utility.GetTrapFishQuantity(__instance, whichFish, who, r);
                __instance.heldObject.Value = new SObject(whichFish, initialStack: fishQuantity, quality: fishQuality);
                return(false);                // don't run original logic
            }
            catch (Exception ex)
            {
                Monitor.Log($"Failed in {nameof(CrabPotDayUpdatePrefix)}:\n{ex}");
                return(true);                // default to original logic
            }
        }
Example #29
0
        public static bool checkForAction_prefix(Farmer who, ref CrabPot __instance, ref bool __result, bool justCheckingForActivity = false)
        {
            if (justCheckingForActivity)
            {
                return(true);
            }

            if (!__instance.readyForHarvest.Value && __instance.bait.Value == null && !who.professions.Contains(Farmer.baitmaster))
            {
                // Nothing to harvest and no bait, not luremaster
                // check inventory for loose bait first, then bait attached to rod
                var resultBait = who.items.FirstOrDefault(item => item.Category == BaitCategory && item.Stack > 0);
                if (resultBait != null)
                {
                    // Get that sweet da-dunk sound
                    bool dropInResult = __instance.performObjectDropInAction(resultBait.getOne(), false, who);
                    if (!dropInResult)
                    {
                        ModEntry.EMonitor?.Log($"performObjectDropInAction failed with {resultBait.Name} x{resultBait.Stack}!", LogLevel.Error);
                        // Let the base code handle this
                        return(true);
                    }

                    resultBait.Stack--;
                    ModEntry.EMonitor?.Log($"Took loose bait {resultBait.Name}");
                    if (resultBait.Stack <= 0)
                    {
                        who.removeItemFromInventory(resultBait);
                        ModEntry.EMonitor?.Log("Used last bait in stack, removing from inventory");
                    }
                    return(false);
                }

                foreach (FishingRod rod in who.items.Where(item => item is FishingRod && item.attachmentSlots() > 0))
                {
                    // Bait goes in index 0, see FishingRod::attach
                    Item baitSlot = rod.attachments[0] ?? new StardewValley.Object();
                    if (baitSlot.Category == BaitCategory && baitSlot.Stack > 0)
                    {
                        // Take one bait and place in pot
                        bool dropInResult = __instance.performObjectDropInAction(baitSlot.getOne(), false, who);
                        if (!dropInResult)
                        {
                            ModEntry.EMonitor?.Log($"performObjectDropInAction failed with {baitSlot.Name} x{baitSlot.Stack}!", LogLevel.Error);
                            // Let the base code handle this
                            return(true);
                        }

                        baitSlot.Stack--;
                        ModEntry.EMonitor?.Log($"Took bait {baitSlot.Name} from {rod.Name}");
                        if (baitSlot.Stack <= 0)
                        {
                            ModEntry.EMonitor?.Log("Used last bait in rod, removing from attachments");
                            rod.attachments[0] = null;
                            // Yoinked from FishingRod::doDoneFishing
                            Game1.showGlobalMessage(Game1.content.LoadString("Strings\\StringsFromCSFiles:FishingRod.cs.14085"));
                        }
                        return(false);
                    }
                }
                ModEntry.EMonitor?.Log("Can't find loose bait or rod, continuing...");
                return(true);
            }
            ModEntry.EMonitor?.Log("Pot doesn't need baiting, continuing...");
            return(true);
        }
 private static Color CrabPotNeedsInputColor(CrabPot obj)
 => ModEntry.Config.VanillaMachines[VanillaMachinesEnum.CrabPot] &&
 obj.bait.Value is null && obj.heldObject.Value is null ? ModEntry.Config.EmptyColor : Color.White;