Beispiel #1
0
        private string[] Token_HatId(ITokenString input)
        {
            if (input == null)
            {
                return(ja.GetAllHatIds().Values.Select((i) => i.ToString()).ToArray <string>());
            }

            var str = input.Value;
            int id  = ja.GetHatId(str);

            if (id == -1)
            {
                return new string[] { }
            }
            ;
            return(new[] { id.ToString() });
        }
Beispiel #2
0
        private void PopulateShop(string dir, int type)
        {
            try
            {
                var stock  = new List <int>();
                var random = new Random();

                var objFolder   = new DirectoryInfo(Path.Combine(Helper.DirectoryPath, dir));
                var firstFolder = objFolder.GetDirectories()[0].GetDirectories()[0].GetDirectories()[0];
                var lastFolder  = objFolder.GetDirectories()[objFolder.GetDirectories().Length - 1];
                lastFolder = lastFolder.GetDirectories()[0].GetDirectories()[lastFolder.GetDirectories()[0]
                                                                             .GetDirectories().Length - 1];

                Log.D($"CatShop first object: {firstFolder.Name}",
                      Config.debugMode);
                Log.D($"CatShop last object: {lastFolder.Name}",
                      Config.debugMode);

                var firstObject = 0;
                var lastObject  = 0;

                switch (type)
                {
                case 0:
                    firstObject = _jsonAssets.GetHatId(firstFolder.Name);
                    lastObject  = _jsonAssets.GetHatId(lastFolder.Name);
                    break;

                case 1:
                    firstObject = _jsonAssets.GetClothingId(firstFolder.Name);
                    lastObject  = _jsonAssets.GetClothingId(lastFolder.Name);
                    break;

                default:
                    Log.E("The CatShop hit a dead end. This feature wasn't finished!");
                    throw new NotImplementedException();
                }

                var goalQty = (lastObject - firstObject) / Const.CatShopQtyRatio;

                Log.D("CatShop Restock bounds:",
                      Config.debugMode);
                Log.D($"index: {firstObject}, end: {lastObject}, goalQty: {goalQty}",
                      Config.debugMode);

                while (stock.Count < goalQty)
                {
                    var id = random.Next(firstObject, lastObject);
                    if (!stock.Contains(id))
                    {
                        stock.Add(id);
                    }
                }

                foreach (var id in stock)
                {
                    switch (type)
                    {
                    case 0:
                        _catShopStock.Add(
                            new StardewValley.Objects.Hat(id), new[]
                            { Const.ClothingCost, 1 });
                        break;

                    case 1:
                        _catShopStock.Add(
                            new StardewValley.Objects.Clothing(id), new[]
                            { Const.ClothingCost, 1 });
                        break;

                    default:
                        Log.E("The CatShop hit a dead end. This feature wasn't finished!");
                        throw new NotImplementedException();
                    }
                }
            }
            catch (Exception ex)
            {
                Log.E("Sailor Styles failed to populate the clothes shop."
                      + "Did you remove all the clothing folders, or did I do something wrong?");
                Log.E("Exception logged:\n" + ex);
            }
        }
Beispiel #3
0
        private void GameLoop_DayStarted(object sender, StardewModdingAPI.Events.DayStartedEventArgs e)
        {
            _currentDialogueIndex.Clear();
            PinGame.claimedPrizes.Clear();

            if (IsShadowFestivalToday())
            {
                Monitor.Log("It's Shadow Festival Day!");
                IJsonAssetsApi api = Helper.ModRegistry.GetApi <IJsonAssetsApi>("spacechase0.JsonAssets");
                if (api == null)
                {
                    Monitor.Log("Can't load JSON Assets API, so custom hats will not be available", LogLevel.Warn);
                    return;
                }
                else
                {
                    // Setting up special vendor. First, 3 vanilla hats.
                    VendorItems.Clear();
                    VendorItems.Add(new Hat(37), new int[] { 5000, 2147483647 });
                    VendorItems.Add(new Hat(38), new int[] { 5000, 2147483647 });
                    VendorItems.Add(new Hat(36), new int[] { 10000, 2147483647 });
                    // Now for JA hats, whose names are all hardcoded.
                    int HatId;
                    Monitor.Log("Adding calming hats to Vendor stock");
                    foreach (string hatName in Data.CalmingHats)
                    {
                        HatId = api.GetHatId(hatName);
                        if (HatId != -1)
                        {
                            VendorItems.Add(new Hat(HatId), new int[] { 750, 2147483647 });
                        }
                        else
                        {
                            Monitor.Log($"Error adding {hatName} to Vendor stock", LogLevel.Warn);
                        }
                    }
                    Monitor.Log("Adding other hats to Vendor stock");
                    foreach (string hatName in Data.OtherHats)
                    {
                        HatId = api.GetHatId(hatName);
                        if (HatId != -1)
                        {
                            VendorItems.Add(new Hat(HatId), new int[] { 500, 2147483647 });
                        }
                        else
                        {
                            Monitor.Log($"Error adding {hatName} to Vendor stock", LogLevel.Warn);
                        }
                    }
                }

                // Make sure our asset changes happened
                Helper.Content.InvalidateCache("Data/mail");
                Helper.Content.InvalidateCache("Characters/Dialogue/Krobus");
                Helper.Content.InvalidateCache("Strings/StringsFromCSFiles");
                Helper.Content.InvalidateCache("Maps/Sewer");
            }
            else
            {
                // Trigger another invalidation to remove our changes
                if (_mapChanged)
                {
                    Helper.Content.InvalidateCache("Maps/Sewer");
                    Helper.Content.InvalidateCache("Characters/Dialogue/Krobus");
                    Helper.Content.InvalidateCache("Strings/StringsFromCSFiles");
                    _mapChanged = false;
                }
            }

            if (IsShadowFestivalTomorrow())
            {
                Monitor.Log("It is the day before the shadow festival.");
                if (!Game1.player.mailReceived.Contains("Wizard_ShadowFestival"))
                {
                    Monitor.Log("Player does not have our mail. Queueing for tomorrow.");
                    Game1.player.mailForTomorrow.Add("Wizard_ShadowFestival");
                }
                else
                {
                    Monitor.Log("Player already has our mail.");
                }
            }
        }
Beispiel #4
0
        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);
            }
        }
Beispiel #5
0
        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);
            }
        }