Иконка ресурса

FREE Craft : 7.0.0 7.0.0

Нет прав для скачивания
C#:
using System.Collections.Generic;
using System.Linq;
using Oxide.Core.Plugins;
using Oxide.Game.Rust.Cui;
using UnityEngine;
using Newtonsoft.Json;


namespace Oxide.Plugins
{
    [Info("Craft", "Я и Я", "7.0.0")]
    class Craft : RustPlugin
    {
        #region Вар
        string Layer = "Craft_UI";

        [PluginReference] Plugin ImageLibrary;

        Dictionary<ulong, string> NameButton = new Dictionary<ulong, string>();

        #endregion

        #region Класс
        public class itemList
        {
            [JsonProperty("Категория")] public string Category;
            [JsonProperty("Название предмета")] public string DisplayName;
            [JsonProperty("Короткое название предмета")] public string ShortName;
            [JsonProperty("Какой верстак нужен для крафта (Если 0 то не нужен)")] public int LevelWorkBench;
            [JsonProperty("Описание предмета")] public string Description;
            [JsonProperty("Картинка предмета")] public string Url;
            [JsonProperty("SkinID предмета")] public ulong SkinID;
            [JsonProperty("Кол-во предмета")] public int Amount;
            [JsonProperty("Список предметов для крафта")] public List<itemcraft> items;
        }

        public class itemcraft
        {
            [JsonProperty("Название предмета")] public string DisplayName;
            [JsonProperty("Короткое название предмета")] public string ShortName;
            [JsonProperty("Кол-во предмета")] public int Amount;
        }
        #endregion

        #region Конфиг
        Configuration config;
        class Configuration 
        {
            [JsonProperty("Категории")] public List<string> Category;
            [JsonProperty("Основные настройки")] public List<itemList> Items;
            public static Configuration GetNewConfig() 
            {
                return new Configuration
                {
                    Category = new List<string>()
                    {
                        "Конструкции",
                        "Предметы",
                        "Одежда",
                        "Инструменты",
                        "Разное",
                        "Еда",
                        "Салюты",
                        "Музыка",
                        "Летнее DLC"
                    },
                    Items = new List<itemList>()
                    {
                        new itemList
                        {
                            Category = "Конструкции",
                            DisplayName = "Забор",
                            ShortName = "wall.graveyard.fence",
                            LevelWorkBench = 0,
                            Description = "Обычный забор, чтобы всякие пидарасы не подходили близко к дому! :D",
                            Url = null,
                            SkinID = 0,
                            Amount = 1,
                            items = new List<itemcraft>()
                            {
                                new itemcraft
                                {
                                    DisplayName = "Дерево",
                                    ShortName = "wood",
                                    Amount = 100
                                },
                                new itemcraft
                                {
                                    DisplayName = "Уголь",
                                    ShortName = "charcoal",
                                    Amount = 1000
                                }
                            }
                        },
                        new itemList
                        {
                            Category = "Летнее DLC",
                            DisplayName = "Хуй",
                            ShortName = "wood",
                            LevelWorkBench = 2,
                            Description = "Обычный забор, чтобы всякие пидарасы не подходили близко к дому! :D",
                            Url = null,
                            SkinID = 0,
                            Amount = 1,
                            items = new List<itemcraft>()
                            {
                                new itemcraft
                                {
                                    DisplayName = "Дерево",
                                    ShortName = "wood",
                                    Amount = 100
                                },
                                new itemcraft
                                {
                                    DisplayName = "Уголь",
                                    ShortName = "charcoal",
                                    Amount = 1000
                                }
                            }
                        },
                    }
                };
            }
        }
        
        protected override void LoadConfig()
        {
            base.LoadConfig();
            try
            {
                config = Config.ReadObject<Configuration>();
                if (config?.Category == null) LoadDefaultConfig();
            }
            catch
            {
                PrintWarning($"Ошибка чтения конфигурации 'oxide/config/{Name}', создаём новую конфигурацию!!");
                LoadDefaultConfig();
            }

            NextTick(SaveConfig);
        }

