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 to set the team from the PlayerInfo type #27

Merged
merged 3 commits into from
Aug 19, 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
9 changes: 9 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.

3 changes: 3 additions & 0 deletions src/Application/Common/Resources/Messages.resx
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,9 @@
<data name="InvalidSkin" xml:space="preserve">
<value>Skin ID must be between 0 and 311</value>
</data>
<data name="InvalidTeam" xml:space="preserve">
<value>Invalid team has been passed. Should be Alpha = 0, Beta = 1 or NoTeam = 255</value>
</data>
<data name="InvalidWeapon" xml:space="preserve">
<value>Invalid weapon has been passed</value>
</data>
Expand Down
20 changes: 20 additions & 0 deletions src/Application/Players/Accounts/PlayerInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ public PlayerInfo() { }
public RoleId RoleId { get; private set; } = RoleId.Basic;
public int SkinId { get; private set; } = NoSkin;
public RankId RankId { get; private set; } = RankId.Noob;
public Team Team { get; private set; } = Team.None;
public DateTime CreatedAt { get; private set; } = DateTime.UtcNow;
public DateTime LastConnection { get; private set; } = DateTime.UtcNow;

Expand Down Expand Up @@ -149,6 +150,25 @@ public Result SetSkin(int id)
return Result.Success();
}

public Result SetTeam(TeamId id)
{
Result<Team> result = id switch
{
TeamId.Alpha => Result<Team>.Success(Team.Alpha),
TeamId.Beta => Result<Team>.Success(Team.Beta),
TeamId.NoTeam => Result<Team>.Success(Team.None),
_ => Result<Team>.Failure()
};

if (result.IsSuccess)
{
Team = result.Value;
return Result.Success();
}

return Result.Failure(Messages.InvalidTeam);
}

public bool CanMoveUpToNextRank()
{
IRank currentRank = RankCollection.GetById(RankId).Value;
Expand Down
2 changes: 1 addition & 1 deletion src/Application/Teams/Flags/Flag.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
namespace CTF.Application.Teams.Flags;

internal class Flag
public class Flag
{
public required FlagModel Model { get; init; }
public required FlagIcon Icon { get; init; }
Expand Down
2 changes: 1 addition & 1 deletion src/Application/Teams/Flags/FlagIcon.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
namespace CTF.Application.Teams.Flags;

internal enum FlagIcon
public enum FlagIcon
{
None = 1,
Red = 20,
Expand Down
2 changes: 1 addition & 1 deletion src/Application/Teams/Flags/FlagModel.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
namespace CTF.Application.Teams.Flags;

internal enum FlagModel
public enum FlagModel
{
None = 0,
Red = 19306,
Expand Down
2 changes: 1 addition & 1 deletion src/Application/Teams/Flags/FlagStatus.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
namespace CTF.Application.Teams.Flags;

internal enum FlagStatus
public enum FlagStatus
{
/// <summary>
/// Indicates that the flag is on its base.
Expand Down
2 changes: 1 addition & 1 deletion src/Application/Teams/SkinTeamId.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
namespace CTF.Application.Teams;

internal enum SkinTeamId
public enum SkinTeamId
{
NoTeam = 0,
Alpha = 170,
Expand Down
2 changes: 1 addition & 1 deletion src/Application/Teams/Team.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
namespace CTF.Application.Teams;

internal class Team
public class Team
{
public static readonly Team Alpha;
public static readonly Team Beta;
Expand Down
2 changes: 1 addition & 1 deletion src/Application/Teams/TeamMembers.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
namespace CTF.Application.Teams;

internal class TeamMembers : IEnumerable<Player>
public class TeamMembers : IEnumerable<Player>
{
private readonly Dictionary<int, Player> _players = [];
public bool IsEmpty() => _players.Count == 0;
Expand Down
2 changes: 1 addition & 1 deletion src/Application/Teams/TeamSounds.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
namespace CTF.Application.Teams;

internal class TeamSounds
public class TeamSounds
{
public string FlagDropped { get; init; } = string.Empty;
public string FlagReturned { get; init; } = string.Empty;
Expand Down
2 changes: 1 addition & 1 deletion src/Application/Teams/TeamStatsPerRound.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
namespace CTF.Application.Teams;

internal class TeamStatsPerRound
public class TeamStatsPerRound
{
public int Score { get; private set; }
public int Kills { get; private set; }
Expand Down
43 changes: 43 additions & 0 deletions tests/Application.Tests/Players/Accounts/SelectedTeamTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
namespace CTF.Application.Tests.Players.Accounts;

public class SelectedTeamTests
{
[TestCase(-1)]
[TestCase(-2)]
[TestCase(2)]
[TestCase(3)]
[TestCase(4)]
[TestCase(254)]
[TestCase(256)]
public void SetTeam_WhenTeamIsInvalid_ShouldReturnsFailureResult(int id)
{
// Arrange
var player = new PlayerInfo();
TeamId teamId = (TeamId)id;
var expectedMessage = Messages.InvalidTeam;

// Act
Result result = player.SetTeam(teamId);

// Asserts
result.IsSuccess.Should().BeFalse();
result.Message.Should().Be(expectedMessage);
player.Team.Id.Should().Be(TeamId.NoTeam);
}

[TestCase(TeamId.Alpha)]
[TestCase(TeamId.Beta)]
[TestCase(TeamId.NoTeam)]
public void SetTeam_WhenTeamIsValid_ShouldReturnsSuccessResult(TeamId teamId)
{
// Arrange
var player = new PlayerInfo();

// Act
Result result = player.SetTeam(teamId);

// Asserts
result.IsSuccess.Should().BeTrue();
player.Team.Id.Should().Be(teamId);
}
}
Loading