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

FREE TournamentBoloto : 1.0.1 1.0.1

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

namespace Oxide.Plugins
{
    [Info("TournamentBoloto", "King", "1.0.1")]
    public class TournamentBoloto : RustPlugin
    {
        #region [Vars]
        [PluginReference] private Plugin RustMap, Clans;
        public Dictionary<string, CupData> CupboardData = new Dictionary<string, CupData>();
        public class CupData
        {
            public string nameClan;
            public int Warn;
            public int Point;
            public int raidPoint;
            public bool isRaided;
            public ulong netID;
            public Vector3 cupPos;
        }
        public string Layer = "UI_Layer";
        private bool newSave = false;

        public List<MapMarkerGenericRadius> RadiusMarker = new List<MapMarkerGenericRadius>();
        #endregion

        #region [Config]
        private PluginConfig config;

        protected override void LoadDefaultConfig()
        {
            config = PluginConfig.DefaultConfig();
        }

        protected override void LoadConfig()
        {
            base.LoadConfig();
            config = Config.ReadObject<PluginConfig>();

            if (config.PluginVersion < Version)
                UpdateConfigValues();

            Config.WriteObject(config, true);
        }

        private void UpdateConfigValues()
        {
            PluginConfig baseConfig = PluginConfig.DefaultConfig();
            if (config.PluginVersion < Version)
            {
                config.PluginVersion = Version;
                if (Version == new VersionNumber(1, 0, 1))
                {
                    config._MarkerInGameSettings.UseGameMarker = false;
                    config._MarkerInGameSettings.MarkerColor = "#FA122CDD";
                    config._MarkerInGameSettings.MarkerRadius = 1f; 
                }

                PrintWarning("Config checked completed!");
            }
            config.PluginVersion = Version;
        }

        protected override void SaveConfig()
        {
            Config.WriteObject(config);
        }

        public class RustMapsSettings
        {
            [JsonProperty("Добавить поддержку RustMap ?")]
            public bool UseRustMap;

            [JsonProperty("Иконка для карты RustMap")]
            public string Icon;

            [JsonProperty("Размеры иконки на карте RustMap")]
            public float sizeMarker;
        }

        public class MarkerInGameSettings
        {
            [JsonProperty("Добавить поддержку отметки на карте G ?")]
            public bool UseGameMarker;

            [JsonProperty("Цвет радиуса")] 
            public string MarkerColor;

            [JsonProperty("Радиус маркера")] 
            public float MarkerRadius;
        }

        private class PluginConfig
        {
            [JsonProperty("Удалять клан из даты при достижении максимального количества предов ?")]
            public bool WarnMaxDel;

            [JsonProperty("Команда для открытия топа")]
            public string openMenuCommand;

            [JsonProperty("Минимальное количество очков для регистрации")]
            public int MinPoints;

            [JsonProperty("После скольки часов после вайпа нельзя регистрироватся?")]
            public int HoursReg;

            [JsonProperty("Максимальное количество предупреждений ?")]
            public int MaxWarn;

            [JsonProperty("Настройки RustMap")] 
            public RustMapsSettings _RustMapsSettings = new RustMapsSettings();

            [JsonProperty("Настройки отметки на карте ( G )")] 
            public MarkerInGameSettings _MarkerInGameSettings = new MarkerInGameSettings();

            [JsonProperty("Config version")]
            public VersionNumber PluginVersion = new VersionNumber();

            public static PluginConfig DefaultConfig()
            {
                return new PluginConfig()
                {
                    WarnMaxDel = true,
                    openMenuCommand = "ttop",
                    MinPoints = 500,
                    HoursReg = 24,
                    MaxWarn = 2,
                    _RustMapsSettings = new RustMapsSettings()
                    {
                        UseRustMap = false,
                        Icon = "https://i.ibb.co/gj54RB5/1.png",
                        sizeMarker = 0.06f,
                    },
                    _MarkerInGameSettings = new MarkerInGameSettings()
                    {
                        UseGameMarker = false,
                        MarkerColor = "#ffb700",
                        MarkerRadius = 1f,
                    },
                    PluginVersion = new VersionNumber()
                };
            }
        }
        #endregion

        #region [Data]
        void LoadData() => CupboardData = Oxide.Core.Interface.Oxide.DataFileSystem.ReadObject<Dictionary<string, CupData>>("TournamentBoloto/Data");
        void SaveData() => Oxide.Core.Interface.Oxide.DataFileSystem.WriteObject("TournamentBoloto/Data", CupboardData);
        #endregion

