Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Allow the administrator to give points to players #127

Merged
merged 3 commits into from
Oct 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions src/Application/Common/Resources/Messages.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions src/Application/Common/Resources/Messages.resx
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,12 @@
<data name="GameModeDescription" xml:space="preserve">
<value>~r~Welcome to Capture The Flag mode~n~~y~It is a game mode in which two teams (Alpha and Beta) compete to capture the other team's flag and bring it back to their own base to score a point</value>
</data>
<data name="GivePointsToAllPlayers" xml:space="preserve">
<value>{PlayerName} has generously given {Points} points to all the players!</value>
</data>
<data name="GivePointsToPlayer" xml:space="preserve">
<value>You have given {Points} points to {PlayerName}</value>
</data>
<data name="InsufficientPoints" xml:space="preserve">
<value>You do not have enough points to obtain this combo</value>
</data>
Expand Down Expand Up @@ -282,6 +288,9 @@
<data name="RankUpAward" xml:space="preserve">
<value>You have gained +100 points, +100 armour, and +100 health</value>
</data>
<data name="ReceivePointsFromPlayer" xml:space="preserve">
<value>Congratulations! You've received {Points} points from {PlayerName}!</value>
</data>
<data name="RedeemedPoints" xml:space="preserve">
<value>{PlayerName} redeemed their points for the combo: {ComboName}</value>
</data>
Expand Down
4 changes: 2 additions & 2 deletions src/Application/Players/Accounts/Systems/ChangeRoleSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@ public void SetRole(
if (currentPlayer.HasLowerRoleThan(RoleId.Admin))
return;

if(currentPlayer == targetPlayer)
if (currentPlayer == targetPlayer)
{
currentPlayer.SendClientMessage(Color.Red, Messages.PlayerIsEqualsToTargetPlayer);
return;
}

if(targetPlayer.IsUnauthenticated())
if (targetPlayer.IsUnauthenticated())
{
currentPlayer.SendClientMessage(Color.Red, Messages.UnauthenticatedPlayer);
return;
Expand Down
70 changes: 70 additions & 0 deletions src/Application/Players/Accounts/Systems/PlayerPointsSystem.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
namespace CTF.Application.Players.Accounts.Systems;

public class PlayerPointsSystem(
IEntityManager entityManager,
IWorldService worldService,
PlayerStatsRenderer playerStatsRenderer) : ISystem
{
[PlayerCommand("givepoints")]
public void GivePointsToPlayer(
Player currentPlayer,
[CommandParameter(Name = "playerId")]Player targetPlayer,
int points)
{
if (currentPlayer.HasLowerRoleThan(RoleId.Admin))
return;

PlayerInfo targetPlayerInfo = targetPlayer.GetInfo();
Result result = targetPlayerInfo.StatsPerRound.AddPoints(points);
if (result.IsFailed)
{
currentPlayer.SendClientMessage(Color.Red, result.Message);
return;
}

{
var message = Smart.Format(Messages.GivePointsToPlayer, new
{
Points = points,
PlayerName = targetPlayer.Name
});
currentPlayer.SendClientMessage(Color.Yellow, message);
}
{
var message = Smart.Format(Messages.ReceivePointsFromPlayer, new
{
Points = points,
PlayerName = currentPlayer.Name
});
targetPlayer.SendClientMessage(Color.Yellow, message);
}
playerStatsRenderer.UpdateTextDraw(targetPlayer);
}

[PlayerCommand("giveallpoints")]
public void GivePointsToAllPlayers(Player currentPlayer, int points)
{
if (currentPlayer.HasLowerRoleThan(RoleId.Admin))
return;

IEnumerable<Player> players = entityManager.GetComponents<Player>();
foreach(Player targetPlayer in players)
{
PlayerInfo targetPlayerInfo = targetPlayer.GetInfo();
Result result = targetPlayerInfo.StatsPerRound.AddPoints(points);
if (result.IsFailed)
{
currentPlayer.SendClientMessage(Color.Red, result.Message);
return;
}
playerStatsRenderer.UpdateTextDraw(targetPlayer);
}

var message = Smart.Format(Messages.GivePointsToAllPlayers, new
{
PlayerName = currentPlayer.Name,
Points = points
});
worldService.SendClientMessage(Color.Yellow, message);
}
}
Loading