[Activity] Add all activities
This commit is contained in:
@@ -26,7 +26,7 @@ public class ActivityFormatter
|
||||
ActivityName.VoidRift => "Failles du néant",
|
||||
ActivityName.OriginsOfWar => "Origine de la guerre",
|
||||
ActivityName.JointOperation => "Opération conjointe",
|
||||
ActivityName.InterstellarExploration => "Exploration interstellaire",
|
||||
ActivityName.InterstellarExploration => "Portes interstellaires",
|
||||
ActivityName.BreakFromDestiny => "Échapper au destin (3v3)",
|
||||
ActivityName.CriticalAbyss => "Abîme critique (8v8)",
|
||||
ActivityName.Event => "Event",
|
||||
@@ -92,29 +92,29 @@ public class ActivityFormatter
|
||||
public string FormatActivityPlayer(ActivityPlayer player, int namePadding) => player switch
|
||||
{
|
||||
ActivityRolePlayer rolePlayer => $"` {player.Name.PadRight(namePadding)} ` **―** {RolesToEmotes(rolePlayer.Roles)}",
|
||||
_ => $"{player.Name})"
|
||||
_ => $"` {player.Name} `"
|
||||
};
|
||||
|
||||
private string RolesToEmotes(ActivityRoles rolePlayerRoles)
|
||||
private string RolesToEmotes(PlayerRoles rolePlayerRoles)
|
||||
{
|
||||
var emotesBuilder = new StringBuilder();
|
||||
|
||||
if (rolePlayerRoles.HasFlag(ActivityRoles.Helper))
|
||||
if (rolePlayerRoles.HasFlag(PlayerRoles.Helper))
|
||||
{
|
||||
emotesBuilder.Append($" {_options.HelperEmote} ");
|
||||
}
|
||||
|
||||
if (rolePlayerRoles.HasFlag(ActivityRoles.Dps))
|
||||
if (rolePlayerRoles.HasFlag(PlayerRoles.Dps))
|
||||
{
|
||||
emotesBuilder.Append($" {_options.DpsEmote} ");
|
||||
}
|
||||
|
||||
if (rolePlayerRoles.HasFlag(ActivityRoles.Tank))
|
||||
if (rolePlayerRoles.HasFlag(PlayerRoles.Tank))
|
||||
{
|
||||
emotesBuilder.Append($" {_options.TankEmote} ");
|
||||
}
|
||||
|
||||
if (rolePlayerRoles.HasFlag(ActivityRoles.Support))
|
||||
if (rolePlayerRoles.HasFlag(PlayerRoles.Support))
|
||||
{
|
||||
emotesBuilder.Append($" {_options.SupportEmote} ");
|
||||
}
|
||||
|
||||
@@ -15,19 +15,19 @@ public class ActivityHelper
|
||||
_options = options.Value;
|
||||
}
|
||||
|
||||
public ActivityRoles GetPlayerRoles(IEnumerable<SocketRole> userRoles)
|
||||
public PlayerRoles GetPlayerRoles(IEnumerable<SocketRole> userRoles)
|
||||
{
|
||||
var roles = ActivityRoles.None;
|
||||
var roles = PlayerRoles.None;
|
||||
|
||||
foreach (var socketRole in userRoles)
|
||||
{
|
||||
roles |= socketRole.Id switch
|
||||
{
|
||||
var role when role == _options.HelperRoleId => ActivityRoles.Helper,
|
||||
var role when role == _options.DpsRoleId => ActivityRoles.Dps,
|
||||
var role when role == _options.TankRoleId => ActivityRoles.Tank,
|
||||
var role when role == _options.SupportRoleId => ActivityRoles.Support,
|
||||
_ => ActivityRoles.None
|
||||
var role when role == _options.HelperRoleId => PlayerRoles.Helper,
|
||||
var role when role == _options.DpsRoleId => PlayerRoles.Dps,
|
||||
var role when role == _options.TankRoleId => PlayerRoles.Tank,
|
||||
var role when role == _options.SupportRoleId => PlayerRoles.Support,
|
||||
_ => PlayerRoles.None
|
||||
};
|
||||
}
|
||||
|
||||
@@ -63,6 +63,7 @@ public class ActivityHelper
|
||||
ActivityType.Event4Players => 4,
|
||||
|
||||
ActivityType.Pve8Players or
|
||||
ActivityType.Pvp8Players or
|
||||
ActivityType.Event8Players => 8,
|
||||
|
||||
ActivityType.Pvp3Players => 3,
|
||||
|
||||
@@ -7,6 +7,7 @@ using Discord;
|
||||
using Discord.Interactions;
|
||||
using Discord.WebSocket;
|
||||
using Microsoft.Extensions.Options;
|
||||
using Alias = Discord.Commands.AliasAttribute;
|
||||
|
||||
namespace Cocotte.Modules.Activities;
|
||||
|
||||
@@ -44,50 +45,163 @@ public partial class ActivityModule : InteractionModuleBase<SocketInteractionCon
|
||||
""");
|
||||
}
|
||||
|
||||
[SlashCommand("abime", "Créer un groupe pour l'Abîme du Néant")]
|
||||
public async Task ActivityAbyss([Summary("étage", "A quel étage êtes vous")] [MinValue(1), MaxValue(6)] uint stage, [Summary("description", "Message accompagnant la demande de groupe")] string description = "")
|
||||
[SlashCommand("abime-néant", "Créer un groupe pour l'Abîme du Néant")]
|
||||
[Alias("abime", "abyss")]
|
||||
public async Task ActivityVoidAbyss([Summary("étage", "A quel étage vous êtes")] [MinValue(1), MaxValue(6)] uint stage, [Summary("description", "Message accompagnant la demande de groupe")] string description = "")
|
||||
{
|
||||
const ActivityName activityName = ActivityName.Abyss;
|
||||
var activityType = ActivityHelper.ActivityNameToType(activityName);
|
||||
var maxPlayers = ActivityHelper.ActivityTypeToMaxPlayers(activityType);
|
||||
|
||||
var activity = new StagedActivity
|
||||
{
|
||||
ActivityId = 0,
|
||||
CreatorDiscordId = Context.User.Id,
|
||||
CreatorDiscordName = ((SocketGuildUser)Context.User).DisplayName,
|
||||
Description = description,
|
||||
Type = activityType,
|
||||
Name = activityName,
|
||||
RoleEnabled = true,
|
||||
MaxPlayers = maxPlayers,
|
||||
Stage = stage
|
||||
};
|
||||
|
||||
await CreateRoleActivity(activity);
|
||||
await CreateActivity(ActivityName.Abyss, description, stage: stage);
|
||||
}
|
||||
|
||||
private async Task CreateRoleActivity(Activity activity)
|
||||
[SlashCommand("origine-guerre", "Créer un groupe pour l'Origine de la guerre")]
|
||||
[Alias("origine", "OOW")]
|
||||
public async Task ActivityOrigins([Summary("étage", "A quel étage vous êtes")] [MinValue(1), MaxValue(25)] uint stage, [Summary("description", "Message accompagnant la demande de groupe")] string description = "")
|
||||
{
|
||||
await CreateActivity(ActivityName.OriginsOfWar, description, stage: stage);
|
||||
}
|
||||
|
||||
[SlashCommand("raids", "Créer un groupe pour les Raids")]
|
||||
public async Task ActivityRaids([Summary("description", "Message accompagnant la demande de groupe")] string description = "")
|
||||
{
|
||||
await CreateActivity(ActivityName.Raids, description);
|
||||
}
|
||||
|
||||
[SlashCommand("conflit-frontalier", "Créer un groupe pour Conflit frontalier")]
|
||||
[Alias("conflit", "FC")]
|
||||
public async Task ActivityFrontierClash([Summary("description", "Message accompagnant la demande de groupe")] string description = "")
|
||||
{
|
||||
await CreateActivity(ActivityName.FrontierClash, description);
|
||||
}
|
||||
|
||||
[SlashCommand("failles-neant", "Créer un groupe pour les Failles du néant")]
|
||||
[Alias("failles", "rift")]
|
||||
public async Task ActivityVoidRift([Summary("description", "Message accompagnant la demande de groupe")] string description = "")
|
||||
{
|
||||
await CreateActivity(ActivityName.VoidRift, description);
|
||||
}
|
||||
|
||||
[SlashCommand("operations-conjointes", "Créer un groupe pour les Opérations conjointes")]
|
||||
[Alias("operations", "JO")]
|
||||
public async Task ActivityJointOperation([Summary("description", "Message accompagnant la demande de groupe")] string description = "")
|
||||
{
|
||||
await CreateActivity(ActivityName.JointOperation, description);
|
||||
}
|
||||
|
||||
[SlashCommand("portes-interstellaires", "Créer un groupe pour les Portes interstellaires")]
|
||||
[Alias("portes")]
|
||||
public async Task ActivityInterstellarExploration([Summary("couleur", "De quel couleur de matériaux s'agît-il")] InterstellarColor color, [Summary("description", "Message accompagnant la demande de groupe")] string description = "")
|
||||
{
|
||||
await CreateActivity(ActivityName.InterstellarExploration, description, areRolesEnabled: false, interstellarColor: color);
|
||||
}
|
||||
|
||||
[SlashCommand("3v3", "Créer un groupe pour le 3v3 (Échapper au destin)")]
|
||||
[Alias("BR")]
|
||||
public async Task ActivityBreakFromDestiny([Summary("description", "Message accompagnant la demande de groupe")] string description = "")
|
||||
{
|
||||
await CreateActivity(ActivityName.BreakFromDestiny, description, areRolesEnabled: false);
|
||||
}
|
||||
|
||||
[SlashCommand("8v8", "Créer un groupe pour le 8v8 (Abîme critique)")]
|
||||
[Alias("critical")]
|
||||
public async Task ActivityCriticalAbyss([Summary("description", "Message accompagnant la demande de groupe")] string description = "")
|
||||
{
|
||||
await CreateActivity(ActivityName.CriticalAbyss, description);
|
||||
}
|
||||
|
||||
[SlashCommand("evenement", "Créer un groupe pour les évènements")]
|
||||
[Alias("event")]
|
||||
public async Task ActivityEvent([Summary("joueurs", "Nombre de joueurs maximum pour cette activité")] [MinValue(2), MaxValue(16)] uint maxPlayers = 8, [Summary("description", "Message accompagnant la demande de groupe")] string description = "")
|
||||
{
|
||||
await CreateActivity(ActivityName.Event, description, areRolesEnabled: false, maxPlayers: maxPlayers);
|
||||
}
|
||||
|
||||
[SlashCommand("peche", "Créer un groupe pour de la pêche")]
|
||||
[Alias("fishing")]
|
||||
public async Task ActivityFishing([Summary("description", "Message accompagnant la demande de groupe")] string description = "")
|
||||
{
|
||||
await CreateActivity(ActivityName.Fishing, description, areRolesEnabled: false);
|
||||
}
|
||||
|
||||
[SlashCommand("course", "Créer un groupe pour les courses de Mirroria")]
|
||||
[Alias("BR")]
|
||||
public async Task ActivityMirroriaRace([Summary("description", "Message accompagnant la demande de groupe")] string description = "")
|
||||
{
|
||||
await CreateActivity(ActivityName.MirroriaRace, description, areRolesEnabled: false);
|
||||
}
|
||||
|
||||
private async Task CreateActivity(ActivityName activityName, string description, bool areRolesEnabled = true, uint? maxPlayers = null, uint? stage = null, InterstellarColor? interstellarColor = null)
|
||||
{
|
||||
var user = (SocketGuildUser)Context.User;
|
||||
_logger.LogTrace("{User} is creating activity {Activity}", user.DisplayName, activity);
|
||||
_logger.LogTrace("{User} is creating activity {Activity}", user.DisplayName, activityName);
|
||||
|
||||
// Activities are identified using their original message id
|
||||
await RespondAsync("> *Création de l'activité en cours...*");
|
||||
|
||||
var response = await GetOriginalResponseAsync();
|
||||
activity.ActivityId = response.Id;
|
||||
|
||||
var activityType = ActivityHelper.ActivityNameToType(activityName);
|
||||
maxPlayers ??= ActivityHelper.ActivityTypeToMaxPlayers(activityType);
|
||||
Activity activity;
|
||||
|
||||
if (stage is not null)
|
||||
{
|
||||
activity = new StagedActivity
|
||||
{
|
||||
ActivityId = response.Id,
|
||||
CreatorDiscordId = Context.User.Id,
|
||||
CreatorDiscordName = ((SocketGuildUser) Context.User).DisplayName,
|
||||
Description = description,
|
||||
Type = activityType,
|
||||
Name = activityName,
|
||||
AreRolesEnabled = areRolesEnabled,
|
||||
MaxPlayers = (uint) maxPlayers,
|
||||
Stage = (uint) stage
|
||||
};
|
||||
}
|
||||
else if (interstellarColor is not null)
|
||||
{
|
||||
activity = new InterstellarActivity
|
||||
{
|
||||
ActivityId = response.Id,
|
||||
CreatorDiscordId = Context.User.Id,
|
||||
CreatorDiscordName = ((SocketGuildUser) Context.User).DisplayName,
|
||||
Description = description,
|
||||
Type = activityType,
|
||||
Name = activityName,
|
||||
AreRolesEnabled = false,
|
||||
MaxPlayers = (uint) maxPlayers,
|
||||
Color = (InterstellarColor) interstellarColor
|
||||
};
|
||||
}
|
||||
else
|
||||
{
|
||||
activity = new Activity
|
||||
{
|
||||
ActivityId = response.Id,
|
||||
CreatorDiscordId = Context.User.Id,
|
||||
CreatorDiscordName = ((SocketGuildUser) Context.User).DisplayName,
|
||||
Description = description,
|
||||
Type = activityType,
|
||||
Name = activityName,
|
||||
AreRolesEnabled = true,
|
||||
MaxPlayers = (uint) maxPlayers
|
||||
};
|
||||
}
|
||||
|
||||
// Add activity to db
|
||||
await _activitiesRepository.AddActivity(activity);
|
||||
|
||||
// Add creator to activity
|
||||
var rolePlayer = new ActivityRolePlayer
|
||||
var rolePlayer = areRolesEnabled ? new ActivityRolePlayer
|
||||
{
|
||||
Activity = activity,
|
||||
DiscordId = user.Id,
|
||||
Name = user.DisplayName,
|
||||
Roles = _activityHelper.GetPlayerRoles(user.Roles)
|
||||
} : new ActivityPlayer
|
||||
{
|
||||
Activity = activity,
|
||||
DiscordId = user.Id,
|
||||
Name = user.DisplayName
|
||||
};
|
||||
|
||||
activity.ActivityPlayers.Add(rolePlayer);
|
||||
@@ -144,7 +258,7 @@ public partial class ActivityModule : InteractionModuleBase<SocketInteractionCon
|
||||
|
||||
_logger.LogTrace("Player {Player} joined activity {Id}", user.DisplayName, activityId);
|
||||
|
||||
var activityPlayer = activity.RoleEnabled ? new ActivityRolePlayer
|
||||
var activityPlayer = activity.AreRolesEnabled ? new ActivityRolePlayer
|
||||
{
|
||||
Activity = activity,
|
||||
DiscordId = user.Id,
|
||||
|
||||
@@ -21,8 +21,8 @@ public partial class ActivityModule
|
||||
Activity = activity,
|
||||
Name = $"Player{Random.Shared.Next(1, 100)}",
|
||||
DiscordId = (ulong) Random.Shared.NextInt64(),
|
||||
Roles = (ActivityRoles) Random.Shared.Next((int) (ActivityRoles.Dps | ActivityRoles.Helper |
|
||||
ActivityRoles.Support | ActivityRoles.Tank) + 1)
|
||||
Roles = (PlayerRoles) Random.Shared.Next((int) (PlayerRoles.Dps | PlayerRoles.Helper |
|
||||
PlayerRoles.Support | PlayerRoles.Tank) + 1)
|
||||
};
|
||||
|
||||
// Add the player to the activity
|
||||
|
||||
@@ -3,7 +3,7 @@ using System.ComponentModel.DataAnnotations.Schema;
|
||||
|
||||
namespace Cocotte.Modules.Activities.Models;
|
||||
|
||||
public abstract class Activity
|
||||
public class Activity
|
||||
{
|
||||
[Key, DatabaseGenerated(DatabaseGeneratedOption.None)]
|
||||
public required ulong ActivityId { get; set; }
|
||||
@@ -13,7 +13,7 @@ public abstract class Activity
|
||||
public string? Description { get; init; }
|
||||
public required ActivityType Type { get; init; }
|
||||
public required ActivityName Name { get; init; }
|
||||
public required bool RoleEnabled { get; init; }
|
||||
public required bool AreRolesEnabled { get; init; }
|
||||
public required uint MaxPlayers { get; set; }
|
||||
|
||||
public List<ActivityPlayer> ActivityPlayers { get; init; } = new();
|
||||
|
||||
@@ -2,5 +2,5 @@
|
||||
|
||||
public class ActivityRolePlayer : ActivityPlayer
|
||||
{
|
||||
public required ActivityRoles Roles { get; init; }
|
||||
public required PlayerRoles Roles { get; init; }
|
||||
}
|
||||
11
Cocotte/Modules/Activities/Models/InterstellarActivity.cs
Normal file
11
Cocotte/Modules/Activities/Models/InterstellarActivity.cs
Normal file
@@ -0,0 +1,11 @@
|
||||
namespace Cocotte.Modules.Activities.Models;
|
||||
|
||||
public class InterstellarActivity : Activity
|
||||
{
|
||||
public required InterstellarColor Color { get; init; }
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return $"{base.ToString()}, {nameof(InterstellarColor)}: {Color}";
|
||||
}
|
||||
}
|
||||
15
Cocotte/Modules/Activities/Models/InterstellarColor.cs
Normal file
15
Cocotte/Modules/Activities/Models/InterstellarColor.cs
Normal file
@@ -0,0 +1,15 @@
|
||||
using Discord.Interactions;
|
||||
|
||||
namespace Cocotte.Modules.Activities.Models;
|
||||
|
||||
public enum InterstellarColor
|
||||
{
|
||||
[ChoiceDisplay("Verte")]
|
||||
Green,
|
||||
[ChoiceDisplay("Rouge")]
|
||||
Red,
|
||||
[ChoiceDisplay("Bleue")]
|
||||
Blue,
|
||||
[ChoiceDisplay("Noire")]
|
||||
Black
|
||||
}
|
||||
@@ -1,7 +1,7 @@
|
||||
namespace Cocotte.Modules.Activities;
|
||||
|
||||
[Flags]
|
||||
public enum ActivityRoles : byte
|
||||
public enum PlayerRoles : byte
|
||||
{
|
||||
None = 0b0000,
|
||||
Helper = 0b0001,
|
||||
@@ -71,7 +71,7 @@ await using(var scope = host.Services.CreateAsyncScope())
|
||||
if (hostEnvironment.IsDevelopment())
|
||||
{
|
||||
var dbContext = scope.ServiceProvider.GetRequiredService<CocotteDbContext>();
|
||||
// await dbContext.Database.EnsureDeletedAsync();
|
||||
await dbContext.Database.EnsureDeletedAsync();
|
||||
await dbContext.Database.EnsureCreatedAsync();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user