Ejemplo n.º 1
0
 /// <summary>
 /// Gets the replacement bait stack, or returns null for not found.
 /// Also handles messaging the player.
 /// </summary>
 /// <param name="original">Original bait.</param>
 /// <returns>Replacement bait, or null if not found.</returns>
 private static SObject?GetReplacementBait(SObject original)
 {
     try
     {
         if (ModEntry.Config.AutomaticRefill && original is not null)
         {
             int?replacementIndex = null;
             for (int i = 0; i < Game1.player.Items.Count; i++)
             {
                 if (Game1.player.Items[i] is not SObject obj || obj.bigCraftable.Value || obj.Category != SObject.baitCategory)
                 {
                     continue;
                 }
                 else if (Utility.IsNormalObjectAtParentSheetIndex(obj, original.ParentSheetIndex))
                 {
                     replacementIndex = i;
                     break;
                 }
                 else if (!ModEntry.Config.SameBaitOnly)
                 {
                     replacementIndex ??= i;
                 }
             }
             if (replacementIndex is not null && Game1.player.Items[replacementIndex.Value] is SObject returnObj)
             {
                 Game1.player.Items[replacementIndex.Value] = null;
                 Game1.showGlobalMessage(original.ParentSheetIndex == returnObj.ParentSheetIndex
                     ? I18n.BaitReplacedSame(original.DisplayName)
                     : I18n.BaitReplaced(original.DisplayName, returnObj.DisplayName));
                 return(returnObj);
             }
         }