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

FREE CaseSystem : 1.0.5 1.0.5

Нет прав для скачивания
C#:
// Все права принадлежат дискорд сообществу https://discord.gg/VgNHPpNrz6
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using ConVar;
using Newtonsoft.Json;
using Oxide.Core;
using Oxide.Core.Plugins;
using Oxide.Game.Rust.Cui;
using Steamworks;
using UnityEngine;
using Random = UnityEngine.Random;
using System.IO;
using Facepunch.Extend;
using UnityEngine.UI;
namespace Oxide.Plugins;
[Info("CaseSystem", "Forum: https://topplugin.ru Ds: alone_sempai Vk: https://vk.com/rustnastroika", "1.0.5")]
internal class CaseSystem : RustPlugin {
    [PluginReference]
    private Plugin ServerRewards, Economics, IQEconomic, BankSystem;
    private Configuration _config;
    private readonly Dictionary<string, int> _shortNameToItemID = new();
    private const bool isEn = false;
#region Config
    private class Configuration {
        [JsonProperty(PropertyName = isEn ? "Should I use the item issue limit?" : "Использовать лимит выдачи предметов?", ObjectCreationHandling = ObjectCreationHandling.Replace)]
        public bool isLimitReward = true;
        [JsonProperty(PropertyName = isEn ? "Setting up privileges for the item issue limit" : "Настройка привилегий для лимита выдачи предметов", ObjectCreationHandling = ObjectCreationHandling.Replace)]
        public Dictionary<string, int> PermList = new() {
            ["casesystem.default"]
            = 5, ["casesystem.vip"] = 7,
        }
        ;
        [JsonProperty(PropertyName = isEn ? "Economics Plugin(1 - Economics, 2 - Server Rewards, 3 - IQEconomic, 4 - Bank System, 5 - Cases)" : "Плагин экономики(1 - Economics, 2 - ServerRewards, 3 - IQEconomic, 4 - BankSystem, 5 - Cases)")]
        public int EconomyPlugin = 5;
        [JsonProperty(PropertyName = isEn ? "Color adjustment(chance-color)" : "Настройка цветов(шанс-цвет)", ObjectCreationHandling = ObjectCreationHandling.Replace)]
        public Dictionary<int, string> ColorList = new() {
            [15]
            = "0.96 0.76 0.37 1.00", [40] = "1.00 0.29 0.30 1.00", [80] = "0.68 0.25 1.00 1.00", [100] = "0.24 0.59 1.00 1.00",
        }
        ;
        [JsonProperty(PropertyName = isEn ? "List of awards" : "Список наград", ObjectCreationHandling = ObjectCreationHandling.Replace)]
        public List<ItemSettings> RewardList = new List<ItemSettings>() {
            new ItemSettings() {
                RewardID = "1", Amount = 1, Chance = 2, Command = "", Shortname = "minigun", ItemImage = "", SkinID = 0
            }
            , new ItemSettings() {
                RewardID = "2", Amount = 1, Chance = 5, Command = "", Shortname = "lmg.m249", ItemImage = "", SkinID = 0
            }
            , new ItemSettings() {
                RewardID = "3", Amount = 1, Chance = 10, Command = "", Shortname = "hmlmg", ItemImage = "", SkinID = 0
            }
            , new ItemSettings() {
                RewardID = "4", Amount = 1, Chance = 15, Command = "", Shortname = "rifle.l96", ItemImage = "", SkinID = 0
            }
            , new ItemSettings() {
                RewardID = "5", Amount = 1, Chance = 35, Command = "", Shortname = "rifle.lr300", ItemImage = "", SkinID = 0
            }
            , new ItemSettings() {
                RewardID = "6", Amount = 1, Chance = 35, Command = "", Shortname = "rifle.ak", ItemImage = "", SkinID = 0
            }
            , new ItemSettings() {
                RewardID = "7", Amount = 1, Chance = 30, Command = "", Shortname = "rifle.sks", ItemImage = "", SkinID = 0
            }
            , new ItemSettings() {
                RewardID = "8", Amount = 1, Chance = 30, Command = "", Shortname = "rifle.bolt", ItemImage = "", SkinID = 0
            }
            , new ItemSettings() {
                RewardID = "9", Amount = 1, Chance = 50, Command = "", Shortname = "smg.mp5", ItemImage = "", SkinID = 0
            }
            , new ItemSettings() {
                RewardID = "10", Amount = 1, Chance = 55, Command = "", Shortname = "rifle.semiauto", ItemImage = "", SkinID = 0
            }
            , new ItemSettings() {
                RewardID = "11", Amount = 1, Chance = 60, Command = "", Shortname = "smg.thompson", ItemImage = "", SkinID = 0
            }
            , new ItemSettings() {
                RewardID = "12", Amount = 1, Chance = 70, Command = "", Shortname = "pistol.m92", ItemImage = "", SkinID = 0
            }
            , new ItemSettings() {
                RewardID = "13", Amount = 1, Chance = 70, Command = "", Shortname = "pistol.prototype17", ItemImage = "", SkinID = 0
            }
            , new ItemSettings() {
                RewardID = "14", Amount = 1, Chance = 75, Command = "", Shortname = "pistol.semiauto", ItemImage = "", SkinID = 0
            }
            , new ItemSettings() {
                RewardID = "15", Amount = 1, Chance = 80, Command = "", Shortname = "pistol.python", ItemImage = "", SkinID = 0
            }
            , new ItemSettings() {
                RewardID = "16", Amount = 1, Chance = 95, Command = "", Shortname = "pistol.revolver", ItemImage = "", SkinID = 0
            }
            , new ItemSettings() {
                RewardID = "17", Amount = 1, Chance = 5, Command = "", Shortname = "electric.generator.small", ItemImage = "", SkinID = 0
            }
            , new ItemSettings() {
                RewardID = "18", Amount = 1, Chance = 10, Command = "", Shortname = "workbench3", ItemImage = "", SkinID = 0
            }
            , new ItemSettings() {
                RewardID = "19", Amount = 1, Chance = 10, Command = "", Shortname = "workbench2", ItemImage = "", SkinID = 0
            }
            , new ItemSettings() {
                RewardID = "20", Amount = 1, Chance = 15, Command = "", Shortname = "autoturret", ItemImage = "", SkinID = 0
            }
            , new ItemSettings() {
                RewardID = "21", Amount = 1, Chance = 25, Command = "", Shortname = "door.double.hinged.toptier", ItemImage = "", SkinID = 0
            }
            , new ItemSettings() {
                RewardID = "22", Amount = 1, Chance = 25, Command = "", Shortname = "door.hinged.toptier", ItemImage = "", SkinID = 0
            }
            , new ItemSettings() {
                RewardID = "23", Amount = 1, Chance = 35, Command = "", Shortname = "furnace.large", ItemImage = "", SkinID = 0
            }
            , new ItemSettings() {
                RewardID = "24", Amount = 1, Chance = 35, Command = "", Shortname = "small.oil.refinery", ItemImage = "", SkinID = 0
            }
            , new ItemSettings() {
                RewardID = "25", Amount = 1, Chance = 45, Command = "", Shortname = "water.catcher.small", ItemImage = "", SkinID = 0
            }
            , new ItemSettings() {
                RewardID = "26", Amount = 1, Chance = 45, Command = "", Shortname = "storage_barrel_b", ItemImage = "", SkinID = 0
            }
            , new ItemSettings() {
                RewardID = "27", Amount = 1, Chance = 45, Command = "", Shortname = "storage_barrel_c", ItemImage = "", SkinID = 0
            }
            , new ItemSettings() {
                RewardID = "28", Amount = 1, Chance = 45, Command = "", Shortname = "gunrack_stand", ItemImage = "", SkinID = 0
            }
            , new ItemSettings() {
                RewardID = "29", Amount = 1, Chance = 55, Command = "", Shortname = "gunrack_wide.horizontal", ItemImage = "", SkinID = 0
            }
            , new ItemSettings() {
                RewardID = "30", Amount = 1, Chance = 65, Command = "", Shortname = "flameturret", ItemImage = "", SkinID = 0
            }
            , new ItemSettings() {
                RewardID = "31", Amount = 1, Chance = 75, Command = "", Shortname = "furnace", ItemImage = "", SkinID = 0
            }
            , new ItemSettings() {
                RewardID = "32", Amount = 1, Chance = 75, Command = "", Shortname = "cupboard.tool.retro", ItemImage = "", SkinID = 0
            }
            , new ItemSettings() {
                RewardID = "33", Amount = 1, Chance = 10, Command = "", Shortname = "rocket.launcher", ItemImage = "", SkinID = 0
            }
            , new ItemSettings() {
                RewardID = "34", Amount = 1, Chance = 15, Command = "", Shortname = "ammo.rocket.basic", ItemImage = "", SkinID = 0
            }
            , new ItemSettings() {
                RewardID = "35", Amount = 1, Chance = 15, Command = "", Shortname = "ammo.rocket.mlrs", ItemImage = "", SkinID = 0
            }
            , new ItemSettings() {
                RewardID = "36", Amount = 1, Chance = 25, Command = "", Shortname = "ammo.rocket.hv", ItemImage = "", SkinID = 0
            }
            , new ItemSettings() {
                RewardID = "37", Amount = 1, Chance = 30, Command = "", Shortname = "ammo.grenadelauncher.he", ItemImage = "", SkinID = 0
            }
            , new ItemSettings() {
                RewardID = "38", Amount = 1, Chance = 35, Command = "", Shortname = "multiplegrenadelauncher", ItemImage = "", SkinID = 0
            }
            , new ItemSettings() {
                RewardID = "39", Amount = 1, Chance = 50, Command = "", Shortname = "ammo.rifle.explosive", ItemImage = "", SkinID = 0
            }
            , new ItemSettings() {
                RewardID = "40", Amount = 1, Chance = 60, Command = "", Shortname = "explosive.satchel", ItemImage = "", SkinID = 0
            }
            , new ItemSettings() {
                RewardID = "41", Amount = 1, Chance = 70, Command = "", Shortname = "grenade.beancan", ItemImage = "", SkinID = 0
            }
            , new ItemSettings() {
                RewardID = "42", Amount = 1, Chance = 5, Command = "", Shortname = "rocket.launcher.dragon", ItemImage = "", SkinID = 0
            }
            , new ItemSettings() {
                RewardID = "43", Amount = 1, Chance = 10, Command = "", Shortname = "coffin.storage", ItemImage = "", SkinID = 0
            }
            , new ItemSettings() {
                RewardID = "44", Amount = 1, Chance = 15, Command = "", Shortname = "legacyfurnace", ItemImage = "", SkinID = 0
            }
            , new ItemSettings() {
                RewardID = "45", Amount = 1, Chance = 25, Command = "", Shortname = "hobobarrel", ItemImage = "", SkinID = 0
            }
            , new ItemSettings() {
                RewardID = "46", Amount = 1, Chance = 35, Command = "", Shortname = "heavyscientistyoutooz", ItemImage = "", SkinID = 0
            }
            , new ItemSettings() {
                RewardID = "47", Amount = 1, Chance = 35, Command = "", Shortname = "hazmatyoutooz", ItemImage = "", SkinID = 0
            }
            , new ItemSettings() {
                RewardID = "48", Amount = 1, Chance = 60, Command = "", Shortname = "cursedcauldron", ItemImage = "", SkinID = 0
            }
            , new ItemSettings() {
                RewardID = "49", Amount = 1, Chance = 75, Command = "", Shortname = "abovegroundpool", ItemImage = "", SkinID = 0
            }
            , new ItemSettings() {
                RewardID = "50", Amount = 1, Chance = 80, Command = "", Shortname = "rail.road.planter", ItemImage = "", SkinID = 0
            }
            , new ItemSettings() {
                RewardID = "51", Amount = 1, Chance = 85, Command = "", Shortname = "wall.graveyard.fence", ItemImage = "", SkinID = 0
            }
            , new ItemSettings() {
                RewardID = "52", Amount = 1, Chance = 95, Command = "", Shortname = "newyeargong", ItemImage = "", SkinID = 0
            }
        }
        ;
        [JsonProperty(PropertyName = isEn ? "Cases" : "Список кейсов", ObjectCreationHandling = ObjectCreationHandling.Replace)]
        public List<Case> CaseList = new() {
            new Case() {
                Id = "1", DisplayName = "Armory", Image = "https://unityplugincore.ru/imgs/images/2024/09/23/ORUZEINYI.png", Price = 100
            }
            , new Case() {
                Id = "2", DisplayName = "Home", Image = "https://unityplugincore.ru/imgs/images/2024/09/23/DOMASNII.png", Price = 125
            }
            , new Case() {
                Id = "3", DisplayName = "Raider", Image = "https://unityplugincore.ru/imgs/images/2024/09/23/REIDERSKII.png", Price = 150
            }
            , new Case() {
                Id = "4", DisplayName = "DLC", Image = "https://unityplugincore.ru/imgs/images/2024/09/23/DLS.png", Price = 150
            }
        }
        ;
        internal class Case {
            [JsonProperty(PropertyName = isEn ? "Case ID" : "ID кейса", ObjectCreationHandling = ObjectCreationHandling.Replace)]
            public string Id = "1";
            [JsonProperty(PropertyName = isEn ? "Case name" : "Название кейса", ObjectCreationHandling = ObjectCreationHandling.Replace)]
            public string DisplayName = "New case";
            [JsonProperty(PropertyName = isEn ? "Image of the case" : "Картинка кейса", ObjectCreationHandling = ObjectCreationHandling.Replace)]
            public string Image;
            [JsonProperty(PropertyName = isEn ? "Discription of the case" : "Описание кейса", ObjectCreationHandling = ObjectCreationHandling.Replace)]
            public string Description = "There will be a description of your case here";
            [JsonProperty(PropertyName = isEn ? "Price of the case" : "Стоимость кейса", ObjectCreationHandling = ObjectCreationHandling.Replace)]
            public int Price = 100;
            [JsonProperty(PropertyName = isEn ? "List the case items" : "Список предметом (Указать только ID предмета из списка наград", ObjectCreationHandling = ObjectCreationHandling.Replace)]
            public List<string> ItemList = new List<string>() {
                "1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13", "14", "15", "16",
            }
            ;
        }
        internal class ItemSettings {
            [JsonProperty(PropertyName = isEn ? "Item ID (Indicated in the list of items in the case)" : "ID предмета (Указывается в списке предметов кейса)", ObjectCreationHandling = ObjectCreationHandling.Replace)]
            public string RewardID = Random.Range(0, 100000).ToString();
            [JsonProperty(PropertyName = isEn ? "Shortname" : "Shortname", ObjectCreationHandling = ObjectCreationHandling.Replace)]
            public string Shortname = "scrap";
            [JsonProperty(PropertyName = isEn ? "Amount" : "Кол-во", ObjectCreationHandling = ObjectCreationHandling.Replace)]
            public int Amount = 1;
            [JsonProperty(PropertyName = isEn ? "Drop chance" : "Шанс выпадения", ObjectCreationHandling = ObjectCreationHandling.Replace)]
            public int Chance = 20;
            [JsonProperty(PropertyName = isEn ? "Name the item" : "Имя предмета", ObjectCreationHandling = ObjectCreationHandling.Replace)]
            public string displayName = "";
            [JsonProperty(PropertyName = isEn ? "Price the item" : "Стоимость предмета", ObjectCreationHandling = ObjectCreationHandling.Replace)]
            public int Price;
            [JsonProperty(PropertyName = isEn ? "URL image the item" : "Картинка кастомного предмета", ObjectCreationHandling = ObjectCreationHandling.Replace)]
            public string ItemImage;
            [JsonProperty(PropertyName = isEn ? "SkinID " : "SkinID ", ObjectCreationHandling = ObjectCreationHandling.Replace)]
            public ulong SkinID = 0;
            [JsonProperty(PropertyName = isEn ? "Console command" : "Команда которая должна выполниться", ObjectCreationHandling = ObjectCreationHandling.Replace)]
            public string Command = "o.grant user %STEAMID% vip";
            [JsonIgnore]
            private ICuiComponent _image;
            public CuiElement GetImageNonCached(string aMin, string aMax, string oMin, string oMax, string parent, string name = null, float fadein = 0, bool update = false, float fadeOut = 0f) {
                ICuiComponent _image = null;
                if (!string.IsNullOrEmpty(ItemImage)) _image = new CuiRawImageComponent {
                    Png = GuiManager.Get(ItemImage), FadeIn = fadein
                }
                ;
                else {
                    var def = ItemManager.FindItemDefinition(Shortname);
                    if (def == null) {
                        Debug.LogError($"[CaseSystem] Shortname {Shortname} is invalid!");
                        return new();
                    }
                    _image = new CuiImageComponent {
                        ItemId = ItemManager.FindItemDefinition(Shortname).itemid, SkinId = SkinID, FadeIn = fadein
                    }
                    ;
                }
                return new CuiElement {
                    Name = string.IsNullOrEmpty(name) ? CuiHelper.GetGuid() : name, Parent = parent, FadeOut = fadeOut, Update = update, Components = {
                        _image, new CuiRectTransformComponent {
                            AnchorMin = aMin, AnchorMax = aMax, OffsetMin = oMin, OffsetMax = oMax
                        }
                    }
                }
                ;
            }
            public CuiElement GetImage(string aMin, string aMax, string oMin, string oMax, string parent, string name = null) {
                if (_image == null) {
                    if (!string.IsNullOrEmpty(ItemImage)) _image = new CuiRawImageComponent {
                        Png = GuiManager.Get(ItemImage)
                    }
                    ;
                    else {
                        var def = ItemManager.FindItemDefinition(Shortname);
                        if (def == null) {
                            Debug.LogError($"[CaseSystem] Shortname {Shortname} is invalid!");
                            return new();
                        }
                        _image = new CuiImageComponent {
                            ItemId = ItemManager.FindItemDefinition(Shortname).itemid, SkinId = SkinID,
                        }
                        ;
                    }
                }
                return new CuiElement {
                    Name = string.IsNullOrEmpty(name) ? CuiHelper.GetGuid() : name, Parent = parent, Components = {
                        _image, new CuiRectTransformComponent {
                            AnchorMin = aMin, AnchorMax = aMax, OffsetMin = oMin, OffsetMax = oMax
                        }
                    }
                }
                ;
            }
        }
    }
    protected override void LoadConfig() {
        base.LoadConfig();
        try {
            _config = Config.ReadObject<Configuration>();
            if (_config == null) throw new Exception();
            SaveConfig();
        }
        catch {
            PrintError("Your configuration file contains an error.Using default configuration values.");
            LoadDefaultConfig();
        }
    }
    protected override void SaveConfig() {
        Config.WriteObject(_config);
    }
    protected override void LoadDefaultConfig() {
        _config = new Configuration();
    }
#endregion
#region Data
    private Dictionary<ulong, Data> _data;
    private class Data {
        public DateTime LastReset = DateTime.MinValue;
        public int AmountToUse = 0;
        public int Balance = 0;
        public Dictionary<string, int> CaseList = new();
        public List<string> Inventory = new();
        public bool FastOpenCase = false;
        public bool IsOpeningCase() => OpeningRoutine != null;
        [JsonIgnore]
        public Coroutine OpeningRoutine;
    }
    private void LoadData() {
        if (!Interface.Oxide.DataFileSystem.ExistsDatafile($"MM_Data/{Name}/PlayerData")) _data = new Dictionary<ulong, Data>();
        else _data = Interface.Oxide.DataFileSystem.ReadObject<Dictionary<ulong, Data>>($"MM_Data/{Name}/PlayerData");
        Interface.Oxide.DataFileSystem.WriteObject($"MM_Data/{Name}/PlayerData", _data);
        if (_data == null) _data = new Dictionary<ulong, Data>();
        foreach (var check in _data.ToArray()) {
            if (check.Value.Inventory.Count == 0 && check.Value.CaseList.Count == 0 && check.Value.Balance == 0) {
                _data.Remove(check.Key);
            }
        }
        foreach (var check in BasePlayer.activePlayerList) OnPlayerConnected(check);
        SaveData();
    }
    private void Init() {
        LoadData();
    }
    private void OnServerSave() {
        SaveData();
    }
    private void SaveData() {
        Interface.Oxide.DataFileSystem.WriteObject($"MM_Data/{Name}/PlayerData", _data);
    }
    private void OnPlayerConnected(BasePlayer player) {
        if (!_data.ContainsKey(player.userID)) _data.Add(player.userID, new Data());
        var amount = GetAmount(player);
        if (_data[player.userID].LastReset.Date != DateTime.Now.Date &&amount > 0) {
            _data[player.userID].LastReset = DateTime.Now.Date;
            _data[player.userID].AmountToUse = amount;
        }
    }
    private int GetAmount(BasePlayer player) {
        int number = 0;
        foreach(var check in _config.PermList) if (permission.UserHasPermission(player.UserIDString, check.Key)) number = Math.Max(number, check.Value);
        return number;
    }
#endregion
#region OxideHooks
    private void OnSectionChanged(BasePlayer player, string section) {
        if (_data.TryGetValue(player.userID, out var data)) if (data.OpeningRoutine != null) {
            player.StopCoroutine(data.OpeningRoutine);
            data.OpeningRoutine = null;
        }
    }
    private Dictionary<string, Configuration.ItemSettings> RewardsCache = new();
    private void OnServerInitialized() {
        foreach (var check in ItemManager.itemList.OrderBy(p => p.category.ToString())) {
            _shortNameToItemID.Add(check.shortname, check.itemid);
        }
        foreach (var check in _config.PermList) {
            permission.RegisterPermission(check.Key, this);
        }
        // foreach (var check in _config.CaseList)
        // {
        //     if (!string.IsNullOrEmpty(check.Image))
        //     {
        //         ImageSettingsList.Add(new ImageSettings()
        //         {
        //             Name = check.Image,
        //             Url = check.Image,
        //         });
        //     }
        //
        //
        // }
        foreach (var x in _config.RewardList) {
            if (!RewardsCache.ContainsKey(x.RewardID)) RewardsCache.Add(x.RewardID, x);
        }
        List<string> images = new();
        images.Add("item_background");
        foreach (var x in _config.CaseList) if (!string.IsNullOrEmpty(x.Image)) images.Add(x.Image);
        foreach (var x in _config.RewardList) if (!string.IsNullOrEmpty(x.ItemImage)) images.Add(x.ItemImage);
        GuiManager.LoadImages(images);
        // foreach (var item in _config.RewardList)
        // {
        //     if (!string.IsNullOrEmpty(item.ItemImage))
        //     {
        //         ImageSettingsList.Add(new ImageSettings()
        //         {
        //             Name = item.ItemImage,
        //             Url = item.ItemImage,
        //         });
        //     }
        // }
        SaveConfig();
        // DownloadImage();
        PrintWarning($"|  Plugin {Title} v{Version} is loaded  |");
    }
    // [ChatCommand("cases")]
    private void CmdChatcases(BasePlayer player, string command, string[] args) {
        ShowMainUI(player, 0);
    }
    private void Unload() {
        foreach (var x in BasePlayer.activePlayerList) {
            if (_data.TryGetValue(x.userID, out var data)) if (data.OpeningRoutine != null) x.StopCoroutine(data.OpeningRoutine);
        }
        GuiManager.Clear();
        SaveData();
    }
#endregion
#region Function
    [ConsoleCommand("UI_CASESS")]
    private void CmdConsoleUI_CASES(ConsoleSystem.Arg arg) {
        var player = arg.Player();
        switch (arg.Args[0]) {
            case "SELL" : {
                var id = arg.Args[1];
                var posId = arg.Args[2].ToInt();
                if(!_data[player.userID].Inventory.Contains(id)) return;
                var reward = _config.RewardList.FirstOrDefault(p => p.RewardID == id);
                if (reward == null) {
                    PrintWarning(isEn? $"The player has a reward {id}, but it is not in the config" : $"У игрока есть награда {id}, но в конфиге ее нет");
                    return;
                }
                EffectNetwork.Send(new("assets/prefabs/deployable/vendingmachine/effects/vending-machine-purchase-human.prefab", player, 0, new(), new()), player.Connection);
                _data[player.userID].Inventory.Remove(id);
                GiveBalance(player, reward.Price);
                if (posId != -2) {
                    UI_UpdateInventoryItems(player, posId);
                    UI_UpdateTargetedInventoryItem(player, _data[player.userID].Inventory.FirstOrDefault(), -1);
                }
                else {
                    if (int.TryParse(arg.Args.ElementAtOrDefault(3), out var index)) {
                        CuiHelper.DestroyUi(player, Layer + ".main.div" + ".opencase.div" + ".sell" + $".{index}");
                        CuiHelper.DestroyUi(player, Layer + ".main.div" + ".opencase.div" + ".buy" + $".{index}");
                    }
                    else {
                        CuiHelper.DestroyUi(player, Layer + ".main.div" + ".opencase.div" + ".sell" + $".1");
                        CuiHelper.DestroyUi(player, Layer + ".main.div" + ".opencase.div" + ".buy" + $".1");
                    }
                }
                if (bool.TryParse(arg.Args.ElementAtOrDefault(3), out var returnToCaseItems)) {
                    if (returnToCaseItems) {
                        UI_DrawCaseItems(arg.Player(), _config.CaseList.FirstOrDefault(x => x.Id == arg.Args[4]));
                        UI_UpdateCaseOpenAmount(player, arg.Args[4], 1);
                        UI_DrawFastOpenMarker(player, arg.Args[4]);
                    }
                }
                break;
            }
            case "SKIP" : {
                if (int.TryParse(arg.Args.ElementAtOrDefault(3), out var index)) {
                    CuiHelper.DestroyUi(player, Layer + ".main.div" + ".opencase.div" + ".sell" + $".{index}");
                    CuiHelper.DestroyUi(player, Layer + ".main.div" + ".opencase.div" + ".buy" + $".{index}");
                }
                else {
                    CuiHelper.DestroyUi(player, Layer + ".main.div" + ".opencase.div" + ".sell" + $".1");
                    CuiHelper.DestroyUi(player, Layer + ".main.div" + ".opencase.div" + ".buy" + $".1");
                }
                if (bool.TryParse(arg.Args.ElementAtOrDefault(3), out var returnToCaseItems)) {
                    if (returnToCaseItems) {
                        UI_DrawCaseItems(arg.Player(), _config.CaseList.FirstOrDefault(x => x.Id == arg.Args[4]));
                        UI_UpdateCaseOpenAmount(player, arg.Args[4], 1);
                        UI_DrawFastOpenMarker(player, arg.Args[4]);
                    }
                }
                break;
            }
            case "TAKEREWARD" : {
                if (IsRaidOrCombatBlocked(player)) return;
                var id = arg.Args[1];
                var itemId = arg.Args[2].ToInt();
                if(!_data[player.userID].Inventory.Contains(id)) return;
                var reward = _config.RewardList.FirstOrDefault(p => p.RewardID == id);
                if (reward == null) {
                    PrintWarning(isEn ? $"The player has a reward {id}, but it is not in the config" : $"У игрока есть награда {id}, но в конфиге ее нет");
                    return;
                }
                _data[player.userID].Inventory.Remove(id);
                var item = ItemManager.CreateByName(reward.Shortname, reward.Amount, reward.SkinID);
                if (item != null) {
                    player.GiveItem(item);
                }
                if(!string.IsNullOrEmpty(reward.Command)) rust.RunServerCommand(reward.Command.Replace("%STEAMID%", player.UserIDString));
                if (itemId != -2) {
                    UI_UpdateInventoryItems(player, itemId);
                    UI_UpdateTargetedInventoryItem(player, _data[player.userID].Inventory.FirstOrDefault(), -1);
                }
                else {
                    if (int.TryParse(arg.Args.ElementAtOrDefault(3), out var index)) {
                        CuiHelper.DestroyUi(player, Layer + ".main.div" + ".opencase.div" + ".sell" + $".{index}");
                        CuiHelper.DestroyUi(player, Layer + ".main.div" + ".opencase.div" + ".buy" + $".{index}");
                    }
                    else {
                        CuiHelper.DestroyUi(player, Layer + ".main.div" + ".opencase.div" + ".sell" + $".1");
                        CuiHelper.DestroyUi(player, Layer + ".main.div" + ".opencase.div" + ".buy" + $".1");
                    }
                }
                break;
            }
        }
    }
    private double GetBalance(BasePlayer player) {
        return _config.EconomyPlugin switch {
            1 => Economics.Call<double>("Balance", player.userID.Get()), 2 => ServerRewards.Call<int>("CheckPoints", player.userID.Get()), 3 => IQEconomic.Call<int>("API_GET_BALANCE", player.userID.Get()), 4 => BankSystem.Call<int>("Balance", player.userID.Get()), 5 => _data[player.userID].Balance, _ => double.MinValue
        }
        ;
    }
    private bool IsRaidOrCombatBlocked(BasePlayer player) {
        var combatBlock = plugins.Find("CombatBlock");
        if (combatBlock) return (bool)combatBlock.Call("IsCombatBlocked", player) || (bool)combatBlock.Call("IsRaidBlocked", player, false);
        return false;
    }
    private void TakeBalance(BasePlayer player, double amount) {
        IQEconomic?.Call("API_REMOVE_BALANCE", player.userID.Get(), Convert.ToInt32(amount));
    }
    private void GiveBalance(BasePlayer player, double amount) {
        IQEconomic?.Call("API_SET_BALANCE", player.userID.Get(), Convert.ToInt32(amount));
    }
    private void UpdateBalance(BasePlayer player) {
        var container = new CuiElementContainer();
        container.Add(new CuiPanel {
            CursorEnabled = false, Image = {
                Color = "0.5215687 0.4470588 0.1843137 0.6"
            }
            , RectTransform = {
                AnchorMin = "0.5 0.5", AnchorMax = "0.5 0.5", OffsetMin = "-402.321 -15", OffsetMax = "-282.321 15"
            }
        }
        , "Topline_Place", "Balance_Panel");
        container.Add(new CuiElement {
            Name = "Balance_Text", Parent = "Balance_Panel", Components = {
                new CuiTextComponent {
                    Text = lang.GetMessage("UI_Balace", this, player.UserIDString) + $" $ {GetBalance(player)}", Font = "robotocondensed-bold.ttf", FontSize = 14, Align = TextAnchor.MiddleCenter, Color = "0.9490196 0.6745098 0.1411765 1"
                }
                , new CuiRectTransformComponent {
                    AnchorMin = "0.5 0.5", AnchorMax = "0.5 0.5", OffsetMin = "-60 -15", OffsetMax = "60 15"
                }
            }
        }
        );
        CuiHelper.DestroyUi(player, "Balance_Panel");
        CuiHelper.AddUi(player, container);
    }
    private void ShowCaseInfo(BasePlayer player, Configuration.Case caseSettings, int buyAmount = 1, int openAmount = 1) {
        var container = new CuiElementContainer();
        container.Add(new CuiPanel {
            CursorEnabled = false, Image = {
                Color = "0 0 0 0"
            }
            , RectTransform = {
                AnchorMin = "0.5 0.5", AnchorMax = "0.5 0.5", OffsetMin = "-407.5 -200", OffsetMax = "407.5 185"
            }
        }
        , "Case_MainPlace", "Body_Place");
        container.Add(new CuiButton {
            Button = {
                Color = "0.3294118 0.5215687 0.1843137 0.6", Command = "chat.say /cases"
            }
            , Text = {
                Text = lang.GetMessage("CasePage", this, player.UserIDString), Font = "robotocondensed-bold.ttf", FontSize = 14, Align = TextAnchor.MiddleCenter, Color = "0.5372549 0.7921569 0.3372549 1"
            }
            , RectTransform = {
                AnchorMin = "0.5 0.5", AnchorMax = "0.5 0.5", OffsetMin = "154.29 -15", OffsetMax = "234.29 15"
            }
        }
        , "Topline_Place", "CasePage_Button");
        container.Add(new CuiPanel {
            CursorEnabled = false, Image = {
                Color = "0 0 0 0.7"
            }
            , RectTransform = {
                AnchorMin = "0.5 0.5", AnchorMax = "0.5 0.5", OffsetMin = "-400.75 3", OffsetMax = "400.75 188"
            }
        }
        , "Body_Place", "Case_TopPlace");
        container.Add(new CuiElement {
            Name = "Case_Image", Parent = "Case_TopPlace", Components = {
                new CuiRawImageComponent {
                    Color = "1 1 1 1", Png = ImageList[caseSettings.Image]
                }
                , new CuiRectTransformComponent {
                    AnchorMin = "0.5 0.5", AnchorMax = "0.5 0.5", OffsetMin = "-72.5 -62.5", OffsetMax = "72.5 82.5"
                }
            }
        }
        );
        container.Add(new CuiPanel {
            CursorEnabled = false, Image = {
                Color = "0 0 0 0.6"
            }
            , RectTransform = {
                AnchorMin = "0.5 0.5", AnchorMax = "0.5 0.5", OffsetMin = "-387.777 -50", OffsetMax = "-87.777 50"
            }
        }
        , "Case_TopPlace", "Panel_Discription");
        container.Add(new CuiElement {
            Name = "Label_CaseName", Parent = "Panel_Discription", Components = {
                new CuiTextComponent {
                    Text = caseSettings.DisplayName, Font = "robotocondensed-bold.ttf", FontSize = 14, Align = TextAnchor.MiddleLeft, Color = "1 1 1 1"
                }
                , new CuiRectTransformComponent {
                    AnchorMin = "0.5 0.5", AnchorMax = "0.5 0.5", OffsetMin = "-145.7 25.141", OffsetMax = "-45.7 45.141"
                }
            }
        }
        );
        container.Add(new CuiElement {
            Name = "Label_Discription", Parent = "Panel_Discription", Components = {
                new CuiTextComponent {
                    Text = caseSettings.Description, Font = "robotocondensed-bold.ttf", FontSize = 12, Align = TextAnchor.MiddleLeft, Color = "0.9056604 0.9056604 0.9056604 1"
                }
                , new CuiRectTransformComponent {
                    AnchorMin = "0.5 0.5", AnchorMax = "0.5 0.5", OffsetMin = "-145 -44.859", OffsetMax = "145 25.141"
                }
            }
        }
        );
        container.Add(new CuiPanel {
            CursorEnabled = false, Image = {
                Color = "0 0 0 0.6"
            }
            , RectTransform = {
                AnchorMin = "0.5 0.5", AnchorMax = "0.5 0.5", OffsetMin = "87.777 -50", OffsetMax = "387.777 50"
            }
        }
        , "Case_TopPlace", "Panel_Purchase");
        container.Add(new CuiElement {
            Name = "Label_Purchase", Parent = "Panel_Purchase", Components = {
                new CuiTextComponent {
                    Text = lang.GetMessage("CaseBuyText", this, player.UserIDString), Font = "robotocondensed-bold.ttf", FontSize = 14, Align = TextAnchor.MiddleLeft, Color = "1 1 1 1"
                }
                , new CuiRectTransformComponent {
                    AnchorMin = "0.5 0.5", AnchorMax = "0.5 0.5", OffsetMin = "-145.7 25.141", OffsetMax = "-45.7 45.141"
                }
            }
        }
        );
        container.Add(new CuiElement {
            Name = "Label_Purchase_Discription", Parent = "Panel_Purchase", Components = {
                new CuiTextComponent {
                    Text = lang.GetMessage("CaseBuySelect", this, player.UserIDString), Font = "robotocondensed-bold.ttf", FontSize = 10, Align = TextAnchor.MiddleLeft, Color = "1 1 1 1"
                }
                , new CuiRectTransformComponent {
                    AnchorMin = "0.5 0.5", AnchorMax = "0.5 0.5", OffsetMin = "-145.7 10.141", OffsetMax = "145 25.141"
                }
            }
        }
        );
        container.Add(new CuiPanel {
            CursorEnabled = false, Image = {
                Color = "1 1 1 0"
            }
            , RectTransform = {
                AnchorMin = "0.5 0.5", AnchorMax = "0.5 0.5", OffsetMin = "-145.7 -22.359", OffsetMax = "145 7.641"
            }
        }
        , "Panel_Purchase", "Panel_Cost");
        container.Add(new CuiPanel {
            CursorEnabled = false, Image = {
                Color = "0.5215687 0.4470588 0.1843137 0.6"
            }
            , RectTransform = {
                AnchorMin = "0.5 0.5", AnchorMax = "0.5 0.5", OffsetMin = "35.7 -10", OffsetMax = "140.7 10"
            }
        }
        , "Panel_Cost", "Panel_Cost");
        container.Add(new CuiElement {
            Name = "Label_Cost", Parent = "Panel_Cost", Components = {
                new CuiTextComponent {
                    Text = lang.GetMessage("Price1Case", this, player.UserIDString) + $" ${caseSettings.Price}", Font = "robotocondensed-bold.ttf", FontSize = 12, Align = TextAnchor.MiddleCenter, Color = "0.9490196 0.6745098 0.1411765 1"
                }
                , new CuiRectTransformComponent {
                    AnchorMin = "0.5 0.5", AnchorMax = "0.5 0.5", OffsetMin = "-52.5 -10", OffsetMax = "52.5 10"
                }
            }
        }
        );
        var color = buyAmount == 1 ? "0.5215687 0.4470588 0.1843137 0.8" : "0.5215687 0.4470588 0.1843137 0.6";
        container.Add(new CuiButton {
            Button = {
                Color = color, Command = $"UI_CASES CHANGEOPEN {caseSettings.Id} 1 {openAmount}"
            }
            , Text = {
                Text = "1", Font = "robotocondensed-bold.ttf", FontSize = 14, Align = TextAnchor.MiddleCenter, Color = "0.9490196 0.6745098 0.1411765 1"
            }
            , RectTransform = {
                AnchorMin = "-0.32 0.5", AnchorMax = "-0.32 0.5", OffsetMin = "-140 -10", OffsetMax = "-110 10"
            }
        }
        , "Panel_Cost", "Button_1");
        color = buyAmount == 2 ? "0.5215687 0.4470588 0.1843137 0.8" : "0.5215687 0.4470588 0.1843137 0.6";
        container.Add(new CuiButton {
            Button = {
                Color = color, Command = $"UI_CASES CHANGEOPEN {caseSettings.Id} 2 {openAmount}"
            }
            , Text = {
                Text = "2", Font = "robotocondensed-bold.ttf", FontSize = 14, Align = TextAnchor.MiddleCenter, Color = "0.9490196 0.6745098 0.1411765 1"
            }
            , RectTransform = {
                AnchorMin = "-0.32 0.5", AnchorMax = "-0.32 0.5", OffsetMin = "-105 -10", OffsetMax = "-75 10"
            }
        }
        , "Panel_Cost", "Button_2");
        color = buyAmount == 3 ? "0.5215687 0.4470588 0.1843137 0.8" : "0.5215687 0.4470588 0.1843137 0.6";
        container.Add(new CuiButton {
            Button = {
                Color = color, Command = $"UI_CASES CHANGEOPEN {caseSettings.Id} 3 {openAmount}"
            }
            , Text = {
                Text = "3", Font = "robotocondensed-bold.ttf", FontSize = 14, Align = TextAnchor.MiddleCenter, Color = "0.9490196 0.6745098 0.1411765 1"
            }
            , RectTransform = {
                AnchorMin = "-0.32 0.5", AnchorMax = "-0.32 0.5", OffsetMin = "-70 -10", OffsetMax = "-40 10"
            }
        }
        , "Panel_Cost", "Button_3");
        color = buyAmount == 4 ? "0.5215687 0.4470588 0.1843137 0.8" : "0.5215687 0.4470588 0.1843137 0.6";
        container.Add(new CuiButton {
            Button = {
                Color = color, Command = $"UI_CASES CHANGEOPEN {caseSettings.Id} 4 {openAmount}"
            }
            , Text = {
                Text = "4", Font = "robotocondensed-bold.ttf", FontSize = 14, Align = TextAnchor.MiddleCenter, Color = "0.9490196 0.6745098 0.1411765 1"
            }
            , RectTransform = {
                AnchorMin = "-0.32 0.5", AnchorMax = "-0.32 0.5", OffsetMin = "-35 -10", OffsetMax = "-5 10"
            }
        }
        , "Panel_Cost", "Button_4");
        color = buyAmount == 5 ? "0.5215687 0.4470588 0.1843137 0.8" : "0.5215687 0.4470588 0.1843137 0.6";
        container.Add(new CuiButton {
            Button = {
                Color = color, Command = $"UI_CASES CHANGEOPEN {caseSettings.Id} 5 {openAmount}"
            }
            , Text = {
                Text = "5", Font = "robotocondensed-bold.ttf", FontSize = 14, Align = TextAnchor.MiddleCenter, Color = "0.9490196 0.6745098 0.1411765 1"
            }
            , RectTransform = {
                AnchorMin = "-0.32 0.5", AnchorMax = "-0.32 0.5", OffsetMin = "0 -10", OffsetMax = "30 10"
            }
        }
        , "Panel_Cost", "Button_5");
        container.Add(new CuiButton {
            Button = {
                Color = "0.5215687 0.4470588 0.1843137 0.6", Command = $"UI_CASES BUY {caseSettings.Id} {buyAmount} {openAmount}"
            }
            , Text = {
                Text = lang.GetMessage("BuyCase", this, player.UserIDString) + $" {buyAmount} " + lang.GetMessage("fortext", this, player.UserIDString) + $" ${caseSettings.Price * buyAmount}", Font = "robotocondensed-bold.ttf", FontSize = 12, Align = TextAnchor.MiddleCenter, Color = "0.9490196 0.6745098 0.1411765 1"
            }
            , RectTransform = {
                AnchorMin = "0.5 0.5", AnchorMax = "0.5 0.5", OffsetMin = "-60 -46", OffsetMax = "60 -26"
            }
        }
        , "Panel_Purchase", "Button_Buy");
        _data[player.userID].CaseList.TryGetValue(caseSettings.Id, out var caseData);
        string textToOpen = caseData switch {
            1 => lang.GetMessage("1case", this, player.UserIDString), 2 or 3 or 4 => lang.GetMessage("234case", this, player.UserIDString), _ => lang.GetMessage("5morecase", this, player.UserIDString)
        }
        ;
        var text = caseData > 0 ? lang.GetMessage("InStock", this, player.UserIDString) + $" {caseData} {textToOpen}" : lang.GetMessage("NoneStock", this, player.UserIDString);
        var command = caseData < openAmount ? "" : $"UI_CASES OPEN {caseSettings.Id} {openAmount}";
        var commandColor = caseData < openAmount ? "0.5686275 0.1803922 0.1215686 0.6" : "0.3294118 0.5215687 0.1843137 0.8";
        var TextButtonColor = caseData < openAmount ? "0.8627451 0.4235294 0.3529412 1" : "0.5372549 0.7921569 0.3372549 1";
        textToOpen = openAmount == 1 ? lang.GetMessage("1case", this, player.UserIDString) : openAmount == 5 ? lang.GetMessage("5morecase", this, player.UserIDString) : lang.GetMessage("234case", this, player.UserIDString);
        container.Add(new CuiButton {
            Button = {
                Color = commandColor, Command = command
            }
            , Text = {
                Text = lang.GetMessage("OpenCase", this, player.UserIDString) + $" {openAmount} {textToOpen}", Font = "robotocondensed-bold.ttf", FontSize = 12, Align = TextAnchor.MiddleCenter, Color = TextButtonColor
            }
            , RectTransform = {
                AnchorMin = "0.5 0.5", AnchorMax = "0.5 0.5", OffsetMin = "-55 -87.5", OffsetMax = "55 -62.5"
            }
        }
        , "Case_TopPlace", "Button_Open");
        container.Add(new CuiElement {
            Name = "Label_MultiOpen", Parent = "Case_TopPlace", Components = {
                new CuiTextComponent {
                    Text = lang.GetMessage("OpenCases", this, player.UserIDString), Font = "robotocondensed-bold.ttf", FontSize = 10, Align = TextAnchor.MiddleCenter, Color = "1 1 1 1"
                }
                , new CuiRectTransformComponent {
                    AnchorMin = "0.5 0.5", AnchorMax = "0.5 0.5", OffsetMin = "-337.507 -85", OffsetMax = "-257.78 -65"
                }
            }
        }
        );
        container.Add(new CuiPanel {
            CursorEnabled = false, Image = {
                Color = "1 1 1 0"
            }
            , RectTransform = {
                AnchorMin = "0.5 0.5", AnchorMax = "0.5 0.5", OffsetMin = "-257.78 -85", OffsetMax = "-87.78 -65"
            }
        }
        , "Case_TopPlace", "Panel_FastOpen");
        color = openAmount == 1 ? "0.3294118 0.5215687 0.1843137 0.8" : "0.3294118 0.5215687 0.1843137 0.6";
        container.Add(new CuiButton {
            Button = {
                Color = color, Command = $"UI_CASES CHANGEBUY {caseSettings.Id} {buyAmount} 1"
            }
            , Text = {
                Text = "1", Font = "robotocondensed-bold.ttf", FontSize = 10, Align = TextAnchor.MiddleCenter, Color = "0.5372549 0.7921569 0.3372549 1"
            }
            , RectTransform = {
                AnchorMin = "0.5 0.5", AnchorMax = "0.5 0.5", OffsetMin = "-85 -10", OffsetMax = "-55 10"
            }
        }
        , "Panel_FastOpen", "Button_Open 1");
        color = openAmount == 2 ? "0.3294118 0.5215687 0.1843137 0.8" : "0.3294118 0.5215687 0.1843137 0.6";
        container.Add(new CuiButton {
            Button = {
                Color = color, Command = $"UI_CASES CHANGEBUY {caseSettings.Id} {buyAmount} 2"
            }
            , Text = {
                Text = "2", Font = "robotocondensed-bold.ttf", FontSize = 10, Align = TextAnchor.MiddleCenter, Color = "0.5372549 0.7921569 0.3372549 1"
            }
            , RectTransform = {
                AnchorMin = "0.5 0.5", AnchorMax = "0.5 0.5", OffsetMin = "-50 -10", OffsetMax = "-20 10"
            }
        }
        , "Panel_FastOpen", "Button_Open 2");
        color = openAmount == 3 ? "0.3294118 0.5215687 0.1843137 0.8" : "0.3294118 0.5215687 0.1843137 0.6";
        container.Add(new CuiButton {
            Button = {
                Color = color, Command = $"UI_CASES CHANGEBUY {caseSettings.Id} {buyAmount} 3"
            }
            , Text = {
                Text = "3", Font = "robotocondensed-bold.ttf", FontSize = 10, Align = TextAnchor.MiddleCenter, Color = "0.5372549 0.7921569 0.3372549 1"
            }
            , RectTransform = {
                AnchorMin = "0.5 0.5", AnchorMax = "0.5 0.5", OffsetMin = "-15 -10", OffsetMax = "15 10"
            }
        }
        , "Panel_FastOpen", "Button_Open 3");
        color = openAmount == 4 ? "0.3294118 0.5215687 0.1843137 0.8" : "0.3294118 0.5215687 0.1843137 0.6";
        container.Add(new CuiButton {
            Button = {
                Color = color, Command = $"UI_CASES CHANGEBUY {caseSettings.Id} {buyAmount} 4"
            }
            , Text = {
                Text = "4", Font = "robotocondensed-bold.ttf", FontSize = 10, Align = TextAnchor.MiddleCenter, Color = "0.5372549 0.7921569 0.3372549 1"
            }
            , RectTransform = {
                AnchorMin = "0.5 0.5", AnchorMax = "0.5 0.5", OffsetMin = "20 -10", OffsetMax = "50 10"
            }
        }
        , "Panel_FastOpen", "Button_Open 4");
        color = open
// ... [Code preview truncated due to length. Full source in attached file] ...

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