-
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.
feat: Implement a timer to apply automatic flag return
This timer starts when the player drops the flag on the ground. After 120 seconds, the flag will automatically return to its base position.
- Loading branch information
1 parent
dd9e973
commit 2e05bd3
Showing
7 changed files
with
73 additions
and
4 deletions.
There are no files selected for viewing
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
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
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
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,56 @@ | ||
namespace CTF.Application.Teams.Services; | ||
|
||
public class FlagAutoReturnTimer( | ||
ITimerService timerService, | ||
IWorldService worldService, | ||
TeamPickupService teamPickupService, | ||
TeamSoundsService teamSoundsService, | ||
ServerSettings serverSettings) | ||
{ | ||
private TimerReference _alphaTeamTimer; | ||
private TimerReference _betaTeamTimer; | ||
|
||
public void Start(Team team) | ||
{ | ||
void OnComplete(IServiceProvider serviceProvider) | ||
{ | ||
teamPickupService.CreateFlagFromBasePosition(team); | ||
teamPickupService.DestroyPickupWithInfo(team); | ||
teamSoundsService.PlayFlagReturnedSound(team); | ||
team.IsFlagAtBasePosition = true; | ||
var message = Smart.Format(Messages.FlagAutoReturn, new | ||
{ | ||
Seconds = serverSettings.FlagAutoReturnTime, | ||
team.ColorName | ||
}); | ||
worldService.SendClientMessage(team.ColorHex, message); | ||
worldService.GameText($"~n~~n~~n~{team.GameText}{team.ColorName} flag returned!", 5000, 3); | ||
Stop(team); | ||
} | ||
|
||
if (team.Id == TeamId.Alpha) | ||
{ | ||
TimeSpan interval = TimeSpan.FromSeconds(serverSettings.FlagAutoReturnTime); | ||
_alphaTeamTimer ??= timerService.Start(OnComplete, interval); | ||
} | ||
else if (team.Id == TeamId.Beta) | ||
{ | ||
TimeSpan interval = TimeSpan.FromSeconds(serverSettings.FlagAutoReturnTime); | ||
_betaTeamTimer ??= timerService.Start(OnComplete, interval); | ||
} | ||
} | ||
|
||
public void Stop(Team team) | ||
{ | ||
if (team.Id == TeamId.Alpha && _alphaTeamTimer is not null) | ||
{ | ||
timerService.Stop(_alphaTeamTimer); | ||
_alphaTeamTimer = default; | ||
} | ||
else if (team.Id == TeamId.Beta && _betaTeamTimer is not null) | ||
{ | ||
timerService.Stop(_betaTeamTimer); | ||
_betaTeamTimer = default; | ||
} | ||
} | ||
} |