Skip to content

Commit

Permalink
fix: Prevent the player from returning to class selection after death (
Browse files Browse the repository at this point in the history
…#73)

Do not allow the player to return to class selection after death. This prevents a bug where the team counter can be affected. For example, if Player A is from Team Alpha and returns to class selection to choose Team Alpha again, it would result in duplicate team members, which is incorrect.
  • Loading branch information
MrDave1999 authored Sep 11, 2024
1 parent 981fa58 commit c3acb80
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 1 deletion.
7 changes: 7 additions & 0 deletions src/Application/Players/ClassSelectionSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,13 @@ public void OnPlayerConnect(Player player)
[Event]
public void OnPlayerRequestClass(Player player, int classId)
{
if(player.HasForcedClassSelectionAfterDeath())
{
player.SetSpawnInfo(player.Team, player.Skin, player.Position, player.Angle);
player.Spawn();
return;
}

player.Color = Color.White;
player.Position = new Vector3(-1389.137451, 3314.043701, 20.493314);
player.CameraPosition = new Vector3(-1399.776000, 3310.254150, 21.525623);
Expand Down
19 changes: 19 additions & 0 deletions src/Application/Players/Extensions/ClassSelectionExtensions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
namespace CTF.Application.Players.Extensions;

public static class ClassSelectionExtensions
{
public static bool IsInClassSelection(this Player player)
=> player.GetComponent<ClassSelectionComponent>().IsInClassSelection;

public static bool IsNotInClassSelection(this Player player)
=> !player.IsInClassSelection();

public static bool HasForcedClassSelectionAfterDeath(this Player player)
=> !player.IsInClassSelection();

public static void SetInClassSelection(this Player player)
=> player.GetComponent<ClassSelectionComponent>().IsInClassSelection = true;

public static void RemoveFromClassSelection(this Player player)
=> player.GetComponent<ClassSelectionComponent>().IsInClassSelection = false;
}
2 changes: 1 addition & 1 deletion src/Application/Players/PlayerSpawnSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public bool OnPlayerRequestSpawn(Player player)
player.GameText(gameText, 999999999, 3);
return false;
}
player.GetComponent<ClassSelectionComponent>().IsInClassSelection = false;
player.RemoveFromClassSelection();
player.GameText("_", 1000, 4);
accountComponent.PlayerInfo.SetTeam(selectedTeam.Id);
selectedTeam.Members.Add(player);
Expand Down

0 comments on commit c3acb80

Please sign in to comment.