Exemplo n.º 1
0
        public static void RegisterShops(ContentModel data, IContentPack contentPack)
        {
            foreach (ShopPack shopPack in data.Shops)
            {
                if (Shops.ContainsKey(shopPack.ShopName))
                {
                    monitor.Log($"A mod is trying to add a Shop \"{shopPack.ShopName}\"," +
                                $" but a shop of this name has already been added. " +
                                $"It will not be added.", LogLevel.Warn);
                }
                else
                {
                    var shop = new Shop(shopPack, contentPack);
                    Shops.Add(shopPack.ShopName, shop);
                }
            }

            foreach (AnimalShopPack animalShopPack in data.AnimalShops)
            {
                if (AnimalShops.ContainsKey(animalShopPack.ShopName))
                {
                    monitor.Log($"A mod is trying to add an AnimalShop \"{animalShopPack.ShopName}\"," +
                                $" but a shop of this name has already been added. " +
                                $"It will not be added.", LogLevel.Warn);
                }
                else
                {
                    var animalShop = new AnimalShop(animalShopPack, animalShopPack.ShopName);
                    AnimalShops.Add(animalShopPack.ShopName, animalShop);
                }
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Reads content packs and loads the relevent information to create the shops
        /// </summary>
        private void LoadContentPacks()
        {
            monitor.Log("Adding Content Packs...", LogLevel.Info);
            foreach (IContentPack contentPack in helper.ContentPacks.GetOwned())
            {
                if (!contentPack.HasFile("shops.json"))
                {
                    monitor.Log($"No shops.json found from the mod {contentPack.Manifest.UniqueID}. " +
                                $"Skipping pack.", LogLevel.Warn);
                }
                else
                {
                    ContentModel data = null;
                    try
                    {
                        data = contentPack.ReadJsonFile <ContentModel>("shops.json");
                    }
                    catch (Exception ex)
                    {
                        Monitor.Log($"Invalid JSON provided by {contentPack.Manifest.UniqueID}. Skipping pack.", LogLevel.Error);
                        Monitor.Log(ex.Message + ex.StackTrace);
                        continue;
                    }

                    Monitor.Log($"      {contentPack.Manifest.Name} by {contentPack.Manifest.Author} | " +
                                $"{contentPack.Manifest.Version} | {contentPack.Manifest.Description}", LogLevel.Info);

                    //adds shops
                    if (data.Shops != null)
                    {
                        foreach (ShopPack s in data.Shops)
                        {
                            if (Shops.ContainsKey(s.ShopName))
                            {
                                monitor.Log($"      {contentPack.Manifest.UniqueID} is trying to add the shop " +
                                            $"\"{s.ShopName}\", but a shop of this name has already been added. " +
                                            $"It will not be added.", LogLevel.Warn);
                            }
                            else
                            {
                                Shops.Add(s.ShopName, new Shop(s, contentPack));
                            }
                        }
                    }

                    //adds animal shops
                    if (data.AnimalShops != null)
                    {
                        foreach (AnimalShopPack animalShopPack in data.AnimalShops)
                        {
                            if (AnimalShops.ContainsKey(animalShopPack.ShopName))
                            {
                                monitor.Log($"      {contentPack.Manifest.UniqueID} is trying to add the animal shop " +
                                            $"\"{animalShopPack.ShopName}\", but a shop of this name has already been added. " +
                                            $"It will not be added.", LogLevel.Warn);
                            }
                            else
                            {
                                if (animalShopPack.ExcludeFromMarnies != null)
                                {
                                    ExcludeFromMarnie.AddRange(animalShopPack.ExcludeFromMarnies);
                                }

                                var animalShop = new AnimalShop(animalShopPack, animalShopPack.ShopName);
                                AnimalShops.Add(animalShopPack.ShopName, animalShop);
                            }
                        }
                    }
                }
            }
        }