        protected override void LoadDefaultConfig() => config = Configuration.GetNewConfig();
        protected override void SaveConfig() => Config.WriteObject(config);
        #endregion

        #region Хуки
        void OnServerInitialized()
        {
            foreach (var check in config.Items)
                ImageLibrary.Call("AddImage", check.Url, check.Url);

            foreach (var check in BasePlayer.activePlayerList)
                OnPlayerConnected(check);
        }

        void OnPlayerConnected(BasePlayer player) => NameButton[player.userID] = config.Category[0];
        #endregion

        #region Команды
        [ConsoleCommand("craft")]
        void ConsoleCraft(ConsoleSystem.Arg args)
        {
            var player = args.Player();

            if (player != null && args.HasArgs(1))
            {
                if (args.Args[0] == "category")
                {
                    string category = "";
                    for (int z = 1; z < args.Args.Length; z++)
                        category += args.Args[z] + " ";

                    category = category.Trim(' ');

                    NameButton[player.userID] = category;
                    CraftUI(player);
                }
                if (args.Args[0] == "item")
                {
                    CraftItemUI(player, args.Args[1]);
                }
                if (args.Args[0] == "rate")
                {
                    CraftItemUI(player, args.Args[1], int.Parse(args.Args[2]));
                }
                if (args.Args[0] == "craft")
                {
                    bool enable = true;
                    var items = config.Items.FirstOrDefault(p => p.ShortName == args.Args[1]);
                    int rate = int.Parse(args.Args[2]);
                    if (player.currentCraftLevel < items.LevelWorkBench)
                    {
                        SendReply(player, $"Нужен верстак {items.LevelWorkBench} уровня");
                        return;
                    }
                    foreach (var check in items.items)
                    {
                        var haveCount = player.inventory.GetAmount(ItemManager.FindItemDefinition(check.ShortName).itemid);
                        if (haveCount >= check.Amount * rate) continue;
                        enable = false;
                    }
                    if (!enable)
                    {
                        SendReply(player, "У вас не хватает ресурсов для крафта");
                        return;
                    }
                    foreach (var check in items.items)
                    {
                        player.inventory.Take(null, ItemManager.FindItemDefinition(check.ShortName).itemid, check.Amount * rate);
                    }
                    var item = ItemManager.CreateByName(items.ShortName, items.Amount * rate);
                    item.skin = items.SkinID;
                    if (!player.inventory.GiveItem(item))
                    {
                        item.Drop(player.inventory.containerMain.dropPosition, player.inventory.containerMain.dropVelocity, new Quaternion());
                        return;
                    }
                    SendReply(player, $"Вы успешно скрафтили: {items.DisplayName}");
                }
            }
        }
        #endregion

        #region Интерфейс
        void CraftUI(BasePlayer player)
        {
            CuiHelper.DestroyUi(player, "CraftInterface");
            var container = new CuiElementContainer();

            container.Add(new CuiPanel
            {
                RectTransform = { AnchorMin = "0.276 0", AnchorMax = "0.955 1", OffsetMax = "0 0" },
                Image = { Color = "0.117 0.121 0.109 0.95" }
            }, "Menu_UI", "CraftInterface");

            container.Add(new CuiPanel
            {
                RectTransform = { AnchorMin = $"0 0", AnchorMax = $"0.3 1", OffsetMax = "0 0" },
                Image = { Color = "0.549 0.270 0.215 0.7" }
            }, "CraftInterface", "Craft");

            container.Add(new CuiLabel
            {
                RectTransform = { AnchorMin = "0.01 0.92", AnchorMax = $"0.55 1", OffsetMax = "0 0" },
                Text = { Text = $"КРАФТ", Color = "1 1 1 0.8", Align = TextAnchor.MiddleCenter, FontSize = 28, Font = "robotocondensed-bold.ttf" }
            }, "Craft");

            float width1 = 0.945f, height1 = 0.063f, startxBox1 = 0.058f, startyBox1 = 0.8f - height1, xmin1 = startxBox1, ymin1 = startyBox1;
            foreach (var check in config.Category)
            {
                var color = NameButton[player.userID] == check ? "0 0 0 0.6" : "0 0 0 0";
                container.Add(new CuiButton
                {
                    RectTransform = { AnchorMin = $"{xmin1} {ymin1}", AnchorMax = $"{xmin1 + width1} {ymin1 + height1 * 1}", OffsetMin = "1 1", OffsetMax = "-1 -1" },
                    Button = { Command = $"craft category {check}", Color = color },
                    Text = { Text = "" }
                }, "Craft", "Category");

                container.Add(new CuiLabel
                {
                    RectTransform = { AnchorMin = $"0 0", AnchorMax = $"1 1", OffsetMax = "0 0" },
                    Text = { Text = $"{check}   ", Color = "1 1 1 0.8", Align = TextAnchor.MiddleRight, FontSize = 20, Font = "robotocondensed-bold.ttf" }
                }, "Category");

                xmin1 += width1;
                if (xmin1 + width1 >= 1)
                {
                    xmin1 = startxBox1;
                    ymin1 -= height1;
                }
            }

            CuiHelper.AddUi(player, container);
            InterfaceUI(player);
        }

