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

FREE RustCases : 1.0.0 1.0.0

Нет прав для скачивания
C#:
using CompanionServer;
using Oxide.Core;
using Oxide.Core.Plugins;
using Oxide.Game.Rust.Cui;
using Oxide.Game.Rust.Libraries;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using UnityEngine;
using UnityEngine.UIElements;

namespace Oxide.Plugins
{
    [Info("RustCases", "VooDoo", "1.0.0")]
    public class RustCases : RustPlugin
    {
        [PluginReference] private Plugin RustMenu;
        [PluginReference] Plugin ImageLibrary;
        bool AddImage(string url, string imageName, ulong imageId = 0, Action callback = null) => (bool)ImageLibrary.Call("AddImage", url, imageName, imageId, callback);
        string GetImage(string imageName, ulong imageId = 0, bool returnUrl = false) => (string)ImageLibrary.Call("GetImage", imageName, imageId, returnUrl);

        #region Case
        private static RustCases Instance { get; set; }
        private bool Initialized { get; set; } = false;
        private const string _currencyName = "sticks";
        private const ulong _currencySkinID = 1761353535UL;

        private Dictionary<ulong, int> _users = new Dictionary<ulong, int>();
        private List<Case> _cases = new List<Case>();
        private Dictionary<string, string> _casesLang = new Dictionary<string, string>();

        private List<Case> _simpleCases = new List<Case>();
        private List<CaseTime> _timeCases = new List<CaseTime>();
        private List<CaseRandom> _randomCases = new List<CaseRandom>();

        public class Case
        {
            public string Name { get; set; }
            public string Image { get; set; }
            public int Cost { get; set; }

            public List<CaseItem> Items = new List<CaseItem>();

            public virtual bool EnoughСurrency(BasePlayer player)
            {
                if (GetCurrencyAmount(player) >= this.Cost)
                    return true;

                return false;
            }

            public virtual int GetCurrencyAmount(BasePlayer player)
            {
                int playerCoins = 0;
                Item[] playerItems = player.inventory.AllItems();
                for (int i = 0; i < playerItems.Length; i++)
                {
                    if (playerItems[i].info.shortname == _currencyName)
                    {
                        if (playerItems[i].skin == _currencySkinID)
                        {
                            playerCoins += playerItems[i].amount;
                        }
                    }
                }

                return playerCoins;
            }

            public virtual void PayForCase(BasePlayer player)
            {
                var caseCost = this.Cost;
                Item[] playerItems = player.inventory.AllItems();
                for (int i = 0; i < playerItems.Length; i++)
                {
                    if (playerItems[i].info.shortname == _currencyName)
                    {
                        if (playerItems[i].skin == _currencySkinID)
                        {
                            if (caseCost >= playerItems[i].amount)
                            {
                                player.inventory.Take(null, playerItems[i].info.itemid, playerItems[i].amount);
                                caseCost -= playerItems[i].amount;
                            }
                            else
                            {
                                player.inventory.Take(null, playerItems[i].info.itemid, caseCost);
                                caseCost -= caseCost;
                            }
                        }
                    }
                }
            }

            public virtual void Receive(BasePlayer player)
            {
                for (int i = 0; i < Items.Count; i++)
                {
                    if (Items[i].IsItem())
                    {
                        Item item = ItemManager.CreateByName(Items[i].Subject, Items[i].Amount, Items[i].SkinID);
                        if (player.inventory.GiveItem(item, player.inventory.containerMain) == false)
                        {
                            if (player.inventory.GiveItem(item, player.inventory.containerBelt) == false)
                            {
                                item.Drop(player.transform.position, Vector3.up);
                            }
                        }
                    }
                    else
                    {
                        Instance.Server.Command(Items[i].Subject.Replace("%", player.UserIDString));
                    }
                }
            }

            public virtual bool CanReceive(BasePlayer player)
            {
                return true;
            }
        }

        public class CaseTime : Case
        {
            public List<ulong> Users = new List<ulong>();

            public override bool EnoughСurrency(BasePlayer player)
            {
                if (GetCurrencyAmount(player) >= this.Cost)
                    return true;

                return false;
            }

            public override int GetCurrencyAmount(BasePlayer player)
            {
                return Instance._users.ContainsKey(player.userID) ? Instance._users[player.userID] : 0;
            }

