diff --git a/Data/CustomGameModeEvents.cs b/Data/CustomGameModeEvents.cs index 920ef97..1a6d236 100644 --- a/Data/CustomGameModeEvents.cs +++ b/Data/CustomGameModeEvents.cs @@ -21,7 +21,7 @@ public static class CustomGameModeEvents public static readonly List HideAndSeekEvents = new() { new HideAndSeekGamemode(), - // new RegionManager() + new RegionManager() }; public static readonly List GunGameEvents = new() diff --git a/Events/GunGameGamemode.cs b/Events/GunGameGamemode.cs index 112ea42..92fb5c0 100644 --- a/Events/GunGameGamemode.cs +++ b/Events/GunGameGamemode.cs @@ -21,18 +21,18 @@ public class GunGameGamemode : Event private int GetPlayerTier(BattleBitPlayer player) { - return player.GetPlayerProperty(PlayerProperties.IGunGamePlayerProperties.Tier) == string.Empty ? 0 : int.Parse(player.GetPlayerProperty("tier")); + return player.GetPlayerProperty(IPlayerProperties.IGunGamePlayerProperties.Tier) == string.Empty ? 0 : int.Parse(player.GetPlayerProperty("tier")); } private void SetPlayerTier(BattleBitPlayer player, int tier) { - player.SetPlayerProperty(PlayerProperties.IGunGamePlayerProperties.Tier, tier.ToString()); + player.SetPlayerProperty(IPlayerProperties.IGunGamePlayerProperties.Tier, tier.ToString()); } private void IncrementPlayerTier(BattleBitPlayer player) { var tier = GetPlayerTier(player); - player.SetPlayerProperty(PlayerProperties.IGunGamePlayerProperties.Tier, (tier + 1).ToString()); + player.SetPlayerProperty(IPlayerProperties.IGunGamePlayerProperties.Tier, (tier + 1).ToString()); } private void StartGunGame() diff --git a/Events/HideAndSeekGamemode.cs b/Events/HideAndSeekGamemode.cs index 7297e8d..a0e3bc3 100644 --- a/Events/HideAndSeekGamemode.cs +++ b/Events/HideAndSeekGamemode.cs @@ -40,33 +40,33 @@ public class HideAndSeekGamemode : Event private static bool IsPlayerSeeking(BattleBitPlayer player) { - var value = player.GetPlayerProperty(PlayerProperties.IHideAndSeekPlayerProperties.IsSeeking); + var value = player.GetPlayerProperty(IPlayerProperties.IHideAndSeekPlayerProperties.IsSeeking); return value != string.Empty && value != "false"; } private static int GetPlayerHidersFound(BattleBitPlayer player) { - var value = player.GetPlayerProperty(PlayerProperties.IHideAndSeekPlayerProperties.HidersFound); + var value = player.GetPlayerProperty(IPlayerProperties.IHideAndSeekPlayerProperties.HidersFound); return value != string.Empty ? int.Parse(value) : 0; } private static void AddPlayerHidersFound(BattleBitPlayer player) { var hidersFound = GetPlayerHidersFound(player); - player.SetPlayerProperty(PlayerProperties.IHideAndSeekPlayerProperties.HidersFound, (hidersFound + 1).ToString()); + player.SetPlayerProperty(IPlayerProperties.IHideAndSeekPlayerProperties.HidersFound, (hidersFound + 1).ToString()); Program.Logger.Info($"{player.Name} has found {hidersFound + 1} hiders!"); } private static void MakePlayerSeeker(BattleBitPlayer player) { - player.SetPlayerProperty(PlayerProperties.IHideAndSeekPlayerProperties.IsSeeking, "true"); + player.SetPlayerProperty(IPlayerProperties.IHideAndSeekPlayerProperties.IsSeeking, "true"); player.ChangeTeam(Team.TeamA); Program.Logger.Info($"{player.Name} is now a seeker!"); } private static void MakePlayerHider(BattleBitPlayer player) { - player.SetPlayerProperty(PlayerProperties.IHideAndSeekPlayerProperties.IsSeeking, "false"); + player.SetPlayerProperty(IPlayerProperties.IHideAndSeekPlayerProperties.IsSeeking, "false"); player.ChangeTeam(Team.TeamB); Program.Logger.Info($"{player.Name} is now a hider!"); } @@ -74,17 +74,17 @@ private static void MakePlayerHider(BattleBitPlayer player) // Set default values for the hide and seek player properties private static void SetDefaultPlayerProperties(BattleBitPlayer player) { - player.SetPlayerProperty(PlayerProperties.IHideAndSeekPlayerProperties.IsSeeking, "false"); - player.SetPlayerProperty(PlayerProperties.IHideAndSeekPlayerProperties.SeekingMeter, "NO LIFE DETECTED (300m+)"); - player.SetPlayerProperty(PlayerProperties.IHideAndSeekPlayerProperties.HidersFound, "0"); + player.SetPlayerProperty(IPlayerProperties.IHideAndSeekPlayerProperties.IsSeeking, "false"); + player.SetPlayerProperty(IPlayerProperties.IHideAndSeekPlayerProperties.SeekingMeter, "NO LIFE DETECTED (300m+)"); + player.SetPlayerProperty(IPlayerProperties.IHideAndSeekPlayerProperties.HidersFound, "0"); Program.Logger.Info($"Set default properties for {player.Name}"); } private static void ClearPlayerProperties(BattleBitPlayer player) { - player.RemovePlayerProperty(PlayerProperties.IHideAndSeekPlayerProperties.IsSeeking); - player.RemovePlayerProperty(PlayerProperties.IHideAndSeekPlayerProperties.SeekingMeter); - player.RemovePlayerProperty(PlayerProperties.IHideAndSeekPlayerProperties.HidersFound); + player.RemovePlayerProperty(IPlayerProperties.IHideAndSeekPlayerProperties.IsSeeking); + player.RemovePlayerProperty(IPlayerProperties.IHideAndSeekPlayerProperties.SeekingMeter); + player.RemovePlayerProperty(IPlayerProperties.IHideAndSeekPlayerProperties.HidersFound); Program.Logger.Info($"Cleared properties for {player.Name}"); } @@ -131,7 +131,7 @@ private async void StartPlayerSeekerMeter() }; if (closestHiderName != "") seekingMeterString += $"{RichTextHelper.NewLine()}Closest Hider: {RichTextHelper.FromColorName("RoyalBlue")}{closestHiderName}"; - seeker.SetPlayerProperty(PlayerProperties.IHideAndSeekPlayerProperties.SeekingMeter, seekingMeterString); + seeker.SetPlayerProperty(IPlayerProperties.IHideAndSeekPlayerProperties.SeekingMeter, seekingMeterString); await Task.Delay(5); }); @@ -180,7 +180,7 @@ private async void StartInfoMessage() foreach (var player in Server.AllPlayers) { var isSeeking = IsPlayerSeeking(player); - var seekerMeter = player.GetPlayerProperty(PlayerProperties.IHideAndSeekPlayerProperties.SeekingMeter); + var seekerMeter = player.GetPlayerProperty(IPlayerProperties.IHideAndSeekPlayerProperties.SeekingMeter); var message = new StringBuilder(); message.AppendLine( $"{RichTextHelper.Size(100)}{RichTextHelper.FromColorName("Snow")}BattleBit Hide and Seek!{RichTextHelper.Size(100)}"); @@ -568,7 +568,7 @@ public override Task OnAPlayerDownedAnotherPlayer(OnPlayerKillArguments= 90) - { - player.Kill(); - player.Message($"You spawned in the {region.Name} and stayed for too long!", - 15); - } - else if ((now - spawnedInSpawnTime).TotalSeconds >= 10) - { - player.Message( - $"You spawned in the {region.Name}, please leave within {(int)(90 - (now - spawnedInSpawnTime).TotalSeconds)} seconds!", - 1f); - } - } + if (player.GetPlayerProperty(IPlayerProperties.IVipPlayerProperties.IsVip) != "true") + continue; + + HandlePlayerInRegion(player, region); + + break; } - else + case "hideandseek": { - if (enteredSpawnTimeStr == string.Empty) - { - player.SetPlayerProperty(PlayerProperties.IVipPlayerProperties.EnteredSpawnTime, - now.ToUniversalTime().ToString()); - } - else if (DateTime.TryParse(enteredSpawnTimeStr, out var enteredSpawnTime)) - { - if ((now - enteredSpawnTime).TotalSeconds >= 20) - { - player.Kill(); - player.Message($"You were in the {region.Name} for too long!", 15); - } - else - { - player.Message( - $"You entered the {region.Name}, please leave within {(int)(20 - (now - enteredSpawnTime).TotalSeconds)} seconds!", - 1f); - } - } + if (player.GetPlayerProperty(IPlayerProperties.IHideAndSeekPlayerProperties.IsSeeking) == "true") + continue; + + HandlePlayerInRegion(player, region); + + break; } } } else { // Reset properties when a player leaves the spawn region - player.RemovePlayerProperty(PlayerProperties.IVipPlayerProperties.SpawnedInSpawn); - player.RemovePlayerProperty(PlayerProperties.IVipPlayerProperties.EnteredSpawnTime); - player.RemovePlayerProperty(PlayerProperties.IVipPlayerProperties.SpawnedInSpawnTime); + player.RemovePlayerProperty(IPlayerProperties.IGeneralPlayerProperties.SpawnedInSpawn); + player.RemovePlayerProperty(IPlayerProperties.IGeneralPlayerProperties.EnteredSpawnTime); + player.RemovePlayerProperty(IPlayerProperties.IGeneralPlayerProperties.SpawnedInSpawnTime); } } @@ -130,8 +97,8 @@ public override Task OnPlayerSpawned(BattleBitPlayer player) var region = RegionHelper.GetIsPlayerInRegion(RegionList.GetMapRegions(Server.Map), player); if (region != null) { - player.SetPlayerProperty(PlayerProperties.IVipPlayerProperties.SpawnedInSpawn, "true"); - player.SetPlayerProperty(PlayerProperties.IVipPlayerProperties.SpawnedInSpawnTime, + player.SetPlayerProperty(IPlayerProperties.IGeneralPlayerProperties.SpawnedInSpawn, "true"); + player.SetPlayerProperty(IPlayerProperties.IGeneralPlayerProperties.SpawnedInSpawnTime, DateTime.UtcNow.ToString()); } @@ -147,4 +114,47 @@ public override Task OnGameStateChanged(GameState oldState, GameState newState) StopRegionManager(); return base.OnGameStateChanged(oldState, newState); } + + private void HandlePlayerInRegion(BattleBitPlayer player, RegionHelper.Region region) + { + var now = DateTime.UtcNow; + var spawnedInSpawn = player.GetPlayerProperty(IPlayerProperties.IGeneralPlayerProperties.SpawnedInSpawn); + var spawnedInSpawnTimeStr = player.GetPlayerProperty(IPlayerProperties.IGeneralPlayerProperties.SpawnedInSpawnTime); + var enteredSpawnTimeStr = player.GetPlayerProperty(IPlayerProperties.IGeneralPlayerProperties.EnteredSpawnTime); + + if (spawnedInSpawn == "true") + { + if (DateTime.TryParse(spawnedInSpawnTimeStr, out var spawnedInSpawnTime)) + { + if ((now - spawnedInSpawnTime).TotalSeconds >= 90) + { + player.Kill(); + player.Message($"You spawned in the {region.Name} and stayed for too long!", 15f); + } + else if ((now - spawnedInSpawnTime).TotalSeconds >= 10) + { + player.Message($"You spawned in the {region.Name}, please leave within {(int)(90 - (now - spawnedInSpawnTime).TotalSeconds)} seconds!", 1f); + } + } + } + else + { + if (enteredSpawnTimeStr == string.Empty) + { + player.SetPlayerProperty(IPlayerProperties.IGeneralPlayerProperties.EnteredSpawnTime, now.ToUniversalTime().ToString()); + } + else if (DateTime.TryParse(enteredSpawnTimeStr, out var enteredSpawnTime)) + { + if ((now - enteredSpawnTime).TotalSeconds >= 20) + { + player.Kill(); + player.Message($"You were in the {region.Name} for too long!", 15f); + } + else + { + player.Message($"You entered the {region.Name}, please leave within {(int)(20 - (now - enteredSpawnTime).TotalSeconds)} seconds!", 1f); + } + } + } + } } \ No newline at end of file diff --git a/Events/VipGamemode.cs b/Events/VipGamemode.cs index 10ed003..e569e32 100644 --- a/Events/VipGamemode.cs +++ b/Events/VipGamemode.cs @@ -45,7 +45,7 @@ private void SetVipSettings(BattleBitPlayer player) player.Modifications.IsExposedOnMap = true; player.KickFromSquad(); player.JoinSquad(Squads.King); - player.SetPlayerProperty(PlayerProperties.IVipPlayerProperties.IsVip, "true"); + player.SetPlayerProperty(IPlayerProperties.IVipPlayerProperties.IsVip, "true"); } private static void SetNonVipSettings(BattleBitPlayer player) @@ -54,7 +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); + player.RemovePlayerProperty(IPlayerProperties.IVipPlayerProperties.IsVip); } // TODO: Implement function to increment player point contribution using player properties @@ -62,10 +62,11 @@ private static void SetNonVipSettings(BattleBitPlayer player) public override Task OnPlayerSpawning(BattleBitPlayer player, OnPlayerSpawnArguments request) { - if (request.Loadout.HeavyGadget.Name.ToLower().Contains("rpg") || request.Loadout.LightGadget.Name.ToLower().Contains("c4") || request.Loadout.LightGadget.Name.ToLower().Contains("claymore") || request.Loadout.Throwable.Name.ToLower().Contains("impact") || request.Loadout.Throwable.Name.ToLower().Contains("frag")) + if (request.Loadout.HeavyGadget.Name.ToLower().Contains("rpg") || request.Loadout.LightGadget.Name.ToLower().Contains("mine") || request.Loadout.LightGadget.Name.ToLower().Contains("c4") || request.Loadout.LightGadget.Name.ToLower().Contains("claymore") || request.Loadout.Throwable.Name.ToLower().Contains("impact") || request.Loadout.Throwable.Name.ToLower().Contains("frag")) { + var color = new[] { "Red", "Green", "Blue" }[_random.Next(3)]; player.SayToChat($"{RichTextHelper.FromColorName("Orange")}You can't use explosives in this gamemode."); - player.Message($"{RichTextHelper.FromColorName("Orange")}You can't use explosives in this gamemode.", 10); + player.Message($"{RichTextHelper.FromColorName(color)}{RichTextHelper.Bold(true)}You can't use explosives in this gamemode.{RichTextHelper.Bold(false)}", 10); return Task.FromResult(null); } @@ -76,7 +77,18 @@ private static void SetNonVipSettings(BattleBitPlayer player) if (_teamAVip == null && _lastTeamAVipSteamId != player.SteamID) { SetVipSettings(player); - request.Wearings = PlayerOutfits.BlueTeam; + + foreach (var teamAPlayer in Server.AllTeamAPlayers) + { + if (teamAPlayer != _teamBVip) + teamAPlayer.Message($"The new VIP in your Team is {RichTextHelper.FromColorName("Gold")}{_teamAVip.Name}"); + } + + request.Wearings.Head = PlayerOutfits.BlueTeam.Head; + request.Wearings.Chest = PlayerOutfits.BlueTeam.Chest; + request.Wearings.Belt = PlayerOutfits.BlueTeam.Belt; + request.Wearings.Backbag = PlayerOutfits.BlueTeam.Backbag; + request.Wearings.Uniform = PlayerOutfits.BlueTeam.Uniform; request.Loadout.PrimaryWeapon = new WeaponItem() { Tool = Weapons.M249, @@ -101,7 +113,18 @@ private static void SetNonVipSettings(BattleBitPlayer player) if (_teamBVip == null && _lastTeamBVipSteamId != player.SteamID) { SetVipSettings(player); - request.Wearings = PlayerOutfits.RedTeam; + + foreach (var teamBPlayer in Server.AllTeamBPlayers) + { + if (teamBPlayer != _teamBVip) + teamBPlayer.Message($"The new VIP in your Team is {RichTextHelper.FromColorName("Gold")}{_teamBVip.Name}"); + } + + request.Wearings.Head = PlayerOutfits.RedTeam.Head; + request.Wearings.Chest = PlayerOutfits.RedTeam.Chest; + request.Wearings.Belt = PlayerOutfits.RedTeam.Belt; + request.Wearings.Backbag = PlayerOutfits.RedTeam.Backbag; + request.Wearings.Uniform = PlayerOutfits.RedTeam.Uniform; request.Loadout.PrimaryWeapon = new WeaponItem() { Tool = Weapons.M249, @@ -135,8 +158,8 @@ public override Task OnGameStateChanged(GameState oldState, GameState newState) { case GameState.Playing: Server.RoundSettings.SecondsLeft = 100000; - Server.RoundSettings.TeamATickets = 350; - Server.RoundSettings.TeamBTickets = 350; + Server.RoundSettings.TeamATickets = 450; + Server.RoundSettings.TeamBTickets = 450; break; case GameState.CountingDown: Server.RoundSettings.SecondsLeft = 10; @@ -188,13 +211,18 @@ public override Task OnAPlayerDownedAnotherPlayer(OnPlayerKillArguments + /// General player properties + /// + public interface IGeneralPlayerProperties + { + public const string SpawnedInSpawn = "spawned_in_spawn"; + public const string SpawnedInSpawnTime = "spawned_in_spawn_time"; + public const string EnteredSpawnTime = "entered_spawn_time"; + } + /// /// Hide and Seek player properties /// @@ -40,8 +50,5 @@ public interface IInfectedPlayerProperties public interface IVipPlayerProperties { public const string IsVip = "player_is_vip"; - public const string SpawnedInSpawn = "spawned_in_spawn"; - public const string SpawnedInSpawnTime = "spawned_in_spawn_time"; - public const string EnteredSpawnTime = "entered_spawn_time"; } } \ No newline at end of file