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

FREE Crafts : 2.10.18 2.10.18

Нет прав для скачивания
C#:
// Все права принадлежат дискорд сообществу https://discord.gg/VgNHPpNrz6
 // #define TESTING
#if TESTING
using System.Diagnostics;
#endif
using System;
using System.Collections;
using System.Collections.Generic;
using System.Globalization;
using Facepunch;
using Newtonsoft.Json;
using Newtonsoft.Json.Converters;
using Oxide.Core;
using Oxide.Core.Libraries;
using Oxide.Core.Libraries.Covalence;
using Oxide.Core.Plugins;
using Oxide.Game.Rust.Cui;
using Oxide.Plugins.CraftsExtensionMethods;
using Rust;
using UnityEngine;
using Debug = UnityEngine.Debug;
using Random = UnityEngine.Random;
#if CARBON
using Carbon.Base;
using Carbon.Modules;
#endif
namespace Oxide.Plugins {
    [Info("Crafts", "Mevent", "2.10.18")]
    public class Crafts : RustPlugin {
#region Fields
        [PluginReference]
        private Plugin ImageLibrary = null, SpawnModularCar = null, Notify = null, UINotify = null, LangAPI = null;
        private static Crafts _instance;
#if CARBON
        private ImageDatabaseModule imageDatabase;
#endif
        private bool _enabledImageLibrary;
        private const bool LangRu = false;
        private const string Layer = "UI.Crafts", EditLayer = "UI.Crafts.Edit", PermEdit = "crafts.edit", PermSetWb = "crafts.setworkbench", PermBypass = "crafts.bypass";
        private List<CraftInfo> _crafts = new();
        private readonly ListHashSet<RecyclerComponent> _recyclers = new();
        private readonly ListHashSet<CarController> _cars = new();
        private readonly List<BasePlayer> _openedUi = new();
        private readonly Dictionary<string, List<KeyValuePair<int, string>>> _itemsCategories = new();
        private readonly ListHashSet<SafeZoneComponent> _safeZones = new();
        private enum WorkbenchLevel {
            None = 0, One = 1, Two = 2, Three = 3
        }
        private enum CraftType {
            Command, Vehicle, Item, Recycler, ModularCar
        }
        private readonly Dictionary<int, ItemForCraft> _itemsById = new();
        private readonly Dictionary<int, CraftInfo> _craftsById = new();
        private readonly Dictionary<BasePlayer, Dictionary<string, object>> _craftEditing = new();
        private readonly Dictionary<BasePlayer, Dictionary<string, object>> _itemEditing = new();
        private readonly Dictionary<ulong, CustomWorkbenchConf> _openedCustomWb = new();
#endregion
#region Config
        private static Configuration _config;
        private class Configuration {
            [JsonProperty(PropertyName = LangRu ? "Команды" : "Commands", ObjectCreationHandling = ObjectCreationHandling.Replace)]
            public string[] Commands = {
                "craft", "crafts"
            }
            ;
            [JsonProperty(PropertyName = LangRu ? "Закрывать UI при повторном использовании команды?" : "Close UI when reusing a command?")]
            public bool CloseReusing = false;
            [JsonProperty(PropertyName = LangRu ? "Включить работу с Notify?" : "Work with Notify?")]
            public bool UseNotify = true;
            [JsonProperty(PropertyName = LangRu ? "Включить работу с LangAPI?" : "Work with LangAPI?")]
            public bool UseLangAPI = true;
            [JsonProperty(PropertyName = LangRu ? "Разрешение (пример: crafts.use)" : "Permission (ex: crafts.use)")]
            public string Permission = string.Empty;
            [JsonProperty(PropertyName = LangRu ? "Экономика" : "Economy")]
            public EconomyConf Economy = new EconomyConf {
                Show = false, Type = EconomyConf.EconomyType.Plugin, AddHook = "Deposit", BalanceHook = "Balance", RemoveHook = "Withdraw", Plug = "Economics", ShortName = "scrap", DisplayName = string.Empty, Skin = 0
            }
            ;
            [JsonProperty(PropertyName = "Categories", ObjectCreationHandling = ObjectCreationHandling.Replace)]
            public List<Category> Categories = new List<Category> {
                new Category {
                    Enabled = true, Permission = string.Empty, Title = "Vehicles", Color = IColor.Create("#161617", 100), Crafts = new List<CraftInfo> {
                        new CraftInfo.CraftInfoBuilder().SetEnabled(true).SetImage("https://i.ibb.co/mqYTq4P/image.png").SetTitle("Minicopter").SetDescription("Fast air transport").SetCmdToGive("givecopter").SetPermission("crafts.all").SetCraftableItem("electric.flasherlight", 2080145158, 1, "Minicopter").SetType(CraftType.Vehicle).SetPrefab("assets/content/vehicles/minicopter/minicopter.entity.prefab").SetCustomizeRotation(true).SetReturnItem(true).SetWorkbenchLevel(WorkbenchLevel.One).SetCraftMenuDescription(new Localization() {
                            Enabled = false, Messages = new Dictionary<string, string> {
                                ["en"]
                                = "Fast air transport", ["fr"] = "Transport aérien rapide"
                            }
                        }
                        ).Build(), new CraftInfo.CraftInfoBuilder().SetEnabled(true).SetImage("https://i.ibb.co/tmsNRcB/newkopter.png").SetTitle("Attack Helicopter").SetDescription("Fast air transport").SetCmdToGive("giveattackhelicopter").SetPermission("crafts.all").SetCraftableItem("electric.flasherlight", 3043024177, 1, "Attack Helicopter").SetType(CraftType.Vehicle).SetPrefab("assets/content/vehicles/attackhelicopter/attackhelicopter.entity.prefab").SetCustomizeRotation(true).SetReturnItem(true).SetWorkbenchLevel(WorkbenchLevel.Two).SetCraftMenuDescription(new Localization() {
                            Enabled = false, Messages = new Dictionary<string, string> {
                                ["en"]
                                = "Fast air transport", ["fr"] = "Transport aérien rapide"
                            }
                        }
                        ).Build(), new CraftInfo.CraftInfoBuilder().SetEnabled(true).SetImage("https://i.ibb.co/LJdqQ6z/image.png").SetTitle("Row Boat").SetDescription("Slow water transport").SetCmdToGive("giverowboat").SetPermission("crafts.all").SetCraftableItem("innertube", 2080150023, 1, "Row Boat").SetType(CraftType.Vehicle).SetPrefab("assets/content/vehicles/boats/rowboat/rowboat.prefab").SetCustomizeRotation(true).SetReturnItem(true).SetWorkbenchLevel(WorkbenchLevel.Two).SetCraftMenuDescription(new Localization() {
                            Enabled = false, Messages = new Dictionary<string, string> {
                                ["en"]
                                = "Slow water transport", ["fr"] = "Transport lent de l'eau"
                            }
                        }
                        ).Build(), new CraftInfo.CraftInfoBuilder().SetEnabled(true).SetImage("https://i.ibb.co/HpkTsBZ/image.png").SetTitle("RHIB").SetDescription("Slow water transport").SetCmdToGive("giverhibboat").SetPermission("crafts.all").SetCraftableItem("innertube", 2080150770, 1, "RHIB").SetType(CraftType.Vehicle).SetPrefab("assets/content/vehicles/boats/rhib/rhib.prefab").SetCustomizeRotation(true).SetReturnItem(true).SetWorkbenchLevel(WorkbenchLevel.Three).SetCraftMenuDescription(new Localization() {
                            Enabled = false, Messages = new Dictionary<string, string> {
                                ["en"]
                                = "Slow water transport", ["fr"] = "Transport lent de l'eau"
                            }
                        }
                        ).Build(), new CraftInfo.CraftInfoBuilder().SetEnabled(true).SetImage("https://i.ibb.co/gr64fDx/image.png").SetTitle("Hot Air Balloon").SetDescription("Slow air transport").SetCmdToGive("givehotair").SetPermission("crafts.all").SetCraftableItem("box.repair.bench", 2080152635, 1, "Hot Air Balloon").SetType(CraftType.Vehicle).SetPrefab("assets/prefabs/deployable/hot air balloon/hotairballoon.prefab").SetCustomizeRotation(true).SetReturnItem(true).SetWorkbenchLevel(WorkbenchLevel.Three).SetCraftMenuDescription(new Localization() {
                            Enabled = false, Messages = new Dictionary<string, string> {
                                ["en"]
                                = "Slow air transport", ["fr"] = "Lenteur du transport aérien"
                            }
                        }
                        ).Build(), new CraftInfo.CraftInfoBuilder().SetEnabled(true).SetImage("https://i.ibb.co/nzXCNws/image.png").SetTitle("Transport Helicopter").SetDescription("Fast air transport").SetCmdToGive("givescrapheli").SetPermission("crafts.all").SetCraftableItem("electric.flasherlight", 2080154394, 1, "Transport Helicopter").SetType(CraftType.Vehicle).SetPrefab("assets/content/vehicles/scrap heli carrier/scraptransporthelicopter.prefab").SetCustomizeRotation(true).SetReturnItem(true).SetWorkbenchLevel(WorkbenchLevel.Three).SetCraftMenuDescription(new Localization() {
                            Enabled = false, Messages = new Dictionary<string, string> {
                                ["en"]
                                = "Fast air transport", ["fr"] = "Transport aérien rapide"
                            }
                        }
                        ).Build(), new CraftInfo.CraftInfoBuilder().SetEnabled(true).SetImage("https://i.ibb.co/gdcVNwr/image.png").SetTitle("Snowmobile").SetDescription("Conquers snow biomes").SetCmdToGive("givesnowmobile").SetPermission("crafts.all").SetCraftableItem("electric.flasherlight", 2747934628, 1, "Snowmobile").SetType(CraftType.Vehicle).SetPrefab("assets/content/vehicles/snowmobiles/snowmobile.prefab").SetCustomizeRotation(true).SetReturnItem(true).SetWorkbenchLevel(WorkbenchLevel.Two).SetCraftMenuDescription(new Localization() {
                            Enabled = false, Messages = new Dictionary<string, string> {
                                ["en"]
                                = "Conquers snow biomes", ["fr"] = "À la conquête des biomes enneigés"
                            }
                        }
                        ).Build(), new CraftInfo.CraftInfoBuilder().SetEnabled(true).SetImage("https://i.ibb.co/jWC9Mrd/image.png").SetTitle("Submarine Solo").SetDescription("Fast underwater transport").SetCmdToGive("givesolosubmarine").SetPermission("crafts.all").SetCraftableItem("barricade.sandbags", 3043043385, 1, "Submarine Solo").SetType(CraftType.Vehicle).SetPrefab("assets/content/vehicles/submarine/submarinesolo.entity.prefab").SetCustomizeRotation(true).SetReturnItem(true).SetWorkbenchLevel(WorkbenchLevel.Three).SetCraftMenuDescription(new Localization() {
                            Enabled = false, Messages = new Dictionary<string, string> {
                                ["en"]
                                = "Fast underwater transport", ["fr"] = "Transport subaquatique rapide"
                            }
                        }
                        ).Build(), new CraftInfo.CraftInfoBuilder().SetEnabled(true).SetImage("https://i.ibb.co/qYNQhTJ/image.png").SetTitle("Submarine Duo").SetDescription("Fast underwater transport").SetCmdToGive("giveduosubmarine").SetPermission("crafts.all").SetCraftableItem("barricade.sandbags", 3043043217, 1, "Submarine Duo").SetType(CraftType.Vehicle).SetPrefab("assets/content/vehicles/submarine/submarineduo.entity.prefab").SetCustomizeRotation(true).SetReturnItem(true).SetWorkbenchLevel(WorkbenchLevel.Three).SetCraftMenuDescription(new Localization() {
                            Enabled = false, Messages = new Dictionary<string, string> {
                                ["en"]
                                = "Fast underwater transport", ["fr"] = "Transport subaquatique rapide"
                            }
                        }
                        ).Build(), new CraftInfo.CraftInfoBuilder().SetEnabled(true).SetImage("https://i.ibb.co/80hKRcm/tugboat.png").SetTitle("Tugboat").SetDescription("Slow water transport").SetCmdToGive("givetugboat").SetPermission("crafts.all").SetCraftableItem("innertube", 3043043217, 1, "Tugboat").SetType(CraftType.Vehicle).SetPrefab("assets/content/vehicles/boats/tugboat/tugboat.prefab").SetCustomizeRotation(true).SetReturnItem(true).SetWorkbenchLevel(WorkbenchLevel.Three).SetCraftMenuDescription(new Localization() {
                            Enabled = false, Messages = new Dictionary<string, string> {
                                ["en"]
                                = "Slow water transport", ["fr"] = "Transport lent de l'eau"
                            }
                        }
                        ).Build(), new CraftInfo.CraftInfoBuilder().SetEnabled(true).SetImage("https://i.ibb.co/hggGgFJ/horse.png").SetTitle("Horse").SetDescription("5KM/H").SetCmdToGive("givehorse").SetPermission("crafts.all").SetCraftableItem("barricade.sandbags", 3258220653, 1, "Horse").SetType(CraftType.Vehicle).SetPrefab("assets/rust.ai/nextai/testridablehorse.prefab").SetCustomizeRotation(true).SetReturnItem(true).SetWorkbenchLevel(WorkbenchLevel.Three).SetCraftMenuDescription(new Localization() {
                            Enabled = false, Messages = new Dictionary<string, string> {
                                ["en"]
                                = "5KM/H", ["fr"] = "5KM/H"
                            }
                        }
                        ).Build(),
                    }
                }
                , new Category {
                    Enabled = true, Permission = string.Empty, Title = "Cars", Color = IColor.Create("#161617", 100), Crafts = new List<CraftInfo> {
                        new CraftInfo.CraftInfoBuilder().SetEnabled(true).SetImage("https://i.ibb.co/MG4N1cs/image.png").SetTitle("Sedan").SetDescription("5KM/H").SetCmdToGive("givesedan").SetPermission("crafts.all").SetCraftableItem("woodcross", 2080151780, 1, "Sedan").SetType(CraftType.Vehicle).SetPrefab("assets/content/vehicles/sedan_a/sedantest.entity.prefab").SetCustomizeRotation(true).SetReturnItem(true).SetWorkbenchLevel(WorkbenchLevel.Two).SetCraftMenuDescription(new Localization() {
                            Enabled = false, Messages = new Dictionary<string, string> {
                                ["en"]
                                = "5KM/H", ["fr"] = "5KM/H"
                            }
                        }
                        ).Build(), new CraftInfo.CraftInfoBuilder().SetEnabled(true).SetImage("https://i.ibb.co/MG4N1cs/image.png").SetTitle("Ferrari").SetDescription("25KM/H").SetCmdToGive("givemod1").SetPermission("crafts.all").SetCraftableItem("electric.flasherlight", 2244308598, 1, "Ferrari").SetType(CraftType.ModularCar).SetWorkbenchLevel(WorkbenchLevel.Two).SetModular(new ModularCarConf() {
                            CodeLock = true, KeyLock = false, EnginePartsTier = 2, FreshWaterAmount = 0, FuelAmount = 140, Modules = new[] {
                                "vehicle.1mod.engine", "vehicle.1mod.cockpit.armored", "vehicle.1mod.cockpit.armored"
                            }
                        }
                        ).SetCraftMenuDescription(new Localization() {
                            Enabled = false, Messages = new Dictionary<string, string> {
                                ["en"]
                                = "25KM/H", ["fr"] = "25KM/H"
                            }
                        }
                        ).Build()
                    }
                }
                , new Category {
                    Enabled = true, Permission = string.Empty, Title = "Misc", Color = IColor.Create("#161617", 100), Crafts = new List<CraftInfo> {
                        new CraftInfo.CraftInfoBuilder().SetEnabled(true).SetImage("https://i.ibb.co/mHRkk5P/image.png").SetTitle("Home Recycler").SetCmdToGive("giverecycler").SetPermission("crafts.all").SetCraftableItem("research.table", 2186833264, 1, "Home Recycler").SetType(CraftType.Recycler).SetPrefab("assets/bundled/prefabs/static/recycler_static.prefab").SetReturnItem(true).SetWorkbenchLevel(WorkbenchLevel.Two).Build(), new CraftInfo.CraftInfoBuilder().SetEnabled(true).SetImage("https://i.ibb.co/024076x/image.png").SetCmdToGive("givelr300").SetPermission("crafts.all").SetCraftableItem("rifle.lr300").SetType(CraftType.Item).SetWorkbenchLevel(WorkbenchLevel.None).Build()
                    }
                }
            }
            ;
            [JsonProperty(PropertyName = LangRu ? "Настройка Верстаков" : "Workbenches Setting", ObjectCreationHandling = ObjectCreationHandling.Replace)]
            public Dictionary<WorkbenchLevel, IColor> Workbenches = new Dictionary<WorkbenchLevel, IColor> {
                [WorkbenchLevel.None]
                = IColor.Create("#FFFFFF", 00), [WorkbenchLevel.One] = IColor.Create("#74884A", 100), [WorkbenchLevel.Two] = IColor.Create("#B19F56", 100), [WorkbenchLevel.Three] = IColor.Create("#B43D3D", 100)
            }
            ;
            [JsonProperty(PropertyName = LangRu ? "Настройка Переработчика" : "Recycler Settings")]
            public RecyclerConfig Recycler = new RecyclerConfig {
                Enabled = true, UseSpeed = true, Speed = 5f, Radius = 7.5f, Text = "<size=19>RECYCLER</size>\n<size=15>{0}/{1}</size>", Color = "#C5D0E6", Delay = 0.75f, Available = true, Owner = true, Amounts = new[] {
                    0.9f, 0, 0, 0, 0, 0.5f, 0, 0, 0, 0.9f, 0.5f, 0.5f, 0, 1, 1, 0.5f, 0, 0, 0, 0, 0, 1, 1
                }
                , Scale = 0.5f, DDraw = true, Building = true, Destroy = new RecyclerDestroy {
                    CheckGround = true, Item = true, Effects = new List<string> {
                        "assets/bundled/prefabs/fx/item_break.prefab", "assets/bundled/prefabs/fx/impacts/stab/rock/stab_rock_01.prefab"
                    }
                }
            }
            ;
            [JsonProperty(PropertyName = LangRu ? "Настройка Машины" : "Car Settings")]
            public CarConfig Car = new CarConfig {
                ActiveItems = new ActiveItemOptions {
                    Disable = true, BlackList = new[] {
                        "explosive.timed", "rocket.launcher", "surveycharge", "explosive.satchel"
                    }
                }
                , Radius = 7.5f, Text = "<size=15>{0}/{1}</size>", Color = "#C5D0E6", Delay = 0.75f
            }
            ;
            [JsonProperty(PropertyName = LangRu ? "Кастомные верстаки (Entity ID - настройки)" : "Custom Workbench Stations (Entity ID - settings)", ObjectCreationHandling = ObjectCreationHandling.Replace)]
            public Dictionary<ulong, CustomWorkbenchConf> CustomWorkbench = new Dictionary<ulong, CustomWorkbenchConf> {
                [123343941]
                = new CustomWorkbenchConf {
                    Categories = new List<string> {
                        "Cars", "Misc"
                    }
                    , SafeZone = true, SafeZoneRadius = 5, WorkBench = new Dictionary<string, int> {
                        ["crafts.default"]
                        = 0, ["crafts.premium"] = 3
                    }
                }
            }
            ;
            [JsonProperty(PropertyName = LangRu ? "Настройка UI" : "UI Settings")]
            public UserInterface UI = new UserInterface {
                CatWidth = 90, CatMargin = 5, CatHeight = 25, Craft = new UserInterface.CraftItem {
                    Width = 125, Height = 125, Margin = 10, IndentY = -115, AmountOnString = 5, MaxLines = 2, Title = new TextSettings() {
                        AnchorMin = "0 1", AnchorMax = "1 1", OffsetMin = "0 -105", OffsetMax = "0 -80", Align = TextAnchor.MiddleCenter, IsBold = true, FontSize = 14, Color = IColor.Create("#FFFFFF")
                    }
                    , Description = new TextSettings() {
                        AnchorMin = "0 0", AnchorMax = "1 1", OffsetMin = "0 0", OffsetMax = "0 -100", Align = TextAnchor.UpperCenter, IsBold = false, FontSize = 10, Color = IColor.Create("#FFFFFF", 50)
                    }
                    , Image = new InterfacePosition() {
                        AnchorMin = "0.5 1", AnchorMax = "0.5 1", OffsetMin = "-36 -84", OffsetMax = "36 -12"
                    }
                    , WorkbenchLevelLine = new InterfacePosition() {
                        AnchorMin = "0 0", AnchorMax = "1 0", OffsetMin = "0 0", OffsetMax = "0 2"
                    }
                }
                , CategoriesAmountOnPage = 7, PageSize = 25, PageSelectedSize = 40, PagesMargin = 5, Color1 = IColor.Create("#0E0E10", 100), Color2 = IColor.Create("#161617", 100), Color3 = IColor.Create("#FFFFFF", 100), Color4 = IColor.Create("#4B68FF", 100), Color5 = IColor.Create("#74884A", 100), Color6 = IColor.Create("#CD4632", 100), Color7 = IColor.Create("#595651", 100), Color8 = IColor.Create("#4B68FF", 70), Color9 = IColor.Create("#0E0E10", 98), Color10 = IColor.Create("#4B68FF", 50), Color11 = IColor.Create("#FF4B4B", 100), BackgroundImage = string.Empty, CloseAfterCraft = true, CraftMenuSettings = new UserInterface.CraftMenu {
                    ItemWidth = 40, ItemHeight = 165, ItemMargin = 105, MaxItemsOnString = 7, ItemUpIndent = 285, Description = new PanelSettings {
                        AnchorMin = "0.5 0", AnchorMax = "0.5 0", OffsetMin = "-200 50", OffsetMax = "200 130", FontSize = 14, Align = TextAnchor.MiddleCenter, Color = IColor.Create("#FFFFFF", 100), Font = "robotocondensed-bold.ttf", BackgroundColor = IColor.Create("#0E0E10", 100)
                    }
                }
            }
            ;
            public VersionNumber Version;
        }
#region Configuration.UI
        private class ImageSettings : InterfacePosition {
            [JsonProperty(PropertyName = LangRu ? "Спрайт" : "Sprite")]
            public string Sprite;
            [JsonProperty(PropertyName = LangRu ? "Материал" : "Material")]
            public string Material;
            [JsonProperty(PropertyName = LangRu ? "Изображение" : "Image")]
            public string Image;
            [JsonProperty(PropertyName = LangRu ? "Цвет" : "Color")]
            public IColor Color;
            private ICuiComponent GetImage() {
                if (!string.IsNullOrEmpty(Image)) {
                    var rawImage = new CuiRawImageComponent {
                        Png = _instance.GetImage(Image), Color = Color.Get
                    }
                    ;
                    if (!string.IsNullOrEmpty(Sprite)) rawImage.Sprite = Sprite;
                    if (!string.IsNullOrEmpty(Material)) rawImage.Material = Material;
                    return rawImage;
                }
                var image = new CuiImageComponent {
                    Color = Color.Get
                }
                ;
                if (!string.IsNullOrEmpty(Sprite)) image.Sprite = Sprite;
                if (!string.IsNullOrEmpty(Material)) image.Material = Material;
                return image;
            }
            public CuiElement GetImage(string parent, string name = null, string destroyUI = null) {
                if (string.IsNullOrEmpty(name)) name = CuiHelper.GetGuid();
                return new CuiElement {
                    Name = name, Parent = parent, DestroyUi = destroyUI, Components = {
                        GetImage(), GetPosition()
                    }
                }
                ;
            }
        }
        private class ButtonSettings : TextSettings {
            [JsonProperty(PropertyName = LangRu ? "Цвет кнопки" : "Button Color")]
            public IColor ButtonColor;
            [JsonProperty(PropertyName = LangRu ? "Спрайт" : "Sprite")]
            public string Sprite;
            [JsonProperty(PropertyName = LangRu ? "Материал" : "Material")]
            public string Material;
            [JsonProperty(PropertyName = LangRu ? "Изображение" : "Image")]
            public string Image;
            [JsonProperty(PropertyName = LangRu ? "Цвет изображения" : "Image Color")]
            public IColor ImageColor;
            public List<CuiElement> Get(string msg, string cmd, string parent, string name = null, string destroyUI = null, string close = null) {
                if (string.IsNullOrEmpty(name)) name = CuiHelper.GetGuid();
                var list = new List<CuiElement>();
                var btn = new CuiButtonComponent {
                    Color = ButtonColor.Get
                }
                ;
                if (!string.IsNullOrEmpty(cmd)) btn.Command = cmd;
                if (!string.IsNullOrEmpty(close)) btn.Close = close;
                if (!string.IsNullOrEmpty(Sprite)) btn.Sprite = Sprite;
                if (!string.IsNullOrEmpty(Material)) btn.Material = Material;
                if (!string.IsNullOrEmpty(Image)) {
                    list.Add(new CuiElement() {
                        Name = name, Parent = parent, DestroyUi = destroyUI, Components = {
                            new CuiRawImageComponent {
                                Png = _instance.GetImage(Image), Color = ImageColor.Get
                            }
                            , GetPosition()
                        }
                    }
                    );
                    list.Add(new CuiElement() {
                        Parent = name, Components = {
                            btn, new CuiRectTransformComponent()
                        }
                    }
                    );
                }
                else {
                    list.Add(new CuiElement {
                        Name = name, Parent = parent, DestroyUi = destroyUI, Components = {
                            btn, GetPosition()
                        }
                    }
                    );
                }
                if (!string.IsNullOrEmpty(msg)) {
                    list.Add(new CuiElement {
                        Parent = name, Components = {
                            GetTextComponent(msg), new CuiRectTransformComponent()
                        }
                    }
                    );
                }
                return list;
            }
        }
        private class TextSettings : InterfacePosition {
            [JsonProperty(PropertyName = LangRu ? "Размер шрифта" : "Font Size")]
            public int FontSize;
            [JsonProperty(PropertyName = LangRu ? "Жирный?" : "Is Bold?")]
            public bool IsBold;
            [JsonProperty(PropertyName = LangRu ? "Выравнивание" : "Align")]
            [JsonConverter(typeof(StringEnumConverter))]
            public TextAnchor Align;
            [JsonProperty(PropertyName = LangRu ? "Цвет" : "Color")]
            public IColor Color;
            public CuiTextComponent GetTextComponent(string msg) {
                return new CuiTextComponent {
                    Text = msg, FontSize = FontSize, Font = IsBold ? "robotocondensed-bold.ttf" : "robotocondensed-regular.ttf", Align = Align, Color = Color.Get
                }
                ;
            }
            public CuiElement GetText(string msg, string parent, string name = null, string destroyUI = null) {
                if (string.IsNullOrEmpty(name)) name = CuiHelper.GetGuid();
                return new CuiElement {
                    Name = name, Parent = parent, DestroyUi = destroyUI, Components = {
                        GetTextComponent(msg), GetPosition()
                    }
                }
                ;
            }
        }
        private class InterfacePosition {
            public string AnchorMin;
            public string AnchorMax;
            public string OffsetMin;
            public string OffsetMax;
            public CuiRectTransformComponent GetPosition() {
                return new CuiRectTransformComponent {
                    AnchorMin = AnchorMin, AnchorMax = AnchorMax, OffsetMin = OffsetMin, OffsetMax = OffsetMax
                }
                ;
            }
        }
        public class IColor {
            [JsonProperty(PropertyName = LangRu ? "Непрозрачность (0 - 100)" : "Opacity (0 - 100)", NullValueHandling = NullValueHandling.Include)]
            public float Alpha;
            [JsonProperty(PropertyName = "HEX", NullValueHandling = NullValueHandling.Include)]
            public string Hex;
            public static IColor Create(string hex, float alpha = 100) {
                return new IColor {
                    Hex = hex, Alpha = alpha
                }
                ;
            }
            [JsonIgnore]
            private string _color;
            [JsonIgnore]
            public string Get {
                get {
                    if (string.IsNullOrEmpty(_color)) UpdateColor();
                    return _color;
                }
            }
            public void UpdateColor() {
                _color = GetColor();
            }
            private string GetColor() {
                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}";
            }
        }
#endregion Configuration.UI
        private class Localization {
            [JsonProperty(PropertyName = LangRu ? "Включено" : "Enabled")]
            public bool Enabled;
            [JsonProperty(PropertyName = LangRu ? "Текст (язык - текст)" : "Text (language - text)", ObjectCreationHandling = ObjectCreationHandling.Replace)]
            public Dictionary<string, string> Messages = new Dictionary<string, string>();
            public string GetMessage(BasePlayer player = null) {
                if (Messages.Count == 0) throw new Exception("The use of localization is enabled, but there are no messages!");
                var userLang = "en";
                if (player != null) userLang = _instance.lang.GetLanguage(player.UserIDString);
                string message;
                if (Messages.TryGetValue(userLang, out message)) return message;
                if (Messages.TryGetValue("en", out message)) return message;
                return Messages.ElementAt(0).Value;
            }
        }
        private class EconomyConf {
            public enum EconomyType {
                Plugin, Item
            }
            [JsonProperty(PropertyName = LangRu ? "Показывать Баланс" : "Show Balance")]
            public bool Show;
            [JsonProperty(PropertyName = LangRu ? "Тип (Plugin/Item)" : "Type (Plugin/Item)")]
            [JsonConverter(typeof(StringEnumConverter))]
            public EconomyType Type;
            [JsonProperty(PropertyName = "Plugin name")]
            public string Plug;
            [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 = "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.UserIDString)), 2);
                    }
                    case EconomyType.Item : {
                        return PlayerItemsCount(player, 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 "BankSystem" : case "ServerRewards" : case "IQEconomic" : plugin.Call(AddHook, player.UserIDString, (int) amount);
                            break;
                            default : plugin.Call(AddHook, player.UserIDString, 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 "BankSystem" : case "ServerRewards" : case "IQEconomic" : plugin.Call(RemoveHook, player.UserIDString, (int) amount);
                            break;
                            default : plugin.Call(RemoveHook, player.UserIDString, amount);
                            break;
                        }
                        return true;
                    }
                    case EconomyType.Item : {
                        var playerItems = Pool.Get<List<Item>>();
                        player.inventory.GetAllItems(playerItems);
                        var am = (int) amount;
                        if (ItemCount(playerItems, ShortName, Skin) < am) {
                            Pool.Free(ref playerItems);
                            return false;
                        }
                        Take(playerItems, ShortName, Skin, am);
                        Pool.Free(ref playerItems);
                        return true;
                    }
                    default : return false;
                }
            }
            public bool Transfer(BasePlayer player, BasePlayer targetPlayer, double amount) {
                if (!RemoveBalance(player, amount)) return false;
                AddBalance(targetPlayer, amount);
                return true;
            }
            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 class CustomWorkbenchConf {
            [JsonProperty(PropertyName = LangRu ? "Категории (Названия) [* - все]" : "Categories (Titles) [* - all]", ObjectCreationHandling = ObjectCreationHandling.Replace)]
            public List<string> Categories;
            [JsonProperty(PropertyName = LangRu ? "Включать safe zone" : "Use safe zone")]
            public bool SafeZone;
            [JsonProperty(PropertyName = LangRu ? "Радиус Safe Zone" : "Safe Zone Radius")]
            public float SafeZoneRadius;
            [JsonProperty(PropertyName = LangRu ? "Уровень Верстака" : "WorkBench Level", ObjectCreationHandling = ObjectCreationHandling.Replace)]
            public Dictionary<string, int> WorkBench = new Dictionary<string, int> {
                ["crafts.default"]
                = 0, ["crafts.premium"] = 0
            }
            ;
            public WorkbenchLevel GetWorkBenchLevel(BasePlayer player) {
                var result = 0;
                foreach (var check in WorkBench) if (!string.IsNullOrEmpty(check.Key) && _instance.permission.UserHasPermission(player.UserIDString, check.Key) && check.Value > result) result = check.Value;
                return (WorkbenchLevel) result;
            }
        }
        private class UserInterface {
            [JsonProperty(PropertyName = LangRu ? "Ширина категории" : "Category Width")]
            public float CatWidth;
            [JsonProperty(PropertyName = LangRu ? "Высота категории" : "Category Height")]
            public float CatHeight;
            [JsonProperty(PropertyName = LangRu ? "Отступ между категориями" : "Category Margin")]
            public float CatMargin;
            [JsonProperty(PropertyName = LangRu ? "Кол-во категорий на странице" : "Categories Amount On Page")]
            public int CategoriesAmountOnPage;
            [JsonProperty(PropertyName = LangRu ? "Крафт" : "Craft Item")]
            public CraftItem Craft;
            [JsonProperty(PropertyName = LangRu ? "Размер страницы" : "Page Size")]
            public float PageSize;
            [JsonProperty(PropertyName = LangRu ? "Размер выделенной страницы" : "Page Selected Size")]
            public float PageSelectedSize;
            [JsonProperty(PropertyName = LangRu ? "Отступ между страницами" : "Pages Margin")]
            public float PagesMargin;
            [JsonProperty(PropertyName = LangRu ? "Цвет 1" : "Color 1")]
            public IColor Color1;
            [JsonProperty(PropertyName = LangRu ? "Цвет 2" : "Color 2")]
            public IColor Color2;
            [JsonProperty(PropertyName = LangRu ? "Цвет 3" : "Color 3")]
            public IColor Color3;
            [JsonProperty(PropertyName = LangRu ? "Цвет 4" : "Color 4")]
            public IColor Color4;
            [JsonProperty(PropertyName = LangRu ? "Цвет 5" : "Color 5")]
            public IColor Color5;
            [JsonProperty(PropertyName = LangRu ? "Цвет 6" : "Color 6")]
            public IColor Color6;
            [JsonProperty(PropertyName = LangRu ? "Цвет 7" : "Color 7")]
            public IColor Color7;
            [JsonProperty(PropertyName = LangRu ? "Цвет 8" : "Color 8")]
            public IColor Color8;
            [JsonProperty(PropertyName = LangRu ? "Цвет 9" : "Color 9")]
            public IColor Color9;
            [JsonProperty(PropertyName = LangRu ? "Цвет 10" : "Color 10")]
            public IColor Color10;
            [JsonProperty(PropertyName = LangRu ? "Цвет 11" : "Color 11")]
            public IColor Color11;
            [JsonProperty(PropertyName = LangRu ? "Фоновое изображение" : "Background Image")]
            public string BackgroundImage;
            [JsonProperty(PropertyName = LangRu ? "Закрывать после крафта?" : "Close after craft?")]
            public bool CloseAfterCraft;
            [JsonProperty(PropertyName = LangRu ? "Меню крафта" : "Craft Menu")]
            public CraftMenu CraftMenuSettings;
            public class CraftMenu {
                [JsonProperty(PropertyName = LangRu ? "Ширина предмета" : "Item Width")]
                public float ItemWidth;
                [JsonProperty(PropertyName = LangRu ? "Высота предмета" : "Item Height")]
                public float ItemHeight;
                [JsonProperty(PropertyName = LangRu ? "Отступ между предметами" : "Item Margin")]
                public float ItemMargin;
                [JsonProperty(PropertyName = LangRu ? "Максимальное кол-во предметов на строке" : "Max Items On String")]
                public int MaxItemsOnString;
                [JsonProperty(PropertyName = LangRu ? "Верхний отступ для предметов" : "Item Up Indent")]
                public float ItemUpIndent;
                [JsonProperty(PropertyName = LangRu ? "Описание" : "Description")]
                public PanelSettings Description;
            }
            public class CraftItem {
                [JsonProperty(PropertyName = LangRu ? "Ширина" : "Width")]
                public float Width;
                [JsonProperty(PropertyName = LangRu ? "Высота" : "Height")]
                public float Height;
                [JsonProperty(PropertyName = LangRu ? "Отступ между" : "Margin")]
                public float Margin;
                [JsonProperty(PropertyName = LangRu ? "Отступ сверху" : "Y Indent")]
                public float IndentY;
                [JsonProperty(PropertyName = LangRu ? "Кол-во на строке" : "Amount On String")]
                public int AmountOnString;
                [JsonProperty(PropertyName = LangRu ? "Максимальное количество строк" : "Max Lines")]
                public int MaxLines;
                [JsonProperty(PropertyName = LangRu ? "Название" : "Title")]
                public TextSettings Title;
                [JsonProperty(PropertyName = LangRu ? "Описание" : "Description")]
                public TextSettings Description;
                [JsonProperty(PropertyName = LangRu ? "Изображение" : "Image")]
                public InterfacePosition Image;
                [JsonProperty(PropertyName = LangRu ? "Линия уровня верстака" : "Workbench Level Line")]
                public InterfacePosition WorkbenchLevelLine;
            }
        }
        private class LabelSettings : InterfacePosition {
            [JsonProperty(PropertyName = "FontSize")]
            public int FontSize;
            [JsonProperty(PropertyName = "Align")]
            [JsonConverter(typeof(StringEnumConverter))]
            public TextAnchor Align;
            [JsonProperty(PropertyName = "Color")]
            public IColor Color;
            [JsonProperty(PropertyName = "Font")]
            public string Font;
        }
        private class PanelSettings : LabelSettings {
            [JsonProperty(PropertyName = "Background Color")]
            public IColor BackgroundColor;
        }
        private class Category {
            [JsonProperty(PropertyName = LangRu ? "Включено" : "Enabled")]
            public bool Enabled;
            [JsonProperty(PropertyName = LangRu ? "Разрешение (пример: crafts.vip)" : "Permission (ex: crafts.vip)")]
            public string Permission;
            [JsonProperty(PropertyName = LangRu ? "Название" : "Title")]
            public string Title;
            [JsonProperty(PropertyName = LangRu ? "Фоновый цвет" : "Background color")]
            public IColor Color;
            [JsonProperty(PropertyName = LangRu ? "Предметы" : "Items", ObjectCreationHandling = ObjectCreationHandling.Replace)]
            public List<CraftInfo> Crafts;
        }
        private class CraftInfo {
#region Fields
            [JsonProperty(PropertyName = "ID")]
            public int ID;
            [JsonProperty(PropertyName = LangRu ? "Включено" : "Enabled")]
            public bool Enabled;
            [JsonProperty(PropertyName = LangRu ? "Изображение" : "Image")]
            public string Image;
            [JsonProperty(PropertyName = LangRu ? "Название" : "Title")]
            public string Title;
            [JsonProperty(PropertyName = LangRu ? "Описание" : "Description")]
            public string Description;
            [JsonProperty(PropertyName = LangRu ? "Команда (для выдачи предмета)" : "Command (to give an item)")]
            public string CmdToGive;
            [JsonProperty(PropertyName = LangRu ? "Разрешение (пример: crafts.vip)" : "Permission (ex: crafts.vip)")]
            public string Permission;
            [JsonProperty(PropertyName = LangRu ? "Отображаемое имя" : "Display Name")]
            public string DisplayName;
            [JsonProperty(PropertyName = LangRu ? "Shortname" : "ShortName")]
            public string ShortName;
            [JsonProperty(PropertyName = LangRu ? "Количество" : "Amount")]
            public int Amount;
            [JsonProperty(PropertyName = LangRu ? "Скин" : "Skin")]
            public ulong SkinID;
            [JsonProperty(PropertyName = LangRu ? "Тип (Item/Command/Vehicle/Recycler)" : "Type (Item/Command/Vehicle/Recycler)")]
            [JsonConverter(typeof(StringEnumConverter))]
            public CraftType Type;
            [JsonProperty(PropertyName = LangRu ? "Префаб" : "Prefab")]
            public string Prefab;
            [JsonProperty(PropertyName = LangRu ? "Команда при получении" : "Command on give")]
            public string GiveCommand;
            [JsonProperty(PropertyName = LangRu ? "Уровень верстака" : "Workbench Level")]
            public WorkbenchLevel Level;
            [JsonProperty(PropertyName = LangRu ? "Проверять дистацию" : "Distance Check")]
            public bool UseDistance;
            [JsonProperty(PropertyName = LangRu ? "Дистанция" : "Distance")]
            public float Distance;
            [JsonProperty(PropertyName = LangRu ? "Установка на землю" : "Place the ground")]
            public bool Ground;
            [JsonProperty(PropertyName = LangRu ? "Установка на строение" : "Place the structure")]
            public bool Structure;
            [JsonProperty(PropertyName = LangRu ? "Предметы для крафта" : "Items For Craft", ObjectCreationHandling = ObjectCreationHandling.Replace)]
            public List<ItemForCraft> Items;
            [JsonProperty(PropertyName = LangRu ? "Modular Car" : "For Modular Car")]
            public ModularCarConf Modular;
            [JsonProperty(PropertyName = LangRu ? "Задержка" : "Cooldown")]
            public float Cooldown;
            [JsonProperty(PropertyName = LangRu ? "Множественный крафт" : "Multiple Craft")]
            public bool MultipleCraft;
            [JsonProperty(PropertyName = LangRu ? "Максимальное количество крафтов" : "Maximum number of crafts")]
            public int MaxAmount;
            [JsonProperty(PropertyName = LangRu ? "Включить Крафт?" : "Enable Craft?")]
            public bool Craft;
            [JsonProperty(PropertyName = LangRu ? "Включить Продажу?" : "Enable Sales?")]
            public bool Sale;
            [JsonProperty(PropertyName = LangRu ? "Стоимость" : "Cost")]
            public float Cost;
            [JsonProperty(PropertyName = LangRu ? "Установить OwnerID для дочерних контейнеров?" : "Set OwnerID for child containers?")]
            public bool SetOwnerID;
            [JsonProperty(PropertyName = LangRu ? "Необходимо настроить ротацию при спавне?" : "Need to customize the rotation when spawning?")]
            public bool CustomizeRotationOnSpawning;
            [JsonProperty(PropertyName = LangRu ? "Настройки описания (в меню крафта)" : "Description settings (in the craft menu)")]
            public Localization CraftMenuDescription;
            [JsonProperty(PropertyName = LangRu ? "Должен ли предмет быть возвращен после его удаления? (с помощью плагина BuildTools)" : "Should the item be returned when it is removed? (using the BuildTools plugin)")]
            public bool ReturnItem;
            [JsonProperty(PropertyName = LangRu ? "Выдавая предмет игроку, разбивай его на стаки?" : "When giving an item to a player, split it into stacks?")]
            public bool SplitStacks;
            [JsonProperty(PropertyName = LangRu ? "Выдавать предмет одним стаком?" : "Give an item to a single stack?")]
            public b
// ... [Code preview truncated due to length. Full source in attached file] ...

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