From a1484ac4045510356cea7036976b8e0a783a280c Mon Sep 17 00:00:00 2001 From: MrAfitol <76150070+MrAfitol@users.noreply.github.com> Date: Sat, 28 Dec 2024 13:16:51 +0100 Subject: [PATCH] 1.4.0 - Updated to a new version of the game (14.0.0) - Updated the lobby system, now more rooms are available to a custom location - Added commands to simplify the control of custom locations --- Lobby/API/LobbyLocationHandler.cs | 42 ++++++--- .../ControlCommands/AddLocationCommand.cs | 69 ++++++++++++++ .../ControlCommands/RemoveLocationCommand.cs | 72 +++++++++++++++ .../DebugCommands/GetLocalDataCommand.cs | 48 ++++++++++ .../DebugCommands/LocationListCommand.cs | 85 +++++++++++++++++ .../DebugCommands/TpLocationCommand.cs | 86 ++++++++++++++++++ Lobby/Command/LobbyParentCommand.cs | 34 +++++++ Lobby/Config.cs | 30 ++++-- Lobby/EventHandlers.cs | 91 ++++++++++--------- Lobby/Extensions/PlayerExtensions.cs | 61 +++++++++++++ Lobby/Lobby.cs | 14 +-- Lobby/Lobby.csproj | 8 ++ Lobby/Patches/StaminaUsageMultiplierPatch.cs | 8 +- Lobby/Properties/AssemblyInfo.cs | 4 +- 14 files changed, 571 insertions(+), 81 deletions(-) create mode 100644 Lobby/Command/ControlCommands/AddLocationCommand.cs create mode 100644 Lobby/Command/ControlCommands/RemoveLocationCommand.cs create mode 100644 Lobby/Command/DebugCommands/GetLocalDataCommand.cs create mode 100644 Lobby/Command/DebugCommands/LocationListCommand.cs create mode 100644 Lobby/Command/DebugCommands/TpLocationCommand.cs create mode 100644 Lobby/Command/LobbyParentCommand.cs create mode 100644 Lobby/Extensions/PlayerExtensions.cs diff --git a/Lobby/API/LobbyLocationHandler.cs b/Lobby/API/LobbyLocationHandler.cs index 2af92aa..59870de 100644 --- a/Lobby/API/LobbyLocationHandler.cs +++ b/Lobby/API/LobbyLocationHandler.cs @@ -1,10 +1,11 @@ -namespace Lobby.API -{ - using MapGeneration; - using System.Collections.Generic; - using System.Linq; - using UnityEngine; +using MapGeneration; +using System; +using System.Collections.Generic; +using System.Linq; +using UnityEngine; +namespace Lobby.API +{ public static class LobbyLocationHandler { public static GameObject Point; @@ -16,9 +17,9 @@ public static class LobbyLocationHandler { LobbyLocationType.Tower_3, new CustomLocationData() { PositionX = 39.262f, PositionY = 1014.112f, PositionZ = -31.844f, RotationX = 0, RotationY = 0, RotationZ = 0 } }, { LobbyLocationType.Tower_4, new CustomLocationData() { PositionX = -15.854f, PositionY = 1014.461f, PositionZ = -31.543f, RotationX = 0, RotationY = 0, RotationZ = 0 } }, { LobbyLocationType.Tower_5, new CustomLocationData() { PositionX = 130.483f, PositionY = 993.366f, PositionZ = 20.601f, RotationX = 0, RotationY = 0, RotationZ = 0 } }, - { LobbyLocationType.Intercom, new CustomRoomLocationData() { RoomNameType = RoomName.EzIntercom, OffsetX = -4.16f, OffsetY = -3.860f, OffsetZ = -2.113f, RotationX = 0, RotationY = 180, RotationZ = 0 } }, - { LobbyLocationType.GR18, new CustomRoomLocationData() { RoomNameType = RoomName.LczGlassroom, OffsetX = 4.8f, OffsetY = 1f, OffsetZ = 2.3f, RotationX = 0, RotationY = 180, RotationZ = 0 } }, - { LobbyLocationType.SCP173, new CustomRoomLocationData() { RoomNameType = RoomName.Lcz173, OffsetX = 17f, OffsetY = 13f, OffsetZ = 8f, RotationX = 0, RotationY = -90, RotationZ = 0 } }, + { LobbyLocationType.Intercom, new CustomRoomLocationData() { RoomNameType = RoomName.EzIntercom.ToString(), OffsetX = -4.16f, OffsetY = -3.860f, OffsetZ = -2.113f, RotationX = 0, RotationY = 180, RotationZ = 0 } }, + { LobbyLocationType.GR18, new CustomRoomLocationData() { RoomNameType = RoomName.LczGlassroom.ToString(), OffsetX = 4.8f, OffsetY = 1f, OffsetZ = 2.3f, RotationX = 0, RotationY = 180, RotationZ = 0 } }, + { LobbyLocationType.SCP173, new CustomRoomLocationData() { RoomNameType = RoomName.Lcz173.ToString(), OffsetX = 17f, OffsetY = 13f, OffsetZ = 8f, RotationX = 0, RotationY = -90, RotationZ = 0 } }, }; public static void SetLocation(LocationData locationData) @@ -27,15 +28,21 @@ public static void SetLocation(LocationData locationData) { RoomIdentifier Room; - Room = RoomIdentifier.AllRoomIdentifiers.First(x => x.Name == customRoomLocation.RoomNameType); - - if (customRoomLocation.RoomNameType == RoomName.EzIntercom) - EventHandlers.IsIntercom = true; + if (Enum.TryParse(customRoomLocation.RoomNameType, out RoomName roomName)) + { + Room = RoomIdentifier.AllRoomIdentifiers.First(x => x.Name == roomName); - if (Room == null) + if (customRoomLocation.RoomNameType == RoomName.EzIntercom.ToString()) + EventHandlers.IsIntercom = true; + } + else if (RoomIdentifier.AllRoomIdentifiers.Count(x => x.name.Contains(customRoomLocation.RoomNameType)) > 0) + { + Room = RoomIdentifier.AllRoomIdentifiers.First(x => x.name.Contains(customRoomLocation.RoomNameType)); + } + else { customRoomLocation = (CustomRoomLocationData)LocationDatas[LobbyLocationType.GR18]; - Room = RoomIdentifier.AllRoomIdentifiers.First(x => x.Name == customRoomLocation.RoomNameType); + Room = RoomIdentifier.AllRoomIdentifiers.First(x => x.Name == ParseEnum(customRoomLocation.RoomNameType)); } Point.transform.SetParent(Room.transform); @@ -48,5 +55,10 @@ public static void SetLocation(LocationData locationData) Point.transform.localRotation = Quaternion.Euler(customLocation.RotationX, customLocation.RotationY, customLocation.RotationZ); } } + + public static T ParseEnum(string value) + { + return (T)Enum.Parse(typeof(T), value, true); + } } } diff --git a/Lobby/Command/ControlCommands/AddLocationCommand.cs b/Lobby/Command/ControlCommands/AddLocationCommand.cs new file mode 100644 index 0000000..8342bcc --- /dev/null +++ b/Lobby/Command/ControlCommands/AddLocationCommand.cs @@ -0,0 +1,69 @@ +using CommandSystem; +using Lobby.Extensions; +using PluginAPI.Core; +using System; +using UnityEngine; + +namespace Lobby.Command.ControlCommands +{ + public class AddLocationCommand : ICommand + { + public string Command => "addloc"; + + public string[] Aliases { get; } = { "add", "ad" }; + + public string Description => "Add a new lobby location."; + + public bool Execute(ArraySegment arguments, ICommandSender sender, out string response) + { + Player playerSender = Player.Get(sender); + + if (!playerSender.IsAllowCommand()) + { + response = $"You don't have permission to use this command!"; + return false; + } + + if (arguments.Count != 1) + { + response = "Incorrect command, use: \nlobby addloc room\nlobby addloc static"; + return false; + } + + var handler = PluginHandler.Get(Lobby.Instance); + + switch (arguments.At(0)) + { + case "room": + GameObject Point = new GameObject("Point"); + Point.transform.position = playerSender.Position; + Point.transform.eulerAngles = playerSender.Rotation; + Point.transform.SetParent(playerSender.Room.transform); + + CustomRoomLocationData roomLocationData = new CustomRoomLocationData(); + roomLocationData.RoomNameType = playerSender.Room.name; + roomLocationData.OffsetX = Point.transform.localPosition.x; roomLocationData.OffsetY = Point.transform.localPosition.y + 0.05f; roomLocationData.OffsetZ = Point.transform.localPosition.z; + roomLocationData.RotationX = Point.transform.localEulerAngles.x; roomLocationData.RotationY = Point.transform.localEulerAngles.y; roomLocationData.RotationZ = Point.transform.localEulerAngles.z; + + Lobby.Config.CustomRoomLocations.Add(roomLocationData); + handler.SaveConfig(Lobby.Instance, nameof(Lobby.Config)); + response = "New custom location added to the config."; + return true; + case "static": + CustomLocationData locationData = new CustomLocationData(); + locationData.PositionX = playerSender.Position.x; locationData.PositionY = playerSender.Position.y + 0.05f; locationData.PositionZ = playerSender.Position.z; + locationData.RotationX = playerSender.Rotation.x; locationData.RotationY = playerSender.Rotation.y; locationData.RotationZ = playerSender.Rotation.z; + + Lobby.Config.CustomLocations.Add(locationData); + handler.SaveConfig(Lobby.Instance, nameof(Lobby.Config)); + response = "New custom location added to the config."; + return true; + default: + response = "Incorrect command, use: \nlobby addloc room\nlobby addloc static"; + return false; + } + } + + + } +} \ No newline at end of file diff --git a/Lobby/Command/ControlCommands/RemoveLocationCommand.cs b/Lobby/Command/ControlCommands/RemoveLocationCommand.cs new file mode 100644 index 0000000..c334d58 --- /dev/null +++ b/Lobby/Command/ControlCommands/RemoveLocationCommand.cs @@ -0,0 +1,72 @@ +using CommandSystem; +using Lobby.Extensions; +using PluginAPI.Core; +using System; + +namespace Lobby.Command.ControlCommands +{ + public class RemoveLocationCommand : ICommand + { + public string Command => "removeloc"; + + public string[] Aliases { get; } = { "remloc", "rloc", "rl" }; + + public string Description => "Remove a new lobby location."; + + public bool Execute(ArraySegment arguments, ICommandSender sender, out string response) + { + Player playerSender = Player.Get(sender); + + if (!playerSender.IsAllowCommand()) + { + response = $"You don't have permission to use this command!"; + return false; + } + + if (arguments.Count != 2) + { + response = "Incorrect command, use: \nlobby removeloc room (index)\nlobby removeloc static (index)"; + return false; + } + + if (!Int32.TryParse(arguments.At(1), out int index)) + { + response = "The index must be a number!"; + return false; + } + + var handler = PluginHandler.Get(Lobby.Instance); + + switch (arguments.At(0)) + { + case "room": + if (Lobby.Config.CustomRoomLocations == null || Lobby.Config.CustomRoomLocations?.Count - 1 < index) + { + response = $"Custom location at index {index} was not found."; + return false; + } + + Lobby.Config.CustomRoomLocations.RemoveAt(index); + + handler.SaveConfig(Lobby.Instance, nameof(Lobby.Config)); + response = $"Custom location at index {index} has been removed."; + return true; + case "static": + if (Lobby.Config.CustomLocations == null || Lobby.Config.CustomLocations?.Count - 1 < index) + { + response = $"Custom location at index {index} was not found."; + return false; + } + + Lobby.Config.CustomLocations.RemoveAt(index); + + handler.SaveConfig(Lobby.Instance, nameof(Lobby.Config)); + response = $"Custom location at index {index} has been removed."; + return true; + default: + response = "Incorrect command, use: \nlobby removeloc room (index)\nlobby removeloc static (index)"; + return false; + } + } + } +} diff --git a/Lobby/Command/DebugCommands/GetLocalDataCommand.cs b/Lobby/Command/DebugCommands/GetLocalDataCommand.cs new file mode 100644 index 0000000..6f7d116 --- /dev/null +++ b/Lobby/Command/DebugCommands/GetLocalDataCommand.cs @@ -0,0 +1,48 @@ +using CommandSystem; +using Lobby.Extensions; +using PluginAPI.Core; +using System; +using UnityEngine; + +namespace Lobby.Command.DebugCommands +{ + public class GetLocalDataCommand : ICommand + { + public string Command => "getlocaldata"; + + public string[] Aliases { get; } = { "getlocdat", "getld", "gld" }; + + public string Description => "Shows the exact position and rotation in the room where the player is located."; + + public bool Execute(ArraySegment arguments, ICommandSender sender, out string response) + { + Player playerSender = Player.Get(sender); + + if (!playerSender.IsAllowCommand()) + { + response = $"You don't have permission to use this command!"; + return false; + } + + if (arguments.Count > 0) + { + response = "Incorrect command, use: \nlobby getlocalpos"; + return false; + } + + if (playerSender.Room == null) + { + response = "An error occurred when getting the room you are in."; + return false; + } + + GameObject Point = new GameObject("Point"); + Point.transform.position = playerSender.Position; + Point.transform.eulerAngles = playerSender.Rotation; + Point.transform.SetParent(playerSender.Room.transform); + + response = $"Room name {playerSender.Room.name}; Local position: {Point.transform.localPosition.ToString()}; Local Rotation: {Point.transform.localEulerAngles.ToString()}."; + return true; + } + } +} \ No newline at end of file diff --git a/Lobby/Command/DebugCommands/LocationListCommand.cs b/Lobby/Command/DebugCommands/LocationListCommand.cs new file mode 100644 index 0000000..9a3b658 --- /dev/null +++ b/Lobby/Command/DebugCommands/LocationListCommand.cs @@ -0,0 +1,85 @@ +using CommandSystem; +using Lobby.Extensions; +using PluginAPI.Core; +using System; + +namespace Lobby.Command.DebugCommands +{ + public class LocationListCommand : ICommand + { + public string Command => "loclist"; + + public string[] Aliases { get; } = { "llist", "ll" }; + + public string Description => "Display a list of custom locations in the console."; + + public bool Execute(ArraySegment arguments, ICommandSender sender, out string response) + { + Player playerSender = Player.Get(sender); + + if (!playerSender.IsAllowCommand()) + { + response = $"You don't have permission to use this command!"; + return false; + } + + if (arguments.Count != 1) + { + response = "Incorrect command, use: \nlobby loclist all\nlobby loclist room\nlobby loclist static"; + return false; + } + + string resString = string.Empty; + + switch (arguments.At(0)) + { + case "all": + resString += "Room locations:\n"; + if (Lobby.Config.CustomRoomLocations?.Count > 0) + { + foreach (var item in Lobby.Config.CustomRoomLocations) + resString += item.RoomNameType + " " + $"({item.OffsetX}, {item.OffsetY}, {item.OffsetZ})\n"; + } + + resString += "\nStatic locations:\n"; + if (Lobby.Config.CustomLocations?.Count > 0) + { + foreach (var item in Lobby.Config.CustomLocations) + resString += $"({item.PositionX}, {item.PositionY}, {item.PositionZ})\n"; + } + + response = resString; + return true; + case "room": + resString += "Room locations:\n"; + if (Lobby.Config.CustomRoomLocations?.Count > 0) + { + for (int i = 0; i < Lobby.Config.CustomRoomLocations.Count; i++) + { + CustomRoomLocationData data = Lobby.Config.CustomRoomLocations[i]; + resString += $"({i}) " + data.RoomNameType + " " + $"({data.OffsetX}, {data.OffsetY}, {data.OffsetZ})\n"; + } + } + + response = resString; + return true; + case "static": + resString += "Static locations:\n"; + if (Lobby.Config.CustomLocations?.Count > 0) + { + for (int i = 0; i < Lobby.Config.CustomLocations.Count; i++) + { + CustomLocationData data = Lobby.Config.CustomLocations[i]; + resString += $"({i}) " + $"({data.PositionX}, {data.PositionY}, {data.PositionZ})\n"; + } + } + + response = resString; + return true; + default: + response = "Incorrect command, use: \nlobby loclist all\nlobby loclist room\nlobby loclist static"; + return false; + } + } + } +} \ No newline at end of file diff --git a/Lobby/Command/DebugCommands/TpLocationCommand.cs b/Lobby/Command/DebugCommands/TpLocationCommand.cs new file mode 100644 index 0000000..65c6451 --- /dev/null +++ b/Lobby/Command/DebugCommands/TpLocationCommand.cs @@ -0,0 +1,86 @@ +using CommandSystem; +using Lobby.Extensions; +using MapGeneration; +using PluginAPI.Core; +using System; +using System.Linq; +using UnityEngine; + +namespace Lobby.Command.DebugCommands +{ + public class TpLocationCommand : ICommand + { + public string Command => "tploc"; + + public string[] Aliases { get; } = { "tpl", "tl" }; + + public string Description => "Teleport to a custom location."; + + public bool Execute(ArraySegment arguments, ICommandSender sender, out string response) + { + Player playerSender = Player.Get(sender); + + if (!playerSender.IsAllowCommand()) + { + response = $"You don't have permission to use this command!"; + return false; + } + + if (arguments.Count != 2) + { + response = "Incorrect command, use: \nlobby tploc room (index)\nlobby tploc static (index)"; + return false; + } + + if (!Int32.TryParse(arguments.At(1), out int index)) + { + response = "The index must be a number"; + return false; + } + + var handler = PluginHandler.Get(Lobby.Instance); + GameObject Point = new GameObject("Point"); + + switch (arguments.At(0)) + { + case "room": + if (Lobby.Config.CustomRoomLocations == null || Lobby.Config.CustomRoomLocations?.Count - 1 < index) + { + response = $"Custom location at index {index} was not found."; + return false; + } + + if (Enum.TryParse(Lobby.Config.CustomRoomLocations[index].RoomNameType, out RoomName roomName)) + Point.transform.SetParent(RoomIdentifier.AllRoomIdentifiers.First(x => x.Name == roomName).transform); + else if (RoomIdentifier.AllRoomIdentifiers.Count(x => x.name.Contains(Lobby.Config.CustomRoomLocations[index].RoomNameType)) > 0) + Point.transform.SetParent(RoomIdentifier.AllRoomIdentifiers.First(x => x.name.Contains(Lobby.Config.CustomRoomLocations[index].RoomNameType)).transform); + + Point.transform.localPosition = new Vector3(Lobby.Config.CustomRoomLocations[index].OffsetX, Lobby.Config.CustomRoomLocations[index].OffsetY, Lobby.Config.CustomRoomLocations[index].OffsetZ); + Point.transform.localEulerAngles = new Vector3(Lobby.Config.CustomRoomLocations[index].RotationX, Lobby.Config.CustomRoomLocations[index].RotationY, Lobby.Config.CustomRoomLocations[index].RotationZ); + + playerSender.Position = Point.transform.position; + playerSender.Rotation = Point.transform.eulerAngles; + + GameObject.Destroy(Point); + + response = $"You have successfully teleported to a custom location at index {index}."; + return true; + case "static": + if (Lobby.Config.CustomLocations == null || Lobby.Config.CustomLocations?.Count - 1 < index) + { + response = $"Custom location at index {index} was not found."; + return false; + } + + playerSender.Position = new Vector3(Lobby.Config.CustomLocations[index].PositionX, Lobby.Config.CustomLocations[index].PositionY, Lobby.Config.CustomLocations[index].PositionZ); + playerSender.Rotation = new Vector3(Lobby.Config.CustomLocations[index].RotationX, Lobby.Config.CustomLocations[index].RotationY, Lobby.Config.CustomLocations[index].RotationZ); + + response = $"You have successfully teleported to a custom location at index {index}."; + return true; + default: + response = "Incorrect command, use: \nlobby tploc room (index)\nlobby tploc static (index)"; + return false; + } + } + } +} \ No newline at end of file diff --git a/Lobby/Command/LobbyParentCommand.cs b/Lobby/Command/LobbyParentCommand.cs new file mode 100644 index 0000000..8c5794d --- /dev/null +++ b/Lobby/Command/LobbyParentCommand.cs @@ -0,0 +1,34 @@ +using CommandSystem; +using Lobby.Command.ControlCommands; +using Lobby.Command.DebugCommands; +using System; + +namespace Lobby.Command +{ + [CommandHandler(typeof(RemoteAdminCommandHandler))] + public class LobbyParentCommand : ParentCommand + { + public LobbyParentCommand() => LoadGeneratedCommands(); + + public override string Command => "lobby"; + + public override string[] Aliases { get; } = { "lb", "ly" }; + + public override string Description => "Lobby parent command."; + + public override void LoadGeneratedCommands() + { + RegisterCommand(new AddLocationCommand()); + RegisterCommand(new RemoveLocationCommand()); + RegisterCommand(new LocationListCommand()); + RegisterCommand(new TpLocationCommand()); + RegisterCommand(new GetLocalDataCommand()); + } + + protected override bool ExecuteParent(ArraySegment arguments, ICommandSender sender, out string response) + { + response = "Incorrect command, use: \nlobby addloc\nlobby removeloc\nlobby loclist\nlobby tploc\nlobby getlocaldata"; + return false; + } + } +} diff --git a/Lobby/Config.cs b/Lobby/Config.cs index 449242d..fce50ca 100644 --- a/Lobby/Config.cs +++ b/Lobby/Config.cs @@ -1,10 +1,10 @@ -namespace Lobby -{ - using MapGeneration; - using PlayerRoles; - using System.Collections.Generic; - using System.ComponentModel; +using MapGeneration; +using PlayerRoles; +using System.Collections.Generic; +using System.ComponentModel; +namespace Lobby +{ public class Config { [Description("Main text ({seconds} - Either it shows how much is left until the start, or the server status is \"Server is suspended\", \"Round starting\", - Change the next text a rainbow color, - Close a rainbow color tag)")] @@ -91,7 +91,7 @@ public class Config { new CustomRoomLocationData() { - RoomNameType = RoomName.EzGateA, + RoomNameType = RoomName.EzGateA.ToString(), OffsetX = 0, OffsetY = 1, OffsetZ = 0, @@ -114,6 +114,18 @@ public class Config RotationZ = 0, }, }; + + [Description("The name of the role that can use commands for Lobby.")] + public List AllowedRank { get; set; } = new List() + { + "owner" + }; + + [Description("User ID that can use commands for the Lobby.")] + public List AllowedUserID { get; set; } = new List() + { + "SomeOtherSteamId64@steam" + }; } public class LocationData @@ -122,7 +134,7 @@ public class LocationData public class CustomRoomLocationData : LocationData { - public RoomName RoomNameType { get; set; } + public string RoomNameType { get; set; } public float OffsetX { get; set; } public float OffsetY { get; set; } public float OffsetZ { get; set; } @@ -140,4 +152,4 @@ public class CustomLocationData : LocationData public float RotationY { get; set; } public float RotationZ { get; set; } } -} +} \ No newline at end of file diff --git a/Lobby/EventHandlers.cs b/Lobby/EventHandlers.cs index ae48b49..b1ec14a 100644 --- a/Lobby/EventHandlers.cs +++ b/Lobby/EventHandlers.cs @@ -1,20 +1,20 @@ -namespace Lobby +using CentralAuth; +using CustomPlayerEffects; +using Lobby.API; +using MEC; +using PlayerRoles; +using PlayerRoles.Voice; +using PluginAPI.Core; +using PluginAPI.Core.Attributes; +using PluginAPI.Events; +using System; +using System.Collections.Generic; +using System.Linq; +using UnityEngine; +using Random = UnityEngine.Random; + +namespace Lobby { - using CentralAuth; - using CustomPlayerEffects; - using global::Lobby.API; - using HarmonyLib; - using MEC; - using PlayerRoles; - using PlayerRoles.Voice; - using PluginAPI.Core; - using PluginAPI.Core.Attributes; - using PluginAPI.Events; - using System; - using System.Collections.Generic; - using System.Linq; - using UnityEngine; - public class EventHandlers { private CoroutineHandle lobbyTimer; @@ -60,32 +60,6 @@ public void OnWaitingForPlayers(WaitingForPlayersEvent ev) } } - public void SpawnManager() - { - try - { - List locationList = new List(); - - if (Lobby.Config.LobbyLocation?.Count > 0) - foreach (var item in Lobby.Config.LobbyLocation) - locationList.Add(LobbyLocationHandler.LocationDatas[item]); - - if (Lobby.Config.CustomRoomLocations?.Count > 0) - foreach (var item in Lobby.Config.CustomRoomLocations) - locationList.Add(item); - - if (Lobby.Config.CustomLocations?.Count > 0) - foreach (var item in Lobby.Config.CustomLocations) - locationList.Add(item); - - LobbyLocationHandler.SetLocation(locationList.RandomItem()); - } - catch (Exception e) - { - Log.Error("[Lobby] [Method: SpawnManager] " + e.ToString()); - } - } - [PluginEvent] public void OnPlayerJoin(PlayerJoinedEvent ev) { @@ -231,6 +205,35 @@ public bool OnPlayerUsingIntercom(PlayerUsingIntercomEvent ev) return true; } + public void SpawnManager() + { + try + { + List locationList = new List(); + + if (Lobby.Config.LobbyLocation?.Count > 0) + foreach (var item in Lobby.Config.LobbyLocation) + locationList.Add(LobbyLocationHandler.LocationDatas[item]); + + if (Lobby.Config.CustomRoomLocations?.Count > 0) + foreach (var item in Lobby.Config.CustomRoomLocations) + locationList.Add(item); + + if (Lobby.Config.CustomLocations?.Count > 0) + foreach (var item in Lobby.Config.CustomLocations) + locationList.Add(item); + + if (locationList.Count <= 0) + locationList.Add(LobbyLocationHandler.LocationDatas.ElementAt(Random.Range(0, LobbyLocationHandler.LocationDatas.Count - 1)).Value); + + LobbyLocationHandler.SetLocation(locationList.RandomItem()); + } + catch (Exception e) + { + Log.Error("[Lobby] [Method: SpawnManager] " + e.ToString()); + } + } + private IEnumerator RainbowColor() { r = 255; g = 0; b = 0; @@ -315,7 +318,7 @@ private IEnumerator LobbyTimer() { if (ply.ReferenceHub.Mode != ClientInstanceMode.Unverified && ply != null) { - ply.ReceiveHint(text, 1f); + ply.ReceiveHint(text, 1.1f); } } } @@ -328,4 +331,4 @@ private IEnumerator LobbyTimer() } } } -} +} \ No newline at end of file diff --git a/Lobby/Extensions/PlayerExtensions.cs b/Lobby/Extensions/PlayerExtensions.cs new file mode 100644 index 0000000..1355813 --- /dev/null +++ b/Lobby/Extensions/PlayerExtensions.cs @@ -0,0 +1,61 @@ +using PluginAPI.Core; +using System; +using System.Linq; + +namespace Lobby.Extensions +{ + public static class PlayerExtensions + { + public static bool IsAllowCommand(this Player player) => player.IsAllowFromRank() || player.IsAllowFromUserID(); + + public static bool IsAllowFromUserID(this Player player) + { + if (!string.IsNullOrEmpty(player.UserId)) + if (Lobby.Config.AllowedUserID?.Count > 0) + if (Lobby.Config.AllowedUserID.Contains(player.UserId)) + return true; + return false; + } + + public static bool IsAllowFromRank(this Player player) + { + if (!string.IsNullOrEmpty(player.GetGroupName())) + if (Lobby.Config.AllowedRank?.Count > 0) + if (Lobby.Config.AllowedRank.Contains(player.GetGroupName())) + return true; + return false; + } + + public static string GetGroupName(this Player player) + { + try + { + if (player.UserId == null) return string.Empty; + + if (ServerStatic.PermissionsHandler._members.ContainsKey(player.UserId)) + { + return ServerStatic.PermissionsHandler._members[player.UserId]; + } + else + { + return player.ReferenceHub.serverRoles.Group != null ? ServerStatic.GetPermissionsHandler()._groups.FirstOrDefault(g => EqualsTo(g.Value, player.ReferenceHub.serverRoles.Group)).Key : string.Empty; + } + } + catch (Exception e) + { + Log.Error("[Lobby] [Event: GetPlayerGroupName] " + e.ToString()); + return string.Empty; + } + } + + private static bool EqualsTo(UserGroup check, UserGroup player) + => check.BadgeColor == player.BadgeColor + && check.BadgeText == player.BadgeText + && check.Permissions == player.Permissions + && check.Cover == player.Cover + && check.HiddenByDefault == player.HiddenByDefault + && check.Shared == player.Shared + && check.KickPower == player.KickPower + && check.RequiredKickPower == player.RequiredKickPower; + } +} diff --git a/Lobby/Lobby.cs b/Lobby/Lobby.cs index 6773f6b..3015511 100644 --- a/Lobby/Lobby.cs +++ b/Lobby/Lobby.cs @@ -1,10 +1,10 @@ -namespace Lobby -{ - using HarmonyLib; - using PluginAPI.Core.Attributes; - using PluginAPI.Enums; - using PluginAPI.Events; +using HarmonyLib; +using PluginAPI.Core.Attributes; +using PluginAPI.Enums; +using PluginAPI.Events; +namespace Lobby +{ public class Lobby { public static Lobby Instance { get; private set; } @@ -15,7 +15,7 @@ public class Lobby public Harmony Harmony { get; private set; } [PluginPriority(LoadPriority.Highest)] - [PluginEntryPoint("Lobby", "1.3.1", "A plugin that adds a lobby when waiting for players.", "MrAfitol")] + [PluginEntryPoint("Lobby", "1.4.0", "A plugin that adds a lobby when waiting for players.", "MrAfitol")] public void LoadPlugin() { Instance = this; diff --git a/Lobby/Lobby.csproj b/Lobby/Lobby.csproj index 9b03a14..ed99143 100644 --- a/Lobby/Lobby.csproj +++ b/Lobby/Lobby.csproj @@ -74,8 +74,15 @@ + + + + + + + @@ -85,5 +92,6 @@ + \ No newline at end of file diff --git a/Lobby/Patches/StaminaUsageMultiplierPatch.cs b/Lobby/Patches/StaminaUsageMultiplierPatch.cs index 82ee25e..105b110 100644 --- a/Lobby/Patches/StaminaUsageMultiplierPatch.cs +++ b/Lobby/Patches/StaminaUsageMultiplierPatch.cs @@ -1,8 +1,8 @@ -namespace Lobby.Patches -{ - using HarmonyLib; - using InventorySystem; +using HarmonyLib; +using InventorySystem; +namespace Lobby.Patches +{ [HarmonyPatch(typeof(Inventory), nameof(Inventory.StaminaUsageMultiplier), MethodType.Getter)] public class StaminaUsageMultiplierPatch { diff --git a/Lobby/Properties/AssemblyInfo.cs b/Lobby/Properties/AssemblyInfo.cs index ae6447c..ab5b206 100644 --- a/Lobby/Properties/AssemblyInfo.cs +++ b/Lobby/Properties/AssemblyInfo.cs @@ -31,5 +31,5 @@ // You can specify all the values or you can default the Build and Revision Numbers // by using the '*' as shown below: // [assembly: AssemblyVersion("1.0.*")] -[assembly: AssemblyVersion("1.3.1.0")] -[assembly: AssemblyFileVersion("1.3.1.0")] +[assembly: AssemblyVersion("1.4.0.0")] +[assembly: AssemblyFileVersion("1.4.0.0")]