private static void PopulateCatShop(bool isHat) { try { IEnumerable <string> contentPacks = isHat ? ModConsts.HatPacks : ModConsts.ClothingPacks.Concat(Config.ExtraContentPacksToSellInTheShop); foreach (string contentPack in contentPacks) { var stock = new Dictionary <string, bool>(); string contentPackId = !ModConsts.HatPacks.Contains(contentPack) && !ModConsts.ClothingPacks.Contains(contentPack) ? contentPack : GetIdFromContentPackName(name: contentPack, isHat: isHat); List <string> contentNames = isHat ? JsonAssets.GetAllHatsFromContentPack(contentPackId) : JsonAssets.GetAllClothingFromContentPack(contentPackId); if (contentNames == null || contentNames.Count < 1) { if (!ModConsts.HatPacks.Contains(contentPack) && !ModConsts.ClothingPacks.Contains(contentPack)) { Log.D($"Did not add content from {contentPack} (as {contentPackId}): Not found.", Config.DebugMode); continue; } throw new NullReferenceException($"Failed to add content from {contentPack}\n({contentPackId})."); } if (contentPack.EndsWith("Kimono")) { contentNames.RemoveAll(name => name.EndsWith("wer")); } int goalQty = Math.Max(1, contentNames.Count / ModConsts.CatShopQtyRatio); string pairedContentPack = contentPack == "Stylish Rogue" ? GetIdFromContentPackName(name: "Tuxedo Top Hats", isHat: true) : null; List <string> pairedContentNames = !string.IsNullOrEmpty(pairedContentPack) ? JsonAssets.GetAllHatsFromContentPack(pairedContentPack) : null; List <string> shuffledContentNames = contentNames; Utility.Shuffle(Game1.random, contentNames); for (int i = 0; i < goalQty; ++i) { string name = contentNames[i]; // Add Tuxedo Top Hats before the tuxedo tops if (contentPack.Equals("Stylish Rogue")) { const string tuxedoHatKey = "Chapeau "; string hatVariant = name.Split(new[] { ' ' }, 2)[1]; string hatName = pairedContentNames.Contains(tuxedoHatKey + hatVariant) ? tuxedoHatKey + hatVariant : new string[] { "De Luxe", "Mystique", "Blonde" }.Contains(hatVariant) ? tuxedoHatKey + "Blanc" : null; if (!string.IsNullOrEmpty(hatName)) { stock[hatName] = true; } } // Add the current hat or top to the shop stock stock[name] = isHat; // Add Sakura Kimono Lowers after the kimono tops if (contentPack.EndsWith("Kimono")) { stock[name.Replace("Upp", "Low")] = false; } } foreach (KeyValuePair <string, bool> nameAndHatFlag in stock) { if (nameAndHatFlag.Value) { CatShopStock[new StardewValley.Objects.Hat(JsonAssets.GetHatId(nameAndHatFlag.Key))] = new[] { GetContentPackCost(contentPack), 1 } } ; else { CatShopStock[new StardewValley.Objects.Clothing(JsonAssets.GetClothingId(nameAndHatFlag.Key))] = new[] { GetContentPackCost(contentPack), 1 } }; } } } catch (Exception ex) { Log.E("Sailor Styles failed to populate the clothes shop." + " Did you remove some clothing folders, or did I break something?"); Log.E("Exception logged:\n" + ex); } }
private void PopulateShop(bool isHat) { try { var random = new Random(); var stock = new List <string>(); var contentPacks = isHat ? Const.HatPacks : Const.ClothingPacks; foreach (var contentPack in contentPacks) { var contentPackId = GetContentPackId(contentPack); var contentNames = isHat ? _ja.GetAllHatsFromContentPack(contentPackId) : _ja.GetAllClothingFromContentPack(contentPackId); if (contentPack.EndsWith("Kimono")) { contentNames.RemoveAll(n => n.EndsWith("wer")); } if (contentNames == null || contentNames.Count < 1) { Log.E($"Failed to populate content from {contentPack}\n({contentPackId})."); throw new NullReferenceException(); } Log.D($"Stocking content from {contentPack}\n({contentPackId}).", Config.DebugMode); stock.Clear(); var currentQty = 0; var goalQty = Math.Max(1, contentNames.Count / Const.CatShopQtyRatio); while (currentQty < goalQty) { var name = contentNames[random.Next(contentNames.Count - 1)]; if (stock.Contains(name)) { continue; } ++currentQty; stock.Add(name); if (!contentPack.EndsWith("Kimono")) { continue; } ++currentQty; stock.Add(name.Replace("Upp", "Low")); } foreach (var name in stock) { Log.D($"CatShop: Adding {name}", Config.DebugMode); if (isHat) { _catShopStock.Add(new StardewValley.Objects.Hat(_ja.GetHatId(name)), new[] { Const.PackCosts[contentPack], 1 }); } else { _catShopStock.Add(new StardewValley.Objects.Clothing(_ja.GetClothingId(name)), new[] { Const.PackCosts[contentPack], 1 }); } } } } catch (Exception ex) { Log.E("Sailor Styles failed to populate the clothes shop." + " Did you install the clothing folders, or did I break something?"); Log.E("Exception logged:\n" + ex); } }