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

FREE Skills : 1.29.1 1.29.1

Нет прав для скачивания
C#:
// Reference: EasyAntiCheat.Server

using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using ConVar;
using Newtonsoft.Json;
using Newtonsoft.Json.Converters;
using Oxide.Core;
using Oxide.Core.Libraries.Covalence;
using Oxide.Core.Plugins;
using Oxide.Game.Rust.Cui;
using Rust;
using UnityEngine;
using Object = UnityEngine.Object;
using Pool = Facepunch.Pool;
using Random = UnityEngine.Random;
using Time = UnityEngine.Time;

namespace Oxide.Plugins
{
    [Info("Skills", "Mevent", "1.29.1")]
    [Description("Adds a system of skills")]
    public class Skills : RustPlugin
    {
        #region Fields

        [PluginReference] private Plugin ImageLibrary, Notifications, Notify, UINotify, TimedPermissions;

        private const string Layer = "Com.Mevent.Main";

        private static Skills _instance;

        private readonly Dictionary<BasePlayer, RecoverComponent> _recoverPlayers =
            new Dictionary<BasePlayer, RecoverComponent>();

        private readonly List<uint> _containers = new List<uint>();

        private readonly List<FurnaceController> _furnaceControllers = new List<FurnaceController>();

        private readonly Dictionary<SkillType, Skill> _skillByType = new Dictionary<SkillType, Skill>();

        private enum SkillType
        {
            Wood,
            Stones,
            Metal,
            Sulfur,
            Attack,
            Secure,
            Regeneration,
            Metabolism,
            ComponentsRates,
            StandUpChance,
            CraftSpeed,
            FastOven,
            Kits,
            None,
            Cloth,
            Butcher,
            Scrap
        }

        #endregion

        #region Config

        private static Configuration _config;

        private class Configuration
        {
            [JsonProperty(PropertyName = "Разрешение | Permission (example: skills.use)")]
            public readonly string Permission = string.Empty;

            [JsonProperty(PropertyName = "Команда | Command")]
            public readonly string Command = "skills";

            [JsonProperty(PropertyName = "Автоматический вайп? | Automatic wipe?")]
            public readonly bool Wipe = true;

            [JsonProperty(PropertyName = "Work with Notify?")]
            public readonly bool UseNotify = true;

            [JsonProperty(PropertyName = "Экономика | Economy")]
            public readonly EconomyConf Economy = new EconomyConf
            {
                Type = EconomyType.Plugin,
                AddHook = "Deposit",
                BalanceHook = "Balance",
                RemoveHook = "Withdraw",
                Plug = "Economics",
                ShortName = "scrap",
                DisplayName = string.Empty,
                Skin = 0
            };

            [JsonProperty(PropertyName = "Оповещение о максимальном уровне | Maximum level alert")]
            public readonly INotify MaxLevel = new INotify
            {
                Image = "warning",
                Url = "https://i.imgur.com/p3tKXJV.png",
                Delay = 0.9f
            };

            [JsonProperty(PropertyName = "Оповещение о нехватке баланса | Out of balance alert")]
            public readonly INotify NotMoney = new INotify
            {
                Image = "warning",
                Url = "https://i.imgur.com/p3tKXJV.png",
                Delay = 0.9f
            };

            [JsonProperty(PropertyName = "Фон | Background")]
            public readonly IPanel Background = new IPanel
            {
                AnchorMin = "0 0", AnchorMax = "1 1",
                OffsetMin = "0 0", OffsetMax = "0 0",
                Image = string.Empty,
                Color = new IColor("#0D1F4E", 95),
                isRaw = false,
                Sprite = "Assets/Content/UI/UI.Background.Tile.psd",
                Material = "Assets/Icons/IconMaterial.mat"
            };

            [JsonProperty(PropertyName = "Заглавие | Title")]
            public readonly IText Title = new IText
            {
                AnchorMin = "0.5 0.5", AnchorMax = "0.5 0.5",
                OffsetMin = "-150 300", OffsetMax = "150 360",
                Font = "robotocondensed-bold.ttf",
                Align = TextAnchor.MiddleCenter,
                FontSize = 38,
                Color = new IColor("#FFFFFF", 100)
            };

            [JsonProperty(PropertyName = "Назад | Back")]
            public readonly IText Back = new IText
            {
                AnchorMin = "0 0.5", AnchorMax = "0 0.5",
                OffsetMin = "0 -40", OffsetMax = "65 40",
                Font = "robotocondensed-bold.ttf",
                Align = TextAnchor.MiddleCenter,
                FontSize = 60,
                Color = new IColor("#FFFFFF", 100)
            };

            [JsonProperty(PropertyName = "Вперёд | Next")]
            public readonly IText Next = new IText
            {
                AnchorMin = "1 0.5", AnchorMax = "1 0.5",
                OffsetMin = "-65 -40", OffsetMax = "0 40",
                Font = "robotocondensed-bold.ttf",
                Align = TextAnchor.MiddleCenter,
                FontSize = 60,
                Color = new IColor("#FFFFFF", 100)
            };


