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

FREE ClubPanel : 0.0.02 0.0.02

Нет прав для скачивания
C#:
using Oxide.Core;
using Oxide.Core.Plugins;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using Network;
using Oxide.Core.Unity.Logging;
using Oxide.Game.Rust.Cui;
using Steamworks;
using UnityEngine;

/*
 * Plugin developer: BadMandarin.
 * Contacts:
 *   - Discord: BadMandarin#4855
 *   - Telegram: @badmandarin
 *  CHANGELOG:
 *   - 0.0.01
 *     - created plugin structure
 *     - added interface
 *     - added exp system
 *     - added api
 *   - 0.0.02
 *     - added exp give hooks (gather, kill, loot)
 */

namespace Oxide.Plugins
{
    [Info("ClubPanel", "BadMandarin", "0.0.02")]
    [Description("ClubPanel")]
    class ClubPanel : RustPlugin
    {
        #region Classes
        private class PluginConfig
        {
            public double ExpRate;
            public double MaxExp;
            public double DefaultRate;
            public Dictionary<string, string> eventsImages;
            public Dictionary<string, string> menuButtons;
        }

        private class PluginInterface
        {
            public string LogoBlock;
            public string EventsBlock;
            public string OnlineBlock;
            public string ExpBlock;
            public string MenuBlock;
            public string MenuButton;
        }

        private class PanelManager : MonoBehaviour
        {
            public ActiveEvents Events;
            public int FakePlayers;
            public double LastOnlineUpdate = GetCurrentTime();
            public double NewFakeGenerate = GetCurrentTime();
            private HashSet<ulong> activeMenus;

            private int MaxFake = 30;
            
            private void Awake()
            {
                activeMenus = new HashSet<ulong>();
                Events = new ActiveEvents();
                
                foreach (BaseEntity e in BaseEntity.serverEntities)
                {
                    if (e is CargoPlane) Events.AirDrop++;
                    else if (e is BaseHelicopter) Events.Heli++;
                    else if (e is CH47Helicopter) Events.Chinook++;
                    else if (e is CargoShip) Events.Ship++;
                    else if (e is BradleyAPC) Events.Tank++;
                }
                
                for (int i = BasePlayer.activePlayerList.Count - 1; i >= 0; i--)
                {
                    var player = BasePlayer.activePlayerList[i];
                    LoadAllInterfacesPlayer(player);
                }
                
                //LoadAllInterfaces();
            }

            public void OnEventUpdated()
            {
                string gui = _interface.EventsBlock;
                // gui = gui.Replace("{HeliColor}", GetColor(Events.Heli == 0 ? "#FA5858" : "#FFFFFF", 1f));
                // gui = gui.Replace("{AirColor}", GetColor(Events.AirDrop == 0 ? "#FAAC58" : "#FFFFFF", 1f));
                // gui = gui.Replace("{TankColor}", GetColor(Events.Tank == 0 ? "#FA8258" : "#FFFFFF", 1f));
                // gui = gui.Replace("{ShipColor}", GetColor(Events.Ship == 0 ? "#5882FA" : "#FFFFFF", 1f));
                // gui = gui.Replace("{Ch47Color}", GetColor(Events.Chinook == 0 ? "#8258FA" : "#FFFFFF", 1f));
                gui = gui.Replace("{HeliColor}", GetColor("#FFFFFF", Events.Heli > 0 ? 1f : 0.5f));
                gui = gui.Replace("{AirColor}", GetColor("#FFFFFF", Events.AirDrop > 0 ? 1f : 0.5f));
                gui = gui.Replace("{TankColor}", GetColor("#FFFFFF", Events.Tank > 0 ? 1f : 0.5f));
                gui = gui.Replace("{ShipColor}", GetColor("#FFFFFF", Events.Ship > 0 ? 1f : 0.5f));
                gui = gui.Replace("{Ch47Color}", GetColor("#FFFFFF", Events.Chinook > 0 ? 1f : 0.5f));
                UpdateInterfaceAll(UI_LayerEvents, gui);
            }

            public void OnOnlineUpdated()
            {
                if (GetCurrentTime() - LastOnlineUpdate < 60)
                    return;

                
                string gui = _interface.OnlineBlock;
                FakeOnlineCalc();
                gui = gui.Replace("{Value}", $"{BasePlayer.activePlayerList.Count + FakePlayers}");
                UpdateInterfaceAll(UI_LayerOnline, gui);

                LastOnlineUpdate = GetCurrentTime();
            }
            
            public void OnExpUpdated(BasePlayer player, double newExp, int newScores)
            {
                string gui = _interface.ExpBlock;
                gui = gui.Replace("{EValue}", $"{(float)newExp / _config.MaxExp}");
                gui = gui.Replace("{SValue}", $"{newScores}");
                UpdateInterfacePlayer(player, UI_LayerExp, gui);
            }