        #region [Oxide]
        private void OnServerInitialized()
        {
            cmd.AddChatCommand(config.openMenuCommand, this, "cmdRaidTop");
            timer.Every(30, TimeHandle);
            if (newSave)
            {
                LoadData();
                CupboardData.Clear();
            }
            else
            {
                LoadData();
                foreach (var data in CupboardData)
                {
                    var entity = BaseNetworkable.serverEntities.Find(new NetworkableId(data.Value.netID));
                    if (entity == null && data.Value.isRaided == false)
                    {
                        data.Value.isRaided = true;
                    }
                    if (entity != null && data.Value.isRaided == false)
                    {
                        if (config._RustMapsSettings.UseRustMap)
                            AddRustMap(data.Value);
                        if (config._MarkerInGameSettings.UseGameMarker)
                            AddGenereticMarker(data.Value);
                    }
                }
            }
        }
        void OnNewSave()
        {
            newSave = true;
        }
        private void Unload()
        {
            SaveData();
            foreach (var data in CupboardData)
            {
                if (data.Value.isRaided == false)
                {
                    if (config._RustMapsSettings.UseRustMap)
                        RemoveRustMap(data.Value);
                    if (config._MarkerInGameSettings.UseGameMarker)  
                        RemoveGenereticMarker(data.Value);
                }
            }
            foreach (var player in BasePlayer.activePlayerList)
            {
                CuiHelper.DestroyUi(player, Layer);
            }
        }
        #endregion

