Exemplo n.º 1
0
        public static bool shopAction(string action, GameLocation location, Vector2 tile, string layer)
        {
            List <string> text = action.Split(' ').ToList();

            if (text.Count < 2)
            {
                return(false);
            }

            List <TileShopItem> items = new List <TileShopItem>();

            if (TMXLoaderMod.tileShops.TryGetValue(text[1], out items))
            {
                Dictionary <Item, int[]> priceAndStock = new Dictionary <Item, int[]>();
                foreach (TileShopItem inventory in items)
                {
                    Item item = null;

                    if (inventory.type == "Object")
                    {
                        if (inventory.index != -1)
                        {
                            item = new StardewValley.Object(inventory.index, 1);
                        }
                        else if (inventory.name != "none")
                        {
                            item = new StardewValley.Object(Game1.objectInformation.getIndexByName(inventory.name), 1);
                        }
                    }
                    else if (inventory.type == "BigObject")
                    {
                        if (inventory.index != -1)
                        {
                            item = new StardewValley.Object(Vector2.Zero, inventory.index);
                        }
                        else if (inventory.name != "none")
                        {
                            item = new StardewValley.Object(Vector2.Zero, Game1.bigCraftablesInformation.getIndexByName(inventory.name));
                        }
                    }
                    else if (inventory.type == "Ring")
                    {
                        if (inventory.index != -1)
                        {
                            item = new Ring(inventory.index);
                        }
                        else if (inventory.name != "none")
                        {
                            item = new Ring(Game1.objectInformation.getIndexByName(inventory.name));
                        }
                    }
                    else if (inventory.type == "Hat")
                    {
                        if (inventory.index != -1)
                        {
                            item = new Hat(inventory.index);
                        }
                        else if (inventory.name != "none")
                        {
                            item = new Hat(TMXLoaderMod.helper.Content.Load <Dictionary <int, string> >(@"Data/hats", ContentSource.GameContent).getIndexByName(inventory.name));
                        }
                    }
                    else if (inventory.type == "Boots")
                    {
                        if (inventory.index != -1)
                        {
                            item = new Boots(inventory.index);
                        }
                        else if (inventory.name != "none")
                        {
                            item = new Boots(TMXLoaderMod.helper.Content.Load <Dictionary <int, string> >(@"Data/Boots", ContentSource.GameContent).getIndexByName(inventory.name));
                        }
                    }
                    else if (inventory.type == "TV")
                    {
                        if (inventory.index != -1)
                        {
                            item = new StardewValley.Objects.TV(inventory.index, Vector2.Zero);
                        }
                        else if (inventory.name != "none")
                        {
                            item = new TV(TMXLoaderMod.helper.Content.Load <Dictionary <int, string> >(@"Data/Furniture", ContentSource.GameContent).getIndexByName(inventory.name), Vector2.Zero);
                        }
                    }
                    else if (inventory.type == "IndoorPot")
                    {
                        item = new StardewValley.Objects.IndoorPot(Vector2.Zero);
                    }
                    else if (inventory.type == "CrabPot")
                    {
                        item = new StardewValley.Objects.CrabPot(Vector2.Zero);
                    }
                    else if (inventory.type == "Chest")
                    {
                        item = new StardewValley.Objects.Chest(true);
                    }
                    else if (inventory.type == "Cask")
                    {
                        item = new StardewValley.Objects.Cask(Vector2.Zero);
                    }
                    else if (inventory.type == "Cask")
                    {
                        item = new StardewValley.Objects.Cask(Vector2.Zero);
                    }
                    else if (inventory.type == "Furniture")
                    {
                        if (inventory.index != -1)
                        {
                            item = new StardewValley.Objects.Furniture(inventory.index, Vector2.Zero);
                        }
                        else if (inventory.name != "none")
                        {
                            item = new Furniture(TMXLoaderMod.helper.Content.Load <Dictionary <int, string> >(@"Data/Furniture", ContentSource.GameContent).getIndexByName(inventory.name), Vector2.Zero);
                        }
                    }
                    else if (inventory.type == "Sign")
                    {
                        item = new StardewValley.Objects.Sign(Vector2.Zero, inventory.index);
                    }
                    else if (inventory.type == "Wallpaper")
                    {
                        item = new StardewValley.Objects.Wallpaper(Math.Abs(inventory.index), false);
                    }
                    else if (inventory.type == "Floors")
                    {
                        item = new StardewValley.Objects.Wallpaper(Math.Abs(inventory.index), true);
                    }
                    else if (inventory.type == "MeleeWeapon")
                    {
                        if (inventory.index != -1)
                        {
                            item = new MeleeWeapon(inventory.index);
                        }
                        else if (inventory.name != "none")
                        {
                            item = new MeleeWeapon(TMXLoaderMod.helper.Content.Load <Dictionary <int, string> >(@"Data/weapons", ContentSource.GameContent).getIndexByName(inventory.name));
                        }
                    }

                    else if (inventory.type == "CustomObject" && PyTK.CustomElementHandler.CustomObjectData.collection.ContainsKey(inventory.name))
                    {
                        item = PyTK.CustomElementHandler.CustomObjectData.collection[inventory.name].getObject();
                    }
                    else if (inventory.type == "SDVType")
                    {
                        try
                        {
                            if (inventory.index == -1)
                            {
                                item = Activator.CreateInstance(PyUtils.getTypeSDV(inventory.name)) is Item i ? i : null;
                            }
                            else
                            {
                                item = Activator.CreateInstance(PyUtils.getTypeSDV(inventory.name), inventory.index) is Item i ? i : null;
                            }
                        }
                        catch
                        {
                            TMXLoaderMod.monitor.Log("Couldn't load to shop SDVType: " + inventory.name);
                        }
                    }
                    else if (inventory.type == "ByType")
                    {
                        try
                        {
                            if (inventory.index == -1)
                            {
                                item = Activator.CreateInstance(Type.GetType(inventory.name)) is Item i ? i : null;
                            }
                            else
                            {
                                item = Activator.CreateInstance(Type.GetType(inventory.name), inventory.index) is Item i ? i : null;
                            }
                        }
                        catch
                        {
                            TMXLoaderMod.monitor.Log("Couldn't load to shop ByType: " + inventory.name);
                        }
                    }
                    int price = 100;
                    try
                    {
                        price = inventory.price > 0 ? inventory.price : item.salePrice();
                    }
                    catch
                    {
                    }

                    if (price < 0)
                    {
                        price = 100;
                    }

                    if (item != null)
                    {
                        priceAndStock.AddOrReplace(item, new int[] { price, inventory.stock });
                    }
                }
                var shop = new ShopMenu(priceAndStock, 0, null);
                if (text.Count > 2)
                {
                    shop.portraitPerson = Game1.getCharacterFromName(text[2]);
                }
                Game1.activeClickableMenu = shop;
                return(true);
            }

            return(false);
        }