            private void UpdateInterfaceAll(string layer, string value)
            {
                for (int i = BasePlayer.activePlayerList.Count - 1; i >= 0; i--)
                {
                    var player = BasePlayer.activePlayerList[i];
                    CuiHelper.DestroyUi(player, layer);
                    CuiHelper.AddUi(player, value);
                }
            }
            
            private void UpdateInterfacePlayer(BasePlayer player, string layer, string value)
            {
                if(!string.IsNullOrEmpty(layer)) CuiHelper.DestroyUi(player, layer);
                CuiHelper.AddUi(player, value);
            }

            private void LoadAllInterfaces()
            {
                string gui = _interface.ExpBlock;
                UpdateInterfaceAll(UI_Layer, _interface.LogoBlock);
                
                gui = _interface.EventsBlock;
                gui = gui.Replace("{HeliColor}", GetColor("#FFFFFF", Events.Heli > 0 ? 1f : 0.5f));
                gui = gui.Replace("{AirColor}", GetColor("#FFFFFF", Events.AirDrop > 0 ? 1f : 0.5f));
                gui = gui.Replace("{TankColor}", GetColor("#FFFFFF", Events.Tank > 0 ? 1f : 0.5f));
                gui = gui.Replace("{ShipColor}", GetColor("#FFFFFF", Events.Ship > 0 ? 1f : 0.5f));
                gui = gui.Replace("{Ch47Color}", GetColor("#FFFFFF", Events.Chinook > 0 ? 1f : 0.5f));
                UpdateInterfaceAll(UI_LayerEvents, gui);
                
                gui = _interface.ExpBlock;
                
                gui = gui.Replace("{EValue}", $"{0}");
                gui = gui.Replace("{SValue}", $"{0}");
                UpdateInterfaceAll(UI_LayerExp, gui);
                
                gui = _interface.OnlineBlock;
                FakeOnlineCalc();
                gui = gui.Replace("{Value}", $"{BasePlayer.activePlayerList.Count + FakePlayers}");
                UpdateInterfaceAll(UI_LayerOnline, gui);
                
                gui = _interface.MenuBlock;
                UpdateInterfaceAll(UI_LayerMenu, gui);
            }
            
            public void LoadAllInterfacesPlayer(BasePlayer player)
            {
                string gui = _interface.ExpBlock;
                UpdateInterfacePlayer(player, UI_Layer, _interface.LogoBlock);
                
                gui = _interface.EventsBlock;
                gui = gui.Replace("{HeliColor}", GetColor("#FFFFFF", Events.Heli > 0 ? 1f : 0.5f));
                gui = gui.Replace("{AirColor}", GetColor("#FFFFFF", Events.AirDrop > 0 ? 1f : 0.5f));
                gui = gui.Replace("{TankColor}", GetColor("#FFFFFF", Events.Tank > 0 ? 1f : 0.5f));
                gui = gui.Replace("{ShipColor}", GetColor("#FFFFFF", Events.Ship > 0 ? 1f : 0.5f));
                gui = gui.Replace("{Ch47Color}", GetColor("#FFFFFF", Events.Chinook > 0 ? 1f : 0.5f));
                UpdateInterfacePlayer(player, UI_LayerEvents, gui);
                
                gui = _interface.ExpBlock;
                LevelInfo pInfo;
                if (_plugin._data.PlayersData.TryGetValue(player.userID, out pInfo))
                {
                    gui = gui.Replace("{EValue}", $"{(float)pInfo.Exp / _config.MaxExp}");
                    gui = gui.Replace("{SValue}", $"{pInfo.Scores}");
                    UpdateInterfacePlayer(player, UI_LayerExp, gui);
                }

                gui = _interface.OnlineBlock;
                gui = gui.Replace("{Value}", $"{BasePlayer.activePlayerList.Count + FakePlayers}");
                UpdateInterfacePlayer(player, UI_LayerOnline, gui);
                
                gui = _interface.MenuBlock;
                UpdateInterfacePlayer(player, UI_LayerMenu, gui);
            }

            public void MenuToggle(BasePlayer player)
            {
                string gui = _interface.MenuBlock;
                UpdateInterfacePlayer(player, UI_LayerMenu, gui);
                
                if (activeMenus.Contains(player.userID))
                {
                    activeMenus.Remove(player.userID);
                }
                else
                {
                    int counter = 0;
                    foreach (var button in _config.menuButtons)
                    {
                        gui = _interface.MenuButton;
                        gui = gui.Replace("{Text}", button.Key);
                        gui = gui.Replace("{Command}", button.Value);
                        gui = gui.Replace("{OffsetMin}", $"0 {-25 - counter * 25}");
                        gui = gui.Replace("{OffsetMax}", $"0 {-5 - counter * 25}");
                        UpdateInterfacePlayer(player, "", gui);

                        counter++;
                    }
                    activeMenus.Add(player.userID);
                }
            }

