diff --git a/ChatCommands/ChatCommandList.cs b/ChatCommands/ChatCommandList.cs index bf4b8ac..b6d0037 100644 --- a/ChatCommands/ChatCommandList.cs +++ b/ChatCommands/ChatCommandList.cs @@ -10,7 +10,8 @@ public class ChatCommandList public static List AdminCommands { get; } = new() { new PlayerDebug(), - new TeleportCommand() + new TeleportCommand(), + new StopServerAndApi() }; public static List ModeratorCommands { get; } = new() diff --git a/ChatCommands/StopServerAndApi.cs b/ChatCommands/StopServerAndApi.cs new file mode 100644 index 0000000..4b0d64d --- /dev/null +++ b/ChatCommands/StopServerAndApi.cs @@ -0,0 +1,36 @@ +using BattleBitMinigames.Enums; +using BattleBitMinigames.Helpers; + +namespace BattleBitMinigames.ChatCommands; + +public class StopServerAndApi : ChatCommand +{ + public StopServerAndApi() : base( + name: "stop", + description: "Stop :)", + usage: "stop", + minimumRequiredRole: PlayerRoles.Admin + ) + { + Action = (args, player) => + { + if (!CanExecute(player)) + { + player.Message("You do not have permission to execute this command."); + return; + } + + Program.Logger.Info("Closing Server..."); + Server.StopServer(); + Server.AnnounceLong("Stopping..."); + + while (Server.IsConnected) + { + Thread.Sleep(1000); + } + + Program.Logger.Info("Quitting API..."); + Environment.Exit(-1); + }; + } +} \ No newline at end of file diff --git a/Data/RegionList.cs b/Data/RegionList.cs index c3d0f0d..79fb536 100644 --- a/Data/RegionList.cs +++ b/Data/RegionList.cs @@ -19,6 +19,11 @@ public class RegionList WineParadiseRegions.TeamASafeZone, WineParadiseRegions.TeamBSafeZone }, + "TensaTown" => new List + { + TensaTownRegions.TeamASafeZone, + TensaTownRegions.TeamBSafeZone + }, _ => new List() }; } diff --git a/Data/Regions/TensaTownRegions.cs b/Data/Regions/TensaTownRegions.cs new file mode 100644 index 0000000..447c934 --- /dev/null +++ b/Data/Regions/TensaTownRegions.cs @@ -0,0 +1,60 @@ +using System.Numerics; +using BattleBitMinigames.Handlers; + +namespace BattleBitMinigames.Data.Regions; + +public class TensaTownRegions +{ + // US safe zone + public static readonly RegionHelper.Region TeamASafeZone = new ( + "US Safe Zone", + "You've entered the US Safe Zone. Please leave immediately.", + new List + { + new (300, -125), + new (265, -187), + new (278, -242), + new (246, -285), + new (162, -272), + new (110, -243), + new (64, -226), + new (-39, -193), + new (-116, -192), + new (-187, -233), + new (-188, -244), + new (-18, -389), + new (306, -436), + new (393, -367), + new (430, -266), + new (341, -155) + } + ); + + // RU safe zone region + public static readonly RegionHelper.Region? TeamBSafeZone = new ( + "RU Safe Zone", + "You've entered the RU Safe Zone. Please leave immediately.", + new List + { + new (-199, 86), + new (-141, 111), + new (-96, 185), + new (-76, 230), + new (-49, 312), + new (-30, 317), + new (38, 342), + new (83, 352), + new (132, 348), + new (135, 248), + new (207, 189), + new (251, 161), + new (324, 142), + new (356, 213), + new (-276, 277), + new (194, 407), + new (-178, 377), + new (-277, 303), + new (-274, 188) + } + ); +} \ No newline at end of file diff --git a/Events/RegionManager.cs b/Events/RegionManager.cs index d2350e8..9bdc268 100644 --- a/Events/RegionManager.cs +++ b/Events/RegionManager.cs @@ -31,7 +31,7 @@ private void StartRegionManager() if (Program.ServerConfiguration.LaunchCustomGamemode == "vip") { var isVip = player.GetPlayerProperty(PlayerProperties.IVipPlayerProperties.IsVip); - if (isVip == "" || isVip == "false") continue; + if (isVip != "true") continue; var now = DateTime.UtcNow; var spawnedInSpawn = @@ -51,10 +51,11 @@ private void StartRegionManager() player.Message($"You spawned in the {region.Name} and stayed for too long!", 15); } - else + else if ((now - spawnedInSpawnTime).TotalSeconds >= 10) { player.Message( - $"You spawned in the {region.Name}, please leave within {(int)(90 - (now - spawnedInSpawnTime).TotalSeconds)} seconds!"); + $"You spawned in the {region.Name}, please leave within {(int)(90 - (now - spawnedInSpawnTime).TotalSeconds)} seconds!", + 1f); } } } @@ -75,7 +76,8 @@ private void StartRegionManager() else { player.Message( - $"You entered the {region.Name}, please leave within {(int)(20 - (now - enteredSpawnTime).TotalSeconds)} seconds!"); + $"You entered the {region.Name}, please leave within {(int)(20 - (now - enteredSpawnTime).TotalSeconds)} seconds!", + 1f); } } } @@ -136,9 +138,13 @@ public override Task OnPlayerSpawned(BattleBitPlayer player) return base.OnPlayerSpawned(player); } - public override Task OnConnected() + public override Task OnGameStateChanged(GameState oldState, GameState newState) { - StartRegionManager(); - return Task.CompletedTask; + if (newState == GameState.Playing) + StartRegionManager(); + + if (newState == GameState.EndingGame) + StopRegionManager(); + return base.OnGameStateChanged(oldState, newState); } } \ No newline at end of file diff --git a/Events/VipGamemode.cs b/Events/VipGamemode.cs index 13bfed2..10ed003 100644 --- a/Events/VipGamemode.cs +++ b/Events/VipGamemode.cs @@ -2,6 +2,7 @@ using BattleBitAPI.Server; using BattleBitMinigames.Api; using BattleBitMinigames.Helpers; +using BattleBitMinigames.Interfaces; namespace BattleBitMinigames.Events; @@ -10,6 +11,8 @@ public class VipGamemode : Event private Random _random = new(); private BattleBitPlayer? _teamAVip; private BattleBitPlayer? _teamBVip; + private ulong? _lastTeamAVipSteamId; + private ulong? _lastTeamBVipSteamId; private bool IsPlayerVip(BattleBitPlayer player) { @@ -22,9 +25,11 @@ private void SetVipSettings(BattleBitPlayer player) { case Team.TeamA: _teamAVip = player; + _lastTeamAVipSteamId = player.SteamID; break; case Team.TeamB: _teamBVip = player; + _lastTeamBVipSteamId = player.SteamID; break; case Team.None: break; @@ -40,6 +45,7 @@ private void SetVipSettings(BattleBitPlayer player) player.Modifications.IsExposedOnMap = true; player.KickFromSquad(); player.JoinSquad(Squads.King); + player.SetPlayerProperty(PlayerProperties.IVipPlayerProperties.IsVip, "true"); } private static void SetNonVipSettings(BattleBitPlayer player) @@ -48,6 +54,7 @@ private static void SetNonVipSettings(BattleBitPlayer player) player.Modifications.FallDamageMultiplier = 1f; player.Modifications.ReceiveDamageMultiplier = 1f; player.Modifications.GiveDamageMultiplier = 1f; + player.RemovePlayerProperty(PlayerProperties.IVipPlayerProperties.IsVip); } // TODO: Implement function to increment player point contribution using player properties @@ -66,7 +73,7 @@ private static void SetNonVipSettings(BattleBitPlayer player) { case Team.TeamA: { - if (_teamAVip == null) + if (_teamAVip == null && _lastTeamAVipSteamId != player.SteamID) { SetVipSettings(player); request.Wearings = PlayerOutfits.BlueTeam; @@ -91,7 +98,7 @@ private static void SetNonVipSettings(BattleBitPlayer player) } case Team.TeamB: { - if (_teamBVip == null) + if (_teamBVip == null && _lastTeamBVipSteamId != player.SteamID) { SetVipSettings(player); request.Wearings = PlayerOutfits.RedTeam; diff --git a/Helpers/CustomGamemodeHelper.cs b/Helpers/CustomGamemodeHelper.cs index 2709dec..7f082db 100644 --- a/Helpers/CustomGamemodeHelper.cs +++ b/Helpers/CustomGamemodeHelper.cs @@ -24,7 +24,6 @@ public static void SetCustomGameMode(string gm, BattleBitServer server) if (IsValidCustomGamemode(gm)) { server.ResetEvents(); - server.SetServerSizeForNextMatch(MapSize._127vs127); switch (gm.ToLower()) { @@ -34,6 +33,7 @@ public static void SetCustomGameMode(string gm, BattleBitServer server) break; case "vip": server.AddEvents(CustomGameModeEvents.VipEvents); + server.SetServerSizeForNextMatch(MapSize._127vs127); server.ForceEndGame(); break; case "hideandseek": diff --git a/Helpers/RoleHelper.cs b/Helpers/RoleHelper.cs index 4b034fb..a064399 100644 --- a/Helpers/RoleHelper.cs +++ b/Helpers/RoleHelper.cs @@ -6,18 +6,15 @@ public class RoleHelper { public static List Admins = new() { - 76561198395073327, - 76561198035784951, - 76561198855127416 + 76561198395073327, // Bims + 76561198035784951, // AgentSmith + 76561198173566107, // Julgers + 76561198051546518, // Terminal + 76561199056414354, // Pom + 76561198833659544 // Silly }; - public static List Moderators = new() - { - 76561198173566107, - 76561198051546518, - 76561199056414354, - 76561198833659544 - }; + public static List Moderators = new() { }; public static List Vips = new() { };