            [JsonProperty(PropertyName = "Баланс | Balance")]
            public readonly IText BalanceText = new IText
            {
                AnchorMin = "0.5 0", AnchorMax = "0.5 0",
                OffsetMin = "-150 0", OffsetMax = "150 75",
                Font = "robotocondensed-regular.ttf",
                Align = TextAnchor.MiddleCenter,
                FontSize = 24,
                Color = new IColor("#FFFFFF", 100)
            };

            [JsonProperty(PropertyName = "Включить иконку баланса | Enable Balance Icon")]
            public bool EnableBalanceIcon;

            [JsonProperty(PropertyName = "Иконка Баланса | Balance Icon")]
            public readonly BalanceIcon BalanceIcon = new BalanceIcon
            {
                OffsetMinY = 20,
                OffsetMaxY = 55,
                Length = 35
            };

            [JsonProperty(PropertyName = "Закрыть | Close")]
            public readonly IText Close = new IText
            {
                AnchorMin = "1 1", AnchorMax = "1 1",
                OffsetMin = "-35 -35", OffsetMax = "-5 -5",
                Font = "robotocondensed-bold.ttf",
                Align = TextAnchor.MiddleCenter,
                FontSize = 24,
                Color = new IColor("#FFFFFF", 100)
            };

            [JsonProperty(PropertyName = "Способность | Skill Panel")]
            public readonly SkillPanel SkillPanel = new SkillPanel
            {
                Background = new SIPanel
                {
                    Image = string.Empty,
                    Color = new IColor("#1D3676", 98),
                    isRaw = false,
                    Sprite = "Assets/Content/UI/UI.Background.Tile.psd",
                    Material = "Assets/Icons/IconMaterial.mat",
                    HeightCorrect = 5
                },
                Image = new InterfacePosition
                {
                    AnchorMin = "0 0", AnchorMax = "0 0",
                    OffsetMin = "10 10", OffsetMax = "160 160"
                },
                Title = new IText
                {
                    AnchorMin = "0 0", AnchorMax = "1 0",
                    OffsetMin = "165 135", OffsetMax = "-5 160",
                    Align = TextAnchor.MiddleLeft,
                    FontSize = 20,
                    Font = "robotocondensed-bold.ttf",
                    Color = new IColor("#FFFFFF", 100)
                },
                Description = new IText
                {
                    AnchorMin = "0 0", AnchorMax = "1 0",
                    OffsetMin = "165 30", OffsetMax = "-5 130",
                    Align = TextAnchor.UpperLeft,
                    FontSize = 14,
                    Font = "robotocondensed-regular.ttf",
                    Color = new IColor("#FFFFFF", 100)
                },
                Button = new IButton
                {
                    AnchorMin = "1 0", AnchorMax = "1 0",
                    OffsetMin = "-105 10", OffsetMax = "-10 30",
                    AColor = new IColor("#B5FFC9", 100),
                    DColor = new IColor("#B5FFC9", 25),
                    TextUi = new IText
                    {
                        AnchorMin = "0 0", AnchorMax = "1 1",
                        OffsetMin = "0 0", OffsetMax = "0 0",
                        Align = TextAnchor.MiddleCenter,
                        FontSize = 14,
                        Font = "robotocondensed-regular.ttf",
                        Color = new IColor("#1D3676", 100)
                    }
                },
                Cost = new IText
                {
                    AnchorMin = "1 0", AnchorMax = "1 0",
                    OffsetMin = "-150 10", OffsetMax = "-110 30",
                    Align = TextAnchor.MiddleRight,
                    FontSize = 14,
                    Font = "robotocondensed-regular.ttf",
                    Color = new IColor("#FFFFFF", 100)
                },
                AddCost = "$",
                EnableCostImage = false,
                AddCostImage = new IPanel
                {
                    AnchorMin = "1 0", AnchorMax = "1 0",
                    OffsetMin = "-130 10", OffsetMax = "-110 30",
                    Color = new IColor("#FFFFFF", 100),
                    isRaw = true,
                    Image = "https://i.imgur.com/5GdD0cU.png",
                    Sprite = string.Empty,
                    Material = string.Empty
                },
                Stages = new IProgress
                {
                    AnchorMin = "0 0", AnchorMax = "0 0",
                    OffsetMin = "160 10", OffsetMax = "160 10",
                    Height = 20,
                    Weidth = 10,
                    Margin = 5,
                    AColor = new IColor("#8C70D6", 100),
                    DColor = new IColor("#8C70D6", 25)
                },
                Count = 6,
                Height = 170,
                Width = 565,
                Margin = 20
            };

