Exemplo n.º 1
0
        public static bool MarkAreaAsComplete_Prefix(
            CommunityCenter __instance,
            int area)
        {
            try
            {
                if (Bundles.IsCustomArea(area))
                {
                    if (Game1.currentLocation is CommunityCenter)
                    {
                        Bundles.CustomAreasComplete[area] = true;

                        if (__instance.areAllAreasComplete())
                        {
                            Reflection.GetField
                            <bool>
                                (obj: __instance, name: "_isWatchingJunimoGoodbye")
                            .SetValue(true);
                        }
                    }
                    return(false);
                }
            }
            catch (Exception e)
            {
                HarmonyPatches.ErrorHandler(e);
            }
            return(true);
        }
Exemplo n.º 2
0
        /// <summary>Get unfinished bundles which require this item.</summary>
        /// <param name="item">The item for which to find bundles.</param>
        private IEnumerable <BundleModel> GetUnfinishedBundles(SObject item)
        {
            // no bundles for Joja members
            if (Game1.player.hasOrWillReceiveMail(Constant.MailLetters.JojaMember))
            {
                yield break;
            }

            // get community center
            CommunityCenter communityCenter = Game1.locations.OfType <CommunityCenter>().First();

            if (communityCenter.areAllAreasComplete())
            {
                yield break;
            }

            // get bundles
            if (item.GetType() == typeof(SObject) && !item.bigCraftable.Value) // avoid false positives with hats, furniture, etc
            {
                foreach (BundleModel bundle in this.GameHelper.GetBundleData())
                {
                    // ignore completed bundle
                    if (communityCenter.isBundleComplete(bundle.ID))
                    {
                        continue;
                    }

                    bool isMissing = this.GetIngredientsFromBundle(bundle, item).Any(p => this.IsIngredientNeeded(bundle, p));
                    if (isMissing)
                    {
                        yield return(bundle);
                    }
                }
            }
        }
Exemplo n.º 3
0
        private void MenuChanged(object sender, MenuChangedEventArgs e)
        {
            var shop = e.NewMenu as StardewValley.Menus.ShopMenu;

            if (shop == null || Game1.currentLocation.Name != "Forest" || !shop.potraitPersonDialogue.Contains("hats"))
            {
                return;
            }

            // no bundles for Joja members
            if (Game1.player.hasOrWillReceiveMail("JojaMember"))
            {
                return;
            }
            CommunityCenter communityCenter = Game1.locations.OfType <CommunityCenter>().First();

            if (communityCenter.areAllAreasComplete())
            {
                return;
            }

            IReflectedField <Dictionary <Item, int[]> > inventoryInformation = this.Helper.Reflection.GetField <Dictionary <Item, int[]> >(shop, "itemPriceAndStock");
            Dictionary <Item, int[]>       itemPriceAndStock  = inventoryInformation.GetValue();
            IReflectedField <List <Item> > forSaleInformation = this.Helper.Reflection.GetField <List <Item> >(shop, "forSale");
            List <Item> forSale = forSaleInformation.GetValue();

            foreach (var bundle in GetBundles())
            {
                if (communityCenter.isBundleComplete(bundle.ID))
                {
                    continue;
                }

                foreach (var ing in bundle.Ingredients)
                {
                    if (communityCenter.bundles[bundle.ID][ing.Index])
                    {
                        continue;
                    }
                    int itemId      = ing.ItemID;
                    var objectToAdd = new StardewValley.Object(Vector2.Zero, itemId, ing.Stack);
                    objectToAdd.Quality = ing.Quality;
                    if (objectToAdd.Name.Contains("rror"))
                    {
                        continue;
                    }
                    itemPriceAndStock.Add(objectToAdd, new int[2] {
                        5000, ing.Stack
                    });
                    forSale.Add(objectToAdd);
                }
            }

            inventoryInformation.SetValue(itemPriceAndStock);
            forSaleInformation.SetValue(forSale);
        }
Exemplo n.º 4
0
        private void PopulateRequiredBundles()
        {
            _prunedRequiredBundles.Clear();
            if (_communityCenter.areAllAreasComplete() || Game1.player.mailReceived.Contains("JojaMember"))
            {
                return;
            }
            foreach (var bundle in _bundleData)
            {
                var bundleRoomInfo = bundle.Key.Split('/');
                var bundleRoom     = bundleRoomInfo[0];
                int roomNum;

                switch (bundleRoom)
                {
                case "Pantry": roomNum = 0; break;

                case "Crafts Room": roomNum = 1; break;

                case "Fish Tank": roomNum = 2; break;

                case "Boiler Room": roomNum = 3; break;

                case "Vault": roomNum = 4; break;

                case "Bulletin Board": roomNum = 5; break;

                default: continue;
                }

                if (!_communityCenter.shouldNoteAppearInArea(roomNum))
                {
                    continue;
                }
                var bundleNumber = bundleRoomInfo[1].SafeParseInt32();
                var bundleInfo   = bundle.Value.Split('/');
                var bundleName   = bundleInfo[0];
                var bundleValues = bundleInfo[2].Split(' ');
                var source       = new List <int>();

                for (var i = 0; i < bundleValues.Length; i += 3)
                {
                    var bundleValue = bundleValues[i].SafeParseInt32();
                    if (bundleValue != -1 &&
                        !_communityCenter.bundles[bundleNumber][i / 3])
                    {
                        source.Add(bundleValue);
                    }
                }

                if (source.Count > 0)
                {
                    _prunedRequiredBundles.Add(bundleName, source);
                }
            }
        }