            private void FakeOnlineCalc()
            {
                if (GetCurrentTime() - NewFakeGenerate < 60)
                    return;

                // max - 30
                // cur - x
                // cur * 30 / max
                
                int maxPlayers = ConVar.Server.maxplayers;

                if (maxPlayers > maxPlayers - MaxFake)
                {
                    FakePlayers = 0;
                    return;
                }
                
                int curPlayers = BasePlayer.activePlayerList.Count;
                int randValue = (curPlayers * MaxFake) / (maxPlayers - 30);

                FakePlayers = randValue;
                NewFakeGenerate = GetCurrentTime();
            }

            private void OnDestroy()
            {
            }

            public class ActiveEvents
            {
                public int Heli;
                public int Tank;
                public int Ship;
                public int Chinook;
                public int AirDrop;
            }
        }
        
        private class PluginData
        {
            public Hash<ulong, LevelInfo> PlayersData;
        }

        private class LevelInfo
        {
            public double Exp { get; set; }
            public int Scores { get; set; }
            public List<double> ExpQueue { get; set; } = new List<double>();
            public bool IsUpdating { get; set; } = false;
        }
        #endregion

        #region Variables
        //default variables
        private static ClubPanel _plugin;
        private bool _initiated;
        private PluginData _data; private string DataPath = $"WIPE/ClubPanel/Data";
        private static PluginConfig _config;

        //interface
        private static PluginInterface _interface;
        
        //Manager
        private PanelManager _panelManager;
        #endregion

        #region Config
        private void Init() => _config = Config.ReadObject<PluginConfig>();

        protected override void LoadDefaultConfig()
        {
            Config.WriteObject(GetDefaultConfig(), true);
        }
        
        private PluginConfig GetDefaultConfig()
        {
            return new PluginConfig
            {
                eventsImages = new Dictionary<string, string>()
                {
                    ["Air"] = "https://i.imgur.com/L5gPtMe.png",
                    ["Heli"] = "https://i.imgur.com/BxL7dCi.png",
                    ["Tank"] = "https://i.imgur.com/f3bKRJw.png",
                    ["Ship"] = "https://i.imgur.com/wS4ugfR.png",
                    ["Ch47"] = "https://i.imgur.com/F8mnbmF.png",
                },
                menuButtons = new Dictionary<string, string>()
                {
                    ["Кнопка 1"] = "chat.say /menu",
                }
            };
        }
        #endregion

        #region OxideHooks
        void OnServerInitialized()
        {
            _plugin = this;
            _initiated = false;

            StartPluginLoad();
        }
        
        void Unload()
        {
            UnloadPanel();
            for (int i = BasePlayer.activePlayerList.Count - 1; i >= 0; i--)
            {
                var player = BasePlayer.activePlayerList[i];
                CuiHelper.DestroyUi(player, UI_Layer);
            }
            
            if (_data == null || _data.PlayersData == null) return;
            Interface.Oxide.DataFileSystem.WriteObject(DataPath, _data);
        }
        
        void OnServerSave()
        {
            if (_data == null || _data.PlayersData == null) return;
            Interface.Oxide.DataFileSystem.WriteObject(DataPath, _data);
        }
        
        void OnPlayerConnected(BasePlayer player)
        {
            if (player == null) return;

            if (player.HasPlayerFlag(BasePlayer.PlayerFlags.ReceivingSnapshot))
            {
                timer.Once(2f, () => OnPlayerConnected(player));
                return;
            }

            if (!player.IsConnected) return;

            LevelInfo info;
            if (!_data.PlayersData.TryGetValue(player.userID, out info))
            {
                info = new LevelInfo();
                _data.PlayersData[player.userID] = info;
            }
            
            _panelManager.LoadAllInterfacesPlayer(player);
            _panelManager.OnOnlineUpdated();
        }

        void OnPlayerDisconnected(BasePlayer player, string reason)
        {
            _panelManager.OnOnlineUpdated();
        }
        
