generated from Bims-sh/BattleBitApi
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
254 additions
and
101 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
using System.Numerics; | ||
using BattleBitMinigames.Handlers; | ||
|
||
namespace BattleBitMinigames.Data.Regions; | ||
|
||
public class WineparadiseRegions | ||
{ | ||
// 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<Vector2> | ||
{ | ||
new (-92, -271), | ||
new (-197, -142), | ||
new (-338, -18), | ||
new (-387, 190), | ||
new (-605, -27), | ||
new (-660, -275), | ||
new (-510, -372), | ||
new (-297, -352) | ||
} | ||
); | ||
|
||
// 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<Vector2> | ||
{ | ||
new (-121, 397), | ||
new (0, 346), | ||
new (140, 182), | ||
new (313, 90), | ||
new (353, 124), | ||
new (380, 289), | ||
new (332, 455), | ||
new (160, 526), | ||
new (-54, 455) | ||
} | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,44 +1,128 @@ | ||
using System.Numerics; | ||
using System.Globalization; | ||
using System.Numerics; | ||
using BattleBitAPI.Common; | ||
using BattleBitMinigames.Api; | ||
using BattleBitMinigames.Data; | ||
using BattleBitMinigames.Handlers; | ||
using BattleBitMinigames.Helpers; | ||
using BattleBitMinigames.Interfaces; | ||
|
||
namespace BattleBitMinigames.Events; | ||
|
||
public class RegionManager : Event | ||
{ | ||
bool Enabled = true; | ||
private CancellationTokenSource? _cancellationTokenSource; | ||
|
||
private void StartRegionManager() | ||
{ | ||
Program.Logger.Info("Started RegionManager!"); | ||
_cancellationTokenSource = new CancellationTokenSource(); | ||
var cancellationToken = _cancellationTokenSource.Token; | ||
|
||
Task.Run(async () => | ||
{ | ||
while (Server.IsConnected) | ||
while (Server.IsConnected && !cancellationToken.IsCancellationRequested) | ||
{ | ||
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) | ||
{ | ||
// TODO: Remove in prod | ||
player.Message($"You are in {RichTextHelper.Bold(true)}{region.Name}{RichTextHelper.Bold(false)}!", 999); | ||
// TODO: Spawn task to kill player after X amount of time, make message prettier. | ||
} | ||
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 (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 | ||
{ | ||
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)) | ||
{ | ||
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!"); | ||
} | ||
} | ||
} | ||
} | ||
else | ||
{ | ||
player.Message("You are not in a region!", 1); | ||
// Reset properties when a player leaves the spawn region | ||
player.RemovePlayerProperty(PlayerProperties.IVipPlayerProperties.SpawnedInSpawn); | ||
player.RemovePlayerProperty(PlayerProperties.IVipPlayerProperties.EnteredSpawnTime); | ||
player.RemovePlayerProperty(PlayerProperties.IVipPlayerProperties.SpawnedInSpawnTime); | ||
} | ||
} | ||
|
||
await Task.Delay(1000); | ||
await Task.Delay(1000, cancellationToken); | ||
} | ||
|
||
Program.Logger.Info("RegionManager stopped."); | ||
}, cancellationToken); | ||
} | ||
|
||
private void StopRegionManager() | ||
{ | ||
if (_cancellationTokenSource is { IsCancellationRequested: false }) | ||
{ | ||
_cancellationTokenSource.Cancel(); | ||
Program.Logger.Info("Stopping RegionManager..."); | ||
} | ||
} | ||
|
||
public override Task<bool> OnPlayerTypedMessage(BattleBitPlayer player, ChatChannel channel, string msg) | ||
{ | ||
if (player.GetHighestRole() == Enums.PlayerRoles.Admin) | ||
{ | ||
if (msg.Contains("?rgm start")) | ||
{ | ||
StartRegionManager(); | ||
} | ||
else if (msg.Contains("?rgm stop")) | ||
{ | ||
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()); | ||
} | ||
|
||
return base.OnPlayerSpawned(player); | ||
} | ||
|
||
public override Task OnConnected() | ||
{ | ||
StartRegionManager(); | ||
return Task.CompletedTask; | ||
} | ||
} | ||
} |
Oops, something went wrong.