            [JsonProperty(PropertyName = "Способности | Skills",
                ObjectCreationHandling = ObjectCreationHandling.Replace)]
            public readonly List<Skill> Skills = new List<Skill>
            {
                new Skill
                {
                    Type = SkillType.Wood,
                    Image = "https://gspics.org/images/2020/09/02/xz6Fy.png",
                    Title = "Дровосек",
                    Description = "Отвечает за добычу дерева\nИзучив способность, рейт добычи увеличивается на x1",
                    Stages = new Dictionary<int, StageConf>
                    {
                        [1] = new StageConf(10, 133, 0),
                        [2] = new StageConf(25, 164, 0),
                        [3] = new StageConf(40, 200, 0)
                    }
                },
                new Skill
                {
                    Type = SkillType.Stones,
                    Image = "https://gspics.org/images/2020/09/02/xz9mX.png",
                    Title = "Камнедобыча",
                    Description = "Отвечает за добычу камня\nИзучив способность, рейт добычи увеличивается на x1",
                    Stages = new Dictionary<int, StageConf>
                    {
                        [1] = new StageConf(10, 133, 0),
                        [2] = new StageConf(25, 164, 0),
                        [3] = new StageConf(40, 200, 0)
                    }
                },
                new Skill
                {
                    Type = SkillType.Metal,
                    Image = "https://gspics.org/images/2020/09/02/xznT3.png",
                    Title = "Чернорабочий",
                    Description =
                        "Отвечает за добычу железной руды\nИзучив способность, рейт добычи увеличивается на x1",
                    Stages = new Dictionary<int, StageConf>
                    {
                        [1] = new StageConf(10, 133, 0),
                        [2] = new StageConf(25, 164, 0),
                        [3] = new StageConf(40, 200, 0)
                    }
                },
                new Skill
                {
                    Type = SkillType.Sulfur,
                    Image = "https://gspics.org/images/2020/09/02/xz4te.png",
                    Title = "Серодобытчик",
                    Description = "Отвечает за добычу серной руды\nИзучив способность, рейт добычи увеличивается на x1",
                    Stages = new Dictionary<int, StageConf>
                    {
                        [1] = new StageConf(10, 133, 0),
                        [2] = new StageConf(25, 164, 0),
                        [3] = new StageConf(40, 200, 0)
                    }
                },
                new Skill
                {
                    Type = SkillType.Attack,
                    Image = "https://gspics.org/images/2020/09/02/xzXza.png",
                    Title = "Нападение",
                    Description =
                        "Изменяет величину урона любого оружия\nИзучив способность, Вы увеличите свой урон на 15%",
                    Stages = new Dictionary<int, StageConf>
                    {
                        [1] = new StageConf(20, 5, 0),
                        [2] = new StageConf(35, 10, 0),
                        [3] = new StageConf(50, 15, 0)
                    }
                },
                new Skill
                {
                    Type = SkillType.Secure,
                    Image = "https://gspics.org/images/2020/09/02/xzAfi.png",
                    Title = "Защита",
                    Description =
                        "Изменяет величину урона любого оружия\nИзучив способность, Вы увеличите свою защиту на 15%",
                    Stages = new Dictionary<int, StageConf>
                    {
                        [1] = new StageConf(20, 5, 0),
                        [2] = new StageConf(35, 10, 0),
                        [3] = new StageConf(50, 15, 0)
                    }
                },
                new Skill
                {
                    Type = SkillType.Regeneration,
                    Image = "https://gspics.org/images/2020/09/02/xzGrO.png",
                    Title = "Регенерация",
                    Description =
                        "Скоростная регенерация здоровья\nИзучив способность, Вы учеличите скорость регенерации на 90%",
                    Stages = new Dictionary<int, StageConf>
                    {
                        [1] = new StageConf(10, 50, 0),
                        [2] = new StageConf(15, 70, 0),
                        [3] = new StageConf(20, 90, 0)
                    }
                },
                new Skill
                {
                    Type = SkillType.Metabolism,
                    Image = "https://gspics.org/images/2020/09/02/xzWdI.png",
                    Title = "Метаболизм",
                    Description =
                        "Изменяет восстановление жажды и голода\nИзучив способность, Вы получите восполнение каллорий и гидратации",
                    Stages = new Dictionary<int, StageConf>
                    {
                        [1] = new StageConf(10, 0.5f, 0),
                        [2] = new StageConf(15, 1, 0),
                        [3] = new StageConf(20, 2, 0)
                    }
                },
                new Skill
                {
                    Type = SkillType.ComponentsRates,
                    Image = "https://gspics.org/images/2020/09/02/xz15L.png",
                    Title = "Рейты на компоненты",
                    Description =
                        "Изменяет рейты добываемых компонентов\nИзучив способность, найденные компоненты будут x4",
                    Stages = new Dictionary<int, StageConf>
                    {
                        [1] = new StageConf(10, 2, 0),
                        [2] = new StageConf(15, 3, 0),
                        [3] = new StageConf(20, 4, 0)
                    }
                },
                new Skill
                {
                    Type = SkillType.StandUpChance,
                    Image = "https://gspics.org/images/2020/09/02/xzTDD.png",
                    Title = "Увеличение шанса встать",
                    Description =
                        "Увеличивает шанс подняться, когда вы ранены\nИзучив способность, шанс увеличивается с стандартных 20% до 50%",
                    Stages = new Dictionary<int, StageConf>
                    {
                        [1] = new StageConf(10, 30, 40),
                        [2] = new StageConf(15, 40, 50),
                        [3] = new StageConf(20, 50, 60)
                    }
                },
                new Skill
                {
                    Type = SkillType.CraftSpeed,
                    Image = "https://i.imgur.com/fAti1Cj.png",
                    Title = "Скорость крафта",
                    Description =
                        "Ускоряет крафт.\nИзучив способность, вы сможете крафтить почти моментально",
                    Stages = new Dictionary<int, StageConf>
                    {
                        [1] = new StageConf(10, 30, 0),
                        [2] = new StageConf(15, 40, 0),
                        [3] = new StageConf(20, 50, 0)
                    }
                },
                new Skill
                {
                    Type = SkillType.Kits,
                    Image = "https://i.imgur.com/Log7sQR.png",
                    Title = "Ускорение наборов",
                    Description =
                        "Ускоряет задержку между получением наборов",
                    Stages = new Dictionary<int, StageConf>
                    {
                        [1] = new StageConf(10, 30, 0),
                        [2] = new StageConf(15, 40, 0),
                        [3] = new StageConf(20, 50, 0)
                    }
                },
                new Skill
                {
                    Type = SkillType.FastOven,
                    Image = "https://i.imgur.com/IifHk5l.png",
                    Title = "Ускорение печей",
                    Description =
                        "Ускорение плавки в печах",
                    Stages = new Dictionary<int, StageConf>
                    {
                        [1] = new StageConf(10, 133, 0),
                        [2] = new StageConf(25, 164, 0),
                        [3] = new StageConf(40, 200, 0)
                    }
                },
                new Skill
                {
                    ID = 0,
                    Type = SkillType.None,
                    Image = "https://i.imgur.com/RqdcAm0.png",
                    Title = "Сортировка",
                    Description =
                        "На каждом этапе открываются новые виды сортировки",
                    Stages = new Dictionary<int, StageConf>
                    {
                        [1] = new StageConf(25, 0, 0, new List<string>(), new List<string>(), new List<string>
                        {
                            "furnacesplitter.use"
                        }),
                        [2] = new StageConf(40, 0, 0, new List<string>(), new List<string>(), new List<string>
                        {
                            "activesort.use"
                        })
                    }
                },
                new Skill
                {
                    ID = 1,
                    Type = SkillType.None,
                    Image = "https://i.imgur.com/S4xulmj.png",
                    Title = "Телепортация",
                    Description =
                        "Вы телепортируетесь быстрее с каждым этапом",
                    Stages = new Dictionary<int, StageConf>
                    {
                        [1] = new StageConf(30, 0, 0, new List<string>(), new List<string>(), new List<string>
                        {
                            "nteleportation.vip"
                        }),
                        [2] = new StageConf(50, 0, 0, new List<string>(), new List<string>(), new List<string>
                        {
                            "nteleportation.premium"
                        }),
                        [2] = new StageConf(80, 0, 0, new List<string>(), new List<string>(), new List<string>
                        {
                            "nteleportation.deluxe"
                        })
                    }
                },
                new Skill
                {
                    Type = SkillType.Cloth,
                    Image = "https://i.imgur.com/5fixMch.png",
                    Title = "Сборщик конопли",
                    Description =
                        "Отвечает за сбор ткани\nИзучив способность, рейт добычи увеличивается на x1",
                    Stages = new Dictionary<int, StageConf>
                    {
                        [1] = new StageConf(10, 133, 0),
                        [2] = new StageConf(25, 164, 0),
                        [3] = new StageConf(40, 200, 0)
                    }
                },
                new Skill
                {
                    Type = SkillType.Butcher,
                    Image = "https://i.imgur.com/4WlHK7u.png",
                    Title = "Butcher",
                    Description =
                        "Отвечает за добычу животных\nИзучив способность, рейт добычи увеличивается на x1",
                    Stages = new Dictionary<int, StageConf>
                    {
                        [1] = new StageConf(10, 133, 0),
                        [2] = new StageConf(25, 164, 0),
                        [3] = new StageConf(40, 200, 0)
                    }
                },
                new Skill
                {
                    Type = SkillType.Scrap,
                    Image = "https://i.imgur.com/SEvG4EU.png",
                    Title = "Scrap",
                    Description =
                        "Изменяет рейты добычи скрапа\nИзучив способность, найденный скрап будет x4",
                    Stages = new Dictionary<int, StageConf>
                    {
                        [1] = new StageConf(10, 2, 0),
                        [2] = new StageConf(15, 3, 0),
                        [3] = new StageConf(20, 4, 0)
                    }
                }
            };