        #region [Rust-Api]
        object OnEntityTakeDamage(BaseCombatEntity entity, HitInfo hitInfo)
        {
            if (entity == null || hitInfo == null) return null;
            if (hitInfo.InitiatorPlayer == null) return null;
            if (entity as BuildingPrivlidge)
            {
                var player = hitInfo?.InitiatorPlayer.ToPlayer();
                string nameClan = ClanTag(player);
                if (string.IsNullOrEmpty(nameClan)) return null;
                var clanDate = FindData(nameClan);
                if (clanDate == "ERRORCLANNAME") return null;
                var clanData = CupboardData[clanDate];
                if (clanData.cupPos == entity.transform.position)
                {
                    var IsFriend = Clans?.CallHook("CheckClans", entity.net.ID, player.OwnerID);
                    if (IsFriend is bool && (bool)IsFriend)
                    {
                        if (player.SecondsSinceAttacked > 5)
                        {
                            player.ChatMessage("Вы не имеете право уничтожать турнирный шкаф своего же клана!");
                            player.lastAttackedTime = UnityEngine.Time.time;
                            return false;
                        }
                        return false;
                    }
                    else if (entity.OwnerID == player.userID)
                    {
                        if (player.SecondsSinceAttacked > 5)
                        {
                            player.ChatMessage("Вы не имеете право уничтожать турнирный шкаф своего же клана!");
                            player.lastAttackedTime = UnityEngine.Time.time;
                            return false;
                        }
                        return false;
                    }
                }
            }
            return null;
        }
        object OnEntityGroundMissing(BaseEntity entity)
        {
            if (entity == null) return null;
            var clanDate = FindDataByNetID(entity.net.ID.Value);
            if (clanDate == "ERRORCLANNAME") return null;
            if (CupboardData[clanDate].netID == entity.net.ID.Value)
            {
                return false;
            }
            return null;
        }
        void OnEntityDeath(BaseCombatEntity entity, HitInfo info)
        {
            if (entity == null) return;
            if (entity as BuildingPrivlidge && info != null && info.InitiatorPlayer != null)
            {
                var killer = info.InitiatorPlayer;
                var clanDate = FindDataByNetID(entity.net.ID.Value);
                if (clanDate != "ERRORCLANNAME")
                {
                    var ClanData = CupboardData[clanDate];
                    string nameClan = ClanTag(killer);
                    var killerDate = FindData(nameClan);
                    if (killerDate != "ERRORCLANNAME")
                    {
                        var killerData = CupboardData[killerDate];

                        Clans?.CallHook("ScoreRemove", ClanData.nameClan, killer.userID);
                        ClanData.isRaided = true;

                        killerData.raidPoint += ClanData.Point;
                        killerData.Point += ClanData.Point;

                        killer.ChatMessage("Вы уничтожили турнирный шкаф чужого клана!");

                        Server.Broadcast($"Клан {nameClan} зарейдил клан {ClanData.nameClan}");
                        if (config._RustMapsSettings.UseRustMap)
                            RemoveRustMap(ClanData);
                        if (config._MarkerInGameSettings.UseGameMarker)  
                            RemoveGenereticMarker(ClanData);
                        CupboardData.Remove(clanDate);
                        SaveData();
                    }
                }
            }
        }
        private void OnLootEntity(BasePlayer player, BaseEntity entity)
        {
            if (player == null || entity == null) return;
            if (entity as BuildingPrivlidge)
            {
                CuiHelper.DestroyUi(player, Layer);
                if (entity.OwnerID != player.userID) return;
                CuiElementContainer container = new CuiElementContainer();
                container.Add(new CuiPanel
                {
                    CursorEnabled = false,
                    RectTransform =
                        {AnchorMin="0.5 0", AnchorMax="0.5 0", OffsetMin="193.5 16", OffsetMax="431 97"},
                    Image = { Color = "1 0.96 0.88 0.15" }
                }, "Overlay", Layer);

                container.Add(new CuiElement
                {
                    Parent = Layer,
                    Components =
                    {
                        new CuiTextComponent { Text = $"УЧАСТНИЕ В КЛАНОВОМ ТУРНИРЕ", Color = "1 1 1 0.65", FontSize = 12, Align = TextAnchor.MiddleCenter, Font = "robotocondensed-regular.ttf" },
                        new CuiRectTransformComponent { AnchorMin = "0 0.7", AnchorMax = "0.991 1" },
                        new CuiOutlineComponent{Color = "0 0 0 1", Distance = "0.25 0.25"},
                    }
                });

                container.Add(new CuiElement
                {
                    Name = "CupRegisterMenu",
                    Parent = Layer,
                    Components =
                        {
                            new CuiImageComponent { Color = "0.3773585 0.3755785 0.3755785 1",Material = "assets/icons/greyout.mat" },
                            new CuiRectTransformComponent {AnchorMin = "0.08 0.08", AnchorMax = "0.925 0.68"}
                        }
                });

                string nameClan = ClanTag(player);
                if (string.IsNullOrEmpty(nameClan))
                {

                    container.Add(new CuiElement
                    {
                        Parent = "CupRegisterMenu",
                        Components =
                        {
                            new CuiTextComponent { Text = $"УЧАСТИЕ ЗАПРЕЩЕНО", Color = "1 1 1 0.65", FontSize = 16, Align = TextAnchor.MiddleCenter, Font = "robotocondensed-regular.ttf" },
                            new CuiRectTransformComponent { AnchorMin = "0 0.33", AnchorMax = "0.991 1" },
                            new CuiOutlineComponent{Color = "0 0 0 1", Distance = "0.25 0.25"},
                        }
                    });
                    
                    container.Add(new CuiElement
                    {
                        Parent = "CupRegisterMenu",
                        Components =
                        {
                            new CuiTextComponent { Text = $"Вы не состоите в клане!", Color = "1 1 1 0.45", FontSize = 8, Align = TextAnchor.MiddleCenter, Font = "robotocondensed-regular.ttf" },
                            new CuiRectTransformComponent { AnchorMin = "0 0", AnchorMax = "1 0.5" },
                            new CuiOutlineComponent{Color = "0 0 0 1", Distance = "0.025 0.025"},
                        }
                    });

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

                if (GetActive(nameClan))
                {
                    container.Add(new CuiElement
                    {
                        Parent = "CupRegisterMenu",
                        Components =
                        {
                            new CuiTextComponent { Text = $"УЧАСТИЕ ЗАПРЕЩЕНО", Color = "1 1 1 0.65", FontSize = 16, Align = TextAnchor.MiddleCenter, Font = "robotocondensed-regular.ttf" },
                            new CuiRectTransformComponent { AnchorMin = "0 0.33", AnchorMax = "0.991 1" },
                            new CuiOutlineComponent{Color = "0 0 0 1", Distance = "0.25 0.25"},
                        }
                    });
                    
                    container.Add(new CuiElement
                    {
                        Parent = "CupRegisterMenu",
                        Components =
                        {
                            new CuiTextComponent { Text = $"Вы уже участвуете!", Color = "1 1 1 0.45", FontSize = 10, Align = TextAnchor.MiddleCenter, Font = "robotocondensed-regular.ttf" },
                            new CuiRectTransformComponent { AnchorMin = "0 0", AnchorMax = "1 0.5" },
                            new CuiOutlineComponent{Color = "0 0 0 1", Distance = "0.025 0.025"},
                        }
                    });
                
                    CuiHelper.AddUi(player, container);
                    return;
                }


                if (IsBlocked() == 0)
                {
                    container.Add(new CuiElement
                    {
                        Parent = "CupRegisterMenu",
                        Components =
                        {
                            new CuiTextComponent { Text = $"УЧАСТИЕ ЗАПРЕЩЕНО", Color = "1 1 1 0.65", FontSize = 16, Align = TextAnchor.MiddleCenter, Font = "robotocondensed-regular.ttf" },
                            new CuiRectTransformComponent { AnchorMin = "0 0.33", AnchorMax = "0.991 1" },
                            new CuiOutlineComponent{Color = "0 0 0 1", Distance = "0.25 0.25"},
                        }
                    });
                    
                    container.Add(new CuiElement
                    {
                        Parent = "CupRegisterMenu",
                        Components =
                        {
                            new CuiTextComponent { Text = $"Прошло 24 часа!", Color = "1 1 1 0.45", FontSize = 10, Align = TextAnchor.MiddleCenter, Font = "robotocondensed-regular.ttf" },
                            new CuiRectTransformComponent { AnchorMin = "0 0", AnchorMax = "1 0.5" },
                            new CuiOutlineComponent{Color = "0 0 0 1", Distance = "0.025 0.025"},
                        }
                    });

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

                if (IsLeader(player) is bool && !(bool)IsLeader(player))
                {

                    container.Add(new CuiElement
                    {
                        Parent = "CupRegisterMenu",
                        Components =
                        {
                            new CuiTextComponent { Text = $"УЧАСТИЕ ЗАПРЕЩЕНО", Color = "1 1 1 0.65", FontSize = 16, Align = TextAnchor.MiddleCenter, Font = "robotocondensed-regular.ttf" },
                            new CuiRectTransformComponent { AnchorMin = "0 0.33", AnchorMax = "0.991 1" },
                            new CuiOutlineComponent{Color = "0 0 0 1", Distance = "0.25 0.25"},
                        }
                    });
                    
                    container.Add(new CuiElement
                    {
                        Parent = "CupRegisterMenu",
                        Components =
                        {
                            new CuiTextComponent { Text = $"Вы не являетесь главной своего клана!", Color = "1 1 1 0.45", FontSize = 8, Align = TextAnchor.MiddleCenter, Font = "robotocondensed-regular.ttf" },
                            new CuiRectTransformComponent { AnchorMin = "0 0", AnchorMax = "1 0.5" },
                            new CuiOutlineComponent{Color = "0 0 0 1", Distance = "0.025 0.025"},
                        }
                    });

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

                if (ClanPoint(player) < 500)
                {
                    container.Add(new CuiElement
                    {
                        Parent = "CupRegisterMenu",
                        Components =
                        {
                            new CuiTextComponent { Text = $"УЧАСТИЕ ЗАПРЕЩЕНО", Color = "1 1 1 0.65", FontSize = 16, Align = TextAnchor.MiddleCenter, Font = "robotocondensed-regular.ttf" },
                            new CuiRectTransformComponent { AnchorMin = "0 0.33", AnchorMax = "0.991 1" },
                            new CuiOutlineComponent{Color = "0 0 0 1", Distance = "0.25 0.25"},
                        }
                    });
                    
                    container.Add(new CuiElement
                    {
                        Parent = "CupRegisterMenu",
                        Components =
                        {
                            new CuiTextComponent { Text = $"недостаточно клановых очков", Color = "1 1 1 0.45", FontSize = 10, Align = TextAnchor.MiddleCenter, Font = "robotocondensed-regular.ttf" },
                            new CuiRectTransformComponent { AnchorMin = "0 0", AnchorMax = "1 0.5" },
                            new CuiOutlineComponent{Color = "0 0 0 1", Distance = "0.025 0.025"},
                        }
                    });
                    CuiHelper.AddUi(player, container);
                    return;
                }

                var findData = FindData(nameClan);
                if (findData != "ERRORCLANNAME")
                {
                    var find = CupboardData[findData];
                    if (find.isRaided == true)
                    {
                        container.Add(new CuiElement
                        {
                            Parent = "CupRegisterMenu",
                            Components =
                            {
                                new CuiTextComponent { Text = $"УЧАСТИЕ ЗАПРЕЩЕНО", Color = "1 1 1 0.65", FontSize = 16, Align = TextAnchor.MiddleCenter, Font = "robotocondensed-regular.ttf" },
                                new CuiRectTransformComponent { AnchorMin = "0 0.33", AnchorMax = "0.991 1" },
                                new CuiOutlineComponent{Color = "0 0 0 1", Distance = "0.25 0.25"},
                            }
                        });
                    
                        container.Add(new CuiElement
                        {
                            Parent = "CupRegisterMenu",
                            Components =
                            {
                                new CuiTextComponent { Text = $"Ваш турнирный шкаф уже был уничтожен", Color = "1 1 1 0.45", FontSize = 10, Align = TextAnchor.MiddleCenter, Font = "robotocondensed-regular.ttf" },
                                new CuiRectTransformComponent { AnchorMin = "0 0", AnchorMax = "1 0.5" },
                                new CuiOutlineComponent{Color = "0 0 0 1", Distance = "0.025 0.025"},
                            }
                        });
                        CuiHelper.AddUi(player, container);
                        return;
                    }
                }

                container.Add(new CuiElement
                {
                    Parent = "CupRegisterMenu",
                    Components =
                    {
                        new CuiTextComponent { Text = $"УЧАСТИЕ РАЗРЕШЕНО", Color = "1 1 1 0.65", FontSize = 16, Align = TextAnchor.MiddleCenter, Font = "robotocondensed-regular.ttf" },
                        new CuiRectTransformComponent { AnchorMin = "0 0.33", AnchorMax = "0.991 1" },
                        new CuiOutlineComponent{Color = "0 0 0 1", Distance = "0.25 0.25"},
                    }
                });

                container.Add(new CuiElement
                {
                    Parent = "CupRegisterMenu",
                    Components =
                    {
                        new CuiTextComponent { Text = $"Зарегистрироваться на турнир", Color = "1 1 1 0.45", FontSize = 10, Align = TextAnchor.MiddleCenter, Font = "robotocondensed-regular.ttf" },
                        new CuiRectTransformComponent { AnchorMin = "0 0", AnchorMax = "1 0.5" },
                        new CuiOutlineComponent{Color = "0 0 0 1", Distance = "0.025 0.025"},
                    }
                });

                container.Add(new CuiButton
                {
                    RectTransform = { AnchorMin = "0 0", AnchorMax = "1 1" },
                    Button = { Color = "0 0 0 0",Material = "assets/icons/greyout.mat", Command = $"regtc {entity.net.ID}" }
                }, "CupRegisterMenu");
                CuiHelper.AddUi(player, container);
            }
        }
        private void OnLootEntityEnd(BasePlayer player, BuildingPrivlidge entity) => CuiHelper.DestroyUi(player, Layer);
        #endregion
 
        #region [ConsoleCommand ** ChatCommand]
        [ConsoleCommand("regtc")]
        void RegClan(ConsoleSystem.Arg args)
        {
            BasePlayer player = args.Player();
            ulong ent = Convert.ToUInt64(args.Args[0]);
            string nameClan = ClanTag(player);
            var EntityPos = BaseNetworkable.serverEntities.Find(new NetworkableId(ent))?.transform.position;

            CupData data = new CupData()
            {
                nameClan = nameClan,
                Warn = 0,
                Point = 0,
                raidPoint = 0,
                isRaided = false,
                netID = ent,
                cupPos = (Vector3)EntityPos
            };

            CupboardData.Add(nameClan, data);
            SaveData();
            if (config._RustMapsSettings.UseRustMap)
                AddRustMap(data);
            if (config._MarkerInGameSettings.UseGameMarker)
                AddGenereticMarker(data);
            CuiHelper.DestroyUi(player, Layer);
                
            player.ChatMessage("Вы успешно зарегистрировали свой клан!");
            player.EndLooting();
        }
        [ChatCommand("tournament")]
        void CommandTournament(BasePlayer player, string command, string[] args)
        {
            if(!player.IsAdmin) return;
            if (args.Length == 0)
            {
                    player.ChatMessage("Доступные команды:"
                                       + "\n/tournament give - Выдать очки кланку" 
                                       + "\n/tournament warn - Выдать предупреждение клану"
                                       + "\n/tournament remwarn - Убрать предупреждение клану");
                return;
            }
            if (args[0] == "give")
            {
                if (args.Length < 3)
                {
                    player.ChatMessage("/tournament give TAG AMOUNT");
                    return;
                }
                var clanName = FindData(args[1]);
                if (clanName == "ERRORCLANNAME")
                {
                    player.ChatMessage("Клан не найден!");
                    return;
                }
                var data = CupboardData[clanName];
                int amount = Convert.ToInt32(args[2]);
                if(amount > 0)
                {
                    data.Point += amount;
                    player.ChatMessage($"Вы выдали клану {clanName}, {amount} очков!");
                    SaveData();
                }
            }
            if (args[0] == "warn")
            {
                if (args.Length < 2)
                {
                    player.ChatMessage("/tournament warn TAG");
                    return;
                }
                var clanName = FindData(args[1]);
                if (clanName == "ERRORCLANNAME")
                {
                    player.ChatMessage("Клан не найден!");
                    return;
                }
                var data = CupboardData[clanName];
                if(args.Length > 3)
                {
                    player.ChatMessage("Нельзя так писать!");
                    return;
                }
                if (data.Warn > config.MaxWarn - 1)
                {
                    player.ChatMessage($"Вы не можете выдать больше {config.MaxWarn} предупреждений!");
                }
                else
                {
                    data.Warn++;
                    player.ChatMessage($"Вы выдали предупреждние клану {clanName}");
                    SaveData();
                }
                if (config.WarnMaxDel)
                {
                    if (data.Warn == config.MaxWarn)
                    {
                        Puts("Клан успешно удален!");
                        if (config._RustMapsSettings.UseRustMap)
                            RemoveRustMap(data);
                        if (config._MarkerInGameSettings.UseGameMarker)  
                            RemoveGenereticMarker(data);
                        CupboardData.Remove(clanName);
                    }
                }
            }
            if (args[0] == "remwarn")
            {
                if (args.Length < 2)
                {
                    player.ChatMessage("/tournament warn TAG");
                    return;
                }
                var clanName = FindData(args[1]);
                if (clanName == "ERRORCLANNAME")
                {
                    player.ChatMessage("Клан не найден!");
                    return;
                }
                var data = CupboardData[clanName];
                if(args.Length > 3)
                {
                    player.ChatMessage("Нельзя так писать!");
                    return;
                }
                if (data.Warn == 0)
                {
                    player.ChatMessage("Нельзя снять варны когда их 0!");
                }
                else
                {
                    data.Warn--;
                    player.ChatMessage($"Вы выдали предупреждние клану {clanName}");
                    SaveData();
                }
            }
        }
        private void TopRaid(BasePlayer player, int page)
        {
            CuiHelper.DestroyUi(player, "TopRaidMenu");
            var container = new CuiElementContainer();
     
            container.Add(new CuiPanel
            {
                CursorEnabled = true,
                RectTransform = { AnchorMin = "0 0", AnchorMax = "1 1", OffsetMax = "0 0" },
                Image = { Material = "assets/content/ui/uibackgroundblur.mat", Color = "0 0 0 0.77" }
            }, "Overlay", "TopRaidMenu");

            container.Add(new CuiButton
            {
                RectTransform = { AnchorMin = "0 0", AnchorMax = "1 1" },
                Button = { Color = "0.36 0.33 0.28 0.3", Material = "assets/icons/greyout.mat", Close = "TopRaidMenu" }
            }, "TopRaidMenu");

            container.Add(new CuiPanel
            {
                RectTransform = { AnchorMin = "0.5 0.5", AnchorMax = "0.5 0.5", OffsetMin = "-240 -120", OffsetMax = "240 195" },
                Image = { Color = "0.3773585 0.3755785 0.3755785 0.3407843", Material = "assets/icons/greyout.mat" }
            }, "TopRaidMenu", "TopRaidMenuLayer");

            container.Add(new CuiPanel
            {
                RectTransform = { AnchorMin = "0 0.935", AnchorMax = $"1 1" },
                Image = { Color = "0 0 0 0" }
            }, "TopRaidMenuLayer", "DescriptionsParent");

            container.Add(new CuiElement
            {
                Parent = "DescriptionsParent",
                Components =
                {
                        new CuiTextComponent { Text = $"#", Color = "1 1 1 1", Align = TextAnchor.MiddleLeft, FontSize = 14, Font = "robotocondensed-regular.ttf" },
                        new CuiRectTransformComponent { AnchorMin = $"0.025 0", AnchorMax = $"1 0.8", OffsetMax = "0 0" },
                }
            });

            container.Add(new CuiElement
            {
                Parent = "DescriptionsParent",
                Components =
                {
                        new CuiTextComponent { Text = $"НАЗВАНИЕ КЛАНА", Color = "1 1 1 1", Align = TextAnchor.MiddleLeft, FontSize = 12, Font = "robotocondensed-regular.ttf" },
                        new CuiRectTransformComponent { AnchorMin = $"0.117 0", AnchorMax = $"1 0.87", OffsetMax = "0 0" },
                }
            });

            container.Add(new CuiElement
            {
                Parent = "DescriptionsParent",
                Components =
                {
                        new CuiTextComponent { Text = $"ОБЩЕЕ КОЛ-ВО ОЧКОВ", Color = "1 1 1 1", Align = TextAnchor.MiddleLeft, FontSize = 12, Font = "robotocondensed-regular.ttf" },
                        new CuiRectTransformComponent { AnchorMin = $"0.35 0", AnchorMax = $"1 0.87", OffsetMax = "0 0" },
                }
            });

            container.Add(new CuiElement
            {
                Parent = "DescriptionsParent",
                Components =
                {
                        new CuiTextComponent { Text = $"ОЧКИ ЗА РЕЙД", Color = "1 1 1 1", Align = TextAnchor.MiddleLeft, FontSize = 12, Font = "robotocondensed-regular.ttf" },
                        new CuiRectTransformComponent { AnchorMin = $"0.63 0", AnchorMax = $"1 0.87", OffsetMax = "0 0" },
                }
            });

            container.Add(new CuiElement
            {
                Parent = "DescriptionsParent",
                Components =
                {
                        new CuiTextComponent { Text = $"ПРЕДЫ", Color = "1 1 1 1", Align = TextAnchor.MiddleLeft, FontSize = 12, Font = "robotocondensed-regular.ttf" },
                        new CuiRectTransformComponent { AnchorMin = $"0.845 0", AnchorMax = $"1 0.87", OffsetMax = "0 0" },
                }
            });

            int i = 0;
            float width = 0.99f, height = 0.0825f, startxBox = 0.005f, startyBox = 0.9375f - height, xmin = startxBox, ymin = startyBox;
            var sortedData = (from x in CupboardData select x).OrderByDescending(x => x.Value.Point);
            foreach (var check in sortedData.Skip(page * 10).Take(10))
            {
                container.Add(new CuiPanel
                {
                    RectTransform = { AnchorMin = $"{xmin} {ymin}", AnchorMax = $"{xmin + width} {ymin + height * 1}", OffsetMin = "2 1", OffsetMax = "-2 -1" },
                    Image = { Color = "0.2 0.2 0.2 0.55" }
                }, "TopRaidMenuLayer", "PlayerTop");

                container.Add(new CuiLabel
                {
                    Text = { Text = $"{i + 1 +(page*10)}", Color = "1 1 1 1", Align = TextAnchor.MiddleLeft, FontSize = 13, Font = "robotocondensed-regular.ttf" },
                    RectTransform = { AnchorMin = $"0.015 0", AnchorMax = $"1 1" },
                }, "PlayerTop");

                container.Add(new CuiLabel
                {
                    Text = { Text = $"{check.Value.nameClan}", Color = "1 1 1 1", Align = TextAnchor.MiddleLeft, FontSize = 13, Font = "robotocondensed-regular.ttf" },
                    RectTransform = { AnchorMin = $"0.11 0", AnchorMax = $"1 1" },
                }, "PlayerTop");

                container.Add(new CuiLabel
                {
                    Text = { Text = $"{check.Value.Point}", Color = "1 1 1 1", Align = TextAnchor.MiddleCenter, FontSize = 13, Font = "robotocondensed-regular.ttf" },
                    RectTransform = { AnchorMin = $"0.35 0", AnchorMax = $"0.6 1" },
                }, "PlayerTop");

                container.Add(new CuiLabel
                {
                    Text = { Text = $"{check.Value.raidPoint}", Color = "1 1 1 1", Align = TextAnchor.MiddleCenter, FontSize = 13, Font = "robotocondensed-regular.ttf" },
                    RectTransform = { AnchorMin = $"0.63 0", AnchorMax = $"0.79 1" },
                }, "PlayerTop");

                container.Add(new CuiLabel
                {
                    Text = { Text = $"{check.Value.Warn}/{config.MaxWarn}", Color = "1 1 1 1", Align = TextAnchor.MiddleCenter, FontSize = 13, Font = "robotocondensed-regular.ttf" },
                    RectTransform = { AnchorMin = $"0.845 0", AnchorMax = $"0.93 1" },
                }, "PlayerTop");

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

            container.Add(new CuiPanel
            {
                RectTransform = { AnchorMin = $"0.115 0.025", AnchorMax = $"0.2125 0.1275" },
                Image = { Color = "0 0 0 0.4", Material = "assets/icons/greyout.mat" }
            }, "TopRaidMenuLayer", "TopRaidMenuLayer_pagetext");

            container.Add(new CuiLabel
            {
                RectTransform = { AnchorMin = $"0 0", AnchorMax = $"1 1" },
                Text = { Text = $"{page + 1}", Color = "1 1 1 1", Font = "robotocondensed-regular.ttf", FontSize = 14, Align = TextAnchor.MiddleCenter }
            }, "TopRaidMenuLayer_pagetext");

            container.Add(new CuiButton
            {
                RectTransform = { AnchorMin = $"0.2125 0.025", AnchorMax = $"0.315 0.13" },
                Button = { Color = "0.46 0.44 0.42 0.6", Material = "assets/icons/greyout.mat", Command = sortedData.Skip(10 * (page + 1)).Count() > 0 ? $"topraid {page + 1}" : "" },
                Text = { Text = $"+", Color = "1 1 1 1", Align = TextAnchor.MiddleCenter, FontSize = 18, Font = "robotocondensed-bold.ttf" }
            }, "TopRaidMenuLayer");

            container.Add(new CuiButton
            {
                RectTransform = { AnchorMin = $"0.0125 0.025", AnchorMax = $"0.115 0.13" },
                Button = { Color = "0.46 0.44 0.42 0.6", Material = "assets/icons/greyout.mat", Command = page >= 1 ? $"topraid {page - 1}" : "" },
                Text = { Text = $"-", Color = "1 1 1 1", Align = TextAnchor.MiddleCenter, FontSize = 18, Font = "robotocondensed-bold.ttf" }
            }, "TopRaidMenuLayer");

            CuiHelper.AddUi(player, container);
        }

        void cmdRaidTop(BasePlayer player)
        {
            TopRaid(player, 0);
        }

        [ConsoleCommand("topraid")]
        void cmdTopRaidPage(ConsoleSystem.Arg arg)
        {
            var player = arg.Player();
            TopRaid(player, arg.Args != null ? int.Parse(arg.Args[0]) : 0);
        }
        #endregion

        #region [RustMaps-Marker]
        void AddRustMap(CupData data)
        {
            RemoveRustMap(data);
            RustMap?.Call("ApiAddPointUrl", config._RustMapsSettings.Icon, $"Marker{data.netID}", data.cupPos, data.nameClan, config._RustMapsSettings.sizeMarker);
        }
        void RemoveRustMap(CupData data)
        {
            RustMap?.Call("ApiRemovePointUrl", $"Marker{data.netID}");
        }
        #endregion

        #region [GenericMarkers]
        private void AddGenereticMarker(CupData data)
        {
            MapMarkerGenericRadius mapMarker = GameManager.server.CreateEntity("assets/prefabs/tools/map/genericradiusmarker.prefab", data.cupPos) as MapMarkerGenericRadius;

            mapMarker.alpha = 0.6f;
            mapMarker.color1 = ConvertToColor(config._MarkerInGameSettings.MarkerColor);
            mapMarker.name = data.nameClan;
            mapMarker.radius = config._MarkerInGameSettings.MarkerRadius;
            RadiusMarker.Add(mapMarker);
            mapMarker.Spawn();
            mapMarker.SendUpdate();
        }
        private void RemoveGenereticMarker(CupData data)
        {
            foreach (var marker in RadiusMarker)
            {
                if (marker != null)
                {
                    if (marker.name == data.nameClan)
                    {
                        marker.Kill();
                        marker.SendUpdate();
                    }
                }
            }
        }
        #endregion

        #region [Func]
        static readonly DateTime epoch = new DateTime(1970, 1, 1, 0, 0, 0);
        static double CurrentTime() { return DateTime.UtcNow.Subtract(epoch).TotalSeconds; }
        private double IsBlocked()
        {
            var lefTime = SaveRestore.SaveCreatedTime.ToUniversalTime().Subtract(new DateTime(1970, 1, 1, 0, 0, 0)).TotalSeconds + (config.HoursReg * 3600) - CurrentTime();
            return lefTime > 0 ? lefTime : 0;
        }
        private string FindDataByNetID(ulong netids)
        {
            foreach (var data in CupboardData)
            {
                if (data.Value.netID == netids)
                {
                    return data.Key;
                }
            }
            return "ERRORCLANNAME";
        }
        private string FindData(string tag)
        {
            foreach (var data in CupboardData)
            {
                if (data.Value.nameClan == tag)
                {
                    return data.Key;
                }
            }
            return "ERRORCLANNAME";
        }
        private Color ConvertToColor(string color)
        {
            if (color.StartsWith("#")) color = color.Substring(1);
            int red = int.Parse(color.Substring(0, 2), NumberStyles.AllowHexSpecifier);
            int green = int.Parse(color.Substring(2, 2), NumberStyles.AllowHexSpecifier);
            int blue = int.Parse(color.Substring(4, 2), NumberStyles.AllowHexSpecifier);
            return new Color((float)red / 255, (float)green / 255, (float)blue / 255);
        }
        public int ClanPoint(BasePlayer player)
        {
            return (int) Clans?.Call("ClanPoint", player.userID);
        }
        public string ClanTag(BasePlayer player)
        {
            return (string) Clans?.CallHook("GetClanTag", player.userID);
        }
        public object IsLeader(BasePlayer player)
        {
            return Clans?.CallHook("ClanCount", player.userID);
        }
        public bool GetActive(string nameClan)
        {
            if (FindData(nameClan) == "ERRORCLANNAME")
                return false;
            return !CupboardData[FindData(nameClan)].isRaided != null;
        }
        bool CheckRegistration(string nameClan)
        {
            if (FindData(nameClan) == "ERRORCLANNAME")
            {
                return false;
            }
            return true;
        }
		private void TimeHandle()
		{
            foreach(var mapMarker in RadiusMarker)
            {
                mapMarker.SendUpdate();
            }
		}
        #endregion
    }
}

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