Skip to content

Commit

Permalink
Finish VIP gamemode
Browse files Browse the repository at this point in the history
  • Loading branch information
Bims-sh committed Aug 9, 2024
1 parent 43a6777 commit 420ba02
Show file tree
Hide file tree
Showing 8 changed files with 133 additions and 21 deletions.
3 changes: 2 additions & 1 deletion ChatCommands/ChatCommandList.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ public class ChatCommandList
public static List<ChatCommand> AdminCommands { get; } = new()
{
new PlayerDebug(),
new TeleportCommand()
new TeleportCommand(),
new StopServerAndApi()
};

public static List<ChatCommand> ModeratorCommands { get; } = new()
Expand Down
36 changes: 36 additions & 0 deletions ChatCommands/StopServerAndApi.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
using BattleBitMinigames.Enums;
using BattleBitMinigames.Helpers;

namespace BattleBitMinigames.ChatCommands;

public class StopServerAndApi : ChatCommand
{
public StopServerAndApi() : base(
name: "stop",
description: "Stop :)",
usage: "stop",
minimumRequiredRole: PlayerRoles.Admin
)
{
Action = (args, player) =>
{
if (!CanExecute(player))
{
player.Message("You do not have permission to execute this command.");
return;
}

Program.Logger.Info("Closing Server...");
Server.StopServer();
Server.AnnounceLong("Stopping...");

while (Server.IsConnected)
{
Thread.Sleep(1000);
}

Program.Logger.Info("Quitting API...");
Environment.Exit(-1);
};
}
}
5 changes: 5 additions & 0 deletions Data/RegionList.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,11 @@ public class RegionList
WineParadiseRegions.TeamASafeZone,
WineParadiseRegions.TeamBSafeZone
},
"TensaTown" => new List<RegionHelper.Region?>
{
TensaTownRegions.TeamASafeZone,
TensaTownRegions.TeamBSafeZone
},
_ => new List<RegionHelper.Region?>()
};
}
Expand Down
60 changes: 60 additions & 0 deletions Data/Regions/TensaTownRegions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
using System.Numerics;
using BattleBitMinigames.Handlers;

namespace BattleBitMinigames.Data.Regions;

public class TensaTownRegions
{
// 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 (300, -125),
new (265, -187),
new (278, -242),
new (246, -285),
new (162, -272),
new (110, -243),
new (64, -226),
new (-39, -193),
new (-116, -192),
new (-187, -233),
new (-188, -244),
new (-18, -389),
new (306, -436),
new (393, -367),
new (430, -266),
new (341, -155)
}
);

// 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 (-199, 86),
new (-141, 111),
new (-96, 185),
new (-76, 230),
new (-49, 312),
new (-30, 317),
new (38, 342),
new (83, 352),
new (132, 348),
new (135, 248),
new (207, 189),
new (251, 161),
new (324, 142),
new (356, 213),
new (-276, 277),
new (194, 407),
new (-178, 377),
new (-277, 303),
new (-274, 188)
}
);
}
20 changes: 13 additions & 7 deletions Events/RegionManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ private void StartRegionManager()
if (Program.ServerConfiguration.LaunchCustomGamemode == "vip")
{
var isVip = player.GetPlayerProperty(PlayerProperties.IVipPlayerProperties.IsVip);
if (isVip == "" || isVip == "false") continue;
if (isVip != "true") continue;

var now = DateTime.UtcNow;
var spawnedInSpawn =
Expand All @@ -51,10 +51,11 @@ private void StartRegionManager()
player.Message($"You spawned in the {region.Name} and stayed for too long!",
15);
}
else
else if ((now - spawnedInSpawnTime).TotalSeconds >= 10)
{
player.Message(
$"You spawned in the {region.Name}, please leave within {(int)(90 - (now - spawnedInSpawnTime).TotalSeconds)} seconds!");
$"You spawned in the {region.Name}, please leave within {(int)(90 - (now - spawnedInSpawnTime).TotalSeconds)} seconds!",
1f);
}
}
}
Expand All @@ -75,7 +76,8 @@ private void StartRegionManager()
else
{
player.Message(
$"You entered the {region.Name}, please leave within {(int)(20 - (now - enteredSpawnTime).TotalSeconds)} seconds!");
$"You entered the {region.Name}, please leave within {(int)(20 - (now - enteredSpawnTime).TotalSeconds)} seconds!",
1f);
}
}
}
Expand Down Expand Up @@ -136,9 +138,13 @@ public override Task OnPlayerSpawned(BattleBitPlayer player)
return base.OnPlayerSpawned(player);
}