            public override void PayForCase(BasePlayer player)
            {
                if (Users.Contains(player.userID))
                {
                    Instance.PrintError($"CaseTime.PayForCase Exception [{player.userID}]. Please show this message to administator");
                }
                else
                {
                    Users.Add(player.userID);
                }
            }

            public override bool CanReceive(BasePlayer player)
            {
                return Users.Contains(player.userID) == false;
            }
        }

        public class CaseRandom : Case
        {
            public override void Receive(BasePlayer player)
            {

            }
        }

        public class CaseItem
        {
            public string Name;
            public string Image;
            public ulong SkinID;
            public int Amount;

            public string Subject;

            public bool IsItem()
            {
                return ItemManager.itemDictionaryByName.ContainsKey(Subject);
            }
        }

        public static int GetCurrencyAmount(BasePlayer player)
        {
            int playerCoins = 0;
            Item[] playerItems = player.inventory.AllItems();
            for (int i = 0; i < playerItems.Length; i++)
            {
                if (playerItems[i].info.shortname == _currencyName)
                {
                    if (playerItems[i].skin == _currencySkinID)
                    {
                        playerCoins += playerItems[i].amount;
                    }
                }
            }

            return playerCoins;
        }
        #endregion
        private Timer initTimer;
        private void OnServerInitialized()
        {
            Instance = this;
            _simpleCases = Interface.Oxide.DataFileSystem.ReadObject<List<Case>>("Cases");
            _timeCases = Interface.Oxide.DataFileSystem.ReadObject<List<CaseTime>>("Cases_Time");
            _randomCases = Interface.Oxide.DataFileSystem.ReadObject<List<CaseRandom>>("Cases_Random");
            _users = Interface.Oxide.DataFileSystem.ReadObject<Dictionary<ulong, int>>("Cases_Users");
            _cases.Clear();
            foreach (var _case in _simpleCases)
            {
                AddImage("file://" + Interface.Oxide.DataDirectory + Path.DirectorySeparatorChar + "Case" + Path.DirectorySeparatorChar + _case.Image, _case.Name);
                _cases.Add(_case);
            }

            foreach (var _case in _timeCases)
            {
                AddImage("file://" + Interface.Oxide.DataDirectory + Path.DirectorySeparatorChar + "Case" + Path.DirectorySeparatorChar + _case.Image, _case.Name);
                _cases.Add(_case);
            }

            foreach (var _case in _randomCases)
            {
                AddImage("file://" + Interface.Oxide.DataDirectory + Path.DirectorySeparatorChar + "Case" + Path.DirectorySeparatorChar + _case.Image, _case.Name);
                _cases.Add(_case);
            }

            initTimer = timer.Every(5f, () =>
            {
                if (RustMenu != null)
                {
                    RustMenu.Call("API_RegisterSubMenu", "SUBMENUCASES", this.Name, "RenderCases", new Dictionary<string, string>()
                    {
                        ["ru"] = "КЕЙСЫ",
                        ["en"] = "CASES"
                    }, "MENUSTORES");

                    if ((bool)RustMenu.Call("API_MenuExist", "MENUSTORES", "SUBMENUCASES"))
                    {
                        initTimer.Destroy();
                    }
                }
            });
            

            Initialized = true;

            for (int i = 0; i < BasePlayer.activePlayerList.Count; i++)
            {
                OnPlayerConnected(BasePlayer.activePlayerList[i]);
            }

            timer.Every(60f, () =>
            {
                for(int i = 0; i < BasePlayer.activePlayerList.Count; i++)
                {
                    if (_users.ContainsKey(BasePlayer.activePlayerList[i].userID))
                        _users[BasePlayer.activePlayerList[i].userID]++;
                    else
                        _users[BasePlayer.activePlayerList[i].userID] = 1;
                }
            });
        }

