コード例 #1
0
 public static void TryToDepositThisItem_Postfix(
     Bundle __instance,
     Item item,
     ClickableTextureComponent slot)
 {
     if (Bundles.IsCustomBundle(bundleName: __instance.name) && slot?.item != null)
     {
         Log.D($"Adding item to bundle donations: {slot.item} => {__instance.name}",
               CustomCommunityCentre.ModEntry.Config.DebugMode);
         Bundles.CustomBundleDonations.Add(slot.item);
     }
 }
コード例 #2
0
        public static void SetUpMenu_Postfix(
            JunimoNoteMenu __instance)
        {
            // Add bundle display names for default locale
            var bundleDisplayNames = Game1.content.Load
                                     <Dictionary <string, string> >
                                         (@"Strings/BundleNames");

            for (int i = 0; i < __instance.bundles.Count; ++i)
            {
                if (Bundles.IsCustomBundle(Bundles.GetBundleNumberFromName(__instance.bundles[i].name)))
                {
                    __instance.bundles[i].label = bundleDisplayNames[__instance.bundles[i].name];
                }
            }
        }
コード例 #3
0
        internal static void Generate(bool isLoadingCustomContent)
        {
            // Fetch initial area-bundle values if not yet set
            if (Bundles.DefaultMaxArea == 0)
            {
                var bundleData = Game1.content.Load
                                 <Dictionary <string, string> >
                                     (@"Data/Bundles");

                // Area count is inclusive of Abandoned Joja Mart area to avoid conflicting logic and cases
                Bundles.DefaultMaxArea = bundleData.Keys
                                         .Select(key => key.Split(Bundles.BundleKeyDelim).First())
                                         .Distinct()
                                         .Count() - 1;

                // Bundle count is inclusive of Abandoned Joja Mart bundles, as each requires a unique ID
                Bundles.DefaultMaxBundle = bundleData.Keys
                                           .Select(key => key.Split(Bundles.BundleKeyDelim).Last())
                                           .ToList()
                                           .ConvertAll(int.Parse)
                                           .Max();

                // Starting index for our custom bundles' unique IDs is after the highest base game bundle ID
                Bundles.CustomBundleInitialIndex = Bundles.DefaultMaxBundle + 1;

                // Starting index for our custom areas' numbers is after the Abandoned Joja Mart area
                // The game will usually consider area 7 as the bulletin board extras, and area 8 as the Junimo Hut, so skip those too
                // Skip 9 to bring us up to a round 10, leaving room for 1 new base game area.
                Bundles.CustomAreaInitialIndex = 10;
            }

            // Reassign world state with or without custom values
            Random r = new ((int)Game1.uniqueIDForThisGame * 9);             // copied from StardewValley.Game1.GenerateBundles(...)

            if (isLoadingCustomContent)
            {
                Helper.Content.InvalidateCache(CustomCommunityCentre.AssetManager.BundleCacheAssetKey);           // Farmhand idiocy
                Dictionary <string, string> bundleData = new StardewValley.BundleGenerator().Generate(
                    bundle_data_path: CustomCommunityCentre.AssetManager.BundleCacheAssetKey,                     // Internal sneaky asset business
                    rng: r);

                // Add bundle data entries, ignoring existing values for mod compatibility
                Dictionary <string, string> oldBundleData = Game1.netWorldState.Value.BundleData;
                bundleData = oldBundleData
                             .Union(bundleData.Where(pair => !oldBundleData.ContainsKey(pair.Key)))
                             .ToDictionary(pair => pair.Key, pair => pair.Value);

                // Reassign bundle data
                Game1.netWorldState.Value.SetBundleData(bundleData);
            }
            else
            {
                if (Context.IsMainPlayer && Bundles.CustomAreaBundleKeys != null)
                {
                    var netBundleData = Reflection.GetField
                                        <NetStringDictionary <string, NetString> >
                                            (obj: Game1.netWorldState.Value, name: "netBundleData")
                                        .GetValue();

                    IEnumerable <int> bundleNumbers = Bundles.GetAllCustomBundleNumbers();

                    foreach (int bundleNumber in bundleNumbers.Where(num => Bundles.IsCustomBundle(num)))
                    {
                        netBundleData.Remove(netBundleData.Keys
                                             .FirstOrDefault(b => bundleNumber == int.Parse(b.Split(Bundles.BundleKeyDelim).Last())));
                        Game1.netWorldState.Value.Bundles.Remove(bundleNumber);
                        Game1.netWorldState.Value.BundleRewards.Remove(bundleNumber);
                    }
                }
            }
        }