        void OnEntityKill(BaseNetworkable entity)
        {
            if (!_initiated) return;
            if (entity == null || _panelManager == null) return;
            
            if (entity is CargoShip)
            {
                _panelManager.Events.Ship--;
                if (_panelManager.Events.Ship < 0) _panelManager.Events.Ship = 0; 
                _panelManager.OnEventUpdated();
            }
            
            if (entity is BaseHelicopter)
            {
                _panelManager.Events.Heli--;
                if (_panelManager.Events.Heli < 0) _panelManager.Events.Heli = 0; 
                _panelManager.OnEventUpdated();
            }
            
            if (entity is CH47Helicopter)
            {
                _panelManager.Events.Chinook--;
                if (_panelManager.Events.Chinook < 0) _panelManager.Events.Chinook = 0; 
                _panelManager.OnEventUpdated();
            }
            
            if (entity is CargoPlane)
            {
                _panelManager.Events.AirDrop--;
                if (_panelManager.Events.AirDrop < 0) _panelManager.Events.AirDrop = 0; 
                _panelManager.OnEventUpdated();
            }

            if (entity is BradleyAPC)
            {
                _panelManager.Events.Tank--;
                if (_panelManager.Events.Tank < 0) _panelManager.Events.Tank = 0; 
                _panelManager.OnEventUpdated();
            }
        }

        void OnEntitySpawned(BaseNetworkable entity)
        {
            if (!_initiated) return;
            if (entity == null || _panelManager == null) return;
            
            if (entity is CargoShip)
            {
                _panelManager.Events.Ship++;
                _panelManager.OnEventUpdated();
            }
            
            if (entity is BaseHelicopter)
            {
                _panelManager.Events.Heli++;
                _panelManager.OnEventUpdated();
            }
            
            if (entity is CH47Helicopter)
            {
                _panelManager.Events.Chinook++;
                _panelManager.OnEventUpdated();
            }
            
            if (entity is CargoPlane)
            {
                _panelManager.Events.AirDrop++;
                _panelManager.OnEventUpdated();
            }

            if (entity is BradleyAPC)
            {
                _panelManager.Events.Tank++;
                _panelManager.OnEventUpdated();
            }
        }

        #region ExpGive

        void OnEntityDeath(BaseCombatEntity entity, HitInfo hitInfo)
        {
            if (!_initiated) return;
            if (entity == null || hitInfo == null) return;

            if (entity is BasePlayer == true)
            {
                PlayerDeath((BasePlayer)entity, hitInfo);
                return;
            }
        }

        private void PlayerDeath(BasePlayer player, HitInfo hitInfo)
        {
            if (player == null) return;
            
            BasePlayer attacker = hitInfo.InitiatorPlayer;
            if (attacker == null) return;
            
            if(player.IsNpc) TryAddExp(attacker, 15);
            else
            {
                if (attacker == player) return;
                
                double give = GetUserExp(player.userID) * 0.4;
                if (give > 1)
                {
                    TryAddExp(attacker, give);
                    WithdrawUserExp(player.userID, give);
                }
            }
        }
        
        object OnDispenserBonus(ResourceDispenser dispenser, BasePlayer player, Item item)
        {
            try
            {
                switch (item.info.shortname)
                {
                    case "sulfur.ore":
                    {
                        TryAddExp(player, 15);
                        break;
                    }
                    case "metal.ore":
                    {
                        TryAddExp(player, 15);
                        break;
                    }
                    case "stones":
                    {
                        TryAddExp(player, 10);
                        break;
                    }
                    case "charcoal":
                    {
                        TryAddExp(player, 5);
                        break;
                    }
                    case "sulfur":
                    {
                        TryAddExp(player, 15);
                        break;
                    }
                    case "metal.fragments":
                    {
                        TryAddExp(player, 15);
                        break;
                    }
                }
            }
            catch (Exception e)
            {
                PrintError("Error in 'OnDispenserBonus', Message: " + e.Message);
            }

            return null;
        }
        
        void OnLootEntityEnd(BasePlayer player, BaseCombatEntity entity)
        {
            if (player == null || entity == null) return;

            if (entity is LootContainer == false) return;
            
            var container = (LootContainer) entity;
            if (container == null || container.inventory.itemList == null || container.OwnerID != 0) return;
            if ((container.SpawnType == LootContainer.spawnType.GENERIC && container.SpawnType == LootContainer.spawnType.PLAYER)) return;
            
            int expgive = 5;

            switch (container.ShortPrefabName)
            {
                case "bradley_crate":
                    expgive = 25;
                    break;
                case "heli_crate":
                    expgive = 25;
                    break;
                case "codelockedhackablecrate":
                    expgive = 20;
                    break;

                case "crate_normal_2":
                    expgive = 10;
                    break;
                case "crate_normal":
                case "crate_elite":
                    expgive = 15;
                    break;
            }
            
            TryAddExp(player, expgive);
        }

        #endregion
        
        #endregion