            [JsonProperty(PropertyName = "Животные | Animals", ObjectCreationHandling = ObjectCreationHandling.Replace)]
            public readonly List<string> Animals = new List<string>
            {
                "chicken.corpse",
                "boar.corpse",
                "bear.corpse",
                "wolf.corpse",
                "stag.corpse"
            };

            [JsonProperty(PropertyName = "Чёрный список печей | Ovens Black List",
                ObjectCreationHandling = ObjectCreationHandling.Replace)]
            public readonly List<string> OvensBlackList = new List<string>
            {
                "entity shortnameprefab 1",
                "entity shortnameprefab 2"
            };

            [JsonProperty(PropertyName = "Чёрный список контейнеров | Containers Black List",
                ObjectCreationHandling = ObjectCreationHandling.Replace)]
            public readonly List<string> ContainersBlackList = new List<string>
            {
                "entity prefab name 1",
                "entity prefab name 2"
            };

            [JsonProperty(PropertyName = "Чёрный список для навыка Attack | Blacklist for Attack skill",
                ObjectCreationHandling = ObjectCreationHandling.Replace)]
            public readonly List<string> AttackBlackList = new List<string>
            {
                "entity prefab name 1",
                "entity prefab name 2"
            };

            public VersionNumber Version;
        }

        private class INotify
        {
            [JsonProperty(PropertyName = "Ключ изображения | Image Key")]
            public string Image;

