-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #103 from MrDave1999/feat/FlagSystem
feat: Implement the main mechanics for Capture the Flag mode
- Loading branch information
Showing
18 changed files
with
453 additions
and
6 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
15 changes: 15 additions & 0 deletions
15
src/Application/Teams/Flags/Events/OnFlagAtBasePosition.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
namespace CTF.Application.Teams.Flags.Events; | ||
|
||
/// <summary> | ||
/// This event occurs when a player attempts to pick up their own team's flag, which is currently at the base. | ||
/// </summary> | ||
public class OnFlagAtBasePosition : IFlagEvent | ||
{ | ||
public FlagStatus FlagStatus => FlagStatus.InitialPosition; | ||
|
||
public void Handle(Team team, Player player) | ||
{ | ||
var text = Smart.Format(Messages.OnFlagAtBasePosition, team); | ||
player.GameText(text, 5000, 3); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
namespace CTF.Application.Teams.Flags.Events; | ||
|
||
/// <summary> | ||
/// This event occurs when a player has captured the opposing team's flag from their base. | ||
/// </summary> | ||
public class OnFlagCaptured( | ||
IPlayerRepository playerRepository, | ||
IWorldService worldService, | ||
TeamPickupService teamPickupService, | ||
TeamSoundsService teamSoundsService, | ||
PlayerStatsRenderer playerStatsRenderer) : IFlagEvent | ||
{ | ||
public FlagStatus FlagStatus => FlagStatus.Captured; | ||
|
||
public void Handle(Team team, Player player) | ||
{ | ||
teamPickupService.CreatePickupWithInfo(team); | ||
teamPickupService.DestroyFlag(team); | ||
teamSoundsService.PlayFlagTakenSound(team); | ||
var message = Smart.Format(Messages.OnFlagCaptured, new | ||
{ | ||
PlayerName = player.Name, | ||
TeamName = team.Name, | ||
ColorName = team.ColorName | ||
}); | ||
worldService.SendClientMessage(team.ColorHex, message); | ||
worldService.GameText($"~n~~n~~n~{team.GameText}{team.ColorName} flag captured!", 5000, 3); | ||
|
||
PlayerInfo playerInfo = player.GetInfo(); | ||
playerInfo.StatsPerRound.AddPoints(5); | ||
playerInfo.AddCapturedFlags(); | ||
playerRepository.UpdateCapturedFlags(playerInfo); | ||
playerStatsRenderer.UpdateTextDraw(player); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
namespace CTF.Application.Teams.Flags.Events; | ||
|
||
/// <summary> | ||
/// This event occurs when a player has dropped the opposing team's flag. | ||
/// </summary> | ||
public class OnFlagDropped( | ||
IPlayerRepository playerRepository, | ||
IWorldService worldService, | ||
TeamPickupService teamPickupService, | ||
TeamSoundsService teamSoundsService) : IFlagEvent | ||
{ | ||
public FlagStatus FlagStatus => FlagStatus.Dropped; | ||
|
||
public void Handle(Team team, Player player) | ||
{ | ||
teamPickupService.CreateFlagFromVector3(team, player.Position); | ||
teamSoundsService.PlayFlagDroppedSound(team); | ||
team.Flag.RemoveCarrier(); | ||
var message = Smart.Format(Messages.OnFlagDropped, new | ||
{ | ||
PlayerName = player.Name, | ||
TeamName = team.Name, | ||
ColorName = team.ColorName | ||
}); | ||
worldService.SendClientMessage(team.ColorHex, message); | ||
worldService.GameText($"~n~~n~~n~{team.GameText}{team.ColorName} flag dropped!", 5000, 3); | ||
|
||
PlayerInfo playerInfo = player.GetInfo(); | ||
playerInfo.AddDroppedFlags(); | ||
playerRepository.UpdateDroppedFlags(playerInfo); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
namespace CTF.Application.Teams.Flags.Events; | ||
|
||
/// <summary> | ||
/// This event occurs when a player has returned the flag to their team's base. | ||
/// </summary> | ||
public class OnFlagReturned( | ||
IPlayerRepository playerRepository, | ||
IWorldService worldService, | ||
TeamPickupService teamPickupService, | ||
TeamSoundsService teamSoundsService, | ||
PlayerStatsRenderer playerStatsRenderer) : IFlagEvent | ||
{ | ||
public FlagStatus FlagStatus => FlagStatus.Returned; | ||
|
||
public void Handle(Team team, Player player) | ||
{ | ||
teamPickupService.CreateFlagFromBasePosition(team); | ||
teamPickupService.DestroyPickupWithInfo(team); | ||
teamSoundsService.PlayFlagReturnedSound(team); | ||
var message = Smart.Format(Messages.OnFlagReturned, new | ||
{ | ||
PlayerName = player.Name, | ||
TeamName = team.Name, | ||
ColorName = team.ColorName | ||
}); | ||
worldService.SendClientMessage(team.ColorHex, message); | ||
worldService.GameText($"~n~~n~~n~{team.GameText}{team.ColorName} flag returned!", 5000, 3); | ||
|
||
PlayerInfo playerInfo = player.GetInfo(); | ||
playerInfo.StatsPerRound.AddPoints(5); | ||
playerInfo.AddReturnedFlags(); | ||
playerRepository.UpdateReturnedFlags(playerInfo); | ||
playerStatsRenderer.UpdateTextDraw(player); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
namespace CTF.Application.Teams.Flags.Events; | ||
|
||
/// <summary> | ||
/// This event occurs when a player has captured the opposing team's flag and brought it back to their own base. | ||
/// </summary> | ||
public class OnFlagScore( | ||
IPlayerRepository playerRepository, | ||
IWorldService worldService, | ||
TeamPickupService teamPickupService, | ||
TeamSoundsService teamSoundsService, | ||
TeamTextDrawRenderer teamTextDrawRenderer, | ||
PlayerStatsRenderer playerStatsRenderer) : IFlagEvent | ||
{ | ||
public FlagStatus FlagStatus => FlagStatus.Brought; | ||
|
||
public void Handle(Team team, Player player) | ||
{ | ||
teamPickupService.CreateFlagFromBasePosition(team.RivalTeam); | ||
teamPickupService.DestroyPickupWithInfo(team.RivalTeam); | ||
teamSoundsService.PlayTeamScoresSound(team); | ||
teamTextDrawRenderer.UpdateTeamScore(team); | ||
|
||
var message = Smart.Format(Messages.OnFlagScore, new | ||
{ | ||
PlayerName = player.Name, | ||
TeamName = team.Name, | ||
ColorName = team.RivalTeam.ColorName | ||
}); | ||
worldService.SendClientMessage(team.ColorHex, message); | ||
worldService.GameText($"~n~~n~~n~{team.GameText}{team.ColorName} team scores!", 5000, 3); | ||
|
||
PlayerInfo playerInfo = player.GetInfo(); | ||
playerInfo.StatsPerRound.AddPoints(8); | ||
playerInfo.AddBroughtFlags(); | ||
playerRepository.UpdateBroughtFlags(playerInfo); | ||
GiveRewards(team); | ||
} | ||
|
||
private void GiveRewards(Team team) | ||
{ | ||
TeamMembers teamMembers = team.Members; | ||
foreach (Player player in teamMembers) | ||
{ | ||
PlayerInfo playerInfo = player.GetInfo(); | ||
playerInfo.StatsPerRound.AddPoints(5); | ||
player.AddHealth(10); | ||
playerStatsRenderer.UpdateTextDraw(player); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
namespace CTF.Application.Teams.Flags.Events; | ||
|
||
/// <summary> | ||
/// This event occurs when a player has taken the flag from a position other than the base. | ||
/// </summary> | ||
public class OnFlagTaken( | ||
IWorldService worldService, | ||
TeamPickupService teamPickupService, | ||
TeamSoundsService teamSoundsService) : IFlagEvent | ||
{ | ||
public FlagStatus FlagStatus => FlagStatus.Taken; | ||
|
||
public void Handle(Team team, Player player) | ||
{ | ||
teamPickupService.DestroyFlag(team); | ||
teamSoundsService.PlayFlagTakenSound(team); | ||
var message = Smart.Format(Messages.OnFlagTaken, new | ||
{ | ||
PlayerName = player.Name, | ||
TeamName = team.Name, | ||
ColorName = team.ColorName | ||
}); | ||
worldService.SendClientMessage(team.ColorHex, message); | ||
worldService.GameText($"~n~~n~~n~{team.GameText}{team.ColorName} flag taken!", 5000, 3); | ||
} | ||
} |
Oops, something went wrong.