Skip to content

Commit

Permalink
Fix hide and seek, make sure commands hide other messages for 5s
Browse files Browse the repository at this point in the history
  • Loading branch information
Bims-sh committed Sep 13, 2024
1 parent 9d80b79 commit b3cab5c
Show file tree
Hide file tree
Showing 8 changed files with 145 additions and 129 deletions.
15 changes: 15 additions & 0 deletions Api/BattleBitPlayer.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System.Collections.Concurrent;
using BattleBitAPI;
using BattleBitMinigames.Enums;
using BattleBitMinigames.Interfaces;

namespace BattleBitMinigames.Api;
public class BattleBitPlayer : Player<BattleBitPlayer>
Expand Down Expand Up @@ -72,4 +73,18 @@ public void ClearAllPlayerProperties()
{
PlayerProperties.Clear();
}

public bool CanReceiveMessage()
{
var now = DateTime.UtcNow;
var lastMessageSentTimeStr = GetPlayerProperty(IPlayerProperties.IGeneralPlayerProperties.LastMessageSentTime);

if (DateTime.TryParse(lastMessageSentTimeStr, out var lastMessageSentTime))
{
if ((now - lastMessageSentTime).TotalSeconds <= 5)
return false;
}

return true;
}
}
8 changes: 7 additions & 1 deletion ChatCommands/ChatCommand.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using BattleBitMinigames.Api;
using BattleBitMinigames.Enums;
using BattleBitMinigames.Interfaces;
using log4net;

namespace BattleBitMinigames.ChatCommands;
Expand Down Expand Up @@ -31,6 +32,11 @@ public override string ToString()

public bool CanExecute(BattleBitPlayer player)
{
return player.PlayerRoles.Any(role => role >= MinimumRequiredRole);
var canExec = player.PlayerRoles.Any(role => role >= MinimumRequiredRole);

if (canExec)
player.SetPlayerProperty(IPlayerProperties.IGeneralPlayerProperties.LastMessageSentTime, DateTime.UtcNow.ToUniversalTime().ToString());

return canExec;
}
}
219 changes: 104 additions & 115 deletions Events/HideAndSeekGamemode.cs

Large diffs are not rendered by default.

6 changes: 6 additions & 0 deletions Events/RegionManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,8 @@ private void HandlePlayerInRegion(BattleBitPlayer player, RegionHelper.Region re
var spawnedInSpawn = player.GetPlayerProperty(IPlayerProperties.IGeneralPlayerProperties.SpawnedInSpawn);
var spawnedInSpawnTimeStr = player.GetPlayerProperty(IPlayerProperties.IGeneralPlayerProperties.SpawnedInSpawnTime);
var enteredSpawnTimeStr = player.GetPlayerProperty(IPlayerProperties.IGeneralPlayerProperties.EnteredSpawnTime);

if (!player.CanReceiveMessage()) return;

if (spawnedInSpawn == "true")
{
Expand All @@ -135,6 +137,8 @@ private void HandlePlayerInRegion(BattleBitPlayer player, RegionHelper.Region re
{
player.Message($"You spawned in the {region.Name}, please leave within {(int)(90 - (now - spawnedInSpawnTime).TotalSeconds)} seconds!", 1f);
}

player.SetPlayerProperty(IPlayerProperties.IGeneralPlayerProperties.LastMessageSentTime, now.ToUniversalTime().ToString());
}
}
else
Expand All @@ -154,6 +158,8 @@ private void HandlePlayerInRegion(BattleBitPlayer player, RegionHelper.Region re
{
player.Message($"You entered the {region.Name}, please leave within {(int)(20 - (now - enteredSpawnTime).TotalSeconds)} seconds!", 1f);
}

player.SetPlayerProperty(IPlayerProperties.IGeneralPlayerProperties.LastMessageSentTime, now.ToUniversalTime().ToString());
}
}
}
Expand Down
19 changes: 11 additions & 8 deletions Events/ServerSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,24 +7,24 @@ public class ServerSettings : Event
{
public override Task OnConnected()
{
foreach (var Map in Server.MapRotation.GetMapRotation())
foreach (var map in Server.MapRotation.GetMapRotation())
{
Server.MapRotation.RemoveFromRotation(Map);
Server.MapRotation.RemoveFromRotation(map);
}

foreach (var Gamemode in Server.GamemodeRotation.GetGamemodeRotation())
foreach (var gamemode in Server.GamemodeRotation.GetGamemodeRotation())
{
Server.GamemodeRotation.RemoveFromRotation(Gamemode);
Server.GamemodeRotation.RemoveFromRotation(gamemode);
}

foreach (var Map in Program.ServerConfiguration.MapRotation)
foreach (var map in Program.ServerConfiguration.MapRotation)
{
Server.MapRotation.AddToRotation(Map);
Server.MapRotation.AddToRotation(map);
}

foreach (var Gamemode in Program.ServerConfiguration.GamemodeRotation)
foreach (var gamemode in Program.ServerConfiguration.GamemodeRotation)
{
Server.GamemodeRotation.AddToRotation(Gamemode);
Server.GamemodeRotation.AddToRotation(gamemode);
}

if (!Server.MapRotation.GetMapRotation().Any())
Expand All @@ -36,6 +36,9 @@ public override Task OnConnected()
{
Program.ReloadConfiguration();
}

Server.ExecuteCommand("setspeedhackdetection false");
Server.ExecuteCommand("setmaxping 999");

var serverRotation = Server.MapRotation.GetMapRotation();
Program.Logger.Info($"Loaded Map Rotation: {string.Join(", ", serverRotation)}");
Expand Down
5 changes: 0 additions & 5 deletions Events/ZombiesGamemode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -131,11 +131,6 @@ private void SetServerSettings()
loadingScreen.AppendLine($"- Do not defend anywhere infected can't access");
Server.SetLoadingScreenText(loadingScreen.ToString());

Server.GamemodeRotation.ClearRotation();
Server.GamemodeRotation.SetRotation("DOMI");
Server.ExecuteCommand("setsize ultra");
Server.ExecuteCommand("setspeedhackdetection false");
Server.ExecuteCommand("setmaxping 999");
Server.ServerSettings.UnlockAllAttachments = true;
Server.ServerSettings.PlayerCollision = true;
Server.ServerSettings.HideMapVotes = false;
Expand Down
1 change: 1 addition & 0 deletions Helpers/CustomGamemodeHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ public static void SetCustomGameMode(string gm, BattleBitServer server)
break;
case "hideandseek":
server.AddEvents(CustomGameModeEvents.HideAndSeekEvents);
server.SetServerSizeForNextMatch(MapSize._127vs127);
server.ForceEndGame();
break;
case "gungame":
Expand Down
1 change: 1 addition & 0 deletions Interfaces/PlayerProperties.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ 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";
public const string LastMessageSentTime = "last_message_sent_time";
}

/// <summary>
Expand Down

0 comments on commit b3cab5c

Please sign in to comment.