            [JsonProperty(PropertyName = "Ссылка на изображение | Image Url")]
            public string Url;

            [JsonProperty(PropertyName = "Время показа | Show Time")]
            public float Delay;
        }

        private enum EconomyType
        {
            Plugin,
            Item
        }

        private class EconomyConf
        {
            [JsonProperty(PropertyName = "Тип (Plugin/Item)")] [JsonConverter(typeof(StringEnumConverter))]
            public EconomyType Type;

            [JsonProperty(PropertyName = "Функция пополнения баланса | Balance add hook")]
            public string AddHook;

            [JsonProperty(PropertyName = "Функция снятия баланса | Balance remove hook")]
            public string RemoveHook;

            [JsonProperty(PropertyName = "Функция показа баланса | Balance show hook")]
            public string BalanceHook;

            [JsonProperty(PropertyName = "Название плагина | Plugin name")]
            public string Plug;

            [JsonProperty(PropertyName = "ShortName")]
            public string ShortName;

            [JsonProperty(PropertyName = "Display Name (пусто - стандартное | empty - default)")]
            public string DisplayName;

            [JsonProperty(PropertyName = "Skin")] public ulong Skin;

            public double ShowBalance(BasePlayer player)
            {
                switch (Type)
                {
                    case EconomyType.Plugin:
                    {
                        var plugin = _instance?.plugins?.Find(Plug);
                        if (plugin == null) return 0;

                        return Math.Round(Convert.ToDouble(plugin.Call(BalanceHook, player.userID)));
                    }
                    case EconomyType.Item:
                    {
                        return ItemCount(player.inventory.AllItems(), ShortName, Skin);
                    }
                    default:
                        return 0;
                }
            }

            public void AddBalance(BasePlayer player, double amount)
            {
                switch (Type)
                {
                    case EconomyType.Plugin:
                    {
                        var plugin = _instance?.plugins?.Find(Plug);
                        if (plugin == null) return;

                        switch (Plug)
                        {
                            case "Economics":
                                plugin.Call(AddHook, player.userID, amount);
                                break;
                            default:
                                plugin.Call(AddHook, player.userID, (int) amount);
                                break;
                        }

                        break;
                    }
                    case EconomyType.Item:
                    {
                        var am = (int) amount;

                        var item = ToItem(am);
                        if (item == null) return;

                        player.GiveItem(item);
                        break;
                    }
                }
            }

            public bool RemoveBalance(BasePlayer player, double amount)
            {
                switch (Type)
                {
                    case EconomyType.Plugin:
                    {
                        if (ShowBalance(player) < amount) return false;

                        var plugin = _instance?.plugins.Find(Plug);
                        if (plugin == null) return false;

                        switch (Plug)
                        {
                            case "Economics":
                                plugin.Call(RemoveHook, player.userID, amount);
                                break;
                            default:
                                plugin.Call(RemoveHook, player.userID, (int) amount);
                                break;
                        }

                        return true;
                    }
                    case EconomyType.Item:
                    {
                        var playerItems = player.inventory.AllItems();
                        var am = (int) amount;

                        if (ItemCount(playerItems, ShortName, Skin) < am) return false;

                        Take(playerItems, ShortName, Skin, am);
                        return true;
                    }
                    default:
                        return false;
                }
            }

            private Item ToItem(int amount)
            {
                var item = ItemManager.CreateByName(ShortName, amount, Skin);
                if (item == null)
                {
                    Debug.LogError($"Error creating item with ShortName: '{ShortName}'");
                    return null;
                }

                if (!string.IsNullOrEmpty(DisplayName)) item.name = DisplayName;

                return item;
            }

            private int ItemCount(Item[] items, string shortname, ulong skin)
            {
                return items.Where(item =>
                        item.info.shortname == shortname && !item.isBroken && (skin == 0 || item.skin == skin)).Sum(item => item.amount);
            }