        protected override void LoadDefaultMessages()
        {
            if (!Initialized)
            {
                NextTick(() => LoadDefaultMessages());
                return;
            }

            foreach (var _case in _cases)
            {
                _casesLang.Add(_case.Name, $"It's case with cost: {_case.Cost}");
            }
            _casesLang.Add("TITLE", "Список кейсов сервера <color=#FFAA00AA>RUSTLAND</color>");
            _casesLang.Add("PLAYERMONEY", "Монет в инвентаре: %");
            _casesLang.Add("PLAYERTIME", "Проведено в игре: % минут");
            _casesLang.Add("BUTTON_RECEIVE", "Купить");
            _casesLang.Add("BUTTON_CANTRECEIVE", "Недостаточно");
            _casesLang.Add("BUTTON_RECEIVETIME", "Взять");
            _casesLang.Add("BUTTON_CANTRECEIVETIME", "Подождите");
            _casesLang.Add("BUTTON_ALREADYRECEIVETIME", "Уже взят");
            _casesLang.Add("TITLE_TIMER", "Таймер");
            _casesLang.Add("TITLE_CANTAKE", "Можно брать");
            _casesLang.Add("TITLE_MONEY", "Стоимость: % монет");
            _casesLang.Add("TITLE_CASESHOW", "<color=#fffffAA>Список содержимого кейса <color=#FFAA00AA>%</color></color>");

            lang.RegisterMessages(_casesLang, this, "en");
            lang.RegisterMessages(_casesLang, this, "ru");
        }

        private void OnPlayerConnected(BasePlayer player)
        {
            if (_users.ContainsKey(player.userID) == false)
                _users.Add(player.userID, 0);
        }

        private void OnNewSave()
        {
            _simpleCases.Clear();
            _timeCases.Clear();
            _randomCases.Clear();
            _users.Clear();
            _cases.Clear();
            _users.Clear();

            _simpleCases = Interface.Oxide.DataFileSystem.ReadObject<List<Case>>("Cases");
            _timeCases = Interface.Oxide.DataFileSystem.ReadObject<List<CaseTime>>("Cases_Time");
            _randomCases = Interface.Oxide.DataFileSystem.ReadObject<List<CaseRandom>>("Cases_Random");
            _users = Interface.Oxide.DataFileSystem.ReadObject<Dictionary<ulong, int>>("Cases_Users");

            for (int i = 0; i < _timeCases.Count; i++)
                _timeCases[i].Users.Clear();

            for (int i = 0; i < _simpleCases.Count; i++)
            {
                _cases.Add(_simpleCases[i]);
            }

            for (int i = 0; i < _timeCases.Count; i++)
            {
                _cases.Add(_timeCases[i]);
            }

            for (int i = 0; i < _randomCases.Count; i++)
            {
                _cases.Add(_randomCases[i]);
            }

            _users.Clear();

            OnServerSave();
        }

        private void OnServerSave()
        {
            _simpleCases.Clear();
            _timeCases.Clear();
            _randomCases.Clear();

            for (int i = 0; i < _cases.Count; i++)
            {
                if (_cases[i] is CaseTime)
                {
                    _timeCases.Add(_cases[i] as CaseTime);
                    continue;
                }

                if (_cases[i] is CaseRandom)
                {
                    _randomCases.Add(_cases[i] as CaseRandom);
                    continue;
                }

                _simpleCases.Add(_cases[i]);
            }

            Interface.Oxide.DataFileSystem.WriteObject("Cases", _simpleCases);
            Interface.Oxide.DataFileSystem.WriteObject("Cases_Time", _timeCases);
            Interface.Oxide.DataFileSystem.WriteObject("Cases_Random", _randomCases);
            Interface.Oxide.DataFileSystem.WriteObject("Cases_Users", _users);
        }

        private void Unload()
        {
            OnServerSave();
        }

