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

FREE Maze : 2.1.0 2.1.0

Нет прав для скачивания
C#:
// Все права принадлежат дискорд сообществу https://discord.gg/VgNHPpNrz6
using Newtonsoft.Json;
using Oxide.Core;
using Oxide.Core.Libraries.Covalence;
using Oxide.Core.Plugins;
using Oxide.Game.Rust.Cui;
using System.Globalization;
using UnityEngine;
using Newtonsoft.Json.Linq;
using Oxide.Core.Configuration;
using Oxide.Core.Libraries;
using Oxide.Plugins;
using System;
using System.Collections.Generic;
using System.Linq;
using Facepunch.Math;
using UnityEngine.AI;
using Rust;
using Time = UnityEngine.Time;
using System.Text.RegularExpressions;
using Mesh = UnityEngine.Mesh;
using System.Text;
using UnityEngine.UI;
using Facepunch;
using Oxide.Ext.RustEdit;
using System.Collections;
using UnityEngine.UIElements;
namespace Oxide.Plugins {
    [Info("Maze", "Ifte", "2.1.0")]
    public class Maze : RustPlugin {
        /*------------------------------------
         *     Updates and Changes
         * v2.0.1 - Fixed bugs   
         * v2.1.0 - Fixed for the April force wipe, Updated config, More optimization, Maze now only get winner from last man standing, Updated lang file (Remove old oxide/lang/en/Maze.json), Fixed OnNewSave not working properly(Now it removes old arena and updates), Added Transfer maze dead bodies loot to center of the arena, Added force stop maze event without breaking anything, Added support for vanish plugin
         *
         ------------------------------------*/
        /*
         * skull_fire_pit, skullspikes.candles,
         * 
         */
#region Variables
        [PluginReference]
        Plugin Clans, ImageLibrary, FClan, Vanish;
        private static Maze ins;
        private Configuration config;
        private MazeEvent maze;
        private bool TeleportStart = false;
        private const string AdminMaze = "Maze.admin";
        private Timer EditingTimer;
        private readonly Dictionary<ulong, Timer> teleportTime = new Dictionary<ulong, Timer>();
        private readonly int MASK = LayerMask.GetMask("Construction", "Deployed");
        private readonly int MASKA = LayerMask.GetMask("Construction", "Deployed", "Ragdoll");
        private Dictionary<string, string> Images = new Dictionary<string, string>();
        private Dictionary<BasePlayer, MazeArenaSetting> EditingPlayer = new Dictionary<BasePlayer, MazeArenaSetting>();
        //private Dictionary<ulong, Vector3> OldLocation = new Dictionary<ulong, Vector3>();
        private ArenaData arenaData;
        private bool DebugBol = false;
        //Debug using this
#endregion
#region configuration
        private class Configuration {
            [JsonProperty(PropertyName = "Maze Automatic Event")]
            public bool holdAutoMaze = false;
            [JsonProperty(PropertyName = "Maze Automatic Event Interval Minimum (In Seconds)")]
            public int mazeAutoIntervalMin = 3600;
            [JsonProperty(PropertyName = "Maze Automatic Event Interval Maximum (In Seconds)")]
            public int mazeAutoIntervalMax = 7200;
            [JsonProperty(PropertyName = "Maze Minimum player requires to starts Auto")]
            public int minPlayers = 2;
            [JsonProperty(PropertyName = "Maze Automatic Event Random From List", ObjectCreationHandling = ObjectCreationHandling.Replace)]
            public List<string> randomList = new List<string> {
                "mazeareana", "maze2areana"
            }
            ;
            [JsonProperty(PropertyName = "Maze Event Player Teleport Timer (In Seconds)")]
            public int mazeteleporttimer = 15;
            [JsonProperty(PropertyName = "Maze Event Before Notification (In Seconds)")]
            public int mazeNotifyTimer = 300;
            [JsonProperty(PropertyName = "Maze Event Door Opening Notification (In Seconds)")]
            public int mazeDoorOpenTimer = 300;
            [JsonProperty(PropertyName = "Maze Event Door Closing In (In Seconds)")]
            public int mazeDoorClosingTimer = 600;
            [JsonProperty(PropertyName = "Maze Event Removing Walls Radius")]
            public int mazeRemoveWallRadius = 10;
            [JsonProperty(PropertyName = "Maze Event Shrink Amount")]
            public int mazeShrinkAmount = 3;
            [JsonProperty(PropertyName = "Maze Event Removing Walls Timer (In Seconds)")]
            public int mazeRemoveWallTimer = 15;
            [JsonProperty(PropertyName = "Show Kill Streak Messages")]
            public bool showkillstreak = true;
            [JsonProperty(PropertyName = "Maze Event Door Prefab")]
            public string mazeDoorPrefab = "assets/content/structures/interactive_garage_door/sliding_blast_door.prefab";
            [JsonProperty(PropertyName = "Maze Walls Item List", ObjectCreationHandling = ObjectCreationHandling.Replace)]
            public List<string> wallItem = new List<string>() {
                "assets/prefabs/building/wall.external.high.stone/wall.external.high.stone.prefab", "assets/prefabs/misc/xmas/icewalls/wall.external.high.ice.prefab", "assets/prefabs/misc/xmas/icewalls/icewall.prefab", "assets/prefabs/deployable/barricades/brarricade.cover.wood_double.prefab"
            }
            ;
            [JsonProperty(PropertyName = "Maze Event Blocked items", ObjectCreationHandling = ObjectCreationHandling.Replace)]
            public List<string> blockItems = new List<string> {
                "grenade.beancan", "grenade.f1", "rock", "rocket.launcher", "ammo.rocket.basic", "ammo.rocket.smoke", "ammo.rocket.hv", "ammo.rocket.seeker", "ammo.rocket.fire", "explosive.satchel", "explosive.timed", "ammo.grenadelauncher.smoke", "ammo.grenadelauncher.buckshot", "ammo.grenadelauncher.he", "grenade.flashbang", "grenade.molotov", "multiplegrenadelauncher", "grenade.smoke"
            }
            ;
            [JsonProperty(PropertyName = "Maze Event Blocked Commands", ObjectCreationHandling = ObjectCreationHandling.Replace)]
            public List<string> blockCommands = new List<string> {
                "kit", "trade", "remove", "tpa", "home", "shop", "clan"
            }
            ;
            [JsonProperty(PropertyName = "Maze Map Marker Setting")]
            public MarkerSetting marker = new MarkerSetting();
            [JsonProperty(PropertyName = "Maze Rewards")]
            public Rewards rewards = new Rewards();
            [JsonProperty(PropertyName = "Maze Chat Setting")]
            public ChatSetting chat = new ChatSetting();
            [JsonProperty(PropertyName = "Discord Setting")]
            public DiscordSetting discord = new DiscordSetting();
            [JsonProperty(PropertyName = "Auto Maze Arena Setup")]
            public AutoArenaSetup autoArenaSetup = new AutoArenaSetup();
        }
        private class Rewards {
            [JsonProperty(PropertyName = "Give commmands rewards upon winning the event")]
            public bool commandRewards = true;
            [JsonProperty(PropertyName = "Rewards player with higest kill from winning clan")]
            public bool rewardWinClanPlayer = true;
            [JsonProperty(PropertyName = "Rewards upon winning({PLAYER})", ObjectCreationHandling = ObjectCreationHandling.Replace)]
            public List<string> listRewards = new List<string> {
                "inventory.giveto {PLAYER} supply.signal 1"
            }
            ;
            [JsonProperty(PropertyName = "Spawn loot boxes in the arena")]
            public bool spawnLootBox = true;
            [JsonProperty(PropertyName = "Loot boxes time in seconds")]
            public int lootBoxTime = 300;
        }
        private class AutoArenaSetup {
            [JsonProperty(PropertyName = "Start Maze Arena Setup")]
            public bool startAuto = true;
            [JsonProperty(PropertyName = "Auto Arena Setup")]
            public Dictionary<string, MazeAutoArena> listauto = new Dictionary<string, MazeAutoArena>() {
                {
                    "AutoMaze1", new MazeAutoArena()
                }
            }
            ;
        }
        private class MazeAutoArena {
            [JsonProperty(PropertyName = "Maze Center Item")]
            public string CenterItem = "skullspikes.candles";
            [JsonProperty(PropertyName = "Maze Arena Locate Radius")]
            public float radius = 100f;
            [JsonProperty(PropertyName = "Maze Arena Wall Radius")]
            public float wallradius = 40f;
            [JsonProperty(PropertyName = "Maze Arena Mesh Top & Bottom Height")]
            public float height = 50f;
            [JsonProperty(PropertyName = "Maze Spawn Points Item")]
            public string SpawnItem = "woodbox_deployed";
            [JsonProperty(PropertyName = "Maze Door Item")]
            public string DoorItem = "workbench1.deployed";
            [JsonProperty(PropertyName = "Maze Corner Item")]
            public string CornerItem = "mailbox";
        }
        private class ChatSetting {
            [JsonProperty(PropertyName = "Chat Avatar Icon")]
            public ulong avatarID = 0;
            [JsonProperty(PropertyName = "Chat Prefix")]
            public string prefix = "<color=#FFFF00>Maze</color> -> ";
            [JsonProperty(PropertyName = "Winner Message", ObjectCreationHandling = ObjectCreationHandling.Replace)]
            public string[] WinnerMsg = new string[] {
                "<color=#FFD700>Maze Results:</color>", "\n", "Winner -> <color=#FFFF00>{WinningClanName}</color>", "", "{PlayerStats}", "", "<color=#FFD700>Totals:</color> Kills: {ClanTotalKills}, Deaths: {ClanTotalDeaths}, KDR: {ClanTotalKDR}", "Damage: {ClanTotalDamage}, Headshots: {ClanTotalHeadshots}", "", "<color=#FFD700>Aggregate Maze Totals:</color>", "- Total Kills: <color=#FFD700>{TotalKills}</color>", "- Total Damage: <color=#FFD700>{TotalDamages}</color>", "- Number of Participants: <color=#FFD700>{Participents}</color>"
            }
            ;
            [JsonProperty(PropertyName = "Participents Message", ObjectCreationHandling = ObjectCreationHandling.Replace)]
            public string[] ParticipentsMessage = new string[] {
                "<color=#FFD700>Personal Stats</color>", "Kills: <color=#FFD700>{Kills}</color>, Deaths: <color=#FFD700>{Deaths}</color>, KDR: <color=#FFD700>{KDR}</color>, Total Damage: <color=#FFD700>{Damages}</color>, HeadShots: <color=#FFD700>{Headshots}</color>", "Shooting Accuracy: <color=#FFD700>{Accuracy}%</color>, HeadShot Accuracy: <color=#FFD700>{HeadshotAccuracy}%</color>"
            }
            ;
            [JsonProperty(PropertyName = "Maze Event Top Bar Message", ObjectCreationHandling = ObjectCreationHandling.Replace)]
            public string[] topBar = new string[] {
                "<size=25><color=#FFFF00><b>MAZE</b></color></size>", "<size=15><color=#FFFF00><b>{DYNAMIC_TIMER}</b></color></size>", "", "<size=15><color=#FFFF00>{TotalTeams}</color><b> TEAMS REMAINING</b></size>", "<size=15><color=#FFFF00>{TotalPlayers}</color><b> PLAYERS REMAINING</b></size>"
            }
            ;
        }
        private class MarkerSetting {
            [JsonProperty(PropertyName = "Display Name")]
            public string markerDisplayName = "Maze";
            [JsonProperty(PropertyName = "Marker Radius")]
            public float markerRadius = 0.4f;
            [JsonProperty(PropertyName = "Marker Transparency")]
            public float markerTransparency = 0.75f;
            [JsonProperty(PropertyName = "Marker Color")]
            public string markerColor = "#FFFF00";
        }
        private class DiscordSetting {
            [JsonProperty(PropertyName = "Enable Discord Webhook")]
            public bool enableWebhook = false;
            [JsonProperty(PropertyName = "Discord Webhook URL")]
            public string discordWebhook = string.Empty;
            [JsonProperty(PropertyName = "Discord Webhook Message", ObjectCreationHandling = ObjectCreationHandling.Replace)]
            public List<string> messageWebhook = new List<string> {
                "**MAZE ARENA**", "", "**Details**", "Total Kills: `{TotalKills}`", "Total Teams: `{TotalTeams}`", "Total Players: `{Participents}`", "", "🏆**Winners**🏆", "**{WinnerClanName}**", "💀 Kills: `{ClanKills}`  ☠️ Deaths: `{ClanDeaths}`", "🎯 Headshots: `{ClanHeadshots}` 💥 Damages: `{ClanDamages}`", "", "👥**Members**👥", "{MembersStats}"
            }
            ;
        }
        protected override void LoadConfig() {
            base.LoadConfig();
            config = Config.ReadObject<Configuration>();
        }
        protected override void LoadDefaultConfig() {
            config = new Configuration();
        }
        protected override void SaveConfig() {
            Config.WriteObject(config, true);
        }
#endregion
#region Lang
        private string GetMessage(string message, params object[] args) {
            return string.Format(lang.GetMessage(message, this), args);
        }
        protected override void LoadDefaultMessages() {
            lang.RegisterMessages(new Dictionary<string, string>() {
                {
                    "EventStartingNotify", "The event begins in {0} seconds.Get ready!"
                }
                , {
                    "EventStartingIn", "The event will start in {0} seconds.Prepare yourself!"
                }
                , {
                    "EventStarted", "The event has begun! Use <color=#FFFF00>/maze</color> to teleport to the Maze."
                }
                , {
                    "EventTeleporting", "Teleporting in {0} seconds.Hold tight!"
                }
                , {
                    "EventStop", "The event has ended.Thanks for participating!"
                }
                , {
                    "EventNoWinner", "No winner was found in this event."
                }
                , {
                    "EventDoorOpening", "The doors will open in {0} seconds.Be ready!"
                }
                , {
                    "EventDoorOpned", "The doors are open! Enter the Maze Arena now."
                }
                , {
                    "EventDoorClosing", "The doors will close in {0} seconds.Hurry up!"
                }
                , {
                    "EventDoorClosed", "The doors are closed! No more players can join."
                }
                , {
                    "EventRemovingWalls", "Outer walls will be removed in {0} seconds.Stay alert!"
                }
                , {
                    "WinningPlayers", "Winning players will be teleported back in {0} seconds.Congratulations!"
                }
                , {
                    "EventBannedItems", "You cannot join the event with banned items! Removed from inventory: <color=#DC143C>{0}</color>"
                }
                , {
                    "NoEventRunning", "There is no active event to teleport to."
                }
                , {
                    "NoClan", "You need to create a Clan before joining the event."
                }
                , {
                    "AlreadyPosition", "You are already at the event location."
                }
                , {
                    "CantTeleport", "You cannot teleport to the Maze right now."
                }
                , {
                    "TeleportCanceled", "Teleportation to the Maze has been canceled."
                }
                , {
                    "LootBoxesTime", "The winner has {0} seconds to collect their loot before it's gone!"
                }
            }
            , this);
        }
#endregion
#region Data
        private class ArenaData {
            public Dictionary<string, MazeArenaSetting> MazeArenas = new Dictionary<string, MazeArenaSetting>();
        }
        private class MazeArenaSetting {
            public string Name;
            public Vector3 Center;
            public float radius = 100;
            public float wallRadius = 50;
            public float meshHeight = 50;
            public List<Vector3> SpawnPoints;
            public List<DoorPosition> Doors;
            public List<WallPosition> Walls;
            public List<Vector3> Corners;
            public MazeArenaSetting() {
                Doors = new List<DoorPosition>();
                SpawnPoints = new List<Vector3>();
                Walls = new List<WallPosition>();
                Corners = new List<Vector3>();
            }
            public void PasteCopyMaze() {
                if (Walls.Count < 1) return;
                foreach (var item in Walls) {
                    BaseEntity entity = GameManager.server.CreateEntity(item.WallName, item.Position, default);
                    entity.Spawn();
                    entity.transform.Rotate(item.Rotation);
                    var c = entity as BaseCombatEntity;
                    c.OwnerID = 0;
                    c.SetMaxHealth(99999);
                    c.SetHealth(999999);
                    c.SendNetworkUpdateImmediate(true);
                }
            }
            public void CleanArena() {
                var entities = new List<BaseEntity>();
                entities.Clear();
                Vis.Entities(Center, radius, entities, ins.MASK);
                foreach (var item in entities) {
                    if (item.IsValid()) item.Kill();
                }
                entities.Clear();
            }
        }
        private class WallPosition {
            public string WallName;
            public Vector3 Position;
            public Vector3 Rotation;
        }
        private class DoorPosition {
            public Vector3 Position;
            public Vector3 Rotation;
        }
        private class CornerPosition {
            public int Num;
            public Vector3 Position;
        }
        private void SetupArenaCustom(bool nobiefy = false)  //do without RustEditAPI now
        {
            if (!config.autoArenaSetup.startAuto && config.autoArenaSetup.listauto.Count < 1) {
                Puts("Auto arena invalid setuped");
                return;
            }
            StringBuilder logBuilder = new StringBuilder();
            logBuilder.Clear();
            foreach (var a in config.autoArenaSetup.listauto) {
                if (arenaData.MazeArenas.ContainsKey(a.Key)) {
                    PrintWarning($"{a.Key} already exists.");
                    PrintWarning("Reseting old arena...");
                    arenaData.MazeArenas.Remove(a.Key);
                }
                MazeAutoArena mazeAutoArena = a.Value;
                List<BaseEntity> allEntitys = new List<BaseEntity>();
                Vector3 pos = Vector3.zero;
                RustEditAPI.GetAllMapEntities(ref allEntitys);
                Puts($"{allEntitys.Count} count");
                List<DoorPosition> doorPos = new List<DoorPosition>();
                List<Vector3> spawnPos = new List<Vector3>();
                List<WallPosition> wallPos = new List<WallPosition>();
                List<Vector3> cornerPos = new List<Vector3>();
                int doorCount = 0, spawnCount = 0, wallCount = 0, cornerCount = 0;
                foreach (BaseEntity ent in allEntitys) {
                    if (ent == null) {
                        Puts($"Found a null BaseEntity {ent.ShortPrefabName}, skipping...");
                        continue;
                    }
                    string prefabName = ent.ShortPrefabName;
                    if (ent.ShortPrefabName.Contains(mazeAutoArena.CenterItem)) {
                        Vector3 center = ent.GetNetworkPosition();
                        ent.Kill();
                        pos = center;
                        if (center == Vector3.zero) {
                            Puts($"Center Position not found for {a.Key}");
                            continue;
                        }
                    }
                    if (prefabName.Contains(mazeAutoArena.DoorItem)) {
                        doorPos.Add(CreateDoorPosition(ent));
                        doorCount++;
                        ent.Kill();
                    }
                    else if (prefabName.Contains(mazeAutoArena.SpawnItem)) {
                        spawnPos.Add(ent.GetNetworkPosition());
                        spawnCount++;
                        ent.Kill();
                    }
                    else if (config.wallItem.Contains(ent.PrefabName)) {
                        wallPos.Add(CreateWallPosition(ent));
                        wallCount++;
                        ent.Kill();
                    }
                    else if (prefabName.Contains(mazeAutoArena.CornerItem)) {
                        cornerPos.Add(ent.GetNetworkPosition());
                        cornerCount++;
                        ent.Kill();
                    }
                }
                logBuilder.AppendLine($"Arena: {a.Key}");
                logBuilder.AppendLine($"Found Doors: {doorCount}");
                logBuilder.AppendLine($"Found Spawn Points: {spawnCount}");
                logBuilder.AppendLine($"Found Walls: {wallCount}");
                logBuilder.AppendLine($"Found Corners: {cornerCount}");
                var arena = new MazeArenaSetting() {
                    Center = pos, Doors = doorPos, SpawnPoints = spawnPos, Walls = wallPos, Name = a.Key, radius = mazeAutoArena.radius, wallRadius = mazeAutoArena.wallradius, meshHeight = mazeAutoArena.height, Corners = cornerPos,
                }
                ;
                arenaData.MazeArenas.Add(a.Key, arena);
                logBuilder.AppendLine($"Arena added: {a.Key}");
                SaveMazeArena();
                allEntitys.Clear();
            }
            Puts(logBuilder.ToString());
            foreach (var player in BasePlayer.activePlayerList) {
                if (!CheckAdmin(player)) return;
                CM(player, logBuilder.ToString());
            }
        }
        private DoorPosition CreateDoorPosition(BaseEntity ent) {
            return new DoorPosition() {
                Position = ent.GetNetworkPosition(), Rotation = ent.GetNetworkRotation().eulerAngles,
            }
            ;
        }
        private WallPosition CreateWallPosition(BaseEntity ent) {
            return new WallPosition() {
                WallName = ent.PrefabName, Position = ent.GetNetworkPosition(), Rotation = ent.GetNetworkRotation().eulerAngles,
            }
            ;
        }
        private void LoadMazeArenas() {
            arenaData = Interface.Oxide.DataFileSystem.ReadObject<ArenaData>($"{Name}/MazeArenas");
        }
        private void SaveMazeArena() {
            Interface.Oxide.DataFileSystem.WriteObject($"{Name}/MazeArenas", arenaData);
        }
        private MazeArenaSetting GetMazeArena(string name) {
            if (!string.IsNullOrEmpty(name)) {
                foreach (var entry in arenaData.MazeArenas) {
                    if (entry.Key == name) return entry.Value;
                }
            }
            return null;
        }
        private MazeData mazeData;
        private class MazeData {
            public Dictionary<ulong, PlayerData> playerData = new Dictionary<ulong, PlayerData>();
        }
        private class PlayerData {
            public int PlayerKills;
            public int Deaths;
            public int ShotsHit;
            public int HeadShots;
            public int ShotsFired;
            public float DamageDealt;
            public int KillStreak;
        }
        private PlayerData FindPlayerData(BasePlayer player) {
            if (mazeData.playerData.TryGetValue(player.userID, out PlayerData data)) {
                return data;
            }
            PlayerData player1 = new PlayerData();
            mazeData.playerData.Add(player.userID, player1);
            return player1;
        }
        private void RemovePlayerData(BasePlayer player) {
            if (mazeData.playerData.TryGetValue(player.userID, out PlayerData data)) {
                mazeData.playerData.Remove(player.userID);
            }
        }
        private List<KeyValuePair<string, int>> GetTop5ClansByKills() {
            Dictionary<string, int> clanKillCounts = new Dictionary<string, int>();
            foreach (var playerData in mazeData.playerData) {
                ulong playerID = playerData.Key;
                PlayerData data = playerData.Value;
                string clanTag = GetPlayerClanTag(playerID);
                if (string.IsNullOrEmpty(clanTag)) continue;
                if (!clanKillCounts.ContainsKey(clanTag)) {
                    clanKillCounts[clanTag] = 0;
                }
                clanKillCounts[clanTag] += data.PlayerKills;
            }
            return clanKillCounts.OrderByDescending(kvp => kvp.Value).Take(5).ToList();
        }
        private KeyValuePair<string, int> GetTopClanByKills() {
            Dictionary<string, int> clanKillCounts = new Dictionary<string, int>();
            foreach (var playerData in mazeData.playerData) {
                ulong playerID = playerData.Key;
                PlayerData data = playerData.Value;
                string clanTag = GetPlayerClanTag(playerID);
                if (string.IsNullOrEmpty(clanTag)) continue;
                if (!clanKillCounts.ContainsKey(clanTag)) {
                    clanKillCounts[clanTag] = 0;
                }
                clanKillCounts[clanTag] += data.PlayerKills;
            }
            return clanKillCounts.OrderByDescending(kvp => kvp.Value).FirstOrDefault();
        }
        private Dictionary<ulong, PlayerData> GetAllPlayersByClanTag(string clanTag) {
            Dictionary<ulong, PlayerData> playersInClan = new Dictionary<ulong, PlayerData>();
            foreach (var playerEntry in mazeData.playerData) {
                ulong playerID = playerEntry.Key;
                PlayerData playerData = playerEntry.Value;
                string playerClanTag = GetPlayerClanTag(playerID);
                if (playerClanTag == clanTag) {
                    playersInClan[playerID] = playerData;
                }
            }
            return playersInClan;
        }
        private BasePlayer GetTopPlayerFromTopClan() {
            var topClan = GetTopClanByKills();
            if (topClan.Equals(default(KeyValuePair<string, int>))) {
                return null;
            }
            string topClanTag = topClan.Key;
            Dictionary<ulong, PlayerData> playersInTopClan = GetAllPlayersByClanTag(topClanTag);
            var topPlayerEntry = playersInTopClan.OrderByDescending(entry => entry.Value.PlayerKills).FirstOrDefault();
            BasePlayer topPlayer = BasePlayer.activePlayerList.FirstOrDefault(player => player.userID == topPlayerEntry.Key);
            return topPlayer;
        }
#endregion
#region Commands
        [ChatCommand("maze")]
        private void ChatCommandMaze(BasePlayer player, string cmd, string[] args) {
            if (args.Length == 0) {
                if (maze == null) {
                    CM(player, GetMessage("NoEventRunning"));
                    return;
                }
                string playerClan = GetPlayerClanTag(player.userID);
                if (string.IsNullOrEmpty(playerClan)) {
                    CM(player, GetMessage("NoClan"));
                    return;
                }
                if (InMazeEvent(player)) {
                    CM(player, GetMessage("AlreadyPosition"));
                    return;
                }
                if (!TeleportStart) {
                    CM(player, GetMessage("CantTeleport"));
                    return;
                }
                if (teleportTime.TryGetValue(player.userID, out Timer timer1)) {
                    // If teleport is in progress, cancel it
                    timer1.Destroy();
                    teleportTime.Remove(player.userID);
                    CM(player, GetMessage("TeleportCanceled"));
                    return;
                }
                CM(player, GetMessage("EventTeleporting", config.mazeteleporttimer));
                MazeArenaSetting arena = maze.arena;
                if (arena != null) {
                    Vector3 teleportPos = arena.SpawnPoints.GetRandom();
                    Timer teleport = timer.Once(config.mazeteleporttimer, () => {
                        teleportPos.y += 0.1f;
                        //CheckForOldPos(player); //Check for old pos and save it
                        TeleportPlayer(player, teleportPos);
                        RemoveItemsFromInventory(player);
                        if (!maze.participents.Contains(player.userID)) maze.participents.Add(player.userID);
                        if (teleportTime.TryGetValue(player.userID, out Timer timer1)) {
                            timer1.Destroy();
                            teleportTime.Remove(player.userID);
                        }
                    }
                    );
                    teleportTime[player.userID] = teleport;
                }
                else {
                    Puts("Arena not found");
                }
                return;
            }
            if (args.Length >= 1) {
                string command = args[0].ToLower();
                if (command == "setup") {
                    if (!CheckAdmin(player)) return;
                    CM(player, GetAdminHelpText());
                    return;
                }
                else if (command == "create" && args.Length >= 2) {
                    string Name = args[1];
                    if (string.IsNullOrEmpty(Name)) {
                        CM(player, "Invalid Usage.\nCommand -> <color=#FFFF00>/maze create</color> <ArenaName>");
                        return;
                    }
                    if (arenaData.MazeArenas.ContainsKey(Name)) {
                        CM(player, "There is already a Maze Arena with that Name");
                        return;
                    }
                    arenaData.MazeArenas.Add(Name, new MazeArenaSetting() {
                        Name = Name, Center = player.transform.position,
                    }
                    );
                    CM(player, $"Maze Arena created <color=#FFFF00>{Name}</color>");
                    player.SendConsoleCommand("ddraw.sphere", 15, Color.blue, player.transform.position, 30);
                }
                else if (command == "edit" && args.Length >= 2) {
                    if (!CheckAdmin(player)) return;
                    string Name = args[1];
                    if (string.IsNullOrEmpty(Name)) {
                        CM(player, $"Invalid Usage.\nCommand -> <color=#FFFF00>/maze edit</color> <ArenaName>");
                        return;
                    }
                    if (!arenaData.MazeArenas.ContainsKey(Name)) {
                        CM(player, "There is no Maze Arena with that Name");
                        return;
                    }
                    MazeArenaSetting arena = GetMazeArena(Name);
                    if (EditingPlayer.ContainsKey(player)) {
                        EditingTimer.Destroy();
                        EditingPlayer.Remove(player);
                    }
                    EditingPlayer.Add(player, arena);
                    CM(player, $"You are now editing <color=#FFFF00>{Name}</color>\n");
                    EditingTimer = timer.Every(1, () => {
                        if (arena.Center != null || arena.Center != Vector3.zero) {
                            player.SendConsoleCommand("ddraw.sphere", 1, Color.blue, arena.Center, arena.radius);
                            player.SendConsoleCommand("ddraw.text", 1, Color.red, arena.Center, "Arena Center");
                            player.SendConsoleCommand("ddraw.sphere", 1, Color.blue, arena.Center, 1f);
                        }
                        if (arena.Corners.Count > 0) {
                            foreach (var corner in arena.Corners) {
                                player.SendConsoleCommand("ddraw.text", 1, Color.yellow, corner, $"Corner\n{corner.ToString()}");
                                player.SendConsoleCommand("ddraw.sphere", 1, Color.red, corner, 1f);
                            }
                        }
                        if (arena.SpawnPoints.Count > 0) {
                            foreach (var corner in arena.SpawnPoints) {
                                player.SendConsoleCommand("ddraw.text", 1, Color.yellow, corner, $"Spawn Points\n{corner.ToString()}");
                                player.SendConsoleCommand("ddraw.sphere", 1, Color.red, corner, 1f);
                            }
                        }
                        if (arena.Doors.Count > 0) {
                            foreach (var corner in arena.Doors) {
                                player.SendConsoleCommand("ddraw.text", 1, Color.yellow, corner.Position, $"Door Position\n{corner.Position}\nRotation: {corner.Rotation}");
                                player.SendConsoleCommand("ddraw.sphere", 1, Color.red, corner.Position, 1f);
                            }
                        }
                        if (arena.wallRadius > 0) {
                            player.SendConsoleCommand("ddraw.sphere", 1, Color.black, arena.Center, arena.wallRadius);
                        }
                    }
                    );
                }
                else if (command == "stopedit") {
                    if (!CheckAdmin(player)) return;
                    if (!EditingPlayer.ContainsKey(player)) {
                        CM(player, "Please specify a Maze Arena first to edit(Command -> <color=#FFFF00>/maze edit</color> <ArenaName>)");
                        return;
                    }
                    if (EditingPlayer.ContainsKey(player)) {
                        EditingTimer.Destroy();
                        EditingPlayer.Remove(player);
                        CM(player, "Stopped editing the Arena");
                    }
                    else {
                        CM(player, "Currently not editing Arena");
                    }
                    return;
                }
                else if (command == "setcorner") {
                    if (!CheckAdmin(player)) return;
                    if (!EditingPlayer.ContainsKey(player)) {
                        CM(player, "Please specify a Maze Arena first to edit(Command -> <color=#FFFF00>/maze edit</color> <ArenaName>)");
                        return;
                    }
                    MazeArenaSetting arena = EditingPlayer[player];
                    if (arena != null) {
                        arena.Corners.Add(player.GetNetworkPosition());
                        CM(player, "Corner added to list");
                        return;
                    }
                    return;
                }
                else if (command == "showmesh") {
                    if (!CheckAdmin(player)) return;
                    if (!EditingPlayer.ContainsKey(player)) {
                        CM(player, "Please specify a Maze Arena first to edit(Command -> <color=#FFFF00>/maze edit</color> <ArenaName>)");
                        return;
                    }
                    MazeArenaSetting arena = EditingPlayer[player];
                    if (arena != null) {
                        if (arena.Center == null || arena.Center == Vector3.zero) {
                            CM(player, "Center not found");
                            return;
                        }
                        if (arena.Corners.Count != 4 && arena.Corners.Count != 6 && arena.Corners.Count != 8) {
                            CM(player, "4, 6, or 8 corners are required to show the mesh.");
                            return;
                        }
                        Mesh mesh = GenerateMeshRandomVec(arena.Center, arena.Corners, arena.meshHeight);
                        // Visualize the mesh
                        Vector3[] vertices = mesh.vertices;
                        int[] triangles = mesh.triangles;
                        for (int i = 0; i < triangles.Length; i += 3) {
                            Vector3 vertex1 = arena.Center + vertices[triangles[i]];
                            Vector3 vertex2 = arena.Center + vertices[triangles[i + 1]];
                            Vector3 vertex3 = arena.Center + vertices[triangles[i + 2]];
                            player.SendConsoleCommand("ddraw.line", 120, Color.green, vertex1, vertex2);
                            player.SendConsoleCommand("ddraw.line", 120, Color.green, vertex2, vertex3);
                            player.SendConsoleCommand("ddraw.line", 120, Color.green, vertex3, vertex1);
                        }
                        timer.In(30, () => {
                            DestroyMesh(mesh);
                        }
                        );
                    }
                }
                else if (command == "copywalls") {
                    if (!CheckAdmin(player)) return;
                    if (!EditingPlayer.ContainsKey(player)) {
                        CM(player, "Please specify a Maze Arena first to edit(Command -> <color=#FFFF00>/maze edit</color> <ArenaName>)");
                        return;
                    }
                    MazeArenaSetting arena = EditingPlayer[player];
                    if (arena != null) {
                        List<BaseEntity> entitys = new List<BaseEntity>();
                        Vis.Entities(arena.Center, arena.radius, entitys, MASK);
                        int amount = 0;
                        arena.Walls.Clear();
                        CM(player, "Cleared old walls in the arena");
                        foreach (var ent in entitys) {
                            foreach (var w in config.wallItem) {
                                if (w == ent.PrefabName) {
                                    WallPosition wall = new WallPosition {
                                        WallName = ent.PrefabName, Position = ent.GetNetworkPosition(), Rotation = ent.GetNetworkRotation().eulerAngles
                                    }
                                    ;
                                    amount++;
                                    arena.Walls.Add(wall);
                                }
                            }
                        }
                        CM(player, amount + " walls found and stored");
                    }
                    return;
                }
                else if (command == "pastewalls") {
                    if (!CheckAdmin(player)) return;
                    if (!EditingPlayer.ContainsKey(player)) {
                        CM(player, "Please specify a Maze Arena first to edit(Command -> <color=#FFFF00>/maze edit</color> <ArenaName>)");
                        return;
                    }
                    MazeArenaSetting arena = EditingPlayer[player];
                    if (arena != null) {
                        arena.PasteCopyMaze();
                        CM(player, arena.Walls.Count + " walls found and pasted");
                    }
                    return;
                }
                else if (command == "adddoor") {
                    if (!CheckAdmin(player)) return;
                    if (!EditingPlayer.ContainsKey(player)) {
                        CM(player, "Please specify a Maze Arena first to edit(Command -> <color=#FFFF00>/maze edit</color> <ArenaName>)");
                        return;
                    }
                    MazeArenaSetting arena = EditingPlayer[player];
                    if (arena != null) {
                        var rotation = player.GetNetworkRotation().eulerAngles;
                        rotation.x = 0;
                        DoorPosition door = new DoorPosition {
                            Position = player.GetNetworkPosition(), Rotation = rotation,
                        }
                        ;
                        arena.Doors.Add(door);
                        CM(player, "Door position added for this location.");
                        var doorTemp = GameManager.server.CreateEntity(config.mazeDoorPrefab, player.GetNetworkPosition());
                        doorTemp.Spawn();
                        var c = doorTemp as BaseCombatEntity;
                        c.SetMaxHealth(99999);
                        c.SetHealth(999999);
                        doorTemp.transform.Rotate(rotation);
                        doorTemp.OwnerID = 6969;
                        doorTemp.SendNetworkUpdateImmediate(true);
                        timer.Once(10, () => {
                            doorTemp.Kill();
                        }
                        );
                    }
                    return;
                }
                else if (command == "removedoor") {
                    if (!CheckAdmin(player)) return;
                    if (!EditingPlayer.ContainsKey(player)) {
                        CM(player, "Please specify a Maze Arena first to edit(Command -> <color=#FFFF00>/maze edit</color> <ArenaName>)");
                        return;
                    }
                    MazeArenaSetting arena = EditingPlayer[player];
                    List<DoorPosition> doorsToRemove = new List<DoorPosition>();
                    foreach (var dor in arena.Doors) {
                        float distance = Vector3.Distance(player.GetNetworkPosition(), dor.Position);
                        if (distance <= 5) {
                            doorsToRemove.Add(dor);
                        }
                    }
                    if (doorsToRemove.Count == 0) {
                        CM(player, "No doors found near this 5 radius area");
                        return;
                    }
                    foreach (var dor in doorsToRemove) {
                        arena.Doors.Remove(dor);
                    }
                    CM(player, "Removed " + doorsToRemove.Count);
                    return;
                }
                else if (command == "location") {
                    if (!CheckAdmin(player)) return;
                    if (!EditingPlayer.ContainsKey(player)) {
                        CM(player, "Please specify a Maze Arena first to edit(Command -> <color=#FFFF00>/maze edit</color> <ArenaName>)");
                        return;
                    }
                    MazeArenaSetting arena = EditingPlayer[player];
                    if (arena != null) {
                        arena.Center = player.transform.position;
                        CM(player, "Maze Arena position changed to your postion.");
                    }
                    return;
                }
                else if (command == "radius" && args.Length >= 2) {
                    if (!CheckAdmin(player)) return;
                    if (!EditingPlayer.ContainsKey(player)) {
                        CM(player, "Please specify a Maze Arena first to edit(Command -> <color=#FFFF00>/maze edit</color> <ArenaName>)");
                        return;
                    }
                    MazeArenaSetting arena = EditingPlayer[player];
                    float Radius = float.Parse(args[1]);
                    if (arena != null) {
                        arena.radius = Radius;
                        CM(player, "Maze Arena radius changed");
                    }
                    return;
                }
                else if (command == "wallradius" && args.Length >= 2) {
                    if (!CheckAdmin(player)) return;
                    if (!EditingPlayer.ContainsKey(player)) {
                        CM(player, "Please specify a Maze Arena first to edit(Command -> <color=#FFFF00>/maze edit</color> <ArenaName>)");
                        return;
                    }
                    MazeArenaSetting arena = EditingPlayer[player];
                    float Radius = float.Parse(args[1]);
                    if (arena != null) {
                        arena.wallRadius = Radius;
                        CM(player, "Maze Arena Wall radius changed");
                    }
                    return;
                }
                else if (command == "meshheight" && args.Length >= 2) {
                    if (!CheckAdmin(player)) return;
                    if (!EditingPlayer.ContainsKey(player)) {
                        CM(player, "Please specify a Maze Arena first to edit(Command -> <color=#FFFF00>/maze edit</color> <ArenaName>)");
                        return;
                    }
                    MazeArenaSetting arena = EditingPlayer[player];
                    float Radius = float.Parse(args[1]);
                    if (arena != null) {
                        arena.meshHeight = Radius;
                        CM(player, "Maze Arena Mesh Height changed");
                    }
                    player.Command("maze showmesh");
                    return;
                }
                else if (command == "start" && args.Length >= 2) {
                    if (!CheckAdmin(player)) return;
                    string Name = args[1];
                    MazeArenaSetting arena = GetMazeArena(Name);
                    if (arena == null) {
                        CM(player, "Arena not found");
                        return;
                    }
                    if (maze != null) {
                        CM(player, "There is already an event running");
                        return;
                    }
                    GameObject gameObject = new GameObject();
                    maze = gameObject.AddComponent<MazeEvent>();
                    maze.Initialize(arena);
                    return;
                }
                else if (command == "cleanarena") {
                    if (!CheckAdmin(player)) return;
                    if (!EditingPlayer.ContainsKey(player)) {
                        CM(player, "Please specify a Maze Arena first to edit(Command -> <color=#FFFF00>/maze edit</color> <ArenaName>)");
                        return;
                    }
                    MazeArenaSetting arena = EditingPlayer[player];
                    arena.CleanArena();
                    CM(player, "Arena cleared");
                }
                else if (command == "cleandoors") {
                    if (!CheckAdmin(player)) return;
                    if (!EditingPlayer.ContainsKey(player)) {
                        CM(player, "Please specify a Maze Arena first to edit(Command -> <color=#FFFF00>/maze edit</color> <ArenaName>)");
                        return;
                    }
                    MazeArenaSetting arena = EditingPlayer[player];
                    if (arena != null) {
                        arena.Doors.Clear();
                        CM(player, "You cleard all door location for the Arena");
                    }
                    else CM(player, "Arena not found");
                }
                else if (command == "setspawn") {
                    if (!CheckAdmin(player)) return;
                    if (!EditingPlayer.ContainsKey(player)) {
                        CM(player, "Please specify 
// ... [Code preview truncated due to length. Full source in attached file] ...

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