            private void Take(IEnumerable<Item> itemList, string shortname, ulong skinId, int iAmount)
            {
                var num1 = 0;
                if (iAmount == 0) return;

                var list = Pool.GetList<Item>();

                foreach (var item in itemList)
                {
                    if (item.info.shortname != shortname ||
                        skinId != 0 && item.skin != skinId || item.isBroken) continue;

                    var num2 = iAmount - num1;
                    if (num2 <= 0) continue;
                    if (item.amount > num2)
                    {
                        item.MarkDirty();
                        item.amount -= num2;
                        num1 += num2;
                        break;
                    }

                    if (item.amount <= num2)
                    {
                        num1 += item.amount;
                        list.Add(item);
                    }

                    if (num1 == iAmount)
                        break;
                }

                foreach (var obj in list)
                    obj.RemoveFromContainer();

                Pool.FreeList(ref list);
            }
        }

        private class Skill
        {
            [JsonProperty(PropertyName = "Включено | Enabled")]
            public bool Enabled;

            [JsonProperty(PropertyName = "Разрешение | Permission")]
            public string Permission;

            [JsonProperty(PropertyName = "Тип | Type")] [JsonConverter(typeof(StringEnumConverter))]
            public SkillType Type;

            [JsonProperty(PropertyName = "ID (для/for None)")]
            public int ID;

            [JsonProperty(PropertyName = "Изображение | Image")]
            public string Image;

            [JsonProperty(PropertyName = "Название | Title")]
            public string Title;

            [JsonProperty(PropertyName = "Описание | Description")]
            public string Description;

            [JsonProperty(PropertyName = "Уровни | Levels", ObjectCreationHandling = ObjectCreationHandling.Replace)]
            public Dictionary<int, StageConf> Stages;
        }

        private class StageConf
        {
            [JsonProperty(PropertyName = "Стоимость | Cost")]
            public readonly float Cost;

            [JsonProperty(PropertyName =
                "Значение [метаболизм - значение, шанс встать - шанс, для всех остальных процент %] | VALUE")]
            public readonly float Value;

            [JsonProperty(PropertyName = "Значение 2")]
            public readonly float Value2;

            [JsonProperty(PropertyName = "Команды | Commands", ObjectCreationHandling = ObjectCreationHandling.Replace)]
            public readonly List<string> Commands;

            [JsonProperty(PropertyName = "Группы | Groups", ObjectCreationHandling = ObjectCreationHandling.Replace)]
            public readonly List<string> Groups;

            [JsonProperty(PropertyName = "Разрешения | Permissions",
                ObjectCreationHandling = ObjectCreationHandling.Replace)]
            public readonly List<string> Permissions;

            public StageConf(float cost, float value, float value2)
            {
                Cost = cost;
                Value = value;
                Value2 = value2;
                Commands = new List<string>();
                Groups = new List<string>();
                Permissions = new List<string>();
            }

            [JsonConstructor]
            public StageConf(float cost, float value, float value2, List<string> commands, List<string> groups,
                List<string> permissions)
            {
                Cost = cost;
                Value = value;
                Value2 = value2;
                Commands = commands;
                Groups = groups;
                Permissions = permissions;
            }
        }

        private class BalanceIcon
        {
            [JsonProperty(PropertyName = "Offset Min Y")]
            public float OffsetMinY;

            [JsonProperty(PropertyName = "Offset Max Y")]
            public float OffsetMaxY;

            [JsonProperty(PropertyName = "Длина | Length")]
            public float Length;
        }

        private class SkillPanel
        {
            [JsonProperty(PropertyName = "Фон | Background")]
            public SIPanel Background;

            [JsonProperty(PropertyName = "Изображение | Image")]
            public InterfacePosition Image;

            [JsonProperty(PropertyName = "Заглавие | Title")]
            public IText Title;

            [JsonProperty(PropertyName = "Описание | Description")]
            public IText Description;

            [JsonProperty(PropertyName = "Кнопка | Button")]
            public IButton Button;

            [JsonProperty(PropertyName = "Стоимость | Cost")]
            public IText Cost;

            [JsonProperty(PropertyName = "Приписка к стоимости | Add to cost")]
            public string AddCost;

            [JsonProperty(PropertyName = "Включить пририску к стоимости (изображение) | Enable Add to cost (image)")]
            public bool EnableCostImage;

            [JsonProperty(PropertyName = "Приписка к стоимости (изображение) | Add to cost (image)")]
            public IPanel AddCostImage;

            [JsonProperty(PropertyName = "Уровни | Levels")]
            public IProgress Stages;

            [JsonProperty(PropertyName = "Количество на страницу | Count On Page")]
            public int Count;

            [JsonProperty(PropertyName = "Высота | Height")]
            public float Height;

            [JsonProperty(PropertyName = "Ширина | Width")]
            public float Width;

            [JsonProperty(PropertyName = "Отступ | Margin")]
            public float Margin;