        void InterfaceUI(BasePlayer player)
        {
            CuiHelper.DestroyUi(player, "Interface");
            var container = new CuiElementContainer();

            container.Add(new CuiPanel
            {
                RectTransform = { AnchorMin = $"0.3 0", AnchorMax = $"1 1", OffsetMax = "0 0" },
                Image = { Color = "0 0 0 0" }
            }, "CraftInterface", "Interface");

            float width = 0.175f, height = 0.152f, startxBox = 0.06f, startyBox = 0.955f - height, xmin = startxBox, ymin = startyBox;
            foreach (var check in config.Items)
            {
                if (check.Category == NameButton[player.userID])
                {
                    container.Add(new CuiButton
                    {
                        RectTransform = { AnchorMin = $"{xmin} {ymin}", AnchorMax = $"{xmin + width} {ymin + height * 1}", OffsetMin = "1 1", OffsetMax = "-1 -1" },
                        Button = { Command = $"craft item {check.ShortName}", Color = "0 0 0 0.7" },
                        Text = { Text = "" }
                    }, "Interface", "Items");

                    container.Add(new CuiPanel
                    {
                        RectTransform = { AnchorMin = $"0 0", AnchorMax = $"1 0.2", OffsetMax = "0 0" },
                        Image = { Color = "0.55 0.8 0.3 0.6" }
                    }, "Items", "Titel");

                    container.Add(new CuiLabel
                    {
                        RectTransform = { AnchorMin = $"0 0", AnchorMax = $"1 1", OffsetMax = "0 0" },
                        Text = { Text = $"{check.DisplayName}", Color = "1 1 1 0.8", Align = TextAnchor.MiddleCenter, FontSize = 12, Font = "robotocondensed-regular.ttf" }
                    }, "Titel");

                    var image = check.Url != null ? check.Url : check.ShortName;
                    container.Add(new CuiElement
                    {
                        Parent = "Items",
                        Components =
                    {
                        new CuiRawImageComponent { Png = (string) ImageLibrary.Call("GetImage", image) },
                        new CuiRectTransformComponent { AnchorMin = "0 0.2", AnchorMax = "1 1", OffsetMin = "18 15", OffsetMax = "-18 -15" }
                    }
                    });

                    xmin += width;
                    if (xmin + width >= 1)
                    {
                        xmin = startxBox;
                        ymin -= height;
                    }
                }
            }

            CuiHelper.AddUi(player, container);
        }

