From 3ca33435e069eefe0134c635ef8fdebcfbbe3a94 Mon Sep 17 00:00:00 2001 From: MrDave1999 Date: Sat, 28 Sep 2024 08:56:21 -0500 Subject: [PATCH 1/3] feat: Add new resources for the team change command --- .../Common/Resources/Messages.Designer.cs | 45 +++++++++++++++++++ .../Common/Resources/Messages.resx | 15 +++++++ 2 files changed, 60 insertions(+) diff --git a/src/Application/Common/Resources/Messages.Designer.cs b/src/Application/Common/Resources/Messages.Designer.cs index 5610441..5d702a2 100644 --- a/src/Application/Common/Resources/Messages.Designer.cs +++ b/src/Application/Common/Resources/Messages.Designer.cs @@ -348,6 +348,15 @@ internal static string NoPermissions { } } + /// + /// Looks up a localized string similar to You do not belong to any team. + /// + internal static string NoTeam { + get { + return ResourceManager.GetString("NoTeam", resourceCulture); + } + } + /// /// Looks up a localized string similar to ~n~~n~~n~{GameText}Defend this flag from enemy capture!. /// @@ -429,6 +438,24 @@ internal static string PasswordSuccessfullyChanged { } } + /// + /// Looks up a localized string similar to Attention, team! {PlayerName} has made the switch and is now part of the {TeamName} team. + /// + internal static string PlayerHasChangedTeams { + get { + return ResourceManager.GetString("PlayerHasChangedTeams", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to You are already a member of that team. + /// + internal static string PlayerIsAlreadyInTeam { + get { + return ResourceManager.GetString("PlayerIsAlreadyInTeam", resourceCulture); + } + } + /// /// Looks up a localized string similar to That player name already exists. /// @@ -510,6 +537,24 @@ internal static string SuccessfulLogin { } } + /// + /// Looks up a localized string similar to The team is currently full. + /// + internal static string TeamIsFull { + get { + return ResourceManager.GetString("TeamIsFull", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Both teams have the same number of members. + /// + internal static string TeamsAreEqualInMembers { + get { + return ResourceManager.GetString("TeamsAreEqualInMembers", resourceCulture); + } + } + /// /// Looks up a localized string similar to It's a tie! Both teams couldn't beat each other this time. /// diff --git a/src/Application/Common/Resources/Messages.resx b/src/Application/Common/Resources/Messages.resx index 893833a..bb1a070 100644 --- a/src/Application/Common/Resources/Messages.resx +++ b/src/Application/Common/Resources/Messages.resx @@ -213,6 +213,9 @@ You do not have permissions to use this command + + You do not belong to any team + ~n~~n~~n~{GameText}Defend this flag from enemy capture! @@ -240,6 +243,12 @@ Password successfully changed. New password: {NewPassword} + + Attention, team! {PlayerName} has made the switch and is now part of the {TeamName} team + + + You are already a member of that team + That player name already exists @@ -267,6 +276,12 @@ You have successfully logged in + + The team is currently full + + + Both teams have the same number of members + It's a tie! Both teams couldn't beat each other this time From ba00d361449126684085ec58d9843f5a6861a907 Mon Sep 17 00:00:00 2001 From: MrDave1999 Date: Sat, 28 Sep 2024 08:57:34 -0500 Subject: [PATCH 2/3] feat(improve): Set the skin id from OnPlayerSpawn --- src/Application/Players/PlayerSpawnSystem.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/Application/Players/PlayerSpawnSystem.cs b/src/Application/Players/PlayerSpawnSystem.cs index 7b66eb1..f6ed102 100644 --- a/src/Application/Players/PlayerSpawnSystem.cs +++ b/src/Application/Players/PlayerSpawnSystem.cs @@ -15,6 +15,7 @@ public void OnPlayerSpawn(Player player) player.Interior = currentMap.Interior; player.Color = playerInfo.Team.ColorHex; player.Team = (int)playerInfo.Team.Id; + player.Skin = (int)playerInfo.Team.SkinId; if (playerInfo.HasSkin()) { player.Skin = playerInfo.SkinId; From 8d8d472a678b3d811045eba7bfed5537bf93b982 Mon Sep 17 00:00:00 2001 From: MrDave1999 Date: Sat, 28 Sep 2024 08:59:39 -0500 Subject: [PATCH 3/3] feat: Allow players to change teams --- .../Teams/Systems/ChangeTeamSystem.cs | 95 +++++++++++++++++++ 1 file changed, 95 insertions(+) create mode 100644 src/Application/Teams/Systems/ChangeTeamSystem.cs diff --git a/src/Application/Teams/Systems/ChangeTeamSystem.cs b/src/Application/Teams/Systems/ChangeTeamSystem.cs new file mode 100644 index 0000000..7f1c11d --- /dev/null +++ b/src/Application/Teams/Systems/ChangeTeamSystem.cs @@ -0,0 +1,95 @@ +namespace CTF.Application.Teams.Systems; + +public class ChangeTeamSystem( + IWorldService worldService, + IDialogService dialogService, + TeamTextDrawRenderer teamTextDrawRenderer, + OnFlagDropped onFlagDropped) : ISystem +{ + [PlayerCommand("team")] + public async void ShowTeams(Player player) + { + PlayerInfo playerInfo = player.GetInfo(); + if (playerInfo.Team == Team.None) + { + player.SendClientMessage(Color.Red, Messages.NoTeam); + return; + } + + var columnHeaders = new[] + { + "Name", + "Members" + }; + var tablistDialog = new TablistDialog( + caption: "Select a team", + button1: "Select", + button2: "Close", + columnHeaders); + + Team alphaTeam = Team.Alpha; + tablistDialog.Add(columns: + [ + $"{alphaTeam.ColorHex}{alphaTeam.Name}", + $"{alphaTeam.ColorHex}{alphaTeam.Members.Count}" + ], tag: alphaTeam); + + Team betaTeam = Team.Beta; + tablistDialog.Add(columns: + [ + $"{betaTeam.ColorHex}{betaTeam.Name}", + $"{betaTeam.ColorHex}{betaTeam.Members.Count}" + ], tag: betaTeam); + + TablistDialogResponse response = await dialogService.ShowAsync(player, tablistDialog); + if (response.IsRightButtonOrDisconnected()) + return; + + Team selectedTeam = response.Item.Tag as Team; + ChangeTeam(player, selectedTeam); + } + + private void ChangeTeam(Player player, Team selectedTeam) + { + Team alphaTeam = Team.Alpha; + Team betaTeam = Team.Beta; + PlayerInfo playerInfo = player.GetInfo(); + if (playerInfo.Team == selectedTeam) + { + player.SendClientMessage(Color.Red, Messages.PlayerIsAlreadyInTeam); + return; + } + + if (alphaTeam.Members.Count == betaTeam.Members.Count) + { + player.SendClientMessage(Color.Red, Messages.TeamsAreEqualInMembers); + return; + } + + if (selectedTeam.IsFull()) + { + player.SendClientMessage(Color.Red, Messages.TeamIsFull); + return; + } + + if (playerInfo.HasCapturedFlag()) + { + onFlagDropped.Handle(selectedTeam, player); + } + + Team rivalTeam = selectedTeam.RivalTeam; + selectedTeam.Members.Add(player); + rivalTeam.Members.Remove(player); + teamTextDrawRenderer.UpdateTeamMembers(selectedTeam); + teamTextDrawRenderer.UpdateTeamMembers(rivalTeam); + var message = Smart.Format(Messages.PlayerHasChangedTeams, new + { + PlayerName = player.Name, + TeamName = selectedTeam.Name + }); + worldService.SendClientMessage(selectedTeam.ColorHex, message); + playerInfo.SetTeam(selectedTeam.Id); + player.Team = (int)selectedTeam.Id; + player.Spawn(); + } +}