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

FREE TournamentBoloto : 1.1.1 1.1.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.1.1")]
    public class TournamentBoloto : RustPlugin
    {
        #region [Vars]
        [PluginReference] private Plugin RustMap = null, Clan = null;
        public string Layer = "UI_Layer";
        private bool newSave = false;

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

        #region [Data-Clans]
        public List<CupData> CupboardData = new List<CupData>();
        public class CupData
        {
            public string nameClan;
            public int Warn;
            public int Point;
            public int raidPoint;
            public bool isRaided;
            public ulong netID;
        }

        private void LoadData() => CupboardData = Oxide.Core.Interface.Oxide.DataFileSystem.ReadObject<List<CupData>>("TournamentBoloto/Data");
        private void SaveData() => Oxide.Core.Interface.Oxide.DataFileSystem.WriteObject("TournamentBoloto/Data", CupboardData);
        #endregion

        #region [Destory-History]
        public List<HistoryData> DestroyHistory = new List<HistoryData>();
        public class HistoryData
        {
            public string nameClan;
            public string deathClan;
            public string DataTime;

            public int timeDestroy;
        }

        private void LoadHistory() => DestroyHistory = Oxide.Core.Interface.Oxide.DataFileSystem.ReadObject<List<HistoryData>>("TournamentBoloto/History");
        private void SaveHistory() => Oxide.Core.Interface.Oxide.DataFileSystem.WriteObject("TournamentBoloto/History", DestroyHistory);
        #endregion

        #region [Oxide]
        private void OnNewSave() => newSave = true;

        private void OnServerInitialized()
        {
            cmd.AddChatCommand(config.openMenuCommand, this, "cmdRaidTop");
            cmd.AddChatCommand(config.openHistoryMenuCommand, this, "cmdHistoryTop");
            timer.Every(5, TimeHandle);
            if (newSave)
            {
                LoadData();
                LoadHistory();
                DestroyHistory.Clear();
                CupboardData.Clear();
            }
            else
            {
                LoadData();
                LoadHistory();
                foreach (var data in CupboardData)
                {
                    var entity = BaseNetworkable.serverEntities.Find(new NetworkableId(data.netID));
                    if (entity == null && data.isRaided == false)
                    {
                        data.isRaided = true;
                    }
                    if (entity != null && data.isRaided == false && data.Warn < config.MaxWarn)
                    {
                        if (config._RustMapsSettings.UseRustMap)
                            AddRustMap(data);
                        if (config._MarkerInGameSettings.UseGameMarker)
                            AddGenereticMarker(data);

                        _List.Add(data.netID);
                    }
                }
            }
        }

        private void Unload()
        {
            SaveData();
            SaveHistory();
            foreach (var data in CupboardData)
            {
                if (data.isRaided == false && data.Warn < config.MaxWarn)
                {
                    if (config._RustMapsSettings.UseRustMap)
                        RemoveRustMap(data);
                    if (config._MarkerInGameSettings.UseGameMarker)  
                        RemoveGenereticMarker(data);
                }
            }

            foreach (var player in BasePlayer.activePlayerList)
                CuiHelper.DestroyUi(player, Layer);
        }
        #endregion

        #region [Rust]
        private object OnEntityTakeDamage(BuildingPrivlidge entity, HitInfo info)
        {
            if (entity == null || info == null) return null;
            if (info.InitiatorPlayer == null) return null;

            BasePlayer player = info.InitiatorPlayer;
            if (player == null) return null;
            if (!_List.Contains(entity.net.ID.Value)) return null;
            
            var IsFriend = (bool)Clan?.CallHook("ApiIsClanMember", entity.OwnerID, player.userID);
            if (IsFriend)
            {
                if (player.SecondsSinceAttacked > 5)
                {
                    player.ChatMessage("Вы не имеете право уничтожать турнирный шкаф своего же клана!");
                    player.lastAttackedTime = UnityEngine.Time.time;
                    return false;
                }
                return false;
            }

            return null;
        }

        private void OnEntityDeath(BaseCombatEntity entity, HitInfo info)
        {
            if (entity == null || info == null) return;

            BasePlayer player = info.InitiatorPlayer;
            if (player == null) return;
            if (!_List.Contains(entity.net.ID.Value)) return;

            var find = CupboardData.FirstOrDefault(p => p.netID == entity.net.ID.Value);
            if (find == null) return;
            if (find.Warn >= config.MaxWarn) return;

            find.isRaided = true;

            if (config._RustMapsSettings.UseRustMap)
                RemoveRustMap(find);
            if (config._MarkerInGameSettings.UseGameMarker)  
                RemoveGenereticMarker(find);

            Server.Broadcast($"Клан {find.nameClan} был зарейжен игроком {player.displayName}");

            var nameClan = GetClanTag(player);
            if (string.IsNullOrEmpty(nameClan)) return;

            var findClan = CupboardData.FirstOrDefault(p => p.nameClan == nameClan);
            if (findClan == null) return;

            //Clan?.CallHook("GetPointRaid", find.nameClan, player.userID);
            findClan.Point += find.raidPoint;

            DestroyHistory.Add(new HistoryData()
            {
                nameClan = nameClan,
                deathClan = find.nameClan,
                DataTime = $"{DateTime.Now.ToString("t")} {DateTime.Now.Day}/{DateTime.Now.Month}/{DateTime.Now.Year}",
                timeDestroy = (int)DateTime.UtcNow.Subtract(epoch).TotalSeconds
            });

            _List.Remove(find.netID);
            SaveHistory();
            SaveData();
        }

        private object OnEntityGroundMissing(BaseEntity entity)
        {
            if (entity == null) return null;
            if (_List.Contains(entity.net.ID.Value)) return false;
            return null;
        }

        private string canRemove(BasePlayer player, BaseEntity entity)
        {
            if (player == null || entity == null) return null;
            var build = entity as BuildingPrivlidge;
            if (build == null) return null;
            if (!_List.Contains(entity.net.ID.Value)) return null;
            return "Нельзя ремувать турнирный шкаф!";
        }

        private void OnLootEntity(BasePlayer player, BuildingPrivlidge entity)
        {
            if (player == null || entity == null) return;

            CuiHelper.DestroyUi(player, Layer);
            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 = GetClanTag(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;
            }

            var find = CupboardData.FirstOrDefault(p => p.nameClan == nameClan);
            if (find != null)
            {
                if (find.isRaided)
                {
                    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 (find.Warn >= config.MaxWarn)
                {
                    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" },
                    }
                });
                
                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;
            }

            bool GetLeader = IsLeader(player);
            if (!GetLeader)
            {
                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) < config.MinPoints)
            {
                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 [Gui]
        private void cmdRaidTop(BasePlayer player)
        {
            TopRaid(player, 0);
        }

        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.1", 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.000 0.000 0.000 0.90", 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.0795f, startxBox = 0.005f, startyBox = 0.9375f - height, xmin = startxBox, ymin = startyBox;
            var sortedData = (from x in CupboardData select x).Where(x => !x.isRaided && x.Warn < config.MaxWarn).OrderByDescending(x => x.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.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.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.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.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", 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.000 0.000 0.000 0", 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.000 0.000 0.000 0", 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);
        }
    
        private void cmdHistoryTop(BasePlayer player)
        {
            HistoryTop(player, 0);
        }

        private void HistoryTop(BasePlayer player, int page)
        {
            CuiHelper.DestroyUi(player, "TopHistory");
            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", "TopHistory");

            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 = "TopHistory" }
            }, "TopHistory");

            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" }
            }, "TopHistory", "TopHistoryMenuLayer");

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

            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.025 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.33 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.795 0", AnchorMax = $"1 0.87", OffsetMax = "0 0" },
                }
            });

            float width = 0.99f, height = 0.0795f, startxBox = 0.005f, startyBox = 0.9375f - height, xmin = startxBox, ymin = startyBox;
            var sortedData = (from x in DestroyHistory select x).OrderByDescending(x => x.timeDestroy);
            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" }
                }, "TopHistoryMenuLayer", "PlayerTop");

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

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

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

                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" }
            }, "TopHistoryMenuLayer", "TopHistoryMenuLayer_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 }
            }, "TopHistoryMenuLayer_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 ? $"tophistory {page + 1}" : "" },
                Text = { Text = $"+", Color = "1 1 1 1", Align = TextAnchor.MiddleCenter, FontSize = 18, Font = "robotocondensed-bold.ttf" }
            }, "TopHistoryMenuLayer");

            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 ? $"tophistory {page - 1}" : "" },
                Text = { Text = $"-", Color = "1 1 1 1", Align = TextAnchor.MiddleCenter, FontSize = 18, Font = "robotocondensed-bold.ttf" }
            }, "TopHistoryMenuLayer");

            CuiHelper.AddUi(player, container);
        }
        #endregion

        #region [GenericMarkers]
        private void AddGenereticMarker(CupData data)
        {
            var entity = BaseNetworkable.serverEntities.Find(new NetworkableId(data.netID));
            MapMarkerGenericRadius mapMarker = GameManager.server.CreateEntity("assets/prefabs/tools/map/genericradiusmarker.prefab", entity.transform.position) 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)
        {
            var marker = RadiusMarker.FirstOrDefault(p => p.name == data.nameClan);
            if (marker == null) return;

            marker.Kill();
            marker.SendUpdate();
        }
        #endregion

        #region [RustMaps-Marker]
        private void AddRustMap(CupData data)
        {
            RemoveRustMap(data);
            var entity = BaseNetworkable.serverEntities.Find(new NetworkableId(data.netID));
            RustMap?.Call("ApiAddPointUrl", config._RustMapsSettings.Icon, $"Marker{data.netID}", entity.transform.position, data.nameClan, config._RustMapsSettings.sizeMarker);
        }

        private void RemoveRustMap(CupData data) => RustMap?.Call("ApiRemovePointUrl", $"Marker{data.netID}");
        #endregion

        #region [ConsoleCommand && ChatCommand]
        [ConsoleCommand("regtc")]
        void cmdRegClan(ConsoleSystem.Arg args)
        {
            BasePlayer player = args?.Player();
            if (player == null || !args.HasArgs()) return;
            
            var nameClan = GetClanTag(player);
            if (string.IsNullOrEmpty(nameClan)) return;

            ulong building = 0;
            if (ulong.TryParse(args.Args[0], out building))
            {
                BuildingPrivlidge entity = BaseNetworkable.serverEntities.Find(new NetworkableId(building)) as BuildingPrivlidge;
                if (entity == null) return;
                
                CupData data = new CupData()
                {
                    nameClan = nameClan,
                    Warn = 0,
                    Point = 0,
                    raidPoint = 0,
                    isRaided = false,
                    netID = entity.net.ID.Value,
                };

                CupboardData.Add(data);

                if (config._RustMapsSettings.UseRustMap)
                    AddRustMap(data);
                if (config._MarkerInGameSettings.UseGameMarker)
                    AddGenereticMarker(data);

                player.ChatMessage("Вы успешно зарегистрировали свой клан!");
                player.EndLooting();
                _List.Add(entity.net.ID.Value);
                SaveData();
            }
        }

        [ChatCommand("tournament")]
        void CommandTournament(BasePlayer player, string command, string[] args)
        {
            if(!player.IsAdmin) return;
            if (args.Length == 0)
            {
                    player.ChatMessage("Доступные команды:"
                                       + "\n/tournament give point - Выдать очки клану" 
                                       + "\n/tournament give raidpoint - Выдать очки за рейд клану"
                                       + "\n/tournament give warn - Выдать предупреждения клану"
                                       + "\n\n/tournament remove point - Снять очки клану"
                                       + "\n/tournament remove raidpoint - Снять очки за рейд клану"
                                       + "\n/tournament remove warn - Снять предупреждения клану");
                return;
            }
            if (args[0] == "give")
            {
                if (args[1] == "point")
                {
                    if (args.Length < 3)
                    {
                        player.ChatMessage("/tournament give point TAG AMOUNT");
                        return;
                    }
                    var find = CupboardData.FirstOrDefault(p => p.nameClan == args[2]);
                    if (find == null)
                    {
                        player.ChatMessage("Клан не найден!");
                        return;
                    }
                    int amount = Convert.ToInt32(args[3]);
                    if (amount == null) return;
                    if(amount > 0)
                    {
                        find.Point += amount;
                        player.ChatMessage($"Вы выдали клану {find.nameClan}, {amount} очков!");
                        SaveData();
                    }
                }
                if (args[1] == "raidpoint")
                {
                    if (args.Length < 3)
                    {
                        player.ChatMessage("/tournament give raidpoint TAG AMOUNT");
                        return;
                    }
                    var find = CupboardData.FirstOrDefault(p => p.nameClan == args[2]);
                    if (find == null)
                    {
                        player.ChatMessage("Клан не найден!");
                        return;
                    }
                    int amount = Convert.ToInt32(args[3]);
                    if(amount > 0)
                    {
                        find.raidPoint += amount;
                        player.ChatMessage($"Вы выдали клану {find.nameClan}, {amount} рейд-очков!");
                        SaveData();
                    }
                }
                if (args[1] == "warn")
                {
                    if (args.Length < 3)
                    {
                        player.ChatMessage("/tournament give warn TAG");
                        return;
                    }
                    var find = CupboardData.FirstOrDefault(p => p.nameClan == args[2]);
                    if (find == null)
                    {
                        player.ChatMessage("Клан не найден!");
                        return;
                    }
                    if (find.Warn >= config.MaxWarn)
                    {
                        player.ChatMessage($"Вы не можете выдать больше {config.MaxWarn} предупреждений!");
                        return;
                    }
                    else
                    {
                        find.Warn++;
                        player.ChatMessage($"Вы выдали предупреждние клану {find.nameClan}");
                        Server.Broadcast($"Клан {find.nameClan} получил предупреждения от администратора {covalence.Players.FindPlayer(player.UserIDString).Name}");
                        SaveData();
                    }
                    if (find.Warn >= config.MaxWarn)
                    {
                        if (config._RustMapsSettings.UseRustMap)
                            RemoveRustMap(find);
                        if (config._MarkerInGameSettings.UseGameMarker)  
                            RemoveGenereticMarker(find);
                        Server.Broadcast($"Клан {find.nameClan} был снят с турнира за максимальное количество предупреждений, администратором {covalence.Players.FindPlayer(player.UserIDString).Name}");
                    }
                }
            }
            if (args[0] == "remove")
            {
                if (args[1] == "point")
                {
                    if (args.Length < 3)
                    {
                        player.ChatMessage("/tournament remove point TAG AMOUNT");
                        return;
                    }
                    var find = CupboardData.FirstOrDefault(p => p.nameClan == args[2]);
                    if (find == null)
                    {
                        player.ChatMessage("Клан не найден!");
                        return;
                    }
                    int amount = Convert.ToInt32(args[3]);
                    if (amount == null) return;
                    if(amount > 0)
                    {
                        find.Point -= amount;
                        player.ChatMessage($"Вы сняли клану {find.nameClan}, {amount} очков!");
                        SaveData();
                    }
                }
                if (args[1] == "raidpoint")
                {
                    if (args.Length < 3)
                    {
                        player.ChatMessage("/tournament remove raidpoint TAG AMOUNT");
                        return;
                    }
                    var find = CupboardData.FirstOrDefault(p => p.nameClan == args[2]);
                    if (find == null)
                    {
                        player.ChatMessage("Клан не найден!");
                        return;
                    }
                    int amount = Convert.ToInt32(args[3]);
                    if(amount > 0)
                    {
                        find.raidPoint -= amount;
                        player.ChatMessage($"Вы сняли клану {find.nameClan}, {amount} рейд-очков!");
                        SaveData();
                    }
                }
                if (args[1] == "warn")
                {
                    if (args.Length < 3)
                    {
                        player.ChatMessage("/tournament remove warn TAG AMOUNT");
                        return;
                    }
                    var find = CupboardData.FirstOrDefault(p => p.nameClan == args[2]);
                    if (find == null)
                    {
                        player.ChatMessage("Клан не найден!");
                        return;
                    }
                    if (find.Warn == 0)
                    {
                        player.ChatMessage("Нельзя снять варны когда их 0!");
                        return;
                    }
                    else
                    {
                        find.Warn--;
                        player.ChatMessage($"Вы убрали предупреждение клану {find.nameClan}");
                        SaveData();
                    }
                }
            }
        }

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

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

        #region [Functional]
        private bool CheckRegistration(string nameClan)
        {
            var findData = CupboardData.FirstOrDefault(p => p.nameClan == nameClan);
            if (findData == null || findData.isRaided || findData.Warn >= config.MaxWarn)
            {
                return false;
            }
            return true;
        }

        static readonly DateTime epoch = new DateTime(1970, 1, 1, 0, 0, 0);
        static double CurrentTime() => DateTime.UtcNow.Subtract(epoch).TotalSeconds;
        private double IsBlocked()
        {
            var lefTime = SaveRestore.SaveCreatedTime.ToUniversalTime().Subtract(epoch).TotalSeconds + (config.HoursReg * 3600) - CurrentTime();
            return lefTime > 0 ? lefTime : 0;
        }

        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),
// ... [Code preview truncated due to length. Full source in attached file] ...

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

Другие ресурсы пользователя 15FPS

Сверху