        #region Interface
        private static string UI_Layer = "UI_ClubPanel.Logo";
        private static string UI_LayerEvents = ".Event";
        private static string UI_LayerExp = ".Exp";
        private static string UI_LayerOnline = ".Online";
        private static string UI_LayerMenu = ".Menu";
        private void BuildInterface()
        {
            _interface = new PluginInterface();
            CuiElementContainer container = new CuiElementContainer()
            {
                {
                    new CuiPanel
                    {
                        CursorEnabled = false,
                        RectTransform =
                        {
                                AnchorMin = $"0 1",
                                AnchorMax = $"0 1",
                                OffsetMin = "10 -55",
                                OffsetMax = "55 -10"
                        },
                        Image = { Color = GetColor("#00FF80", 0.6f) }
                    }, "Overlay", UI_Layer
                },
                {
                    new CuiElement
                    {
                        Parent = $"{UI_Layer}",
                        Components =
                        {
                            new CuiTextComponent
                            {
                                Text = "RC", Align = TextAnchor.MiddleCenter, Color = GetColor("#FFFFFF", 1f), FontSize = 32
                            },
                            new CuiRectTransformComponent
                            {
                                AnchorMin = $"0 0",
                                AnchorMax = $"1 1",
                                OffsetMax = "0 0"
                            },
                            new CuiOutlineComponent
                            {
                                Color = "0 0 0 1", Distance = "1 1"
                            }
                        }
                    }  
                },
                {
                    new CuiButton
                    {
                        RectTransform = { AnchorMin = "0 0", AnchorMax = "1 1" },
                        Button = { Color = "0 0 0 0", Command = "chat.say /panel"},
                        Text = { Text = "" }
                    }, UI_Layer
                },
            };
            _interface.LogoBlock = container.ToJson();
            
            container = new CuiElementContainer()
            {
                {
                    new CuiElement
                    {
                        Parent = $"{UI_Layer}",
                        Name = $"{UI_LayerEvents}",
                        Components =
                        {
                            new CuiImageComponent
                            {
                                Color = "0 0 0 0"
                            },
                            new CuiRectTransformComponent
                            {
                                AnchorMin = $"1 1",
                                AnchorMax = $"1 1",
                                OffsetMin = "5 -20",
                                OffsetMax = "120 0"
                            }
                        }
                    }  
                },
                {
                    new CuiElement
                    {
                        Parent = $"{UI_LayerEvents}",
                        Name = $"{UI_LayerEvents}.Heli",
                        Components =
                        {
                            new CuiImageComponent
                            {
                                Color = GetColor("#00FF80", 0.6f)
                            },
                            new CuiRectTransformComponent
                            {
                                AnchorMin = $"0 0",
                                AnchorMax = $"0 1",
                                OffsetMin = "0 0",
                                OffsetMax = "20 0"
                            }
                        }
                    }  
                },
                {
                    new CuiElement
                    {
                        Parent = $"{UI_LayerEvents}.Heli",
                        Components =
                        {
                            new CuiRawImageComponent
                            {
                                Png = GetImage(GetNameByURL(_config.eventsImages["Heli"])), Color = "{HeliColor}"
                            },
                            new CuiRectTransformComponent
                            {
                                AnchorMin = $"0 0",
                                AnchorMax = $"1 1",
                                OffsetMin = "3 3",
                                OffsetMax = "-3 -3"
                            }
                        }
                    }  
                },
                {
                    new CuiElement
                    {
                        Parent = $"{UI_LayerEvents}",
                        Name = $"{UI_LayerEvents}.Air",
                        Components =
                        {
                            new CuiImageComponent
                            {
                                Color = GetColor("#00FF80", 0.6f)
                            },
                            new CuiRectTransformComponent
                            {
                                AnchorMin = $"0 0",
                                AnchorMax = $"0 1",
                                OffsetMin = "25 0",
                                OffsetMax = "45 0"
                            }
                        }
                    }  
                },
                {
                    new CuiElement
                    {
                        Parent = $"{UI_LayerEvents}.Air",
                        Components =
                        {
                            new CuiRawImageComponent
                            {
                                Png = GetImage(GetNameByURL(_config.eventsImages["Air"])), Color = "{AirColor}"
                            },
                            new CuiRectTransformComponent
                            {
                                AnchorMin = $"0 0",
                                AnchorMax = $"1 1",
                                OffsetMin = "3 3",
                                OffsetMax = "-3 -3"
                            }
                        }
                    }  
                },
                {
                    new CuiElement
                    {
                        Parent = $"{UI_LayerEvents}",
                        Name = $"{UI_LayerEvents}.Tank",
                        Components =
                        {
                            new CuiImageComponent
                            {
                                Color = GetColor("#00FF80", 0.6f)
                            },
                            new CuiRectTransformComponent
                            {
                                AnchorMin = $"0 0",
                                AnchorMax = $"0 1",
                                OffsetMin = "50 0",
                                OffsetMax = "70 0"
                            }
                        }
                    }  
                },
                {
                    new CuiElement
                    {
                        Parent = $"{UI_LayerEvents}.Tank",
                        Components =
                        {
                            new CuiRawImageComponent
                            {
                                Png = GetImage(GetNameByURL(_config.eventsImages["Tank"])), Color = "{TankColor}"
                            },
                            new CuiRectTransformComponent
                            {
                                AnchorMin = $"0 0",
                                AnchorMax = $"1 1",
                                OffsetMin = "3 3",
                                OffsetMax = "-3 -3"
                            }
                        }
                    }  
                },
                {
                    new CuiElement
                    {
                        Parent = $"{UI_LayerEvents}",
                        Name = $"{UI_LayerEvents}.Ship",
                        Components =
                        {
                            new CuiImageComponent
                            {
                                Color = GetColor("#00FF80", 0.6f)
                            },
                            new CuiRectTransformComponent
                            {
                                AnchorMin = $"0 0",
                                AnchorMax = $"0 1",
                                OffsetMin = "75 0",
                                OffsetMax = "95 0"
                            }
                        }
                    }  
                },
                {
                    new CuiElement
                    {
                        Parent = $"{UI_LayerEvents}.Ship",
                        Components =
                        {
                            new CuiRawImageComponent
                            {
                                Png = GetImage(GetNameByURL(_config.eventsImages["Ship"])), Color = "{ShipColor}"
                            },
                            new CuiRectTransformComponent
                            {
                                AnchorMin = $"0 0",
                                AnchorMax = $"1 1",
                                OffsetMin = "3 3",
                                OffsetMax = "-3 -3"
                            }
                        }
                    }  
                },
                {
                    new CuiElement
                    {
                        Parent = $"{UI_LayerEvents}",
                        Name = $"{UI_LayerEvents}.CH47",
                        Components =
                        {
                            new CuiImageComponent
                            {
                                Color = GetColor("#00FF80", 0.6f)
                            },
                            new CuiRectTransformComponent
                            {
                                AnchorMin = $"0 0",
                                AnchorMax = $"0 1",
                                OffsetMin = "100 0",
                                OffsetMax = "120 0"
                            }
                        }
                    }  
                },
                {
                    new CuiElement
                    {
                        Parent = $"{UI_LayerEvents}.CH47",
                        Components =
                        {
                            new CuiRawImageComponent
                            {
                                Png = GetImage(GetNameByURL(_config.eventsImages["Ch47"])), Color = "{Ch47Color}"
                            },
                            new CuiRectTransformComponent
                            {
                                AnchorMin = $"0 0",
                                AnchorMax = $"1 1",
                                OffsetMin = "3 3",
                                OffsetMax = "-3 -3"
                            }
                        }
                    }  
                },
            };
            _interface.EventsBlock = container.ToJson();

            container = new CuiElementContainer()
            {

                {
                    new CuiElement
                    {
                        Parent = $"{UI_Layer}",
                        Name = $"{UI_LayerExp}",
                        Components =
                        {
                            new CuiImageComponent
                            {
                                Color = GetColor("#00FF80", 0.6f)
                            },
                            new CuiRectTransformComponent
                            {
                                AnchorMin = $"1 1",
                                AnchorMax = $"1 1",
                                OffsetMin = "5 -45",
                                OffsetMax = "75 -25"
                            }
                        }
                    }
                },
                {
                    new CuiElement
                    {
                        Parent = $"{UI_LayerExp}",
                        Name = $"{UI_LayerExp}.Image",
                        Components =
                        {
                            new CuiImageComponent
                            {
                                Color = GetColor("#FFFFFF", 1f), Sprite = "assets/icons/xp.png"
                            },
                            new CuiRectTransformComponent
                            {
                                AnchorMin = $"0 0",
                                AnchorMax = $"0 1",
                                OffsetMin = "0 0",
                                OffsetMax = "20 0"
                            },
                            new CuiOutlineComponent
                            {
                                Color = "0 0 0 1", Distance = "1 1"
                            }
                        }
                    }
                },
                {
                    new CuiElement
                    {
                        Parent = $"{UI_LayerExp}",
                        Name = $"{UI_LayerExp}.XpBar",
                        Components =
                        {
                            new CuiImageComponent
                            {
                                Color = GetColor("#0B3B0B", 1f) //, Material = "assets/content/ui/uibackgroundblur.mat"
                            },
                            new CuiRectTransformComponent
                            {
                                AnchorMin = $"0 0",
                                AnchorMax = $"1 1",
                                OffsetMin = "25 5",
                                OffsetMax = "-5 -5"
                            }
                        }
                    }
                },
                {
                    new CuiElement
                    {
                        Parent = $"{UI_LayerExp}.XpBar",
                        Name = $"{UI_LayerExp}.XpBarFill",
                        Components =
                        {
                            new CuiImageComponent
                            {
                                Color = GetColor("#2EFE9A", 1f), Material = "assets/content/ui/uibackgroundblur.mat"
                            },
                            new CuiRectTransformComponent
                            {
                                AnchorMin = $"0 0",
                                AnchorMax = "{EValue} 1",
                                OffsetMin = "2 2",
                                OffsetMax = "-2 -2"
                            }
                        }
                    }
                },
                {
                    new CuiElement
                    {
                        Parent = $"{UI_LayerExp}",
                        Name = $"{UI_LayerExp}.Scores",
                        Components =
                        {
                            new CuiImageComponent
                            {
                                Color = GetColor("#00FF80", 0.6f)
                            },
                            new CuiRectTransformComponent
                            {
                                AnchorMin = $"1 0",
                                AnchorMax = $"1 1",
                                OffsetMin = "5 0",
                                OffsetMax = "50 0"
                            }
                        }
                    }
                },
                {
                    new CuiElement
                    {
                        Parent = $"{UI_LayerExp}.Scores",
                        Name = $"{UI_LayerExp}.Scores.Text",
                        Components =
                        {
                            new CuiImageComponent
                            {
                                Color = GetColor("#FFFFFF", 1f), Sprite = "assets/icons/favourite_servers.png"
                            },
                            new CuiRectTransformComponent
                            {
                                AnchorMin = $"0 0",
                                AnchorMax = $"0 1",
                                OffsetMin = "0 0",
                                OffsetMax = "20 0"
                            },
                            new CuiOutlineComponent
                            {
                                Color = "0 0 0 1", Distance = "1 1"
                            }
                        }
                    }
                },
                {
                    new CuiElement
                    {
                        Parent = $"{UI_LayerExp}.Scores",
                        Name = $"{UI_LayerExp}.Scores.XpBar",
                        Components =
                        {
                            new CuiImageComponent
                            {
                                Color = GetColor("#0B3B0B", 1f) //, Material = "assets/content/ui/uibackgroundblur.mat"
                            },
                            new CuiRectTransformComponent
                            {
                                AnchorMin = $"0 0",
                                AnchorMax = $"1 1",
                                OffsetMin = "20 2",
                                OffsetMax = "-2 -2"
                            }
                        }
                    }
                },
                {
                    new CuiElement
                    {
                        Parent = $"{UI_LayerExp}.Scores.XpBar",
                        Components =
                        {
                            new CuiTextComponent
                            {
                                Text = "{SValue}", Align = TextAnchor.MiddleCenter, Color = GetColor("#2EFE9A", 1f), FontSize = 8
                            },
                            new CuiRectTransformComponent
                            {
                                AnchorMin = $"0 0",
                                AnchorMax = $"1 1",
                                OffsetMin = "0 0",
                                OffsetMax = "0 0"
                            },
                            new CuiOutlineComponent
                            {
                                Color = "0 0 0 1", Distance = "1 1"
                            }
                        }
                    }
                },
            };
            _interface.ExpBlock = container.ToJson();
            
            container = new CuiElementContainer()
            {

                {
                    new CuiElement
                    {
                        Parent = $"{UI_Layer}",
                        Name = $"{UI_LayerOnline}",
                        Components =
                        {
                            new CuiImageComponent
                            {
                                Color = GetColor("#00FF80", 0.6f)
                            },
                            new CuiRectTransformComponent
                            {
                                AnchorMin = $"0 0",
                                AnchorMax = $"1 0",
                                OffsetMin = "0 -25",
                                OffsetMax = "0 -5"
                            }
                        }
                    }
                },
                {
                    new CuiElement
                    {
                        Parent = $"{UI_LayerOnline}",
                        Components =
                        {
                            new CuiTextComponent
                            {
                                Text = "{Value}", Align = TextAnchor.MiddleCenter, Color = GetColor("#FFFFFF", 1f), FontSize = 14
                            },
                            new CuiRectTransformComponent
                            {
                                AnchorMin = $"0 0",
                                AnchorMax = $"1 1",
                                OffsetMin = "0 0",
                                OffsetMax = "0 0"
                            }
                        }
                    }
                },
            };
            _interface.OnlineBlock = container.ToJson();
            
            container = new CuiElementContainer()
            {
                {
                    new CuiButton
                    {
                        RectTransform = 
                        {
                            AnchorMin = $"1 0",
                            AnchorMax = $"1 0",
                            OffsetMin = "5 -25",
                            OffsetMax = "125 -5" 
                        },
                        Button = { Color = GetColor("#00FF80", 0.6f), Command = "chat.say /menu"},
                        Text = { Text = "-> МЕНЮ <-", Align = TextAnchor.MiddleCenter, Color = GetColor("#FFFFFF", 1f), FontSize = 14 }
                    }, UI_Layer, UI_LayerMenu
                },
            };
            _interface.MenuBlock = container.ToJson();
            
            container = new CuiElementContainer()
            {
                {
                    new CuiButton
                    {
                        RectTransform = 
                        {
                            AnchorMin = $"0 0",
                            AnchorMax = $"1 0",
                            OffsetMin = "{OffsetMin}",
                            OffsetMax = "{OffsetMax}" 
                        },
                        Button = { Color = GetColor("#00FF80", 0.6f), Command = "{Command}"},
                        Text = { Text = "{Text}", Align = TextAnchor.MiddleCenter, Color = GetColor("#FFFFFF", 1f), FontSize = 14 }
                    }, UI_LayerMenu
                },
            };
            _interface.MenuButton = container.ToJson();
        }
        #endregion

