Skip to content

Commit

Permalink
Finish VIP gamemode and RegionManager, implement RegionManager into h…
Browse files Browse the repository at this point in the history
…ideandseek
  • Loading branch information
Bims-sh committed Sep 13, 2024
1 parent d87fb21 commit 9d80b79
Show file tree
Hide file tree
Showing 8 changed files with 160 additions and 105 deletions.
2 changes: 1 addition & 1 deletion Data/CustomGameModeEvents.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public static class CustomGameModeEvents
public static readonly List<Event> HideAndSeekEvents = new()
{
new HideAndSeekGamemode(),
// new RegionManager()
new RegionManager()
};

public static readonly List<Event> GunGameEvents = new()
Expand Down
6 changes: 3 additions & 3 deletions Events/GunGameGamemode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
28 changes: 14 additions & 14 deletions Events/HideAndSeekGamemode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,51 +40,51 @@ 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!");
}

// 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}");
}

Expand Down Expand Up @@ -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);
});
Expand Down Expand Up @@ -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)}");
Expand Down Expand Up @@ -568,7 +568,7 @@ public override Task OnAPlayerDownedAnotherPlayer(OnPlayerKillArguments<BattleBi
{
AddPlayerHidersFound(killer);
MakePlayerSeeker(victim);
Server.SayToAllChat($"{RichTextHelper.Bold(true)}{killer.Name}{RichTextHelper.Bold(false)} found {RichTextHelper.Bold(true)}{victim.Name}{RichTextHelper.Bold(false)}! They've found {killer.GetPlayerProperty(PlayerProperties.IHideAndSeekPlayerProperties.HidersFound)} hiders!");
Server.SayToAllChat($"{RichTextHelper.Bold(true)}{killer.Name}{RichTextHelper.Bold(false)} found {RichTextHelper.Bold(true)}{victim.Name}{RichTextHelper.Bold(false)}! They've found {killer.GetPlayerProperty(IPlayerProperties.IHideAndSeekPlayerProperties.HidersFound)} hiders!");
}

// If all hiders are found, end the game
Expand Down
116 changes: 63 additions & 53 deletions Events/RegionManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,67 +28,34 @@ private void StartRegionManager()
var region = RegionHelper.GetIsPlayerInRegion(RegionList.GetMapRegions(Server.Map), player);
if (region != null)
{
if (Program.ServerConfiguration.LaunchCustomGamemode == "vip")
switch (Program.ServerConfiguration.LaunchCustomGamemode)
{
var isVip = player.GetPlayerProperty(PlayerProperties.IVipPlayerProperties.IsVip);
if (isVip != "true") continue;

var now = DateTime.UtcNow;
var spawnedInSpawn =
player.GetPlayerProperty(PlayerProperties.IVipPlayerProperties.SpawnedInSpawn);
var spawnedInSpawnTimeStr =
player.GetPlayerProperty(PlayerProperties.IVipPlayerProperties.SpawnedInSpawnTime);
var enteredSpawnTimeStr =
player.GetPlayerProperty(PlayerProperties.IVipPlayerProperties.EnteredSpawnTime);

if (spawnedInSpawn == "true")
case "vip":
{
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!",
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);
}
}

Expand Down Expand Up @@ -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());
}

Expand All @@ -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);
}
}
}
}
}
Loading

0 comments on commit 9d80b79

Please sign in to comment.