        private void RenderCases(Dictionary<string, object> args)
        {
            BasePlayer player = (BasePlayer)args["player"];
            CuiElementContainer Container = (CuiElementContainer)args["container"];
            string menuName = (string)args["menuName"];
            string subMenuName = (string)args["subMenuName"];

            Container.Add(new CuiElement
            {
                Name = "RustMenu" + ".Content" + ".Right.Cases",
                Parent = "RustMenu" + ".Content" + ".Right",
                Components =
                            {
                                new CuiImageComponent
                                {
                                    Color = "0 0 0 0",
                                },
                                new CuiRectTransformComponent
                                {
                                    AnchorMin = "0 0",
                                    AnchorMax = "1 1",
                                }
                            }
            });

            Container.Add(new CuiElement
            {
                Name = "RustMenu" + ".Content" + ".Right" + ".Balance",
                Parent = "RustMenu" + ".Content" + ".Right.Cases",
                Components =
                {
                        new CuiImageComponent
                        {
                            Color = "0 0 0 0.7",
                        },
                        new CuiRectTransformComponent
                        {
                            AnchorMin = "0 0",
                             AnchorMax = "1 1",
                        }
                }
            });

            Container.Add(new CuiElement
            {
                Name = "RustMenu" + ".Content" + ".Right" + $".UserMoney",
                Parent = "RustMenu" + ".Content" + ".Right" + ".Balance",
                Components =
                            {
                                new CuiTextComponent
                                {
                                    Text = $"<color=#fff9f9AA>{lang.GetMessage("PLAYERMONEY", this, player.UserIDString).Replace("%", GetCurrencyAmount(player).ToString())}</color>",
                                    Align = TextAnchor.MiddleCenter,
                                    FontSize = 18,
                                    Font = "robotocondensed-bold.ttf",
                                    FadeIn = 0.5f,
                                },
                                new CuiRectTransformComponent
                                {
                                    AnchorMin = "0 1",
                                    AnchorMax = "0 1",
                                    OffsetMin = $"50 {-100}",
                                    OffsetMax = $"200 {0}"
                                }
                            }
            });
            Container.Add(new CuiElement
            {
                Name = "RustMenu" + ".Content" + ".Right" + $".Title",
                Parent = "RustMenu" + ".Content" + ".Right" + ".Balance",
                Components =
                            {
                                new CuiTextComponent
                                {
                                    Text = $"<color=#fff9f9AA>{lang.GetMessage("TITLE", this, player.UserIDString)}</color>",
                                    Align = TextAnchor.MiddleCenter,
                                    FontSize = 24,
                                    Font = "robotocondensed-bold.ttf",
                                    FadeIn = 0.5f,
                                },
                                new CuiRectTransformComponent
                                {
                                    AnchorMin = "0.5 1",
                                    AnchorMax = "0.5 1",
                                    OffsetMin = $"-75 {-100}",
                                    OffsetMax = $"75 {0}"
                                }
                            }
            });
            Container.Add(new CuiElement
            {
                Name = "RustMenu" + ".Content" + ".Right" + $".UserTime",
                Parent = "RustMenu" + ".Content" + ".Right" + ".Balance",
                Components =
                            {
                                new CuiTextComponent
                                {
                                    Text = $"<color=#fff9f9AA>{lang.GetMessage("PLAYERTIME", this, player.UserIDString).Replace("%", _users[player.userID].ToString())}</color>",
                                    Align = TextAnchor.MiddleCenter,
                                    FontSize = 18,
                                    Font = "robotocondensed-bold.ttf",
                                    FadeIn = 0.5f,
                                },
                                new CuiRectTransformComponent
                                {
                                    AnchorMin = "1 1",
                                    AnchorMax = "1 1",
                                    OffsetMin = $"-200 {-100}",
                                    OffsetMax = $"-50 {0}"
                                }
                            }
            });


            for (int i = 0, x = 0, y = 0; i < _cases.Count; i++, x++)
            {
                if (x == 3)
                {
                    x = 0;
                    y++;
                }

                RenderCase(player, Container, i, x, y);
            }
        }