Exemplo n.º 5
0
        /// <summary>Get unfinished bundles which require this item.</summary>
        /// <param name="item">The item for which to find bundles.</param>
        private IEnumerable <BundleModel> GetUnfinishedBundles(SObject item)
        {
            // no bundles for Joja members
            if (Game1.player.hasOrWillReceiveMail(Constant.MailLetters.JojaMember))
            {
                yield break;
            }

            // avoid false positives
            if (item.bigCraftable.Value || item is Cask or Fence or Furniture or IndoorPot or Sign or Torch or Wallpaper)
            {
                yield break; // avoid false positives
            }
            // get community center
            CommunityCenter communityCenter = Game1.locations.OfType <CommunityCenter>().First();

            bool IsBundleOpen(int id)
            {
                try
                {
                    return(!communityCenter.isBundleComplete(id));
                }
                catch
                {
                    return(false); // invalid bundle data
                }
            }

            // get bundles
            if (!communityCenter.areAllAreasComplete() || IsBundleOpen(36))
            {
                foreach (BundleModel bundle in this.GameHelper.GetBundleData())
                {
                    if (!IsBundleOpen(bundle.ID))
                    {
                        continue;
                    }

                    bool isMissing = this.GetIngredientsFromBundle(bundle, item).Any(p => this.IsIngredientNeeded(bundle, p));
                    if (isMissing)
                    {
                        yield return(bundle);
                    }
                }
            }
        }
Exemplo n.º 6
0
        public static void ResetSharedState_Postfix(
            CommunityCenter __instance)
        {
            if (Game1.MasterPlayer.mailReceived.Contains("JojaMember"))
            {
                return;
            }

            if (__instance.areAllAreasComplete())
            {
                if (Bundles.AreAnyCustomAreasLoaded())
                {
                    __instance.numberOfStarsOnPlaque.Value += 1;
                }
            }
            else
            {
                if (__instance.mapPath.Value == "Maps\\CommunityCenter_Refurbished")
                {
                    // When all base areas are complete,
                    // CommunityCenter.TransferDataFromSavedLocation() will call CommunityCenter.areAllAreasComplete(),
                    // which will return true and set the map as if the CC were complete.
                    // If any custom areas are incomplete,
                    // we undo the map change here to revert to the incomplete state map.
                    __instance.mapPath.Value = "Maps\\CommunityCenter_Ruins";
                    __instance.updateMap();
                }
                foreach (int areaNumber in Bundles.CustomAreasComplete.Keys)
                {
                    if (Bundles.ShouldNoteAppearInCustomArea(cc: __instance, areaNumber: areaNumber))
                    {
                        string areaName = Bundles.GetCustomAreaNameFromNumber(areaNumber);
                        CustomCommunityCentre.Data.BundleMetadata bundleMetadata = Bundles.GetAllCustomBundleMetadataEntries()
                                                                                   .First(bmd => bmd.AreaName == areaName);

                        Vector2 tileLocation = Utility.PointToVector2(bundleMetadata.NoteTileLocation + bundleMetadata.JunimoOffsetFromNoteTileLocation);

                        Junimo j = new (position : tileLocation * Game1.tileSize, whichArea : areaNumber);
                        __instance.characters.Add(j);
                    }
                }
            }

            CustomCommunityCentre.Events.Game.InvokeOnResetSharedState(communityCentre: __instance);
        }
Exemplo n.º 7
0
        /// <summary>Get unfinished bundles which require this item.</summary>
        /// <param name="item">The item for which to find bundles.</param>
        private IEnumerable <BundleModel> GetUnfinishedBundles(SObject item)
        {
            // no bundles for Joja members
            if (Game1.player.hasOrWillReceiveMail(Constant.MailLetters.JojaMember))
            {
                yield break;
            }

            // get community center
            CommunityCenter communityCenter = Game1.locations.OfType <CommunityCenter>().First();

            if (communityCenter.areAllAreasComplete())
            {
                yield break;
            }

            // get bundles
            if (item.GetType() == typeof(SObject) && !item.bigCraftable.Value) // avoid false positives with hats, furniture, etc
            {
                foreach (BundleModel bundle in DataParser.GetBundles())
                {
                    // ignore completed bundle
                    if (communityCenter.isBundleComplete(bundle.ID))
                    {
                        continue;
                    }

                    // get ingredient
                    BundleIngredientModel ingredient = bundle.Ingredients.FirstOrDefault(p => p.ItemID == item.ParentSheetIndex && p.Quality <= (ItemQuality)item.Quality);
                    if (ingredient == null)
                    {
                        continue;
                    }

                    // yield if missing
                    if (!communityCenter.bundles[bundle.ID][ingredient.Index])
                    {
                        yield return(bundle);
                    }
                }
            }
        }