            public void Get(ref CuiElementContainer container, string layer, int page, string parent, int index,
                BasePlayer player, Skill skill,
                float oMinX, float oMinY, float oMaxX, float oMaxY)
            {
                Background?.Get(ref container, parent, parent + $".Skill.{index}", oMinX, oMinY, oMaxX, oMaxY);

                container.Add(new CuiElement
                {
                    Parent = parent + $".Skill.{index}",
                    Components =
                    {
                        new CuiRawImageComponent
                            {Png = _instance?.ImageLibrary?.Call<string>("GetImage", skill.Image)},
                        new CuiRectTransformComponent
                        {
                            AnchorMin = Image.AnchorMin, AnchorMax = Image.AnchorMax, OffsetMin = Image.OffsetMin,
                            OffsetMax = Image.OffsetMax
                        }
                    }
                });

                Title?.Get(ref container, parent + $".Skill.{index}", null, skill.Title);

                Description?.Get(ref container, parent + $".Skill.{index}", null, skill.Description);

                var cost = _instance?.GetNextPrice(player.userID, skill) ?? -1;

                Button?.Get(ref container, player, parent + $".Skill.{index}", null,
                    $"UI_Skills upgrade {skill.Type} {page} {layer} {skill.ID}", "", cost > 0);

                if (cost > 0) Cost?.Get(ref container, parent + $".Skill.{index}", null, $"{cost}{AddCost}");

                #region Stages

                container.Add(new CuiPanel
                {
                    RectTransform =
                    {
                        AnchorMin = Stages.AnchorMin, AnchorMax = Stages.AnchorMax,
                        OffsetMin = Stages.OffsetMin, OffsetMax = Stages.OffsetMax
                    },
                    Image = {Color = "0 0 0 0"}
                }, parent + $".Skill.{index}", parent + $".Skill.{index}.Stages");

                var skillData = _instance?.GetPlayerData(player.userID)?.Skills
                    ?.FirstOrDefault(x => x.Type == skill.Type);

                var xSwitch = 0f;
                foreach (var i in skill.Stages.Keys)
                {
                    var color = skillData != null && i <= skillData.Stage ? Stages.AColor : Stages.DColor;

                    container.Add(new CuiPanel
                    {
                        RectTransform =
                        {
                            AnchorMin = "0 0", AnchorMax = "0 0",
                            OffsetMin = $"{xSwitch} 0", OffsetMax = $"{xSwitch + Stages.Weidth} {Stages.Height}"
                        },
                        Image = {Color = color.Get()}
                    }, parent + $".Skill.{index}.Stages", parent + $".Skill.{index}.Stages.{i}");

                    xSwitch += Stages.Weidth + Stages.Margin;
                }

                #endregion
            }
        }

        private class IProgress : InterfacePosition
        {
            [JsonProperty(PropertyName = "Высота | Height")]
            public float Height;

            [JsonProperty(PropertyName = "Ширина | Weidth")]
            public float Weidth;

            [JsonProperty(PropertyName = "Отступ | Margin")]
            public float Margin;

            [JsonProperty(PropertyName = "Активный цвет | Active Color")]
            public IColor AColor;

            [JsonProperty(PropertyName = "Не активный цвет | No Active Color")]
            public IColor DColor;
        }

        private class IButton : InterfacePosition
        {
            [JsonProperty(PropertyName = "Цвет | Color")]
            public IColor AColor;

            [JsonProperty(PropertyName = "Не активный цвет | No Active Color")]
            public IColor DColor;

            [JsonProperty(PropertyName = "Настройка текста | Text Setting")]
            public IText TextUi;

            public void Get(ref CuiElementContainer container, BasePlayer player, string parent, string name = null,
                string cmd = "",
                string close = "", bool color = true)
            {
                if (string.IsNullOrEmpty(name))
                    name = CuiHelper.GetGuid();

                container.Add(new CuiPanel
                {
                    RectTransform =
                    {
                        AnchorMin = AnchorMin, AnchorMax = AnchorMax, OffsetMin = OffsetMin,
                        OffsetMax = OffsetMax
                    },
                    Image = {Color = color ? AColor.Get() : DColor.Get()}
                }, parent, name);

                TextUi?.Get(ref container, name, null, _instance.Msg(Upgrade, player.UserIDString));

                container.Add(new CuiButton
                {
                    RectTransform = {AnchorMin = "0 0", AnchorMax = "1 1"},
                    Text = {Text = ""},
                    Button =
                    {
                        Command = cmd,
                        Close = close,
                        Color = "0 0 0 0"
                    }
                }, name);
            }
        }

        private class SIPanel
        {
            [JsonProperty(PropertyName = "Изображение | Image")]
            public string Image;

            [JsonProperty(PropertyName = "Цвет | Color")]
            public IColor Color;

            [JsonProperty(PropertyName = "Сохранять цвет изображения? | Save Image Color")]
            public bool isRaw;

            [JsonProperty(PropertyName = "Sprite")]
            public string Sprite;

            [JsonProperty(PropertyName = "Material")]
            public string Material;

            [JsonProperty(PropertyName = "Отклонение по высоте | Height deviation")]
            public float HeightCorrect;