public override Task OnConnected()
public override Task OnGameStateChanged(GameState oldState, GameState newState)
{
StartRegionManager();
return Task.CompletedTask;
if (newState == GameState.Playing)
StartRegionManager();

if (newState == GameState.EndingGame)
StopRegionManager();
return base.OnGameStateChanged(oldState, newState);
}
}
11 changes: 9 additions & 2 deletions Events/VipGamemode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using BattleBitAPI.Server;
using BattleBitMinigames.Api;
using BattleBitMinigames.Helpers;
using BattleBitMinigames.Interfaces;

namespace BattleBitMinigames.Events;

Expand All @@ -10,6 +11,8 @@ public class VipGamemode : Event
private Random _random = new();
private BattleBitPlayer? _teamAVip;
private BattleBitPlayer? _teamBVip;
private ulong? _lastTeamAVipSteamId;
private ulong? _lastTeamBVipSteamId;

private bool IsPlayerVip(BattleBitPlayer player)
{
Expand All @@ -22,9 +25,11 @@ private void SetVipSettings(BattleBitPlayer player)
{
case Team.TeamA:
_teamAVip = player;
_lastTeamAVipSteamId = player.SteamID;
break;
case Team.TeamB:
_teamBVip = player;
_lastTeamBVipSteamId = player.SteamID;
break;
case Team.None:
break;
Expand All @@ -40,6 +45,7 @@ private void SetVipSettings(BattleBitPlayer player)
player.Modifications.IsExposedOnMap = true;
player.KickFromSquad();
player.JoinSquad(Squads.King);
player.SetPlayerProperty(PlayerProperties.IVipPlayerProperties.IsVip, "true");
}

private static void SetNonVipSettings(BattleBitPlayer player)
Expand All @@ -48,6 +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);
}

// TODO: Implement function to increment player point contribution using player properties
Expand All @@ -66,7 +73,7 @@ private static void SetNonVipSettings(BattleBitPlayer player)
{
case Team.TeamA:
{
if (_teamAVip == null)
if (_teamAVip == null && _lastTeamAVipSteamId != player.SteamID)
{
SetVipSettings(player);
request.Wearings = PlayerOutfits.BlueTeam;
Expand All @@ -91,7 +98,7 @@ private static void SetNonVipSettings(BattleBitPlayer player)
}
case Team.TeamB:
{
if (_teamBVip == null)
if (_teamBVip == null && _lastTeamBVipSteamId != player.SteamID)
{
SetVipSettings(player);
request.Wearings = PlayerOutfits.RedTeam;
Expand Down
2 changes: 1 addition & 1 deletion Helpers/CustomGamemodeHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ public static void SetCustomGameMode(string gm, BattleBitServer server)
if (IsValidCustomGamemode(gm))
{
server.ResetEvents();
server.SetServerSizeForNextMatch(MapSize._127vs127);

switch (gm.ToLower())
{
Expand All @@ -34,6 +33,7 @@ public static void SetCustomGameMode(string gm, BattleBitServer server)
break;
case "vip":
server.AddEvents(CustomGameModeEvents.VipEvents);
server.SetServerSizeForNextMatch(MapSize._127vs127);
server.ForceEndGame();
break;
case "hideandseek":
Expand Down
17 changes: 7 additions & 10 deletions Helpers/RoleHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,15 @@ public class RoleHelper
{
public static List<ulong> Admins = new()
{
76561198395073327,
76561198035784951,
76561198855127416
76561198395073327, // Bims
76561198035784951, // AgentSmith
76561198173566107, // Julgers
76561198051546518, // Terminal
76561199056414354, // Pom
76561198833659544 // Silly
};

public static List<ulong> Moderators = new()
{
76561198173566107,
76561198051546518,
76561199056414354,
76561198833659544
};
public static List<ulong> Moderators = new() { };

public static List<ulong> Vips = new() { };

Expand Down

0 comments on commit 420ba02

Please sign in to comment.