Exemplo n.º 8
0
 private bool isMasterNoteVisible(CommunityCenter cc)
 {
     // do nothing if cc is finished or not yet seen wizard to get skills.
     if (Game1.MasterPlayer.mailReceived.Contains("JojaMember") || cc.areAllAreasComplete() || !Game1.MasterPlayer.hasOrWillReceiveMail("canReadJunimoText"))
     {
         return(false);
     }
     // They can opt-out entirely.
     if (GameState.Current.Declined)
     {
         return(false);
     }
     // if finished any full rooms in vanilla, they can't play hard mode anymore
     if (!GameState.Current.Activated && cc.areasComplete.Any(x => x))
     {
         return(false);
     }
     // TODO: check for unpurchased upgrades
     return(true);
 }
Exemplo n.º 9
0
 public static void MakeMapModifications_Postfix(
     CommunityCenter __instance)
 {
     if (!Game1.MasterPlayer.mailReceived.Contains("JojaMember") && !__instance.areAllAreasComplete())
     {
         foreach (int areaNumber in Bundles.CustomAreasComplete.Keys)
         {
             bool isAvailable = Bundles.ShouldNoteAppearInCustomArea(cc: __instance, areaNumber: areaNumber);
             bool isComplete  = Bundles.IsCustomAreaComplete(areaNumber);
             if (isAvailable)
             {
                 __instance.addJunimoNote(area: areaNumber);
             }
             else if (isComplete)
             {
                 __instance.loadArea(area: areaNumber, showEffects: false);
             }
         }
     }
 }
Exemplo n.º 10
0
        public static IList <Fish> GetFishForToday()
        {
            var             fish        = Game1.content.Load <Dictionary <int, string> >("Data\\Fish");
            var             neededItems = new List <int>();
            CommunityCenter cc          = Game1.locations.OfType <CommunityCenter>().SingleOrDefault();


            // get fish still needed for cc bundles
            if (cc != null && !Game1.MasterPlayer.mailReceived.Contains("JojaMember") && !cc.areAllAreasComplete())
            {
                foreach (var b in Game1.content.Load <Dictionary <string, string> >("Data\\Bundles"))
                {
                    var bid   = int.Parse(b.Key.Split('/')[1]);
                    var items = b.Value.Split('/')[2].Split(' ').GroupsOf(3).Select(y => y.First()).ToList();
                    for (var i = 0; i < items.Count; i++)
                    {
                        if (cc.bundles[bid][i])
                        {
                            continue;
                        }
                        var itemId      = int.Parse(items[i]);
                        var objectToAdd = new Object(Vector2.Zero, itemId, 1);
                        if (objectToAdd.Name.Contains("rror") || objectToAdd.Category != -4)
                        {
                            continue;
                        }
                        neededItems.Add(itemId);
                    }
                }
            }

            var locations = Game1.content.Load <Dictionary <string, string> >("Data\\Locations")
                            .Where(x => x.Key != "fishingGame" && x.Key != "Temp" && x.Key != "Backwoods");
            var fishField = 4 + Utility.getSeasonNumber(Game1.currentSeason);


            return(fish.Where(x => !x.Value.Contains("/trap/"))
                   .Select(x =>
            {
                var parts = x.Value.Split('/');
                var o = new StardewValley.Object(x.Key, 1);
                return new Fish
                {
                    ID = x.Key,
                    Name = parts[0],
                    Difficulty = int.Parse(parts[1]),
                    Description = o.getDescription().Replace("\r\n", ""),
                    Times = parts[5].Split(' ').GroupsOf(2).Select(y => string.Join("-", y)).ToArray(),
                    MinLevel = int.Parse(parts[12]),
                    Weather = parts[7],
                    NumSeasons = parts[6].Split(' ').Length,
                    NeedForCC = neededItems.Contains(x.Key),
                    NeedForCollection = !Game1.player.fishCaught.ContainsKey(x.Key),
                    Locations = locations.Where(y => {
                        var fishes = y.Value.Split('/')[fishField];
                        return fishes.Contains(x.Key.ToString());
                    }).Select(y => y.Key).ToArray(),
                };
            })
                   // filter for today's weather
                   .Where(x => x.Weather == "both" || (x.Weather == "rainy") == (Game1.isRaining))
                   // filter for those with valid locations this season
                   .Where(x => x.Locations.Length > 0)

                   .OrderByDescending(x => x.NeedForCC)                       // all cc fish first
                   .ThenByDescending(x => x.NeedForCollection || x.NeedForCC) // then unmet collection requirements
                   .ThenByDescending(x => x.Weather == "rainy")               // rainy day fish higher on rainy days get highest priority
                   .ThenBy(x => x.NumSeasons)                                 // fewer seasons makes it more urgent
                   .ThenBy(x => x.Difficulty)                                 // easiest first
                   .ToList());
        }