        void CraftItemUI(BasePlayer player, string name, int rate = 1)
        {
            CuiHelper.DestroyUi(player, "Interface");
            CuiHelper.DestroyUi(player, "Items");
            var container = new CuiElementContainer();

            var check = config.Items.FirstOrDefault(z => z.ShortName == name);

            container.Add(new CuiPanel
            {
                RectTransform = { AnchorMin = $"0.29 0", AnchorMax = $"1 1", OffsetMax = "0 0" },
                Image = { Color = "0 0 0 0" }
            }, "CraftInterface", "Items");

            container.Add(new CuiPanel
            {
                RectTransform = { AnchorMin = $"0.03 0.71", AnchorMax = $"0.24 0.9", OffsetMax = "0 0" },
                Image = { Color = "0 0 0 0.7" }
            }, "Items", "Image");

            var image = check.Url != null ? check.Url : check.ShortName;
            container.Add(new CuiElement
            {
                Parent = "Image",
                Components =
                {
                    new CuiRawImageComponent { Png = (string) ImageLibrary.Call("GetImage", image) },
                    new CuiRectTransformComponent { AnchorMin = "0 0", AnchorMax = "1 1", OffsetMin = "15 22", OffsetMax = "-15 -22" }
                }
            });

            container.Add(new CuiPanel
            {
                RectTransform = { AnchorMin = $"0.03 0.65", AnchorMax = $"0.24 0.71", OffsetMax = "0 0" },
                Image = { Color = "0.55 0.8 0.3 0.6" }
            }, "Items", "Titel");

            container.Add(new CuiLabel
            {
                RectTransform = { AnchorMin = $"0 0", AnchorMax = $"1 1", OffsetMax = "0 0" },
                Text = { Text = $"{check.DisplayName}", Color = "1 1 1 0.8", Align = TextAnchor.MiddleCenter, FontSize = 18, Font = "robotocondensed-regular.ttf" }
            }, "Titel");
                       
            container.Add(new CuiPanel
            {
                RectTransform = { AnchorMin = $"0.28 0.65", AnchorMax = $"0.97 0.9", OffsetMax = "0 0" },
                Image = { Color = "0 0 0 0.7" }
            }, "Items", "Description");

            container.Add(new CuiLabel
            {
                RectTransform = { AnchorMin = $"0 0", AnchorMax = $"1 0.9", OffsetMax = "0 0" },
                Text = { Text = $"<b><size=20>Описание предмета</size></b>\n{check.Description}", Color = "1 1 1 0.8", Align = TextAnchor.UpperCenter, FontSize = 12, Font = "robotocondensed-regular.ttf" }
            }, "Description");

            container.Add(new CuiLabel
            {
                RectTransform = { AnchorMin = $"0 0", AnchorMax = $"1 0.18", OffsetMax = "0 0" },
                Text = { Text = $"Необходим верстак {check.LevelWorkBench} уровня", Color = "1 1 1 0.8", Align = TextAnchor.UpperCenter, FontSize = 14, Font = "robotocondensed-regular.ttf" }
            }, "Description");

            container.Add(new CuiPanel
            {
                RectTransform = { AnchorMin = $"0.03 0.2", AnchorMax = $"0.97 0.62", OffsetMax = "0 0" },
                Image = { Color = "0 0 0 0.7" }
            }, "Items", "Buy");

            container.Add(new CuiLabel
            {
                RectTransform = { AnchorMin = $"0 0.85", AnchorMax = $"1 1", OffsetMax = "0 0" },
                Text = { Text = $"Количество                  Название ингредиентов                  Всего                  Имеется", Color = "1 1 1 0.8", Align = TextAnchor.MiddleCenter, FontSize = 14, Font = "robotocondensed-regular.ttf" }
            }, "Buy");

            container.Add(new CuiButton
            {
                RectTransform = { AnchorMin = $"0.03 0.12", AnchorMax = $"0.1 0.17", OffsetMax = "0 0" },
                Button = { Command = rate != 1 ? $"craft rate {check.ShortName} {rate - 1}" : "", Color = "0.55 0.8 0.3 0.6" },
                Text = { Text = "<", Color = "1 1 1 0.8", Align = TextAnchor.MiddleCenter, FontSize = 14, Font = "robotocondensed-regular.ttf" }
            }, "Items");

            container.Add(new CuiButton
            {
                RectTransform = { AnchorMin = $"0.11 0.12", AnchorMax = $"0.18 0.17", OffsetMax = "0 0" },
                Button = { Color = "0 0 0 0.7" },
                Text = { Text = $"{rate}", Color = "1 1 1 0.8", Align = TextAnchor.MiddleCenter, FontSize = 14, Font = "robotocondensed-regular.ttf" }
            }, "Items");

            container.Add(new CuiButton
            {
                RectTransform = { AnchorMin = $"0.19 0.12", AnchorMax = $"0.26 0.17", OffsetMax = "0 0" },
                Button = { Command = $"craft rate {check.ShortName} {rate + 1}", Color = "0.55 0.8 0.3 0.6" },
                Text = { Text = ">", Color = "1 1 1 0.8", Align = TextAnchor.MiddleCenter, FontSize = 14, Font = "robotocondensed-regular.ttf" }
            }, "Items");

            container.Add(new CuiButton
            {
                RectTransform = { AnchorMin = $"0.8 0.12", AnchorMax = $"0.97 0.17", OffsetMax = "0 0" },
                Button = { Command = $"craft craft {check.ShortName} {rate}", Color = "0.55 0.8 0.3 0.6" },
                Text = { Text = "Скрафтить", Color = "1 1 1 0.8", Align = TextAnchor.MiddleCenter, FontSize = 14, Font = "robotocondensed-regular.ttf" }
            }, "Items");

            float width = 0.885f, height = 0.09f, startxBox = 0.06f, startyBox = 0.87f - height, xmin = startxBox, ymin = startyBox;
            foreach (var item in check.items)
            {
                container.Add(new CuiPanel
                {
                    RectTransform = { AnchorMin = $"{xmin} {ymin}", AnchorMax = $"{xmin + width} {ymin + height * 1}", OffsetMin = "1 1", OffsetMax = "-1 -1" },
                    Image = { Color = "1 1 1 0" }
                }, "Buy", "Item");

                container.Add(new CuiLabel
                {
                    RectTransform = { AnchorMin = $"0.026 0", AnchorMax = $"0.2 1", OffsetMax = "0 0" },
                    Text = { Text = $"{item.Amount}", Color = "1 1 1 0.8", Align = TextAnchor.MiddleLeft, FontSize = 14, Font = "robotocondensed-regular.ttf" }
                }, "Item");

                container.Add(new CuiLabel
                {
                    RectTransform = { AnchorMin = $"0.35 0", AnchorMax = $"0.5 1", OffsetMax = "0 0" },
                    Text = { Text = $"{item.DisplayName}", Color = "1 1 1 0.8", Align = TextAnchor.MiddleCenter, FontSize = 14, Font = "robotocondensed-regular.ttf" }
                }, "Item");

                container.Add(new CuiLabel
                {
                    RectTransform = { AnchorMin = $"0.67 0", AnchorMax = $"0.77 1", OffsetMax = "0 0" },
                    Text = { Text = $"{item.Amount * rate}", Color = "1 1 1 0.8", Align = TextAnchor.MiddleCenter, FontSize = 14, Font = "robotocondensed-regular.ttf" }
                }, "Item");

                int haveCount = player.inventory.GetAmount(ItemManager.FindItemDefinition(item.ShortName).itemid);
                container.Add(new CuiLabel
                {
                    RectTransform = { AnchorMin = $"0.8 0", AnchorMax = $"0.97 1", OffsetMax = "0 0" },
                    Text = { Text = $"{haveCount}", Color = "1 1 1 0.8", Align = TextAnchor.MiddleRight, FontSize = 14, Font = "robotocondensed-regular.ttf" }
                }, "Item");

                xmin += width;
                if (xmin + width >= 1)
                {
                    xmin = startxBox;
                    ymin -= height;
                }
            }

            CuiHelper.AddUi(player, container);
        }
        #endregion
    }
}

Автор
15FPS
Скачиваний
0
Просмотры
1
Первый выпуск
Обновление
Оценка
0.00 звёзд 0 оценок
Сверху