        private void RenderCase(BasePlayer player, CuiElementContainer Container, int number, int positionX, int positionY)
        {
            CuiHelper.DestroyUi(player, "RustMenu" + ".Content" + ".Right" + $".Case.{number}");
            var UserMoney = GetCurrencyAmount(player); 
            var UserTime = _users[player.userID];

            string BtnColor = "1 0.22 0.15 0.3";
            string MessageCost = "", MessageGet = "";
            string Time = TimeExtensions.FormatShortTime(TimeSpan.FromMinutes(_cases[number].Cost - UserTime));
            bool CanTake = false;

            if (_cases[number] is CaseTime == false)
            {
                MessageCost = $"<size=12>{lang.GetMessage("TITLE_MONEY", this, player.UserIDString).Replace("%", _cases[number].Cost.ToString())}\n</size>";
                MessageGet = lang.GetMessage("BUTTON_RECEIVE", this, player.UserIDString);

                if (_cases[number].Cost <= UserMoney)
                {
                    BtnColor = "0.66 1 0.3 0.2";
                    CanTake = true;
                }
                else
                {
                    MessageGet = lang.GetMessage("BUTTON_CANTRECEIVE", this, player.UserIDString);
                }
            }
            else
            {
                MessageCost = $"<size=12>{lang.GetMessage("TITLE_CANTAKE", this, player.UserIDString)}</size>";
                MessageGet = lang.GetMessage("BUTTON_RECEIVETIME", this, player.UserIDString);

                if (_cases[number].Cost <= UserTime)
                {
                    BtnColor = "0.66 1 0.3 0.2";
                    CanTake = true;
                }
                else
                {
                    MessageCost = $"<size=12>{lang.GetMessage("TITLE_TIMER", this, player.UserIDString)}: {Time}</size>";
                    MessageGet = lang.GetMessage("BUTTON_CANTRECEIVETIME", this, player.UserIDString);
                }
            }

            if (_cases[number] is CaseTime && (_cases[number] as CaseTime).CanReceive(player) == false)
            {
                BtnColor = "1 0.22 0.15 0.3";
                MessageCost = $"";
                MessageGet = lang.GetMessage("BUTTON_ALREADYRECEIVETIME", this, player.UserIDString);
                CanTake = false;
            }

            Container.Add(new CuiElement
            {
                Name = "RustMenu" + ".Content" + ".Right" + $".Case.{number}",
                Parent = "RustMenu" + ".Content" + ".Right.Cases",
                Components =
                            {
                                new CuiImageComponent
                                {
                                    Color = "0 0 0 0.5",
                                },
                                new CuiRectTransformComponent
                                {
                                    AnchorMin = "0.5 1",
                                    AnchorMax = "0.5 1",
                                    OffsetMin = $"{-305 + positionX * 205} {-200 - positionY * 105}",
                                    OffsetMax = $"{-105 + positionX * 205} {-100 - positionY * 105}"
                                }
                            }
            });
            Container.Add(new CuiElement
            {
                Name = "RustMenu" + ".Content" + ".Right" + $".Case.{number}.Background",
                Parent = "RustMenu" + ".Content" + ".Right" + $".Case.{number}",
                Components =
                                {
                                    new CuiImageComponent
                                    {
                                        Color = "1 1 1 0.05",
                                    },
                                    new CuiRectTransformComponent
                                    {
                                        AnchorMin = "0.025 0.05",
                                        AnchorMax = "0.475 0.95",
                                    }
                                }
            });
            Container.Add(new CuiElement
            {
                Name = "RustMenu" + ".Content" + ".Right" + $".Case.{number}.Img",
                Parent = "RustMenu" + ".Content" + ".Right" + $".Case.{number}",
                Components =
                                {
                                    new CuiRawImageComponent
                                    {
                                        Png = Instance.GetImage(_cases[number].Name),
                                    },
                                    new CuiRectTransformComponent
                                    {
                                        AnchorMin = "0.025 0.05",
                                        AnchorMax = "0.475 0.95",
                                    }
                                }
            });
            Container.Add(new CuiButton
            {
                Button = { Color = "1 1 1 0", Command = $"caseshow {_cases.ElementAt(number).Name}" },
                RectTransform = { AnchorMin = "0 0", AnchorMax = "1 1", },
                Text = { Text = "", Align = TextAnchor.MiddleCenter }
            }, "RustMenu" + ".Content" + ".Right" + $".Case.{number}.Img");
            Container.Add(new CuiElement
            {
                Name = "RustMenu" + ".Content" + ".Right" + $".Case.{number}.Title",
                Parent = "RustMenu" + ".Content" + ".Right" + $".Case.{number}",
                Components =
                            {
                                new CuiTextComponent
                                {
                                    Text = $"<color=#fff9f9AA>{lang.GetMessage(_cases[number].Name, this, player.UserIDString)}</color>",
                                    Align = TextAnchor.MiddleCenter,
                                    FontSize = 10,
                                    Font = "robotocondensed-bold.ttf",
                                    FadeIn = 0.5f,
                                },
                                new CuiRectTransformComponent
                                {
                                    AnchorMin = "0.5 0.7",
                                    AnchorMax = "1 1",
                                },
                                new CuiOutlineComponent
                                {
                                         Color = "0 0 0 1",
                                         Distance = "-0.5 0.5"
                                }
                            }
            });
            Container.Add(new CuiElement
            {
                Name = "RustMenu" + ".Content" + ".Right" + $".Case.{number}.BtnBackground",
                Parent = "RustMenu" + ".Content" + ".Right" + $".Case.{number}",
                Components =
                            {
                                new CuiImageComponent
                                {
                                    Material = "assets/content/ui/uibackgroundblur-ingamemenu.mat",
                                    Color = BtnColor,
                                    FadeIn = 0.5f,
                                },
                                new CuiRectTransformComponent
                                {
                                    AnchorMin = "0.525 0.05",
                                    AnchorMax = "0.95 0.3",
                                },
                            }
            });
            Container.Add(new CuiElement
            {
                Name = "RustMenu" + ".Content" + ".Right" + $".Case.{number}.Timer",
                Parent = "RustMenu" + ".Content" + ".Right" + $".Case.{number}",
                Components =
                    {
                        new CuiTextComponent
                        {
                             Text = $"<color=#fff9f9AA>{MessageCost}</color>",
                             Align = TextAnchor.LowerCenter,
                             FontSize = 14,
                             Font = "robotocondensed-bold.ttf",
                             FadeIn = 0.5f,
                        },
                        new CuiRectTransformComponent
                        {
                             AnchorMin = "0.5 0.35",
                             AnchorMax = "1 0.7",
                        }
                    }
            });
            Container.Add(new CuiElement
            {
                Name = "RustMenu" + ".Content" + ".Right" + $".Case.{number}.BtnTitle",
                Parent = "RustMenu" + ".Content" + ".Right" + $".Case.{number}",
                Components =
                                {
                                    new CuiTextComponent
                                    {
                                        Text = $"<color=#fff9f9AA>{MessageGet}</color>",
                                        Align = TextAnchor.MiddleCenter,
                                        FontSize = 14,
                                        Font = "robotocondensed-bold.ttf",
                                        FadeIn = 0.5f,
                                    },
                                    new CuiRectTransformComponent
                                    {
                                        AnchorMin = "0.525 0.05",
                                        AnchorMax = "0.95 0.3",
                                    }
                                }
            });

            if (CanTake)
            {
                Container.Add(new CuiButton
                {
                    Button = { Color = "1 1 1 0", Command = $"rustcases.get {number} {positionX} {positionY}" },
                    RectTransform = { AnchorMin = "0 0", AnchorMax = "1 1" },
                    Text = { Text = "", Align = TextAnchor.MiddleCenter }
                }, "RustMenu" + ".Content" + ".Right" + $".Case.{number}.BtnTitle");
            }
        }