Exemplo n.º 2
0
        public static Item getItem(string type, int index = -1, string name = "none")
        {
            Item item = null;

            if (type == "Object")
            {
                if (index != -1)
                {
                    item = new StardewValley.Object(index, 1);
                }
                else if (name != "none")
                {
                    item = new StardewValley.Object(Game1.objectInformation.getIndexByName(name), 1);
                }
            }
            else if (type == "BigObject")
            {
                if (index != -1)
                {
                    item = new StardewValley.Object(Vector2.Zero, index);
                }
                else if (name != "none")
                {
                    item = new StardewValley.Object(Vector2.Zero, Game1.bigCraftablesInformation.getIndexByName(name));
                }
            }
            else if (type == "Ring")
            {
                if (index != -1)
                {
                    item = new Ring(index);
                }
                else if (name != "none")
                {
                    item = new Ring(Game1.objectInformation.getIndexByName(name));
                }
            }
            else if (type == "Hat")
            {
                if (index != -1)
                {
                    item = new Hat(index);
                }
                else if (name != "none")
                {
                    item = new Hat(TMXLoaderMod.helper.Content.Load <Dictionary <int, string> >(@"Data/hats", ContentSource.GameContent).getIndexByName(name));
                }
            }
            else if (type == "Boots")
            {
                if (index != -1)
                {
                    item = new Boots(index);
                }
                else if (name != "none")
                {
                    item = new Boots(TMXLoaderMod.helper.Content.Load <Dictionary <int, string> >(@"Data/Boots", ContentSource.GameContent).getIndexByName(name));
                }
            }
            else if (type == "Clothing")
            {
                if (index != -1)
                {
                    item = new Clothing(index);
                }
                else if (name != "none")
                {
                    item = new Clothing(TMXLoaderMod.helper.Content.Load <Dictionary <int, string> >(@"Data/ClothingInformation", ContentSource.GameContent).getIndexByName(name));
                }
            }
            else if (type == "TV")
            {
                if (index != -1)
                {
                    item = new StardewValley.Objects.TV(index, Vector2.Zero);
                }
                else if (name != "none")
                {
                    item = new TV(TMXLoaderMod.helper.Content.Load <Dictionary <int, string> >(@"Data/Furniture", ContentSource.GameContent).getIndexByName(name), Vector2.Zero);
                }
            }
            else if (type == "IndoorPot")
            {
                item = new StardewValley.Objects.IndoorPot(Vector2.Zero);
            }
            else if (type == "CrabPot")
            {
                item = new StardewValley.Objects.CrabPot(Vector2.Zero);
            }
            else if (type == "Chest")
            {
                item = new StardewValley.Objects.Chest(true);
            }
            else if (type == "Cask")
            {
                item = new StardewValley.Objects.Cask(Vector2.Zero);
            }
            else if (type == "Cask")
            {
                item = new StardewValley.Objects.Cask(Vector2.Zero);
            }
            else if (type == "Furniture")
            {
                if (index != -1)
                {
                    item = new StardewValley.Objects.Furniture(index, Vector2.Zero);
                }
                else if (name != "none")
                {
                    item = new Furniture(TMXLoaderMod.helper.Content.Load <Dictionary <int, string> >(@"Data/Furniture", ContentSource.GameContent).getIndexByName(name), Vector2.Zero);
                }
            }
            else if (type == "Sign")
            {
                item = new StardewValley.Objects.Sign(Vector2.Zero, index);
            }
            else if (type == "Wallpaper")
            {
                item = new StardewValley.Objects.Wallpaper(Math.Abs(index), false);
            }
            else if (type == "Floors")
            {
                item = new StardewValley.Objects.Wallpaper(Math.Abs(index), true);
            }
            else if (type == "MeleeWeapon")
            {
                if (index != -1)
                {
                    item = new MeleeWeapon(index);
                }
                else if (name != "none")
                {
                    item = new MeleeWeapon(TMXLoaderMod.helper.Content.Load <Dictionary <int, string> >(@"Data/weapons", ContentSource.GameContent).getIndexByName(name));
                }
            }
            else if (type == "CustomObject" && PyTK.CustomElementHandler.CustomObjectData.collection.ContainsKey(name))
            {
                item = PyTK.CustomElementHandler.CustomObjectData.collection[name].getObject();
            }
            else if (type == "SDVType")
            {
                try
                {
                    if (index == -1)
                    {
                        item = Activator.CreateInstance(PyUtils.getTypeSDV(name)) is Item i ? i : null;
                    }
                    else
                    {
                        item = Activator.CreateInstance(PyUtils.getTypeSDV(name), index) is Item i ? i : null;
                    }
                }
                catch (Exception ex)
                {
                    TMXLoaderMod.monitor?.Log(ex.Message + ":" + ex.StackTrace, LogLevel.Error);
                    TMXLoaderMod.monitor?.Log("Couldn't load item SDVType: " + name);
                }
            }
            else if (type == "ByType")
            {
                try
                {
                    if (index == -1)
                    {
                        item = Activator.CreateInstance(Type.GetType(name)) is Item i ? i : null;
                    }
                    else
                    {
                        item = Activator.CreateInstance(Type.GetType(name), index) is Item i ? i : null;
                    }
                }
                catch (Exception ex)
                {
                    TMXLoaderMod.monitor?.Log(ex.Message + ":" + ex.StackTrace, LogLevel.Error);
                    TMXLoaderMod.monitor?.Log("Couldn't load item ByType: " + name);
                }
            }

            return(item);
        }