        #region Commands
        [ChatCommand("menu")]
        void Chat_menu(BasePlayer player, string command, string[] args)
        {
            _panelManager.MenuToggle(player);
        }
        
        
        [ChatCommand("getsc")]
        void Chat_GetSc(BasePlayer player, string command, string[] args)
        {
            if (!_initiated || !player.IsAdmin) return;

            DepositUserScores(player.userID, Int32.Parse(args[0]));
        }
        #endregion

        #region ImageLibrary
        [PluginReference] private Plugin ImageLibrary;

        private string GetSizedImade(string name, int size) => GetImage($"{name}_{size}");

        private string GetImage(string name)
        {
            string ID = (string)ImageLibrary?.Call("GetImage", name);
            if (ID == "")
                ID = (string)ImageLibrary?.Call("GetImage", name) ?? ID;

            return ID;
        }

        private void AddImage(string name)
        {
            if (!(bool)ImageLibrary.Call("HasImage", GetNameByURL(name)))
                ImageLibrary.Call("AddImage", name, GetNameByURL(name));
        }

        private static string GetNameByURL(string url)
        {
            var splitted = url.Split('/');
            var endUrl = splitted[splitted.Length - 1];
            var name = endUrl.Split('.')[0];
            return name;
        }
        
        #endregion