        [ConsoleCommand("caseshow")]
        void CaseShowCmd(ConsoleSystem.Arg arg)
        {
            if (arg.HasArgs())
            {
                if (arg.Args[0] == "close")
                {
                    CuiHelper.DestroyUi(arg.Player(), "RustMenu" + ".Content" + ".Right");

                    return;
                }
                Case _case = _cases.Find(x => x.Name == arg.Args[0]);
                if (_case == null)
                {
                    return;
                }

                RenderKitInfo(arg.Player(), _case);
            }
        }

        private void RenderKitInfo(BasePlayer player, Case _case)
        {
            CuiHelper.DestroyUi(player, "RustMenu" + ".Content" + ".Right.Cases");
            CuiElementContainer Container = new CuiElementContainer();
            Container.Add(new CuiElement
            {
                Name = "RustMenu" + ".Content" + ".Right" + $".Title",
                Parent = "RustMenu" + ".Content" + ".Right",
                Components =
                    {
                        new CuiTextComponent
                        {
                            Text = lang.GetMessage("TITLE_CASESHOW", this, player.UserIDString).Replace("%", lang.GetMessage(_case.Name, this, player.UserIDString)),
                            Align = TextAnchor.MiddleCenter,
                            FontSize = 24,
                            Font = "robotocondensed-bold.ttf",
                            FadeIn = 0.5f,
                        },
                        new CuiRectTransformComponent
                        {
                            AnchorMin = "0.5 1",
                            AnchorMax = "0.5 1",
                            OffsetMin = $"-275 -75",
                            OffsetMax = $"275 0",
                        }
                    }
            });

            for (int i = 0, x = 0, y = 0; i < _case.Items.Count; i++)
            {
                if (x > 5)
                {
                    x = 0;
                    y++;
                }
                if (ItemManager.itemDictionaryByName.ContainsKey(_case.Items[i].Subject))
                {
                    Container.Add(new CuiElement
                    {
                        Name = "RustMenu" + ".Content" + ".Right" + $"Case.Info.Item{i}.Background",
                        Parent = "RustMenu" + ".Content" + ".Right",
                        Components =
                                {
                                    new CuiImageComponent
                                    {
                                        Color = "1 1 1 0.05",
                                    },
                                    new CuiRectTransformComponent
                                    {
                                        AnchorMin = "0.5 1",
                                        AnchorMax = "0.5 1",
                                        OffsetMin = $"{-275 + x * 90} {-155 - y * 90}",
                                        OffsetMax = $"{-195 + x * 90} {-75 - y * 90}",
                                    }
                                }
                    });

                    Container.Add(new CuiElement
                    {
                        Name = "RustMenu" + ".Content" + ".Right" + $"Case.Info.Item{i}.Background.Img",
                        Parent = "RustMenu" + ".Content" + ".Right" + $"Case.Info.Item{i}.Background",
                        Components =
                            {
                                new CuiRawImageComponent
                                {
                                    FadeIn = 0.5f,
                                    Png = GetImage(_case.Items[i].Subject),
                                },
                                new CuiRectTransformComponent
                                {
                                    AnchorMin = $"0.1 0.1",
                                    AnchorMax = $"0.9 0.9",
                                }
                            }
                    });

                    Container.Add(new CuiElement
                    {
                        Name = "RustMenu" + ".Content" + ".Right" + $"Case.Info.Item{i}.Background.Amount",
                        Parent = "RustMenu" + ".Content" + ".Right" + $"Case.Info.Item{i}.Background",
                        Components =
                        {
                            new CuiTextComponent
                            {
                                Text = _case.Items[i].Amount + " шт",
                                Align = TextAnchor.MiddleCenter,
                                FontSize = 12,
                                Font = "robotocondensed-bold.ttf",
                                FadeIn = 0.5f,
                            },
                            new CuiRectTransformComponent
                            {
                                AnchorMin = $"0 0",
                                AnchorMax = $"1 0.3",
                            }
                        }
                    });
                    x++;
                }
            }

            CuiHelper.AddUi(player, Container);
        }