            public void Get(ref CuiElementContainer container, string parent = "Hud", string name = null,
                float oMinX = 0, float oMinY = 0, float oMaxX = 0, float oMaxY = 0)
            {
                if (string.IsNullOrEmpty(name))
                    name = CuiHelper.GetGuid();

                if (isRaw)
                    container.Add(new CuiElement
                    {
                        Name = name,
                        Parent = parent,
                        Components =
                        {
                            new CuiRawImageComponent
                            {
                                Png = !string.IsNullOrEmpty(Image)
                                    ? _instance.ImageLibrary.Call<string>("GetImage", Image)
                                    : null,
                                Color = Color.Get(),
                                Material = Material,
                                Sprite = !string.IsNullOrEmpty(Sprite) ? Sprite : "Assets/Icons/rust.png"
                            },
                            new CuiRectTransformComponent
                            {
                                AnchorMin = "0.5 0.5", AnchorMax = "0.5 0.5",
                                OffsetMin = $"{oMinX} {oMinY + HeightCorrect}",
                                OffsetMax = $"{oMaxX} {oMaxY + HeightCorrect}"
                            }
                        }
                    });
                else
                    container.Add(new CuiPanel
                    {
                        RectTransform =
                        {
                            AnchorMin = "0.5 0.5", AnchorMax = "0.5 0.5",
                            OffsetMin = $"{oMinX} {oMinY + HeightCorrect}",
                            OffsetMax = $"{oMaxX} {oMaxY + HeightCorrect}"
                        },
                        Image =
                        {
                            Png = !string.IsNullOrEmpty(Image)
                                ? _instance.ImageLibrary.Call<string>("GetImage", Image)
                                : null,
                            Color = Color.Get(),
                            Sprite =
                                !string.IsNullOrEmpty(Sprite) ? Sprite : "Assets/Content/UI/UI.Background.Tile.psd",
                            Material = !string.IsNullOrEmpty(Material) ? Material : "Assets/Icons/IconMaterial.mat"
                        }
                    }, parent, name);
            }
        }

        private class InterfacePosition
        {
            public string AnchorMin;

            public string AnchorMax;

            public string OffsetMin;

            public string OffsetMax;
        }

        private class IColor
        {
            [JsonProperty(PropertyName = "HEX")] public string HEX;

            [JsonProperty(PropertyName = "Непрозрачность | Opacity (0 - 100)")]
            public readonly float Alpha;

            public string Get()
            {
                if (string.IsNullOrEmpty(HEX)) HEX = "#FFFFFF";

                var str = HEX.Trim('#');
                if (str.Length != 6) throw new Exception(HEX);
                var r = byte.Parse(str.Substring(0, 2), NumberStyles.HexNumber);
                var g = byte.Parse(str.Substring(2, 2), NumberStyles.HexNumber);
                var b = byte.Parse(str.Substring(4, 2), NumberStyles.HexNumber);

                return $"{(double) r / 255} {(double) g / 255} {(double) b / 255} {Alpha / 100}";
            }

            public IColor(string hex, float alpha)
            {
                HEX = hex;
                Alpha = alpha;
            }
        }

        private class IPanel : InterfacePosition
        {
            [JsonProperty(PropertyName = "Изображение | Image")]
            public string Image;

            [JsonProperty(PropertyName = "Цвет | Color")]
            public IColor Color;

            [JsonProperty(PropertyName = "Сохранять цвет изображения? | Save Image Color")]
            public bool isRaw;

            [JsonProperty(PropertyName = "Sprite")]
            public string Sprite;

            [JsonProperty(PropertyName = "Material")]
            public string Material;

            public void Get(ref CuiElementContainer container, string parent = "Hud", string name = null,
                bool cursor = false)
            {
                if (string.IsNullOrEmpty(name))
                    name = CuiHelper.GetGuid();

                if (isRaw)
                {
                    var element = new CuiElement
                    {
                        Name = name,
                        Parent = parent,
                        Components =
                        {
                            new CuiRawImageComponent
                            {
                                Png = !string.IsNullOrEmpty(Image)
                                    ? _instance.ImageLibrary.Call<string>("GetImage", Image)
                                    : null,
                                Color = Color.Get(),
                                Material = Material,
                                Sprite = !string.IsNullOrEmpty(Sprite) ? Sprite : "Assets/Icons/rust.png"
                            },
                            new CuiRectTransformComponent
                            {
                                AnchorMin = AnchorMin, AnchorMax = AnchorMax, OffsetMin = OffsetMin,
                                OffsetMax = OffsetMax
                            }
                        }
                    };

                    if (cursor) element.Components.Add(new CuiNeedsCursorComponent());

                    container.Add(element);
                }
                else
                {
                    container.Add(new CuiPanel
                    {
                        RectTransform =
                        {
                            AnchorMin = AnchorMin, AnchorMax = AnchorMax, OffsetMin = OffsetMin, OffsetMax = OffsetMax
                        },
                        Image =
                        {
                            Png = !string.IsNullOrEmpty(Image)
                                ? _instance.ImageLibrary.Call<string>("GetImage", Image)
                                : null,
                            Color = Color.Get(),
                            Sprite =
                                !string.IsNullOrEmpty(Sprite) ? Sprite : "Assets/Content/UI/UI.Background.Tile.psd",
                            Material = !string.IsNullOrEmpty(Material) ? Material : "Assets/Icons/IconMaterial.mat"
                        },
                        CursorEnabled = cursor
                    }, parent, name);
      
// ... [Code preview truncated due to length. Full source in attached file] ...

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