Skip to content

Commit

Permalink
fix a few things
Browse files Browse the repository at this point in the history
  • Loading branch information
Bims-sh committed Aug 9, 2024
1 parent 89e2fa0 commit 43a6777
Show file tree
Hide file tree
Showing 8 changed files with 68 additions and 49 deletions.
7 changes: 3 additions & 4 deletions Data/RegionList.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using System.Numerics;
using BattleBitMinigames.Data.Regions;
using BattleBitMinigames.Data.Regions;
using BattleBitMinigames.Handlers;

namespace BattleBitMinigames.Data;
Expand All @@ -17,8 +16,8 @@ public class RegionList
},
"WineParadise" => new List<RegionHelper.Region?>
{
WineparadiseRegions.TeamASafeZone,
WineparadiseRegions.TeamBSafeZone
WineParadiseRegions.TeamASafeZone,
WineParadiseRegions.TeamBSafeZone
},
_ => new List<RegionHelper.Region?>()
};
Expand Down
2 changes: 1 addition & 1 deletion Data/Regions/WineparadiseRegions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

namespace BattleBitMinigames.Data.Regions;

public class WineparadiseRegions
public class WineParadiseRegions
{
// US safe zone
public static readonly RegionHelper.Region TeamASafeZone = new (
Expand Down
88 changes: 52 additions & 36 deletions Events/RegionManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,11 @@
using BattleBitMinigames.Interfaces;

namespace BattleBitMinigames.Events;

public class RegionManager : Event
{
private CancellationTokenSource? _cancellationTokenSource;

private void StartRegionManager()
{
Program.Logger.Info("Started RegionManager!");
Expand All @@ -21,47 +22,61 @@ private void StartRegionManager()
{
while (Server.IsConnected && !cancellationToken.IsCancellationRequested)
{
foreach (var player in Server.AllPlayers.Where(player => player.IsAlive && player.Position != Vector3.Zero))
foreach (var player in Server.AllPlayers.Where(player =>
player.IsAlive && player.Position != Vector3.Zero))
{
var region = RegionHelper.GetIsPlayerInRegion(RegionList.GetMapRegions(Server.Map), player);
if (region != null)
{
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")
if (Program.ServerConfiguration.LaunchCustomGamemode == "vip")
{
if (DateTime.TryParse(spawnedInSpawnTimeStr, out var spawnedInSpawnTime))
var isVip = player.GetPlayerProperty(PlayerProperties.IVipPlayerProperties.IsVip);
if (isVip == "" || isVip == "false") 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")
{
if ((now - spawnedInSpawnTime).TotalSeconds >= 90)
{
player.Kill();
player.Message($"You spawned in the {region.Name} and stayed for too long!", 15);
}
else
if (DateTime.TryParse(spawnedInSpawnTimeStr, out var spawnedInSpawnTime))
{
player.Message($"You spawned in the {region.Name}, please leave within {(int)(90 - (now - spawnedInSpawnTime).TotalSeconds)} seconds!");
if ((now - spawnedInSpawnTime).TotalSeconds >= 90)
{
player.Kill();
player.Message($"You spawned in the {region.Name} and stayed for too long!",
15);
}
else
{
player.Message(
$"You spawned in the {region.Name}, please leave within {(int)(90 - (now - spawnedInSpawnTime).TotalSeconds)} seconds!");
}
}
}
}
else
{
if (enteredSpawnTimeStr == string.Empty)
{
player.SetPlayerProperty(PlayerProperties.IVipPlayerProperties.EnteredSpawnTime, now.ToUniversalTime().ToString());
}
else if (DateTime.TryParse(enteredSpawnTimeStr, out var enteredSpawnTime))
else
{
if ((now - enteredSpawnTime).TotalSeconds >= 20)
if (enteredSpawnTimeStr == string.Empty)
{
player.Kill();
player.Message($"You were in the {region.Name} for too long!", 15);
player.SetPlayerProperty(PlayerProperties.IVipPlayerProperties.EnteredSpawnTime,
now.ToUniversalTime().ToString());
}
else
else if (DateTime.TryParse(enteredSpawnTimeStr, out var enteredSpawnTime))
{
player.Message($"You entered the {region.Name}, please leave within {(int)(20 - (now - enteredSpawnTime).TotalSeconds)} seconds!");
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!");
}
}
}
}
Expand All @@ -77,7 +92,7 @@ private void StartRegionManager()

await Task.Delay(1000, cancellationToken);
}

Program.Logger.Info("RegionManager stopped.");
}, cancellationToken);
}
Expand All @@ -104,25 +119,26 @@ public override Task<bool> OnPlayerTypedMessage(BattleBitPlayer player, ChatChan
StopRegionManager();
}
}

return base.OnPlayerTypedMessage(player, channel, msg);
}

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, DateTime.UtcNow.ToString());
player.SetPlayerProperty(PlayerProperties.IVipPlayerProperties.SpawnedInSpawnTime,
DateTime.UtcNow.ToString());
}

return base.OnPlayerSpawned(player);
}

public override Task OnConnected()
{
StartRegionManager();
return Task.CompletedTask;
}
}
}
3 changes: 2 additions & 1 deletion Events/ServerSettings.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using BattleBitMinigames.Api;
using BattleBitAPI.Common;
using BattleBitMinigames.Api;

namespace BattleBitMinigames.Events;

Expand Down
1 change: 1 addition & 0 deletions Events/VipGamemode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@ public override Task OnGameStateChanged(GameState oldState, GameState newState)
Server.RoundSettings.TeamBTickets = 350;
break;
case GameState.CountingDown:
Server.RoundSettings.SecondsLeft = 10;
break;
case GameState.WaitingForPlayers:
break;
Expand Down
12 changes: 7 additions & 5 deletions Helpers/CustomGamemodeHelper.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using BattleBitMinigames.Api;
using BattleBitAPI.Common;
using BattleBitMinigames.Api;
using BattleBitMinigames.Data;

namespace BattleBitMinigames.Helpers;
Expand All @@ -23,24 +24,25 @@ public static void SetCustomGameMode(string gm, BattleBitServer server)
if (IsValidCustomGamemode(gm))
{
server.ResetEvents();
server.SetServerSizeForNextMatch(MapSize._127vs127);

switch (gm.ToLower())
{
case "zombies":
server.AddEvents(CustomGameModeEvents.ZombieEvents);
// server.ForceEndGame();
server.ForceEndGame();
break;
case "vip":
server.AddEvents(CustomGameModeEvents.VipEvents);
// server.ForceEndGame();
server.ForceEndGame();
break;
case "hideandseek":
server.AddEvents(CustomGameModeEvents.HideAndSeekEvents);
// server.ForceEndGame();
server.ForceEndGame();
break;
case "gungame":
server.AddEvents(CustomGameModeEvents.GunGameEvents);
// server.ForceEndGame();
server.ForceEndGame();
break;
default:
return;
Expand Down
3 changes: 1 addition & 2 deletions Helpers/RoleHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,7 @@ public class RoleHelper
76561198173566107,
76561198051546518,
76561199056414354,
76561198833659544,
286535187884408832
76561198833659544
};

public static List<ulong> Vips = new() { };
Expand Down
1 change: 1 addition & 0 deletions Interfaces/PlayerProperties.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ public interface IInfectedPlayerProperties
/// </summary>
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";
Expand Down

0 comments on commit 43a6777

Please sign in to comment.