        #region PluginLoading
        private void StartPluginLoad()
        {
            if (ImageLibrary != null)
            {
                //Load your images here
                foreach (var value in _config.eventsImages)
                {
                    //Да-да
                    AddImage(value.Value);
                }
                CheckStatus();
            }
            else
            {
                PrintError($"ImageLibrary not found! Please, check your plugins list.");
            }
        }

        private void CheckStatus()
        {
            if (!(bool)ImageLibrary.Call("IsReady"))
            {
                PrintError("Plugin is not ready! Images are loading.");
                timer.Once(10f, () => CheckStatus());
            }
            else
            {
                FullLoad();
                PrintWarning("Plugin succesfully loaded! Author: BadMandarin.");
            }
        }

        private void FullLoad()
        {
            if (Interface.Oxide.DataFileSystem.ExistsDatafile(DataPath))
                _data = Interface.Oxide.DataFileSystem.ReadObject<PluginData>(DataPath);
            else
            {
                _data = new PluginData()
                {
                    PlayersData = new Hash<ulong, LevelInfo>()
                };
            }

            if (_data == null || _data.PlayersData == null)
            {
                _data = new PluginData()
                {
                    PlayersData = new Hash<ulong, LevelInfo>()
                };
            }

            BuildInterface();
            _initiated = true;
            
            StartPanel();

            for(int i = 0; i<BasePlayer.activePlayerList.Count; i++)
                OnPlayerConnected(BasePlayer.activePlayerList[i]);
            
        }
        #endregion
        
        #region Utils55
        private void TryAddExp(BasePlayer player, double amount)
        {
            LevelInfo pInfo;
            if (!_data.PlayersData.TryGetValue(player.userID, out pInfo))
                return;

            pInfo.Exp += amount;
            if (pInfo.Exp >= _config.MaxExp)
            {
                do
                {
                    pInfo.Exp -= _config.MaxExp;
                    pInfo.Scores += 1;
                } 
                while (pInfo.Exp >= _config.MaxExp);

                if (pInfo.Exp < 0) pInfo.Exp = 0;
            }
            
            _panelManager.OnExpUpdated(player, pInfo.Exp, pInfo.Scores);
        }
        
        private void StartPanel()
        {
            _panelManager = new GameObject().AddComponent<PanelManager>();
            _p
// ... [Code preview truncated due to length. Full source in attached file] ...

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