Exemplo n.º 3
0
        public ISalable GetSalable(string type, int index = -1, string name = "none")
        {
            Item item = null;

            if (type == "Object")
            {
                if (index != -1)
                {
                    item = new StardewValley.Object(index, 1);
                }
                else if (name != "none")
                {
                    item = new StardewValley.Object(GetIndexByName(Game1.objectInformation, name), 1);
                }
            }
            else if (type == "BigObject")
            {
                if (index != -1)
                {
                    item = new StardewValley.Object(Vector2.Zero, index);
                }
                else if (name != "none")
                {
                    item = new StardewValley.Object(Vector2.Zero, GetIndexByName(Game1.bigCraftablesInformation, name));
                }
            }
            else if (type == "Ring")
            {
                if (index != -1)
                {
                    item = new Ring(index);
                }
                else if (name != "none")
                {
                    item = new Ring(GetIndexByName(Game1.objectInformation, name));
                }
            }
            else if (type == "Hat")
            {
                if (index != -1)
                {
                    item = new Hat(index);
                }
                else if (name != "none")
                {
                    item = new Hat(GetIndexByName(Plato.ModHelper.Content.Load <Dictionary <int, string> >(@"Data/hats", ContentSource.GameContent), name));
                }
            }
            else if (type == "Boots")
            {
                if (index != -1)
                {
                    item = new Boots(index);
                }
                else if (name != "none")
                {
                    item = new Boots(GetIndexByName(Plato.ModHelper.Content.Load <Dictionary <int, string> >(@"Data/Boots", ContentSource.GameContent), name));
                }
            }
            else if (type == "Clothing")
            {
                if (index != -1)
                {
                    item = new Clothing(index);
                }
                else if (name != "none")
                {
                    item = new Clothing(GetIndexByName(Plato.ModHelper.Content.Load <Dictionary <int, string> >(@"Data/ClothingInformation", ContentSource.GameContent), name));
                }
            }
            else if (type == "TV")
            {
                if (index != -1)
                {
                    item = new StardewValley.Objects.TV(index, Vector2.Zero);
                }
                else if (name != "none")
                {
                    item = new TV(GetIndexByName(Plato.ModHelper.Content.Load <Dictionary <int, string> >(@"Data/Furniture", ContentSource.GameContent), name), Vector2.Zero);
                }
            }
            else if (type == "IndoorPot")
            {
                item = new StardewValley.Objects.IndoorPot(Vector2.Zero);
            }
            else if (type == "CrabPot")
            {
                item = new StardewValley.Objects.CrabPot(Vector2.Zero);
            }
            else if (type == "Chest")
            {
                item = new StardewValley.Objects.Chest(true);
            }
            else if (type == "Cask")
            {
                item = new StardewValley.Objects.Cask(Vector2.Zero);
            }
            else if (type == "Cask")
            {
                item = new StardewValley.Objects.Cask(Vector2.Zero);
            }
            else if (type == "Furniture")
            {
                if (index != -1)
                {
                    item = new StardewValley.Objects.Furniture(index, Vector2.Zero);
                }
                else if (name != "none")
                {
                    item = new Furniture(GetIndexByName(Plato.ModHelper.Content.Load <Dictionary <int, string> >(@"Data/Furniture", ContentSource.GameContent), name), Vector2.Zero);
                }
            }
            else if (type == "Sign")
            {
                item = new StardewValley.Objects.Sign(Vector2.Zero, index);
            }
            else if (type == "Wallpaper")
            {
                item = new StardewValley.Objects.Wallpaper(Math.Abs(index), false);
            }
            else if (type == "Floors")
            {
                item = new StardewValley.Objects.Wallpaper(Math.Abs(index), true);
            }
            else if (type == "MeleeWeapon")
            {
                if (index != -1)
                {
                    item = new MeleeWeapon(index);
                }
                else if (name != "none")
                {
                    item = new MeleeWeapon(GetIndexByName(Plato.ModHelper.Content.Load <Dictionary <int, string> >(@"Data/weapons", ContentSource.GameContent), name));
                }
            }
            else if (type == "SDVType")
            {
                if (index == -1)
                {
                    item = Activator.CreateInstance(GetTypeSDV(name)) is Item i ? i : null;
                }
                else
                {
                    item = Activator.CreateInstance(GetTypeSDV(name), index) is Item i ? i : null;
                }
            }
            else if (type == "ByType")
            {
                try
                {
                    if (index == -1)
                    {
                        item = Activator.CreateInstance(Type.GetType(name)) is Item i ? i : null;
                    }
                    else
                    {
                        item = Activator.CreateInstance(Type.GetType(name), index) is Item i ? i : null;
                    }
                }
                catch (Exception ex)
                {
                }
            }

            return(item);
        }