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

FREE WarMode : 1.3.5 1.3.5

Нет прав для скачивания
C#:
using static Oxide.Plugins.WarMode;
using Newtonsoft.Json;
using System.Text;
using Oxide.Game.Rust.Cui;
using Newtonsoft.Json.Converters;
using Oxide.Core.Plugins;
using System.Collections.Generic;
using ProtoBuf;
using System.Data;
using System.IO;
using Oxide.Plugins.WarModeMethods;
using System;
using UnityEngine;
using Oxide.Core.Libraries.Covalence;
using Oxide.Core;
using System.Linq;
namespace Oxide.Plugins {
    [Info("WarMode", "mr01sam", "1.3.5")]
    [Description("Flag players as PvP or PvE.")]
    public partial class WarMode : CovalencePlugin {
        [PluginReference]
        private readonly Plugin SimpleStatus, AdvancedStatus, ZoneManager, AbandonedBases, RaidableBases, WarModeAdminPanel, Toastify, BetterChat, NoEscape;
        internal const string PermissionFlag = "warmode.flag";
        internal const string PermissionAdmin = "warmode.admin";
        internal const string PermissionBypass = "warmode.bypass";
        public static bool DEBUGGING => INSTANCE.config.Settings.ShowDebugMessagesInConsole;
        public bool isNewSave = false;
        public static void Debug(string message, Func<bool> condition = null) {
            if (DEBUGGING && (condition?.Invoke() ?? true)) {
                INSTANCE.Puts($"[DEBUG]: {message}");
            }
        }
        public static void DebugAction(string action, BaseEntity initiator, BaseEntity target, HitInfo info = null, TargetType? ttoverride = null) {
            if (!DEBUGGING) {
                return;
            }
            if (!(initiator is BasePlayer)) {
                return;
            }
            var basePlayer = initiator as BasePlayer;
            var privInfo = target.GetPrivInfo();
            var tt = ttoverride ?? target.GetTargetType();
            Debug($"{basePlayer.displayName} {action} {initiator.GetTargetType()}({initiator.GetMode().Name()}) -> {tt}({target.GetMode().Name()}){(privInfo.NotExists ? "" : $"(base is {
                privInfo.GetMode().Name()
            }
            )")}");
        }
        public static WarMode INSTANCE;
        void Init() {
            INSTANCE = this;
            UnsubscribeAll(nameof(OnEntityTakeDamage), nameof(CanLootPlayer), nameof(CanLootEntity), nameof(OnItemPickup), nameof(OnLootEntity), nameof(OnPlayerSleepEnded), nameof(OnPlayerDisconnected), nameof(OnUserConnected), nameof(OnPlayerInput), nameof(OnUserGroupAdded), nameof(OnTeamInvite), nameof(OnTeamUpdate), nameof(CanBeTargeted), nameof(OnSamSiteTarget), nameof(OnTrapTrigger), nameof(OnRackedWeaponMount), nameof(OnRackedWeaponUnload), nameof(OnRackedWeaponLoad), nameof(OnRackedWeaponSwap), nameof(OnRackedWeaponTake), nameof(OnGrowableGather), nameof(CanTakeCutting), nameof(CanAdministerVending), nameof(CanMountEntity), nameof(CanRenameBed) );
        }
        private List<string> _subscriptions = new List<string>();
        public void UnsubscribeAll(params string[] methods) {
            _subscriptions.AddRange(methods);
            foreach(var method in _subscriptions) {
                Unsubscribe(method);
            }
        }
        public void SubscribeAll() {
            foreach (var method in _subscriptions) {
                switch(method) {
                    // Methods that are dynamically subscribed can go here
                    default : Subscribe(method);
                    break;
                }
            }
        }
        void OnServerInitialized() {
            RevealConfigOptions();
            if (!isNewSave) {
                LoadData();
            }
            ValidateModes();
            // Add Default Modes
            ConfigWasUpdated();
            // Localization
            LoadDefaultMessages();
            // Permissions
            permission.RegisterPermission(PermissionFlag, this);
            permission.RegisterPermission(PermissionBypass, this);
            // Commands
            if (!string.IsNullOrWhiteSpace(config.Flagging.ChatCommand)) {
                AddCovalenceCommand(config.Flagging.ChatCommand, nameof(CmdFlagPvp), PermissionFlag);
            }
            // SimpleStatus
            if (SimpleStatus.IsLoaded()) {
                foreach(var kvp in config.SimpleStatus.ModeStatusBars) {
                    var statusBar = kvp.Value;
                    if (statusBar.Show) {
                        SimpleStatus.CallHook("CreateStatus", this, $"warmode.{kvp.Key}", statusBar.BackgroundColor, $"ss title {kvp.Key}", statusBar.TitleColor, $"ss text {kvp.Key}", statusBar.TextColor, statusBar.Image, statusBar.ImageColor);
                    }
                }
                foreach (var basePlayer in BasePlayer.activePlayerList) {
                    UpdateStatusBar(basePlayer.UserIDString);
                }
            }
            // BetterChat
            if (BetterChat.IsLoaded()) {
                BetterChat_AddTitles();
            }
            // Subscribe All
            SubscribeAll();
            // Init Players
            foreach (var player in covalence.Players.All) {
                OnUserConnected(player);
            }
        }
        void Unload() {
            SaveData();
            Marker.ClearAllBehaviors();
            // Unbsubscribe
            Unsubscribe(nameof(OnPlayerInput));
            Unsubscribe(nameof(OnEntityTakeDamage));
            Unsubscribe(nameof(CanLootPlayer));
            Unsubscribe(nameof(CanLootEntity));
            if (SimpleStatus.IsLoaded()) {
                foreach(var basePlayer in BasePlayer.activePlayerList) {
                    SimpleStatus.CallHook("SetStatus", basePlayer.UserIDString, "warmode.pve", 0);
                    SimpleStatus.CallHook("SetStatus", basePlayer.UserIDString, "warmode.pvp", 0);
                }
            }
        }
        void OnNewSave(string filename) {
            INSTANCE.isNewSave = true;
        }
        private Dictionary<ulong, ulong> cachedPrivs = new Dictionary<ulong, ulong>();
        public static BaseNetworkable FindEntity(ulong entityId) {
            return BaseNetworkable.serverEntities.Find(new NetworkableId(entityId));
        }
        public BuildingPrivlidge GetPriv(BaseEntity entity) {
            if (cachedPrivs.ContainsKey(entity.net.ID.Value)) {
                var eid = cachedPrivs[entity.net.ID.Value];
                return FindEntity(eid) as BuildingPrivlidge;
            }
            var priv = entity.GetBuildingPrivilege();
            if (priv == null) {
                return null;
            }
            cachedPrivs[entity.net.ID.Value] = priv.net.ID.Value;
            return priv;
        }
        string json = null;
        string GetMarkerJson() {
            if (json != null) {
                return json;
            }
            var container = new CuiElementContainer();
            var size = config.Marker.Size;
            var up = 0;
            container.Add(new CuiElement {
                Name = "warmode.marker", Parent = "Hud", FadeOut = 0.1f, Components = {
                    new CuiRectTransformComponent {
                        AnchorMin = "0.5 0.5", AnchorMax = "0.5 0.5", OffsetMin = $"{-size} {-size+up}", OffsetMax = $"{size} {size+up}"
                    }
                    , new CuiImageComponent {
                        FadeIn = 0.1f, Sprite = config.Marker.Image, Color = config.Marker.Color,
                    }
                }
            }
            );
            json = container.ToJson();
            return json;
        }
        private static T FindObject<T>(BasePlayer basePlayer, float distance) where T : BaseEntity {
            Ray ray = new Ray(basePlayer.eyes.position, basePlayer.eyes.HeadForward());
            RaycastHit hit;
            return !Physics.Raycast(ray, out hit, distance) ? null : hit.GetEntity() as T;
        }
        // key is compound key of userid|messageid
        private Dictionary<string, float> NotifyDelays = new Dictionary<string, float>();
        public void Notify(Plugin plugin, BasePlayer basePlayer, string loc, bool positive, float cooldown, params object[] args) {
            var userid = basePlayer.UserIDString;
            var key = CompoundKey(userid, loc);
            if (cooldown > 0 && NotifyDelays.GetValueOrDefault(key) > UnityEngine.Time.realtimeSinceStartup) {
                return;
            }
            var localizedText = Lang(loc, userid, args);
            var overrule = (bool?) CallHook("WarMode_NotificationSent", userid, loc, localizedText);
            if (overrule != null) {
                return;
            }
            // Chat
            if (config.Notifications.Chat) {
                var chatText = localizedText;
                if (config.Chat.ShowPluginPrefix) {
                    chatText = $"<color={config.Chat.PluginPrefixColor}>[WarMode]</color> " + localizedText;
                }
                ConsoleNetwork.SendClientCommand(basePlayer.Connection, "chat.add", 2, config.Chat.SteamIdForIcon, chatText);
                if (!positive && !string.IsNullOrWhiteSpace(config.Chat.SfxFail)) {
                    EffectNetwork.Send(new Effect(config.Chat.SfxFail, basePlayer, 0, Vector3.zero, Vector3.forward), basePlayer.net.connection);
                }
                else if (positive && !string.IsNullOrWhiteSpace(config.Chat.SfxSuccess)) {
                    EffectNetwork.Send(new Effect(config.Chat.SfxSuccess, basePlayer, 0, Vector3.zero, Vector3.forward), basePlayer.net.connection);
                }
            }
            // Toastify
            if (config.Notifications.Toastify && Toastify.IsLoaded()) {
                Toastify?.CallHook("SendToast", basePlayer, positive ? config.Toastify.PositiveToastID : config.Toastify.NegativeToastID, null, localizedText, config.Toastify.Duration);
            }
            if (cooldown > 0) {
                NotifyDelays[key] = UnityEngine.Time.realtimeSinceStartup + cooldown;
            }
        }
        private HashSet<ulong> teamStartedSync = new HashSet<ulong>();
        public void UpdateStatusBar(string userid) {
            if (!SimpleStatus.IsLoaded()) {
                return;
            }
            // SimpleStatus
            var modeName = userid.GetMode()?.Name;
            foreach (var mode in Modes.Values) {
                if (mode.Name == modeName) {
                    continue;
                }
                SimpleStatus.CallHook("SetStatus", userid, $"warmode.{mode.Name}", 0);
            }
            if (AdvancedStatus?.IsLoaded ?? false) {
                timer.In(1f, () => {
                    SimpleStatus.CallHook("SetStatus", userid, $"warmode.{modeName}", int.MaxValue);
                }
                );
            }
            else {
                SimpleStatus.CallHook("SetStatus", userid, $"warmode.{modeName}", int.MaxValue);
            }
        }
        private static string CompoundKey(object obj1, object obj2) => $"{obj1}|{obj2}";
    }
}
namespace Oxide.Plugins {
    public partial class WarMode {
        // The following are hooks that other plugins can subscribe to
        /*
        
        // Called when a player's mode has been updated or config changes have ocurred that may affect the mode.private void WarMode_PlayerModeUpdated(string userid, string modeId)
        {

        }

        */
        // Returns the mode of the given entity.Also takes into account if the entity is in a forced mode zone.private string GetEntityMode(BaseEntity entity)
        {
            return entity?.GetMode()?.Name ?? string.Empty;
        }
        // Returns the group name for the given mode.For example if given 'pve' will return 'warmodepve'
        private string GetModeGroup(string modeId) {
            return Modes.GetValueOrDefault(modeId)?.Group ?? string.Empty;
        }
        // Returns the target type for a given entity.Target types are the category that an entity falls into.// For example, if given a BasePlayer entity, it will return 'players'.If given a horse entity is will
        // return 'horses'.private string GetEntityTargetType(BaseEntity entity)
        {
            return entity?.GetTargetType().ToString() ?? string.Empty;
        }
    }
}
namespace Oxide.Plugins {
    public partial class WarMode {
        public void BetterChat_AddTitles() {
            BetterChat?.CallHook("API_RegisterThirdPartyTitle", this, new Func<IPlayer, string>(GetBetterChatModeTitle));
        }
        public string GetBetterChatModeTitle(IPlayer player) {
            if (player == null) {
                return null;
            }
            var mode = player.GetMode();
            if (mode == null) {
                return null;
            }
            if (!config.BetterChat.Modes.ContainsKey(mode.Name()) || !config.BetterChat.Modes[mode.Name()].ShowModeTitleInChat) {
                return null;
            }
            return string.Format(config.BetterChat.Modes[mode.Name()].ModeTitleFormat, mode.Title(player.Id, colored : false));
        }
    }
}
namespace Oxide.Plugins {
    public partial class WarMode {
        /* This file is intentionally blank to use as a template */
    }
}
namespace Oxide.Plugins {
    public partial class WarMode {
        [Command("warmode"), Permission(PermissionAdmin)]
        private void CmdWarmode(IPlayer player, string command, string[] args) {
            var commands = new[] {
                new {
                    Enabled = WarModeAdminPanel?.IsLoaded ?? false, Commands = new string[] {
                        "warmode.config", "wmc"
                    }
                    , Args = new string[] {
                    }
                    , Description = "Opens a UI panel that allows you to edit modes in game."
                }
                , new {
                    Enabled = true, Commands = new string[] {
                        "warmode.setplayer"
                    }
                    , Args = new string[] {
                        "player", "mode"
                    }
                    , Description = "Sets the mode for the given player."
                }
                , new {
                    Enabled = true, Commands = new string[] {
                        "warmode.setall"
                    }
                    , Args = new string[] {
                        "mode"
                    }
                    , Description = "Sets the mode for all players on the server."
                }
                , new {
                    Enabled = true, Commands = new string[] {
                        "warmode.mode"
                    }
                    , Args = new string[] {
                        "player?"
                    }
                    , Description = "Display the mode for the specified player name OR your own mode if left blank."
                }
                , new {
                    Enabled = true, Commands = new string[] {
                        "warmode.tc"
                    }
                    , Args = new string[] {
                    }
                    , Description = "Display the mode for the base you are standing in.Will display nothing if not within a base."
                }
                , new {
                    Enabled = true, Commands = new string[] {
                        "warmode.getmode"
                    }
                    , Args = new string[] {
                    }
                    , Description = "Display the mode for the entity or player you are looking at.Does not work for every entity."
                }
            }
            ;
            var str = "";
            str += Size("[ " + Color("WarMode Admin Commands", "#55e076") + " ]", 16) + "\n";
            foreach(var cmd in commands.Where(x => x.Enabled)) {
                foreach(var cmd2 in cmd.Commands) {
                    str += $"\n/{Color(cmd2, "#f7ce83")} {(string.Join(" ", cmd.Args.Select(x => Color("<" + x + ">", "#83f7f5"))))}";
                }
                str += "\n" + Size(cmd.Description, 10) + "\n";
            }
            player.Message(Size(str, 13));
        }
        [Command("warmode.setplayer"), Permission(PermissionAdmin)]
        private void CmdSetPlayer(IPlayer player, string command, string[] args) {
            // warmode.setplayer <player> <pve|pvp>
            try {
                var userIdOrString = args[0];
                var mode = args[1].ToLower();
                var target = covalence.Players.FindPlayer(userIdOrString);
                if (target == null) {
                    player.Message($"No player found with ID or name matching '{userIdOrString}'");
                    return;
                }
                if (GetModeGroupByTitle(mode) == null) {
                    player.Message($"No mode named '{mode}' exists, valid modes are {Modes.Select(x => x.Value.Name).ToSentence()}");
                    return;
                }
                SetModeByName(target.Id, mode);
                player.Message($"Set MODE={mode} for {target.Name}");
            }
            catch {
                player.Message("Usage: warmode.setplayer <player> <pve|pvp>");
            }
        }
        [Command("warmode.setall"), Permission(PermissionAdmin)]
        private void CmdSetAll(IPlayer player, string command, string[] args) {
            // warmode.setall <pve|pvp>
            try {
                var i = 0;
                var mode = args[0].ToLower();
                if (GetModeGroupByTitle(mode) == null) {
                    player.Message($"No mode named '{mode}' exists, valid modes are {Modes.Select(x => x.Value.Name).ToSentence()}'");
                    return;
                }
                foreach (var basePlayer in covalence.Players.All) {
                    SetModeByName(basePlayer.Id, mode);
                    i++;
                }
                player.Message($"Set MODE={mode} for {i} players");
            }
            catch {
                player.Message("Usage: warmode.setall <pve|pvp>");
            }
        }
        [Command("warmode.getmode"), Permission(PermissionAdmin)]
        private void CmdGetMode(IPlayer player, string command, string[] args) {
            // warmode.getmode
            try {
                BasePlayer basePlayer = player.Object as BasePlayer;
                Ray ray = new Ray(basePlayer.eyes.position, basePlayer.eyes.HeadForward());
                BaseEntity target = FindObject(ray, 4f);
                if (target == null) {
                    player.Message("You must be looking at an entity");
                    return;
                }
                ModeConfig mode = null;
                if (target is BasePlayer targetBasePlayer) {
                    mode = targetBasePlayer.GetMode();
                }
                else if (target is BaseVehicle targetVehicle) {
                    mode = targetVehicle.GetMode();
                }
                else {
                    mode = target.GetMode();
                }
                var message = $"Mode of that {target.GetType()} is {mode?.Name.ToUpper() ?? "NONE"}";
                var privInfo = target.GetPrivInfo();
                if (!privInfo.NotExists) {
                    message += $" but is within base with a mode of {privInfo.GetMode()?.Name.ToUpper() ?? "NONE"}";
                }
                player.Message(message);
            }
            catch {
                player.Message("Usage: warmode.getmode");
            }
        }
    }
}
namespace Oxide.Plugins {
    public partial class WarMode : CovalencePlugin {
        public static Configuration CONFIG => INSTANCE.config;
        public Configuration config;
        public class Configuration {
            [ConfigDescription("")]
            public SettingsConfig Settings = new SettingsConfig();
            [ConfigDescription("")]
            public FlaggingConfig Flagging = new FlaggingConfig();
            [ConfigDescription("")]
            public MarkerConfig Marker = new MarkerConfig();
            [ConfigDescription("")]
            public NotificationsConfig Notifications = new NotificationsConfig();
            [ConfigDescription("")]
            public ChatConfig Chat = new ChatConfig();
            [ConfigDescription("")]
            public TeamsConfig Teams = new TeamsConfig();
            // ADD PLUGIN INTEGRATION
            [Newtonsoft.Json.JsonProperty(NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)]
            [ConfigDescription("")]
            public SimpleStatusConfig SimpleStatus = null;
            [Newtonsoft.Json.JsonProperty(NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)]
            [ConfigDescription("")]
            public ZoneManagerConfig ZoneManager = null;
            [Newtonsoft.Json.JsonProperty(NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)]
            [ConfigDescription("")]
            public RaidableBasesConfig RaidableBases = null;
            [Newtonsoft.Json.JsonProperty(NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)]
            [ConfigDescription("")]
            public BetterChatConfig BetterChat = null;
            [Newtonsoft.Json.JsonProperty(NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)]
            [ConfigDescription("")]
            public NoEscapeConfig NoEscape = null;
            [Newtonsoft.Json.JsonProperty(NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)]
            [ConfigDescription("")]
            public ToastifyConfig Toastify = null;
            [ConfigDescription("")]
            public ModeConfig[] Modes = new ModeConfig[] {
                new ModeConfig {
                    Priority = 1, Name = "pvp", DisplayName = "PVP", Group = "warmodepvp", ColorHex = "#e6573a", CanAttackTypes = TargetTypesForCategory.Attacking.ToDictionary(ttype => ttype, value => {
                        return new string[] {
                            "pvp", "npc"
                        }
                        ;
                    }
                    ), CanLootTypes = TargetTypesForCategory.Looting.ToDictionary(ttype => ttype, value => {
                        return new string[] {
                            "pvp", "npc"
                        }
                        ;
                    }
                    ), CanTargetTypes = TargetTypesForCategory.Targeting.ToDictionary(ttype => ttype, value => {
                        return new string[] {
                            "pvp", "npc"
                        }
                        ;
                    }
                    ), CanMountTypes = TargetTypesForCategory.Mounting.ToDictionary(ttype => ttype, value => {
                        return new string[] {
                            "pvp", "npc"
                        }
                        ;
                    }
                    ), ShowMarkerWhenAimedAt = false
                }
                , new ModeConfig {
                    Priority = 2, Name = "pve", DisplayName = "PVE", Group = "warmodepve", ColorHex = "#8bda00", CanAttackTypes = TargetTypesForCategory.Attacking.ToDictionary(ttype => ttype, value => {
                        return new string[] {
                            "npc"
                        }
                        ;
                    }
                    ), CanLootTypes = TargetTypesForCategory.Looting.ToDictionary(ttype => ttype, value => {
                        return new string[] {
                            "npc"
                        }
                        ;
                    }
                    ), CanTargetTypes = TargetTypesForCategory.Targeting.ToDictionary(ttype => ttype, value => {
                        return new string[] {
                            "npc"
                        }
                        ;
                    }
                    ), CanMountTypes = TargetTypesForCategory.Mounting.ToDictionary(ttype => ttype, value => {
                        return new string[] {
                            "npc"
                        }
                        ;
                    }
                    ), ShowMarkerWhenAimedAt = true
                }
                , new ModeConfig {
                    Name = "npc", DisplayName = "NPC", ColorHex = "#47a3e3", CanAttackTypes = TargetTypesForCategory.Attacking.ToDictionary(ttype => ttype, value => {
                        return new string[] {
                            "pve", "pvp", "npc"
                        }
                        ;
                    }
                    ), CanLootTypes = TargetTypesForCategory.Looting.ToDictionary(ttype => ttype, value => {
                        return new string[] {
                            "pve", "pvp", "npc"
                        }
                        ;
                    }
                    ), CanTargetTypes = TargetTypesForCategory.Targeting.ToDictionary(ttype => ttype, value => {
                        return new string[] {
                            "pve", "pvp", "npc"
                        }
                        ;
                    }
                    ), CanMountTypes = TargetTypesForCategory.Mounting.ToDictionary(ttype => ttype, value => {
                        return new string[] {
                            "pve", "pvp", "npc"
                        }
                        ;
                    }
                    ), ShowMarkerWhenAimedAt = false
                }
            }
            ;
            public Core.VersionNumber Version {
                get;
                set;
            }
            = new Core.VersionNumber(0, 0, 0);
        }
#region Simple Status
        public class SimpleStatusConfig {
            [ConfigDescription("")]
            public Dictionary<string, StatusDetailsConfig> ModeStatusBars;
        }
        public class StatusDetailsConfig {
            public bool Show;
            public string BackgroundColor;
            [ConfigDescription("Icon that will display, currently only Sprites are supported")]
            public string Image;
            public string ImageColor;
            public string TitleColor;
            public string TextColor;
        }
#endregion
#region BetterChat
        public class BetterChatConfig {
            [ConfigDescription("If true, then the current mode of the player will appear as a title in the better chat window.")]
            public bool ShowModePrefixInChat = true;
            [ConfigDescription("")]
            public Dictionary<string, BetterChatModeConfig> Modes;
        }
        public class BetterChatModeConfig {
            [ConfigDescription("If true, then this mode will appear as a title in chat if a player belongs to it.")]
            public bool ShowModeTitleInChat = true;
            [ConfigDescription("The string format of how the mode title will appear before the player's name.The {0} will be replaced with the mode display name.Emojis are also supported.")]
            public string ModeTitleFormat = "[{0}]";
        }
#endregion
        public class TeamsConfig {
            [ConfigDescription("If true, then when a player joins a team, the modes of all the members will be synced to match the shared mode with the LOWEST priority.")]
            public bool SyncModeWithTeamMembers = true;
        }
        public class ChatConfig {
            [ConfigDescription("If true, then [WarMode] will appear in front of chat messages.")]
            public bool ShowPluginPrefix = true;
            [ConfigDescription("Only matters if ShowPluginPrefix is true.")]
            public string PluginPrefixColor = "#aaee32";
            [ConfigDescription("Steam id for the icon that will show for the chat messages.")]
            public ulong SteamIdForIcon = 0;
            [ConfigDescription("Sfx that is played when a negative chat message is shown.Other effects can be found <a href=\"https://github.com/OrangeWulf/Rust-Docs/blob/master/Extended/Effects.mdt\">here</a>")]
            public string SfxFail = "assets/prefabs/locks/keypad/effects/lock.code.denied.prefab";
            [ConfigDescription("Sfx that is played when a positive chat message is shown.Other effects can be found <a href=\"https://github.com/OrangeWulf/Rust-Docs/blob/master/Extended/Effects.mdt\">here</a>")]
            public string SfxSuccess = "assets/prefabs/locks/keypad/effects/lock.code.updated.prefab";
        }
        public class MarkerConfig {
            [ConfigDescription("If false, then the marker icons that are shown when a player aims their weapon at another player will be disabled for all modes.")]
            public bool Show = true;
            [ConfigDescription("Distance that the marker will start appearing.")]
            public float Distance = 100f;
            [ConfigDescription("The time in seconds that the marker will refresh, lower values will cause it to update more frequently, but may impact server performance.")]
            public float UpdateInterval = 0.5f;
            [ConfigDescription("The sprite asset path for the indicator icon.Other valid sprites can be found <a href=\"https://github.com/OrangeWulf/Rust-Docs/blob/master/Extended/UI.md\">here</a>")]
            public string Image = "assets/icons/peace.png";
            public float Size = 16;
            public string Color = "0 1 0 0.5";
        }
        public class FlaggingConfig {
            [ConfigDescription("If true, then the user must be in a safe zone to use the flag command.")]
            public bool RequiresSafeZone = true;
            [ConfigDescription("If true, then the user must not be marked as hostile to use the flag command.")]
            public bool RequiresNoHostile = true;
            [ConfigDescription("If true, then the use must be a leader of their team to use the flag command.If they are not in a team, this restriction will be ignored.")]
            public bool RequiresTeamLeader = false;
            [ConfigDescription("The amount of seconds before a player can use the flag command again.Set to 0 for no cooldown.")]
            public int CooldownSeconds = 60;
            public string ChatCommand = "flag";
            [ConfigDescription("These are the modes that are available for players to choose from when using the flag command.They can either specify the mode they want to switch to, or it will rotate through them if no mode is specified.")]
            public string[] ModeOptions = new string[] {
                "pve", "pvp"
            }
            ;
        }
        public class NotificationsConfig {
            public bool Chat = true;
            public bool Toastify = false;
        }
        public class ModeConfig {
            public static ModeConfig New() {
                var newMode = new ModeConfig();
                // EDIT HERE
                newMode.CanAttackTypes = TargetTypesForCategory.Attacking.ToDictionary(ttype => ttype, value => Array.Empty<string>());
                newMode.CanLootTypes = TargetTypesForCategory.Looting.ToDictionary(ttype => ttype, value => Array.Empty<string>());
                newMode.CanTargetTypes = TargetTypesForCategory.Targeting.ToDictionary(ttype => ttype, value => Array.Empty<string>());
                newMode.CanMountTypes = TargetTypesForCategory.Mounting.ToDictionary(ttype => ttype, value => Array.Empty<string>());
                newMode.CanEnterTypes = TargetTypesForCategory.Entering.ToDictionary(ttype => ttype, value => Array.Empty<string>());
                newMode.Name = "mymode";
                newMode.DisplayName = "My Mode";
                newMode.ShowMarkerWhenAimedAt = false;
                newMode.Group = "warmodemymode";
                return newMode;
            }
            // WarMode
            [ConfigDescription("When multiple modes are considered, the mode with the LOWEST priority will be applied.For example, in the case where a team has a mixture of ModeA and ModeB, the mode with the LOWEST priority will be used.")]
            [Newtonsoft.Json.JsonProperty(NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)]
            public int? Priority = null;
            [ConfigDescription("The oxide permission group associated with this mode.Leave as NULL if this mode is intended only for NPCs.If specified, you MUST provided a Priority as well.")]
            [Newtonsoft.Json.JsonProperty(NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)]
            public string Group = null;
            [ConfigDescription("Unique name of the mode.This is NOT the display name.")]
            public string Name = "";
            [ConfigDescription("The name of the mode that is displayed to players.This is not a localized value.")]
            public string DisplayName = null;
            [ConfigDescription("The color associated with this mode, it will appear this color when mentioned in messages or the UI.")]
            public string ColorHex = null;
            [JsonIgnore]
            public string ColorRgb {
                get {
                    var color = UnityEngine.Color.white;
                    ColorUtility.TryParseHtmlString(ColorHex, out color);
                    return color.ToColorString();
                }
            }
            [ConfigDescription("If true then a marker icon will be displayed on the reticle when another player aims their weapon at this player.")]
            public bool ShowMarkerWhenAimedAt = true;
            [ConfigDescription("If true then the fire damage over time effect will always deal damage to this player and anything they own.This will always allow fire damage regardless of what mode caused the fire.")]
            public bool AlwaysAllowFireDamage = false;
            [ConfigDescription("If true then patrol helicopters will be able to damage players and bases of this mode.If false, then they will be protected from the damage of these helicopters.")]
            public bool CanTakePatrolHeliDamage = true;
            // LEGACY CONFIG - This needs to stay to convert old configs
            [Newtonsoft.Json.JsonProperty(NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)]
            public string[] CanRaid = null;
            [Newtonsoft.Json.JsonProperty(NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)]
            public string[] CanAttack = null;
            [Newtonsoft.Json.JsonProperty(NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)]
            public string[] CanLoot = null;
            [Newtonsoft.Json.JsonProperty(NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)]
            public string[] CanTargetWithTraps = null;
            [Newtonsoft.Json.JsonProperty(NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)]
            public string[] CanEnterOwnedMonuments = null;
            public bool CanEnterOwnedMonumentMode(ModeConfig otherMode) => otherMode == null ? true : CanEnterOwnedMonuments.Contains(otherMode.Name);
            // ATTACKING
            public Dictionary<TargetType, string[]> CanAttackTypes = TargetTypesForCategory.Attacking.ToDictionary(ttype => ttype, value => Array.Empty<string>());
            public bool CanAttackMode(ModeConfig otherMode, TargetType ttype) => otherMode == null ? true : CanAttackTypes.GetValueOrDefault(ttype, Array.Empty<string>()).Contains(otherMode.Name);
            // LOOTING
            public Dictionary<TargetType, string[]> CanLootTypes = TargetTypesForCategory.Looting.ToDictionary(ttype => ttype, value => Array.Empty<string>());
            public bool CanLootMode(ModeConfig otherMode, TargetType ttype) => otherMode == null ? true : CanLootTypes.GetValueOrDefault(ttype, Array.Empty<string>()).Contains(otherMode.Name);
            // TARGETING
            public Dictionary<TargetType, string[]> CanTargetTypes = TargetTypesForCategory.Targeting.ToDictionary(ttype => ttype, value => Array.Empty<string>());
            public bool CanTargetMode(ModeConfig otherMode, TargetType ttype) => otherMode == null ? true : CanTargetTypes.GetValueOrDefault(ttype, Array.Empty<string>()).Contains(otherMode.Name);
            // MOUNTING
            public Dictionary<TargetType, string[]> CanMountTypes = TargetTypesForCategory.Mounting.ToDictionary(ttype => ttype, value => Array.Empty<string>());
            public bool CanMountMode(ModeConfig otherMode, TargetType ttype) => otherMode == null ? true : CanMountTypes.GetValueOrDefault(ttype, Array.Empty<string>()).Contains(otherMode.Name);
            // MONUMENT OWNER
            public Dictionary<TargetType, string[]> CanEnterTypes = new Dictionary<TargetType, string[]>();
            // EDIT HERE
            // RaidableBases
            [Newtonsoft.Json.JsonIgnore]
            public bool CanEnterPvpRaidableBases => CONFIG.RaidableBases?.CanEnterPvpRaidableBases.Contains(Name) ?? false;
            [Newtonsoft.Json.JsonIgnore]
            public bool CanEnterPveRaidableBases => CONFIG.RaidableBases?.CanEnterPveRaidableBases.Contains(Name) ?? false;
        }
        // These are for use in the AdminPanel creator, they do not get saved
        public class AdminPanelConfig {
            public string DisplayName {
                get;
                set;
            }
            = null;
        }
        public class ZoneManagerConfig {
            [ConfigDescription("If using ZoneManager you can specify zones that will temporarily force players into a certain mode when entered.They key must be in the format of <property><operator><value> where property can be 'name' or 'id', operator can be '=' or '~' and value would be the zone id or zone name respectively.The '=' operator will do an exact match, the '~' will do a partial match.\n\nFor example 'id=abc123'='pve' will make any zone with the exact id of 'abc123' a pve zone.While 'name~123'='pvp' will make any zone that contains '123' in their name a pvp zone.")]
            public Dictionary<string, string> ForceModeInZone = new Dictionary<string, string>();
        }
        public class RaidableBasesConfig {
            [ConfigDescription("This needs to match the protection radius property in the Raidable Bases config.")]
            public float ProtectionRadius {
                get;
                set;
            }
            = 50f;
            [ConfigDescription("A list of modes that can enter raidable bases marked as PVP.")]
            public string[] CanEnterPvpRaidableBases = new string[] {
                "pvp"
            }
            ;
            [ConfigDescription("A list of modes that can enter raidable bases marked as PVE.")]
            public string[] CanEnterPveRaidableBases = new string[] {
                "pve", "pvp"
            }
            ;
        }
        public class ToastifyConfig {
            [ConfigDescription("Toast ID of the toast used for positive messages.Should align with your Toastify config values.")]
            public string PositiveToastID = "success";
            [ConfigDescription("Toast ID of the toast used for negative messages.Should align with your Toastify config values.")]
            public string NegativeToastID = "error";
            [ConfigDescription("Duration the toasts will last for in seconds.")]
            public float Duration = 4f;
        }
        public class SettingsConfig {
            [ConfigDescription("New players will spawn with this mode assigned to them.")]
            public string InitialPlayerMode = "pvp";
            [ConfigDescription("This is the mode that NPC players will be assigned.These NPCs are usually spawned by other plugins.Vanilla scientists are NOT counted as NPCs.")]
            public string NpcMode = "npc";
            [ConfigDescription("If true, then modes will respect ownership of vehicles from plugins like VehicleLicense.Once enabled, claimed horses and vehicles will now have their own rules that differ from unclaimed ones.")]
            public bool AllowVehicleModeOwnership = false;
            [ConfigDescription("If true, then twig building blocks can be attacked regardless of mode settings.")]
            public bool AlwaysAllowTwigDamage = true;
            [ConfigDescription("If true, then messages will appear in the server console when things are interacted with.This will spam your console, so only turn on if you are debugging issues.")]
            public bool ShowDebugMessagesInConsole = false;
        }
        public class NoEscapeConfig {
            [ConfigDescription("If true, then a player cannot use the flag command if they are combat blocked.")]
            public bool PreventFlaggingWhileCombatBlocked = true;
            [ConfigDescription("If true, then a player cannot use the flag command if they are raid blocked.")]
            public bool PreventFlaggingWhileRaidBlocked = true;
            [ConfigDescription("If true, then a player cannot use the flag command if they are escape blocked.")]
            public bool PreventFlaggingWhileEscapeBlocked = true;
        }
        private void UpdateConfig() {
            // EDIT HERE
            var configUpdateStr = "[CONFIG UPDATE] Updating to Version {0}";
            var defaultConfig = new Configuration();
            // Update to 1.3.x
            if (config.Version.Minor < 3) {
                PrintWarning(string.Format(configUpdateStr, "1.3.0"));
                foreach(var mode in config.Modes) {
                    if (mode.CanRaid != null) {
                        mode.CanAttackTypes = new Dictionary<TargetType, string[]>();
                        foreach(var ttype in TargetTypesForCategory.Attacking) {
                            mode.CanAttackTypes[ttype] = mode.CanRaid;
                        }
                        mode.CanRaid = null;
                    }
                    if (mode.CanAttack != null) {
                        if (mode.CanAttackTypes == null) {
                            mode.CanAttackTypes = new Dictionary<TargetType, string[]>();
                        }
                        mode.CanAttackTypes[TargetType.players] = mode.CanAttack;
                        mode.CanAttack = null;
                    }
                    if (mode.CanTargetWithTraps != null) {
                        mode.CanTargetTypes = new Dictionary<TargetType, string[]>();
                        foreach (var ttype in TargetTypesForCategory.Targeting) {
                            mode.CanTargetTypes[ttype] = mode.CanTargetWithTraps;
                        }
                        mode.CanTargetWithTraps = null;
                    }
                    if (mode.CanLoot != null) {
                        mode.CanLootTypes = new Dictionary<TargetType, string[]>();
                        foreach (var ttype in TargetTypesForCategory.Looting) {
                            mode.CanLootTypes[ttype] = mode.CanLoot;
                        }
                        mode.CanLoot = null;
                    }
                    if (mode.CanEnterOwnedMonuments != null) {
                        mode.CanEnterTypes = new Dictionary<TargetType, string[]>();
                        mode.CanEnterTypes[TargetType.claimedmonuments] = mode.CanEnterOwnedMonuments;
                        mode.CanEnterOwnedMonuments = null;
                    }
                    // Setup new config properties
                    var matchingMode = defaultConfig.Modes.FirstOrDefault(x => x.Name == mode.Name);
                    if (mode.ColorHex == null) {
                        mode.ColorHex = matchingMode?.ColorHex ?? ColorUtility.ToHtmlStringRGBA(UnityEngine.Color.white);
                    }
                    if (mode.DisplayName == null) {
                        mode.DisplayName = matchingMode?.DisplayName ?? mode.Name.ToUpper();
                    }
                }
            }
            // EDIT HERE
            // Init Missing Ttypes
            foreach(var mode in config.Modes) {
                foreach (var ttype in TargetTypesForCategory.Attacking) {
                    if (!mode.CanAttackTypes.ContainsKey(ttype)) {
                        mode.CanAttackTypes[ttype] = new string[0];
                    }
                }
                foreach (var ttype in TargetTypesForCategory.Looting) {
                    if (!mode.CanLootTypes.ContainsKey(ttype)) {
                        mode.CanLootTypes[ttype] = new string[0];
                    }
                }
                foreach (var ttype in TargetTypesForCategory.Targeting) {
                    if (!mode.CanTargetTypes.ContainsKey(ttype)) {
                        mode.CanTargetTypes[ttype] = new string[0];
                    }
                }
                foreach (var ttype in TargetTypesForCategory.Mounting) {
                    if (!mode.CanMountTypes.ContainsKey(ttype)) {
                        mode.CanMountTypes[ttype] = new string[0];
                    }
                }
                foreach (var ttype in TargetTypesForCategory.Entering) {
                    if (!mode.CanEnterTypes.ContainsKey(ttype)) {
                        mode.CanEnterTypes[ttype] = new string[0];
                    }
                }
            }
            config.Version = this.Version;
        }
        private void RevealConfigOptions() {
            var hasRevealed = false;
            // ADD PLUGIN INTEGRATION
            // SimpleStatus
            if (SimpleStatus.IsLoaded() && config.SimpleStatus == null) {
                config.SimpleStatus = new SimpleStatusConfig() {
                    ModeStatusBars = new Dictionary<string, StatusDetailsConfig> {
                        ["pve"]
                        = new StatusDetailsConfig {
                            Show = true, BackgroundColor = "0.385 0.478 0.228 1", Image = "assets/icons/peace.png", ImageColor = "0.545 0.855 0 1", TitleColor = "0.99 0.99 0.99 1", TextColor = "0.855 0.855 0.855 1"
                        }
                        , ["pvp"] = new StatusDetailsConfig {
                            Show = true, BackgroundColor = "0.77255 0.23922 0.15686 1", Image = "assets/icons/warning.png", ImageColor = "1 0.82353 0.44706 1", TitleColor = "1 0.82353 0.44706 1", TextColor = "1 0.82353 0.44706 1"
                        }
                    }
                }
                ;
                hasRevealed = true;
            }
            // ZoneManager
            if (ZoneManager.IsLoaded() && config.ZoneManager == null) {
                config.ZoneManager = new ZoneManagerConfig() {
                    ForceModeInZone = new Dictionary<string, string> {
                        ["id=examplezoneid"]
                        = "pvp", ["name~examplezonename"] = "pve"
                    }
                }
                ;
                hasRevealed = true;
            }
            // RaidableBases
            if (RaidableBases.IsLoaded() && config.RaidableBases == null) {
                config.RaidableBases = new RaidableBasesConfig();
                hasRevealed = true;
            }
            // BetterChat
            if (BetterChat.IsLoaded() && config.BetterChat == null) {
                config.BetterChat = new BetterChatConfig() {
         
// ... [Code preview truncated due to length. Full source in attached file] ...

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

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

Сверху