        [ConsoleCommand("rustcases.get")]
        private void CMDGet(ConsoleSystem.Arg arg)
        {
            if (arg.HasArgs(3))
            {
                int caseNum;
                if (int.TryParse(arg.Args[0], out caseNum))
                {
                    int positionX = int.Parse(arg.Args[1]);
                    int positionY = int.Parse(arg.Args[2]);
                    BasePlayer player = arg.Player();
                    Case box = _cases[caseNum];

                    if (box.EnoughСurrency(player) && box.CanReceive(player))
                    {
                        box.PayForCase(player);
                        box.Receive(player);
                        CuiElementContainer Container = new CuiElementContainer();
                        if(_cases[caseNum] is CaseRandom == false)
                            RenderCase(player, Container, caseNum, positionX, positionY);
                        CuiHelper.AddUi(player, Container);
                    }
                }
            }
        }
    }

    #region Helpers
    public static class TimeExtensions
    {
        public static string FormatShortTime(TimeSpan time)
        {
            string result = string.Empty;
            if (time.Days != 0)
                result += $"{time.Days}д ";

            if (time.Hours != 0)
                result += $"{time.Hours}ч ";

            if (time.Minutes != 0)
                result += $"{time.Minutes}м ";

            if (time.Seconds != 0)
                result += $"{time.Seconds}с ";

            return result;
        }

        public static string FormatTime(TimeSpan time)
        {
            string result = string.Empty;
            if (time.Days != 0)
                result += $"{Format(time.Days, "дней", "дня", "день")} ";

            if (time.Hours != 0)
                result += $"{Format(time.Hours, "часов", "часа", "час")} ";

            if (time.Minutes != 0)
                result += $"{Format(time.Minutes, "минут", "минуты", "минута")} ";

            if (time.Seconds != 0)
                result += $"{Format(time.Seconds, "секунд", "секунды", "секунда")} ";

            return result;
        }

        private static string Format(int units, string form1, string form2, string form3)
        {
            var tmp = units % 10;

            if (units >= 5 && units <= 20 || tmp >= 5 && tmp <= 9)
                return $"{units} {form1}";

            if (tmp >= 2 && tmp <= 4)
                return $"{units} {form2}";

            return $"{units} {form3}";
        }
    }
    #endregion
}

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