Skip to content

Commit

Permalink
feat: Allow moderators to change the map (#96)
Browse files Browse the repository at this point in the history
  • Loading branch information
MrDave1999 authored Sep 18, 2024
1 parent f95ef05 commit 5531cf2
Show file tree
Hide file tree
Showing 3 changed files with 117 additions and 0 deletions.
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 @@ -171,6 +171,9 @@
<data name="LoginOrRegisterToContinue" xml:space="preserve">
<value>Please log in or register to continue</value>
</data>
<data name="MapChangeForced" xml:space="preserve">
<value>{PlayerName} forced the map change to {MapName}</value>
</data>
<data name="MapIsLoading" xml:space="preserve">
<value>Please wait while the map is being loaded</value>
</data>
Expand All @@ -189,12 +192,18 @@
<data name="NameSuccessfullyChanged" xml:space="preserve">
<value>{OldName} changed their name to {NewName}</value>
</data>
<data name="NextMapSelection" xml:space="preserve">
<value>{PlayerName} decided that the next map will be in {MapName}</value>
</data>
<data name="NextMapWillBeLoadedSoon" xml:space="preserve">
<value>The next map will be loaded soon: {Name}</value>
</data>
<data name="NextRank" xml:space="preserve">
<value>You moved up to {Name} rank, congratulations!</value>
</data>
<data name="NoMatchFound" xml:space="preserve">
<value>No match found</value>
</data>
<data name="NoPermissions" xml:space="preserve">
<value>You do not have permissions to use this command</value>
</data>
Expand Down
81 changes: 81 additions & 0 deletions src/Application/Maps/Systems/MapRotationSystem.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
namespace CTF.Application.Maps.Systems;

public class MapRotationSystem(
IWorldService worldService,
IDialogService dialogService,
MapInfoService mapInfoService,
MapRotationService mapRotationService,
MapTextDrawRenderer mapTextDrawRenderer) : ISystem
{
Expand Down Expand Up @@ -33,4 +36,82 @@ public void SetTimeLeft(Player player, int minutes)

mapTextDrawRenderer.UpdateTimeLeft(timeLeft);
}

[PlayerCommand("maps")]
public async void ShowMaps(Player player, string findBy = default)
{
if (player.HasLowerRoleThan(RoleId.Moderator))
return;

var listDialog = new ListDialog(string.Empty, "Select", "Close");
CurrentMap currentMap = mapInfoService.Read();
IEnumerable<IMap> maps = string.IsNullOrEmpty(findBy) ?
MapCollection.GetAll() :
MapCollection.GetAll(findBy);

foreach (IMap map in maps)
{
if (map.Id == currentMap.NextMap.Id)
listDialog.Add(text: $"{map.Name} {Color.Red}[Next Map]", tag: map.Id);
else
listDialog.Add(text: map.Name, tag: map.Id);
}

if (listDialog.Rows.Count == 0)
{
player.SendClientMessage(Color.Red, Messages.NoMatchFound);
return;
}

listDialog.Caption = $"Maps: {listDialog.Rows.Count}/{MapCollection.Count}";
ListDialogResponse listDialogResponse = await dialogService.ShowAsync(player, listDialog);
if (listDialogResponse.Response == DialogResponse.LeftButton)
{
int selectedMapId = (int)listDialogResponse.Item.Tag;
IMap selectedMap = MapCollection.GetById(selectedMapId).Value;
ShowConfirmationDialog(player, selectedMap);
}
}

private async void ShowConfirmationDialog(Player player, IMap selectedMap)
{
var confirmationDialog = new MessageDialog(
caption: "Confirmation",
content: "Do you want to force the map change right now?",
button1: "Yes",
button2: "No"
);
MessageDialogResponse confirmationDialogResponse = await dialogService.ShowAsync(player, confirmationDialog);
if (mapRotationService.IsMapLoading())
{
player.SendClientMessage(Color.Red, Messages.MapIsLoading);
return;
}

if (confirmationDialogResponse.Response == DialogResponse.LeftButton)
{
TimeLeft timeLeft = mapRotationService.TimeLeft;
timeLeft.SetInterval(new Minutes(0));
mapTextDrawRenderer.UpdateTimeLeft(timeLeft);
var message = Smart.Format(Messages.MapChangeForced, new
{
PlayerName = player.Name,
MapName = selectedMap.Name
});
worldService.SendClientMessage(Color.Orange, message);
CurrentMap currentMap = mapInfoService.Read();
currentMap.SetNextMap(selectedMap);
}
else if(confirmationDialogResponse.Response == DialogResponse.RightButtonOrCancel)
{
var message = Smart.Format(Messages.NextMapSelection, new
{
PlayerName = player.Name,
MapName = selectedMap.Name
});
worldService.SendClientMessage(Color.Orange, message);
CurrentMap currentMap = mapInfoService.Read();
currentMap.SetNextMap(selectedMap);
}
}
}

0 comments on commit 5531cf2

Please sign in to comment.