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

FREE RemoverTool : 4.2.9 4.2.9

Нет прав для скачивания
C#:
// Все права принадлежат дискорд сообществу https://discord.gg/VgNHPpNrz6
using System.Collections.Generic;
using System;
using System.Reflection;
using System.Data;
using UnityEngine;
using Facepunch;
using Oxide.Core;
using Oxide.Core.Libraries;
using Oxide.Core.Plugins;
using System.Linq;
using Oxide.Core.Libraries.Covalence;
using Oxide.Game.Rust.Cui;
using System.Collections;
namespace Oxide.Plugins {
    [Info("RemoverTool", "Reneb/Fuji", "4.2.9", ResourceId = 651)]
    class RemoverTool : RustPlugin {
        [PluginReference]
        Plugin Friends, Clans, Economics;
        static RemoverTool rt = new RemoverTool();
#region Fields
        int colliderRemovable = LayerMask.GetMask("Construction", "Deployed", "Default");
        int colliderBuilding = LayerMask.GetMask("Construction");
        int colliderPlayer = LayerMask.GetMask("Player (Server)");
        bool RemoveOverride = false;
        string permissionNormal = "removertool.remove";
        string permissionOverride = "removertool.override";
        string permissionAdmin = "removertool.admin";
        string permissionAll = "removertool.all";
        string permissionTarget = "removertool.target";
        int authTarget = 1;
        int authNormal = 0;
        int authAdmin = 2;
        int authAll = 2;
        int authOverride = 1;
        int removeDistanceNormal = 3;
        int removeDistanceAdmin = 20;
        int removeDistanceAll = 100;
        bool removeGibsNormal = true;
        bool removeGibsAdmin = true;
        bool removeGibsAll = false;
        bool removeUnequipStart = true;
        bool removeUnequipUpdate = false;
        int RemoveDefaultTime = 30;
        int RemoveMaxTime = 300;
        bool RemoveContainerWithDrop = true;
        bool RemoveContainerWithContent = true;
        bool RemoveFractionedObjects = false;
        bool RemoveFractionedObjectsExcludeBuildingBlocks = true;
        int RemoveFractionedPercent = 90;
        bool RemoveWithToolCupboards = false;
        bool RemoveWithEntityOwners = true;
        bool RemoveWithBuildingOwners = true;
        bool RemoveWithRustIO = true;
        bool RemoveWithFriends = true;
        bool RemoveWithClans = true;
        bool RaidBlocker = true;
        bool RaidBlockerBlockBuildingID = true;
        bool RaidBlockerBlockSurroundingPlayers = true;
        int RaidBlockerRadius = 120;
        int RaidBlockerTime = 300;
        bool CoolDownEnabled = false;
        float CoolDownTime = 60f;
        bool CoolDownExcludeAdmins = true;
        Dictionary<string, object> Price = new Dictionary<string, object>();
        bool PriceEnabled = true;
        Dictionary<string, object> Refund = new Dictionary<string, object>();
        bool RefundEnabled = true;
        Dictionary<string, object> ValidEntities = new Dictionary<string, object>();
        Dictionary<string, DateTime> cooldownTimes = new Dictionary<string, DateTime>();
        string GUIRemoverToolBackgroundColor = "0.1 0.1 0.1 0";
        string GUIRemoverToolAnchorMin = "0.1 0.65";
        string GUIRemoverToolAnchorMax = "0.4 0.95";
        string GUIRemoveBackgroundColor = "0.1 0.1 0.1 0.98";
        string GUIRemoveAnchorMin = "0 0.9";
        string GUIRemoveAnchorMax = "0.55 1";
        string GUIRemoveTextColor = "1 0.1 0.1 0.98";
        int GUIRemoveTextSize = 16;
        string GUIRemoveTextAnchorMin = "0.1 0";
        string GUIRemoveTextAnchorMax = "1 1";
        string GUITimeLeftBackgroundColor = "0.1 0.1 0.1 0.98";
        string GUITimeLeftAnchorMin = "0.55 0.9";
        string GUITimeLeftAnchorMax = "1 1";
        string GUITimeLeftTextColor = "1 1 1 0.98";
        int GUITimeLeftTextSize = 16;
        string GUITimeLeftTextAnchorMin = "0 0";
        string GUITimeLeftTextAnchorMax = "0.9 1";
        string GUIEntityBackgroundColor = "0.1 0.1 0.1 0.98";
        string GUIEntityAnchorMin = "0 0.8";
        string GUIEntityAnchorMax = "1 0.9";
        string GUIEntityTextColor = "1 1 1 0.98";
        int GUIEntityTextSize = 16;
        string GUIEntityTextAnchorMin = "0.05 0";
        string GUIEntityTextAnchorMax = "1 1";
        bool GUIAuthorizations = true;
        string GUIAllowedBackgroundColor = "0.1 1 0.1 0.3";
        string GUIRefusedBackgroundColor = "1 0.1 0.1 0.3";
        string GUIAuthorizationsAnchorMin = "0 0.8";
        string GUIAuthorizationsAnchorMax = "1 0.9";
        string GUIPriceBackgroundColor = "0.1 0.1 0.1 0.98";
        string GUIPriceAnchorMin = "0 0.60";
        string GUIPriceAnchorMax = "1 0.80";
        bool GUIPrices = true;
        string GUIPriceTextColor = "1 1 1 0.98";
        int GUIPriceTextSize = 16;
        string GUIPriceTextAnchorMin = "0.05 0";
        string GUIPriceTextAnchorMax = "0.3 1";
        string GUIPrice2TextColor = "1 1 1 0.98";
        int GUIPrice2TextSize = 16;
        string GUIPrice2TextAnchorMin = "0.35 0";
        string GUIPrice2TextAnchorMax = "1 1";
        string GUIRefundBackgroundColor = "0.1 0.1 0.1 0.98";
        string GUIRefundAnchorMin = "0 0.40";
        string GUIRefundAnchorMax = "1 0.60";
        bool GUIRefund = true;
        string GUIRefundTextColor = "1 1 1 0.98";
        int GUIRefundTextSize = 16;
        string GUIRefundTextAnchorMin = "0.05 0";
        string GUIRefundTextAnchorMax = "0.3 1";
        string GUIRefund2TextColor = "1 1 1 0.98";
        int GUIRefund2TextSize = 16;
        string GUIRefund2TextAnchorMin = "0.35 0";
        string GUIRefund2TextAnchorMax = "1 1";
        Dictionary<string, string> PrefabNameToDeployable = new Dictionary<string, string>();
        Dictionary<string, string> PrefabNameToItemName = new Dictionary<string, string>();
        Dictionary<string, string> PrefabNameToStructure = new Dictionary<string, string>();
        Dictionary<string, int> ItemNameToItemID = new Dictionary<string, int>();
        Hash<uint, float> LastAttackedBuildings = new Hash<uint, float>();
        Hash<ulong, float> LastBlockedPlayers = new Hash<ulong, float>();
        public enum RemoveType {
            All, Structure, Admin, Normal
        }
#endregion
#region Config
        protected override void LoadDefaultConfig() {
        }
        private void CheckCfg<T>(string Key, ref T var) {
            if (Config[Key] is T) var = (T)Config[Key];
            else Config[Key] = var;
        }
#endregion
#region Oxide Hooks
        void LoadConfigs() {
            CheckCfg<string>("Remove - Access - Oxide Permissions - Normal", ref permissionNormal);
            CheckCfg<string>("Remove - Access - Oxide Permissions - Override", ref permissionOverride);
            CheckCfg<string>("Remove - Access - Oxide Permissions - Admin", ref permissionAdmin);
            CheckCfg<string>("Remove - Access - Oxide Permissions - All", ref permissionAll);
            CheckCfg<string>("Remove - Access - Oxide Permissions - Target", ref permissionTarget);
            CheckCfg<int>("Remove - Access - AuthLevel - Normal", ref authNormal);
            CheckCfg<int>("Remove - Access - AuthLevel - Override", ref authOverride);
            CheckCfg<int>("Remove - Access - AuthLevel - Admin", ref authAdmin);
            CheckCfg<int>("Remove - Access - AuthLevel - All", ref authAll);
            CheckCfg<int>("Remove - Access - AuthLevel - Target", ref authTarget);
            CheckCfg<int>("Remove - Distance - Normal", ref removeDistanceNormal);
            CheckCfg<int>("Remove - Distance - Admin", ref removeDistanceAdmin);
            CheckCfg<int>("Remove - Distance - All/Structure", ref removeDistanceAll);
            CheckCfg<bool>("Remove - Gibs - Normal", ref removeGibsNormal);
            CheckCfg<bool>("Remove - Gibs - Admin", ref removeGibsAdmin);
            CheckCfg<bool>("Remove - Gibs - All", ref removeGibsAll);
            CheckCfg<bool>("Remove - Check held item - Start", ref removeUnequipStart);
            CheckCfg<bool>("Remove - Check held item - Always", ref removeUnequipUpdate);
            CheckCfg<int>("Remove - Time - Default", ref RemoveDefaultTime);
            CheckCfg<int>("Remove - Time - Max", ref RemoveMaxTime);
            CheckCfg<bool>("Remove - Cooldown - Enabled", ref CoolDownEnabled);
            CheckCfg<float>("Remove - Cooldown - Time", ref CoolDownTime);
            CheckCfg<bool>("Remove - Cooldown - ExcludeAdmins", ref CoolDownExcludeAdmins);
            CheckCfg<bool>("Remove - Normal - Use Tool Cupboards (strongly unrecommended)", ref RemoveWithToolCupboards);
            CheckCfg<bool>("Remove - Normal - Use Entity Owners", ref RemoveWithEntityOwners);
            CheckCfg<bool>("Remove - Normal - Use Building Owners (You will need Building Owners plugin)", ref RemoveWithBuildingOwners);
            CheckCfg<bool>("Remove - Normal - Use Friends (RustIO)", ref RemoveWithRustIO);
            CheckCfg<bool>("Remove - Normal - Use Friends (Friends)", ref RemoveWithFriends);
            CheckCfg<bool>("Remove - Normal - Use Clans", ref RemoveWithClans);
            CheckCfg<bool>("Remove - Normal - Drop items from StorageContainer", ref RemoveContainerWithDrop);
            CheckCfg<bool>("Remove - Normal - Enable remove of not empty storages", ref RemoveContainerWithContent);
            CheckCfg<bool>("Remove - Normal - Remove fractioned objects", ref RemoveFractionedObjects);
            CheckCfg<bool>("Remove - Normal - Remove fractioned objects - exclude BuildingBlocks", ref RemoveFractionedObjectsExcludeBuildingBlocks);
            CheckCfg<int>("Remove - Normal - Remove fractioned objects percentage", ref RemoveFractionedPercent);
            CheckCfg<bool>("Remove - Normal - RaidBlocker", ref RaidBlocker);
            CheckCfg<bool>("Remove - Normal - RaidBlocker - By Buildings", ref RaidBlockerBlockBuildingID);
            CheckCfg<bool>("Remove - Normal - RaidBlocker - By Surrounding Players", ref RaidBlockerBlockSurroundingPlayers);
            CheckCfg<int>("Remove - Normal - RaidBlocker - By Surrounding Players - Radius", ref RaidBlockerRadius);
            CheckCfg<int>("Remove - Normal - RaidBlocker - Time", ref RaidBlockerTime);
            ValidEntities = DefaultEntities();
            Price = DefaultPay();
            Refund = DefaultRefund();
            CheckCfg<Dictionary<string, object>>("Remove - Normal - Allowed Entities", ref ValidEntities);
            CheckCfg<Dictionary<string, object>>("Remove - Normal - Price", ref Price);
            CheckCfg<bool>("Remove - Normal - PriceEnabled", ref PriceEnabled);
            CheckCfg<Dictionary<string, object>>("Remove - Normal - Refund", ref Refund);
            CheckCfg<bool>("Remove - Normal - RefundEnabled", ref RefundEnabled);
            CheckCfg<string>("Remove - GUI - Main Box - Min Anchor (in Rust Window)", ref GUIRemoverToolAnchorMin);
            CheckCfg<string>("Remove - GUI - Main Box - Max Anchor (in Rust Window)", ref GUIRemoverToolAnchorMax);
            CheckCfg<string>("Remove - GUI - Main Box - Background Color", ref GUIRemoverToolBackgroundColor);
            CheckCfg<string>("Remove - GUI - Remove - Box - Min Anchor (in Main Box)", ref GUIRemoveAnchorMin);
            CheckCfg<string>("Remove - GUI - Remove - Box - Max Anchor (in Main Box)", ref GUIRemoveAnchorMax);
            CheckCfg<string>("Remove - GUI - Remove - Box - Background Color", ref GUIRemoveBackgroundColor);
            CheckCfg<string>("Remove - GUI - Remove - Text - Min Anchor (in Remove Box)", ref GUIRemoveTextAnchorMin);
            CheckCfg<string>("Remove - GUI - Remove - Text - Max Anchor (in Remove Box)", ref GUIRemoveTextAnchorMax);
            CheckCfg<string>("Remove - GUI - Remove - Text - Text Color", ref GUIRemoveTextColor);
            CheckCfg<int>("Remove - GUI - Remove - Text - Text Size", ref GUIRemoveTextSize);
            CheckCfg<string>("Remove - GUI - Timeleft - Box - Min Anchor (in Main Box)", ref GUITimeLeftAnchorMin);
            CheckCfg<string>("Remove - GUI - Timeleft - Box - Max Anchor (in Main Box)", ref GUITimeLeftAnchorMax);
            CheckCfg<string>("Remove - GUI - Timeleft - Box - Background Color", ref GUITimeLeftBackgroundColor);
            CheckCfg<string>("Remove - GUI - Timeleft - Text - Min Anchor (in Timeleft Box)", ref GUITimeLeftTextAnchorMin);
            CheckCfg<string>("Remove - GUI - Timeleft - Text - Max Anchor (in Timeleft Box)", ref GUITimeLeftTextAnchorMax);
            CheckCfg<string>("Remove - GUI - Timeleft - Text - Text Color", ref GUITimeLeftTextColor);
            CheckCfg<int>("Remove - GUI - Timeleft - Text - Text Size", ref GUITimeLeftTextSize);
            CheckCfg<string>("Remove - GUI - Entity - Box - Min Anchor (in Main Box)", ref GUIEntityAnchorMin);
            CheckCfg<string>("Remove - GUI - Entity - Box - Max Anchor (in Main Box)", ref GUIEntityAnchorMax);
            CheckCfg<string>("Remove - GUI - Entity - Box - Background Color", ref GUIEntityBackgroundColor);
            CheckCfg<string>("Remove - GUI - Entity - Text - Min Anchor (in Entity Box)", ref GUIEntityTextAnchorMin);
            CheckCfg<string>("Remove - GUI - Entity - Text - Max Anchor (in Entity Box)", ref GUIEntityTextAnchorMax);
            CheckCfg<string>("Remove - GUI - Entity - Text - Text Color", ref GUIEntityTextColor);
            CheckCfg<int>("Remove - GUI - Entity - Text - Text Size", ref GUIEntityTextSize);
            CheckCfg<bool>("Remove - GUI - Authorization Check Hightlighting Box", ref GUIAuthorizations);
            CheckCfg<string>("Remove - GUI - Authorization Check Hightlighting Box - Min Anchor (in Main Box)", ref GUIAuthorizationsAnchorMin);
            CheckCfg<string>("Remove - GUI - Authorization Check Hightlighting Box - Max Anchor (in Main Box)", ref GUIAuthorizationsAnchorMax);
            CheckCfg<string>("Remove - GUI - Authorization Check Hightlighting Box - Allowed Background", ref GUIAllowedBackgroundColor);
            CheckCfg<string>("Remove - GUI - Authorization Check Hightlighting Box - Refused Background", ref GUIRefusedBackgroundColor);
            CheckCfg<bool>("Remove - GUI - Price", ref GUIPrices);
            CheckCfg<string>("Remove - GUI - Price - Box - Min Anchor (in Main Box)", ref GUIPriceAnchorMin);
            CheckCfg<string>("Remove - GUI - Price - Box - Max Anchor (in Main Box)", ref GUIPriceAnchorMax);
            CheckCfg<string>("Remove - GUI - Price - Box - Background Color", ref GUIPriceBackgroundColor);
            CheckCfg<string>("Remove - GUI - Price - Text - Min Anchor (in Price Box)", ref GUIPriceTextAnchorMin);
            CheckCfg<string>("Remove - GUI - Price - Text - Max Anchor (in Price Box)", ref GUIPriceTextAnchorMax);
            CheckCfg<string>("Remove - GUI - Price - Text - Text Color", ref GUIPriceTextColor);
            CheckCfg<int>("Remove - GUI - Price - Text - Text Size", ref GUIPriceTextSize);
            CheckCfg<string>("Remove - GUI - Price - Text2 - Min Anchor (in Price Box)", ref GUIPrice2TextAnchorMin);
            CheckCfg<string>("Remove - GUI - Price - Text2 - Max Anchor (in Price Box)", ref GUIPrice2TextAnchorMax);
            CheckCfg<string>("Remove - GUI - Price - Text2 - Text Color", ref GUIPrice2TextColor);
            CheckCfg<int>("Remove - GUI - Price - Text2 - Text Size", ref GUIPrice2TextSize);
            CheckCfg<bool>("Remove - GUI - Refund", ref GUIRefund);
            CheckCfg<string>("Remove - GUI - Refund - Box - Min Anchor (in Main Box)", ref GUIRefundAnchorMin);
            CheckCfg<string>("Remove - GUI - Refund - Box - Max Anchor (in Main Box)", ref GUIRefundAnchorMax);
            CheckCfg<string>("Remove - GUI - Refund - Box - Background Color", ref GUIRefundBackgroundColor);
            CheckCfg<string>("Remove - GUI - Refund - Text - Min Anchor (in Refund Box)", ref GUIRefundTextAnchorMin);
            CheckCfg<string>("Remove - GUI - Refund - Text - Max Anchor (in Refund Box)", ref GUIRefundTextAnchorMax);
            CheckCfg<string>("Remove - GUI - Refund - Text - Text Color", ref GUIRefundTextColor);
            CheckCfg<int>("Remove - GUI - Refund - Text - Text Size", ref GUIRefundTextSize);
            CheckCfg<string>("Remove - GUI - Refund - Text2 - Min Anchor (in Refund Box)", ref GUIRefund2TextAnchorMin);
            CheckCfg<string>("Remove - GUI - Refund - Text2 - Max Anchor (in Refund Box)", ref GUIRefund2TextAnchorMax);
            CheckCfg<string>("Remove - GUI - Refund - Text2 - Text Color", ref GUIRefund2TextColor);
            CheckCfg<int>("Remove - GUI - Refund - Text2 - Text Size", ref GUIRefund2TextSize);
            SaveConfig();
        }
        void OnServerInitialized() {
            LoadConfigs();
            InitializeRustIO();
            InitializeItems();
            InitializeConstruction();
            permission.RegisterPermission(permissionNormal, this);
            permission.RegisterPermission(permissionAdmin, this);
            permission.RegisterPermission(permissionTarget, this);
            permission.RegisterPermission(permissionAll, this);
            rt = this;
        }
        void Loaded() {
            lang.RegisterMessages(new Dictionary<string, string> {
                {
                    "You don't have access to this command.", "You don't have access to this command."
                }
                , {
                    "{0} {1} now has remover tool activated for {2} seconds ({3})", "{0} {1} now has remover tool activated for {2} seconds ({3})"
                }
                , {
                    "Couldn't use the RemoverTool: You don't have enough resources.", "Couldn't use the RemoverTool: You don't have enough resources."
                }
                , {
                    "RemoverTool from your target has been deactivated.", "RemoverTool from your target has been deactivated."
                }
                , {
                    "Couldn't use the RemoverTool: Admin has restricted this entity from being removed.", "Couldn't use the RemoverTool: Admin has restricted this entity from being removed."
                }
                , {
                    "Couldn't use the RemoverTool: Admin has restricted damaged objects from being removed.", "Couldn't use the RemoverTool: Admin has restricted damaged objects from being removed."
                }
                , {
                    "Couldn't use the RemoverTool: An external plugin blocked the usage", "Couldn't use the RemoverTool: An external plugin blocked the usage"
                }
                , {
                    "Couldn't use the RemoverTool: No valid entity targeted", "Couldn't use the RemoverTool: No valid entity targeted"
                }
                , {
                    "Couldn't use the RemoverTool: Paying system crashed! Contact an administrator with the time and date to help him understand what happened.", "Couldn't use the RemoverTool: Paying system crashed! Contact an administrator with the time and date to help him understand what happened."
                }
                , {
                    "Couldn't use the RemoverTool: No valid entity targeted, or entity is too far.", "Couldn't use the RemoverTool: No valid entity targeted, or entity is too far."
                }
                , {
                    "Couldn't use the RemoverTool: Entity storage is not empty", "Couldn't use the RemoverTool: Entity storage is not empty"
                }
                , {
                    "You need to wait {0} seconds to use the Remover again", "You need to wait {0} seconds to use the Remover again"
                }
                , {
                    "Refund:", "Refund:"
                }
                , {
                    "Nothing", "Nothing"
                }
                , {
                    "Price:", "Price:"
                }
                , {
                    "Free", "Free"
                }
                , {
                    "Timeleft: {0}secs", "Timeleft: {0}secs"
                }
                , {
                    "Remover Tool {0}", "Remover Tool {0}"
                }
                , {
                    "RemoverTool is currently disabled.\n", "RemoverTool is currently disabled.\n"
                }
                , {
                    "You are not allowed to use this command option.\n", "You are not allowed to use this command option.\n"
                }
                , {
                    "You are not allowed to use this command.\n", "You are not allowed to use this command.\n"
                }
                , {
                    "Couldn't use the RemoverTool: The Remover Tool is blocked for another {0} seconds.", "Couldn't use the RemoverTool: The Remover Tool is blocked for another {0} seconds."
                }
                , {
                    "Couldn't find player.Multiple players match: {0}.\n", "Couldn't find player.Multiple players match: {0}.\n"
                }
                , {
                    "Couldn't find player.No players match this name: {0}.\n", "Couldn't find player.No players match this name: {0}.\n"
                }
                , {
                    "Couldn't use the RemoverTool: You don't have any rights to remove this.", "Couldn't use the RemoverTool: You don't have any rights to remove this."
                }
                , {
                    "<size=18>Remover Tool</size> by <color=#ce422b>Reneb</color>\n<color=\"#ffd479\">/remove optional:TimerInSeconds</color> - Activate/Deactivate the Remover Tool, You will need to have no highlighted items in your belt bar.", "<size=18>Remover Tool</size> by <color=#ce422b>Reneb</color>\n<color=\"#ffd479\">/remove optional:TimerInSeconds</color> - Activate/Deactivate the Remover Tool, You will need to have no highlighted items in your belt bar."
                }
            }
            , this);
        }
        void Unload() {
            foreach (ToolRemover toolremover in Resources.FindObjectsOfTypeAll<ToolRemover>()) {
                toolremover.Destroy();
            }
        }
#endregion
        /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
        /// RustIO Inclusion
        /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
        private Library RustIO;
        private MethodInfo isInstalled;
        private MethodInfo hasFriend;
        private bool RustIOIsInstalled() {
            if (RustIO == null) return false;
            return (bool)isInstalled.Invoke(RustIO, new object[] {
            }
            );
        }
        private void InitializeRustIO() {
            if (!RemoveWithRustIO) {
                RustIO = null;
                return;
            }
            RustIO = Interface.GetMod().GetLibrary<Library>("RustIO");
            if (RustIO == null || (isInstalled = RustIO.GetFunction("IsInstalled")) == null || (hasFriend = RustIO.GetFunction("HasFriend")) == null) {
                RustIO = null;
                Puts("{0}: {1}", Title, "Rust:IO is not present.You need to install Rust:IO first in order to use the RustIO option!");
            }
        }
        private bool HasFriend(string playerId, string friendId) {
            if (RustIO == null) return false;
            return (bool)hasFriend.Invoke(RustIO, new object[] {
                playerId, friendId
            }
            );
        }
#region Initializing
        void InitializeItems() {
            foreach (var item in ItemManager.GetItemDefinitions()) {
                if (!ItemNameToItemID.ContainsKey(item.displayName.english.ToLower())) ItemNameToItemID.Add(item.displayName.english.ToLower(), item.itemid);
                var itemdeployable = item?.GetComponent<ItemModDeployable>();
                if (itemdeployable == null) continue;
                if (!PrefabNameToDeployable.ContainsKey(itemdeployable.entityPrefab.resourcePath)) PrefabNameToDeployable.Add(itemdeployable.entityPrefab.resourcePath, item.displayName.english);
                if(!PrefabNameToItemName.ContainsKey(itemdeployable.entityPrefab.resourcePath)) PrefabNameToItemName.Add(itemdeployable.entityPrefab.resourcePath, item.shortname);
            }
        }
        void InitializeConstruction() {
            foreach (var construction in PrefabAttribute.server.GetAll<Construction>()) {
                if (construction.deployable == null && construction.info.name.english != string.Empty) if (!PrefabNameToStructure.ContainsKey(construction.fullName)) PrefabNameToStructure.Add(construction.fullName, construction.info.name.english);
            }
        }
        Dictionary<string, object> DefaultPay() {
            var d = new Dictionary<string, object> {
                {
                    "Twigs", new Dictionary<string, object> {
                        {
                            "wood", 1
                        }
                    }
                }
                , {
                    "Wood", new Dictionary<string, object> {
                        {
                            "wood", 10
                        }
                    }
                }
                , {
                    "Stone", new Dictionary<string, object> {
                        {
                            "stones", 50
                        }
                        , {
                            "wood", 10
                        }
                    }
                }
                , {
                    "Metal", new Dictionary<string, object> {
                        {
                            "metal fragments", 75
                        }
                    }
                }
                , {
                    "TopTier", new Dictionary<string, object> {
                        {
                            "high quality metal", 5
                        }
                    }
                }
                ,
            }
            ;
            foreach (var itemname in PrefabNameToDeployable.Values) {
                d.Add(itemname, new Dictionary<string, object> {
                    {
                        "wood", 75
                    }
                    , {
                        "metal fragments", 10
                    }
                }
                );
            }
            return d;
        }
        Dictionary<string, object> DefaultEntities() {
            var d = new Dictionary<string, object> {
                {
                    "Twigs", true
                }
                , {
                    "Wood", true
                }
                , {
                    "Stone", true
                }
                , {
                    "Metal", true
                }
                , {
                    "TopTier", true
                }
            }
            ;
            foreach (var itemname in PrefabNameToStructure.Values) {
                d.Add(itemname, true);
            }
            foreach (var itemname in PrefabNameToDeployable.Values) {
                d.Add(itemname, true);
            }
            return d;
        }
        Dictionary<string, object> DefaultRefund() {
            var d = new Dictionary<string, object> {
                {
                    "Twigs", new Dictionary<string, object> {
                        {
                            "wood", 1
                        }
                    }
                }
                , {
                    "Wood", new Dictionary<string, object> {
                        {
                            "wood", 10
                        }
                    }
                }
                , {
                    "Stone", 50
                }
                , {
                    "Metal", new Dictionary<string, object> {
                        {
                            "metal fragments", 50
                        }
                    }
                }
                , {
                    "TopTier", new Dictionary<string, object> {
                        {
                            "high quality metal", 2
                        }
                    }
                }
                ,
            }
            ;
            foreach (var itemname in PrefabNameToDeployable.Values) {
                d.Add(itemname, new Dictionary<string, object> {
                    {
                        itemname.ToLower(), 1
                    }
                }
                );
            }
            return d;
        }
#endregion
#region Methods
        string GetMsg(string key, BasePlayer source = null) {
            return rt.lang.GetMessage(key, rt, source == null ? null : source.UserIDString);
        }
        bool hasPermission(BasePlayer player, string perm, int authlevel) {
            if (player == null) return true;
            if (player.net.connection.authLevel >= authlevel) return true;
            return permission.UserHasPermission(player.userID.ToString(), perm);
        }
        string ListPlayersToString(List<IPlayer> players) {
            var returnstring = string.Empty;
            foreach (var player in players) {
                returnstring += string.Format("{0} {1}\n", player.Id, player.Name);
            }
            return returnstring;
        }
        bool GetParameters(BasePlayer player, string[] args, out RemoveType RemoveType, out BasePlayer Target, out int Time, out string Reason) {
            Reason = string.Empty;
            Target = player;
            RemoveType = RemoveType.Normal;
            Time = RemoveDefaultTime;
            if (args != null) {
                foreach (var arg in args) {
                    switch (arg.ToLower()) {
                        case "normal" : RemoveType = RemoveType.Normal;
                        break;
                        case "admin" : RemoveType = RemoveType.Admin;
                        break;
                        case "all" : RemoveType = RemoveType.All;
                        break;
                        case "structure" : RemoveType = RemoveType.Structure;
                        break;
                        default : ulong userid = 0L;
                        int temptime = 0;
                        if (arg.Length == 17 && ulong.TryParse(arg, out userid)) {
                            Target = BasePlayer.Find(arg);
                        }
                        else if (int.TryParse(arg, out temptime)) {
                            Time = temptime;
                        }
                        else {
                            var players = covalence.Players.FindPlayers(arg).Where(x => x.IsConnected).ToList();
                            if (players.Count == 0) {
                                Reason += string.Format(GetMsg("Couldn't find player.No players match this name: {0}.\n", player), arg);
                            }
                            else if (players.Count > 1) {
                                Reason += string.Format(GetMsg("Couldn't find player.Multiple players match: {0}.\n", player), ListPlayersToString(players));
                            }
                            else {
                                Target = (BasePlayer)players[0]?.Object;
                            }
                        }
                        break;
                    }
                }
            }
            if (Target != player && !hasPermission(player, permissionTarget, authTarget)) Reason += string.Format(GetMsg("You are not allowed to use this command option.\n", player));
            if (RemoveType == RemoveType.Normal && !hasPermission(player, permissionNormal, authNormal)) Reason += string.Format(GetMsg("You are not allowed to use this command.\n", player));
            if ((RemoveType == RemoveType.All || RemoveType == RemoveType.Structure) && !hasPermission(player, permissionAll, authAll)) Reason += string.Format(GetMsg("You are not allowed to use this command option.\n", player));
            if (RemoveType == RemoveType.Admin && !hasPermission(player, permissionAdmin, authAdmin)) Reason += string.Format(GetMsg("You are not allowed to use this command option.\n", player));
            if (RemoveOverride && !hasPermission(player, permissionOverride, authOverride)) Reason += string.Format(GetMsg("RemoverTool is currently disabled.\n", player));
            if (Time > RemoveMaxTime) Time = RemoveMaxTime;
            return (Reason == string.Empty);
        }
        void DoRemove(BaseEntity Entity, bool gibs = true) {
            if (Entity != null) {
                Interface.Oxide.CallHook("OnRemovedEntity", Entity);
                if (!Entity.IsDestroyed) Entity.Kill(gibs ? BaseNetworkable.DestroyMode.Gib : BaseNetworkable.DestroyMode.None);
            }
        }
#endregion
#region UI
        public class UI {
            public static CuiElementContainer CreateElementContainer(string parent, string panelName, string color, string aMin, string aMax, bool useCursor) {
                var NewElement = new CuiElementContainer() {
                    {
                        new CuiPanel {
                            Image = {
                                Color = color
                            }
                            , RectTransform = {
                                AnchorMin = aMin, AnchorMax = aMax
                            }
                            , CursorEnabled = useCursor
                        }
                        , new CuiElement().Parent = parent, panelName
                    }
                }
                ;
                return NewElement;
            }
            public static void CreatePanel(ref CuiElementContainer container, string panel, string color, string aMin, string aMax, bool cursor = false) {
                container.Add(new CuiPanel {
                    Image = {
                        Color = color
                    }
                    , RectTransform = {
                        AnchorMin = aMin, AnchorMax = aMax
                    }
                    , CursorEnabled = cursor
                }
                , panel);
            }
            public static void CreateLabel(ref CuiElementContainer container, string panel, string color, string text, int size, string aMin, string aMax, TextAnchor align = TextAnchor.MiddleCenter) {
                container.Add(new CuiLabel {
                    Text = {
                        Color = color, FontSize = size, Align = align, Text = text
                    }
                    , RectTransform = {
                        AnchorMin = aMin, AnchorMax = aMax
                    }
                }
                , panel);
            }
            public static void CreateButton(ref CuiElementContainer container, string panel, string color, string text, int size, string aMin, string aMax, string command, TextAnchor align = TextAnchor.MiddleCenter) {
                container.Add(new CuiButton {
                    Button = {
                        Color = color, Command = command, FadeIn = 1.0f
                    }
                    , RectTransform = {
                        AnchorMin = aMin, AnchorMax = aMax
                    }
                    , Text = {
                        Text = text, FontSize = size, Align = align
                    }
                }
                , panel);
            }
        }
        public static string GetName(string prefabname) {
            if (rt.PrefabNameToStructure.ContainsKey(prefabname)) return rt.PrefabNameToStructure[prefabname];
            else if (rt.PrefabNameToDeployable.ContainsKey(prefabname)) return rt.PrefabNameToDeployable[prefabname];
            return string.Empty;
        }
        public static void CreateGUI(BasePlayer player, RemoveType removeType) {
            var panelName = "RemoverTool";
            CuiHelper.DestroyUi(player, panelName);
            var Class_Element = UI.CreateElementContainer("Hud", panelName, rt.GUIRemoverToolBackgroundColor, rt.GUIRemoverToolAnchorMin, rt.GUIRemoverToolAnchorMax, false);
            CuiHelper.AddUi(player, Class_Element);
            var panelName2 = "Remove";
            CuiHelper.DestroyUi(player, panelName2);
            var Class_Element2 = UI.CreateElementContainer(panelName, panelName2, rt.GUIRemoveBackgroundColor, rt.GUIRemoveAnchorMin, rt.GUIRemoveAnchorMax, false);
            UI.CreateLabel(ref Class_Element2, panelName2, rt.GUIRemoveTextColor, string.Format(rt.GetMsg("Remover Tool {0}", player), removeType == RemoveType.Normal ? string.Empty : string.Format("({0})", removeType.ToString())), rt.GUIRemoveTextSize, rt.GUIRemoveTextAnchorMin, rt.GUIRemoveTextAnchorMax, TextAnchor.MiddleLeft);
            CuiHelper.AddUi(player, Class_Element2);
        }
        public static void GUITimeLeftUpdate(BasePlayer player, int timeleft) {
            var panelName = "RemoverToolTimeLeft";
            CuiHelper.DestroyUi(player, panelName);
            var Class_Element = UI.CreateElementContainer("RemoverTool", panelName, rt.GUITimeLeftBackgroundColor, rt.GUITimeLeftAnchorMin, rt.GUITimeLeftAnchorMax, false);
            UI.CreateLabel(ref Class_Element, panelName, rt.GUITimeLeftTextColor, string.Format(rt.GetMsg("Timeleft: {0}secs", player), timeleft.ToString()), rt.GUITimeLeftTextSize, rt.GUITimeLeftTextAnchorMin, rt.GUITimeLeftTextAnchorMax, TextAnchor.MiddleLeft);
            CuiHelper.AddUi(player, Class_Element);
        }
        public static void GUIEntityUpdate(BasePlayer player, BaseEntity TargetEntity) {
            var panelName = "RemoverToolEntity";
            CuiHelper.DestroyUi(player, panelName);
            if (TargetEntity == null) return;
            var Name = GetName(TargetEntity.PrefabName);
            var Class_Element = UI.CreateElementContainer("RemoverTool", panelName, rt.GUIEntityBackgroundColor, rt.GUIEntityAnchorMin, rt.GUIEntityAnchorMax, false);
            UI.CreateLabel(ref Class_Element, panelName, rt.GUIEntityTextColor, Name, rt.GUIEntityTextSize, rt.GUIEntityTextAnchorMin, rt.GUIEntityTextAnchorMax, TextAnchor.MiddleLeft);
            CuiHelper.AddUi(player, Class_Element);
        }
        public static void GUIPricesUpdate(BasePlayer player, bool usePrice, BaseEntity TargetEntity) {
            var panelName = "RemoverToolPrice";
            CuiHelper.DestroyUi(player, panelName);
            if (TargetEntity == null) return;
            Dictionary<string, object> price = new Dictionary<string, object>();
            if (usePrice) {
                price = rt.GetPrice(TargetEntity);
            }
            string cost = string.Empty;
            if (price.Count == 0) cost = rt.GetMsg("Free", player);
            else {
                foreach (KeyValuePair<string, object> p in price) {
                    cost += string.Format("{2}{0} x{1}", p.Key, p.Value.ToString(), cost != string.Empty ? "\n" : string.Empty);
                }
            }
            var Class_Element = UI.CreateElementContainer("RemoverTool", panelName, rt.GUIPriceBackgroundColor, rt.GUIPriceAnchorMin, rt.GUIPriceAnchorMax, false);
            UI.CreateLabel(ref Class_Element, panelName, rt.GUIPriceTextColor, rt.GetMsg("Price:", player), rt.GUIPriceTextSize, rt.GUIPriceTextAnchorMin, rt.GUIPriceTextAnchorMax, TextAnchor.MiddleLeft);
            UI.CreateLabel(ref Class_Element, panelName, rt.GUIPrice2TextColor, cost, rt.GUIPrice2TextSize, rt.GUIPrice2TextAnchorMin, rt.GUIPrice2TextAnchorMax, TextAnchor.MiddleLeft);
            CuiHelper.AddUi(player, Class_Element);
        }
        public static void GUIRefundUpdate(BasePlayer player, bool useRefund, BaseEntity TargetEntity) {
            var panelName = "RemoverToolRefund";
            CuiHelper.DestroyUi(player, panelName);
            if (TargetEntity == null) return;
            Dictionary<string, object> refund = new Dictionary<string, object>();
            if (useRefund) {
                refund = rt.GetRefund(TargetEntity);
            }
            string r = string.Empty;
            if (refund.Count == 0) r = rt.GetMsg("Nothing", player);
            else {
                foreach (KeyValuePair<string, object> p in refund) {
                    r += string.Format("{2}{0} x{1}", p.Key, p.Value.ToString(), r != string.Empty ? "\n" : string.Empty);
                }
            }
            var Class_Element = UI.CreateElementContainer("RemoverTool", panelName, rt.GUIRefundBackgroundColor, rt.GUIRefundAnchorMin, rt.GUIRefundAnchorMax, false);
            UI.CreateLabel(ref Class_Element, panelName, rt.GUIRefundTextColor, rt.GetMsg("Refund:", player), rt.GUIRefundTextSize, rt.GUIRefundTextAnchorMin, rt.GUIRefundTextAnchorMax, TextAnchor.MiddleLeft);
            UI.CreateLabel(ref Class_Element, panelName, rt.GUIRefund2TextColor, r, rt.GUIRefund2TextSize, rt.GUIRefund2TextAnchorMin, rt.GUIRefund2TextAnchorMax, TextAnchor.MiddleLeft);
            CuiHelper.AddUi(player, Class_Element);
        }
        public static void GUIAuthorizationUpdate(BasePlayer player, RemoveType removeType, BaseEntity TargetEntity, bool shouldPay) {
            var panelName = "RemoverToolAuth";
            CuiHelper.DestroyUi(player, panelName);
            if (TargetEntity == null) return;
            string Reason = string.Empty;
            string GUIColor = rt.CanRemoveEntity(player, removeType, TargetEntity, shouldPay, out Reason) ? rt.GUIAllowedBackgroundColor : rt.GUIRefusedBackgroundColor;
            var Class_Element = UI.CreateElementContainer("RemoverTool", panelName, GUIColor, rt.GUIAuthorizationsAnchorMin, rt.GUIAuthorizationsAnchorMax, false);
            CuiHelper.AddUi(player, Class_Element);
        }
        public void DestroyGUI(BasePlayer player) {
            CuiHelper.DestroyUi(player, "RemoverTool");
        }
#endregion
#region ToolRemover Class
        class ToolRemover : MonoBehaviour {
            public BasePlayer player {
                get;
                set;
            }
            public BasePlayer source {
                get;
                set;
            }
            public int timeLeft {
                get;
                set;
            }
            public float distance {
                get;
                set;
            }
            public RemoveType removetype {
                get;
                set;
            }
            public bool Pay {
                get;
                set;
            }
            public bool Refund {
                get;
                set;
            }
            public BaseEntity TargetEntity {
                get;
                set;
            }
            uint currentItemID;
            HeldEntity heldEntity;
            RaycastHit RayHit;
            float lastUpdate {
                get;
                set;
            }
            float lastRemove {
                get;
                set;
            }
            void Awake() {
                player = GetComponent<BasePlayer>();
                lastUpdate = UnityEngine.Time.realtimeSinceStartup;
                lastRemove = UnityEngine.Time.realtimeSinceStartup;
                if (rt.removeUnequipStart || rt.removeUnequipUpdate) {
                    currentItemID = player.svActiveItemID;
                    UnEquip();
                }
            }
            public void Start() {
                CreateGUI(player, removetype);
                CancelInvoke("RemoveUpdate");
                InvokeRepeating("RemoveUpdate", 0f, 1f);
            }
            void RemoveUpdate() {
                timeLeft--;
                if (timeLeft <= 0) {
                    Destroy();
                    return;
                }
                GUITimeLeftUpdate(player, timeLeft);
                GUIEntityUpdate(player, TargetEntity);
                if (removetype == RemoveType.Normal && rt.GUIAuthorizations) GUIAuthorizationUpdate(player, removetype, TargetEntity, Pay);
                if (removetype == RemoveType.Normal && rt.GUIPrices) GUIPricesUpdate(player, Pay, TargetEntity);
                if (removetype == RemoveType.Normal && rt.GUIRefund) GUIRefundUpdate(player, Refund, TargetEntity);
            }
            void FixedUpdate() {
                if (player.IsSleeping() || !player.IsConnected) {
                    Destroy();
                    return;
                }
                if (player.svActiveItemID != currentItemID && (rt.removeUnequipStart || rt.removeUnequipUpdate)) {
                    currentItemID = player.svActiveItemID;
                    if (currentItemID > 0u) {
                        if (!rt.removeUnequipUpdate) {
                            Destroy();
                            return;
                        }
                        else UnEquip();
                    }
                }
                float currentTime = UnityEngine.Time.realtimeSinceStartup;
                if (currentTime - lastUpdate >= 0.5f) {
                    bool flag1 = Physics.Raycast(player.eyes.HeadRay(), out RayHit, distance, rt.colliderRemovable);
                    TargetEntity = flag1 ? RayHit.GetEntity() : null;
                    lastUpdate = currentTime;
                }
                if (player.serverInput.IsDown(BUTTON.FIRE_PRIMARY)) {
                    if (currentTime - lastRemove >= 0.5f) {
                        var returnmsg = rt.TryRemove(player, removetype, distance, Pay, Refund);
                        if (returnmsg != string.Empty) player.ChatMessage(returnmsg);
                        lastRemove = currentTime;
                    }
                }
            }
            void UnEquip() {
                var item = player.GetActiveItem();
                if (item == null || item.GetHeldEntity() == null) return;
                var slot = item.position;
                item.SetParent(null);
                item.MarkDirty();
                rt.timer.Once(0.15f, () => {
                    if (item == null) return;
                    item.SetParent(player.inventory.containerBelt);
                    item.position = slot;
                    item.MarkDirty();
                }
                );
            }
            public void Destroy() {
                CancelInvoke("RemoveUpdate");
                rt.DestroyGUI(player);
                if (rt.CoolDownEnabled) rt.cooldownTimes[player.UserIDString + "-box"] = DateTime.UtcNow;
                GameObject.Destroy(this);
            }
        }
#endregion
#region Pay
        bool Pay(BasePlayer player, BaseEntity TargetEntity) {
            var cost = GetPrice(TargetEntity);
            try {
                List<Item> collect = new List<Item>();
                foreach (KeyValuePair<string, object> p in cost) {
                    var priceName = p.Key.ToLower();
                    var amount = (int)p.Value;
                    if (ItemNameToItemID.ContainsKey(priceName)) {
                        var itemid = ItemNameToItemID[priceName];
                        player.inventory.Take(collect, itemid, amount);
                        player.Command("
// ... [Code preview truncated due to length. Full source in attached file] ...

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