Skip to content

Commit 7ba7ccf

Browse files
committed
Add a command to search a quest by a quest step id
1 parent 8e4b774 commit 7ba7ccf

File tree

7 files changed

+97
-41
lines changed

7 files changed

+97
-41
lines changed

Cyberia.Api/Data/Quests/QuestsRepository.cs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,26 @@ internal QuestsRepository()
4646
return questData;
4747
}
4848

49+
public QuestData? GetQuestDataByQuestStepId(int questStepId, out int index)
50+
{
51+
foreach (var quest in Quests.Values)
52+
{
53+
var questStepsId = quest.QuestStepsId;
54+
55+
for (var i = 0; i < questStepsId.Count; i++)
56+
{
57+
if (questStepsId[i] == questStepId)
58+
{
59+
index = i;
60+
return quest;
61+
}
62+
}
63+
}
64+
65+
index = -1;
66+
return null;
67+
}
68+
4969
public IEnumerable<QuestData> GetQuestDataByName(string name, Language language)
5070
{
5171
return GetQuestsDataByName(name, language.ToCulture());

Cyberia.Langzilla.Enums/LangType.cs

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,3 @@ public enum LangType
1818
/// </summary>
1919
Temporis
2020
}
21-
22-
public static class LangTypeExtensions
23-
{
24-
public static string ToStringFast(this LangType type)
25-
{
26-
return Enum.GetName(type) ?? type.ToString();
27-
}
28-
}

Cyberia.Langzilla.Enums/Language.cs

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -54,11 +54,6 @@ public static class LanguageExtensions
5454
{ Language.pt, CultureInfo.GetCultureInfo("pt") }
5555
}.ToFrozenDictionary();
5656

57-
public static string ToStringFast(this Language language)
58-
{
59-
return Enum.GetName(language) ?? language.ToString();
60-
}
61-
6257
/// <summary>
6358
/// Converts a <see cref="Language"/> to its corresponding <see cref="CultureInfo"/>.
6459
/// </summary>

Cyberia.Salamandra/Commands/Admin/Search/SearchCommandModule.cs

Lines changed: 50 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using Cyberia.Api.Data;
22
using Cyberia.Api.Utils;
3+
using Cyberia.Salamandra.Commands.Dofus.Quest;
34
using Cyberia.Salamandra.Enums;
45
using Cyberia.Salamandra.Services;
56

@@ -31,23 +32,23 @@ public SearchCommandModule(ICultureService cultureService, DofusDatacenter dofus
3132
_embedBuilderService = embedBuilderService;
3233
}
3334

34-
[Command("effect"), Description("Search where the effect is used")]
35+
[Command("criterion"), Description("Search where the criterion is used")]
3536
[SlashCommandTypes(DiscordApplicationCommandType.SlashCommand)]
36-
public async Task EffectExecuteAsync(SlashCommandContext ctx,
37-
[Parameter("where"), Description("Where to look for the effect")]
38-
SearchLocation location,
39-
[Parameter("id"), Description("Effect id")]
40-
[MinMaxValue(-1, 9999)]
41-
int effectId)
37+
public async Task CriterionExecuteAsync(SlashCommandContext ctx,
38+
[Parameter("where"), Description("Where to look for the criterion")]
39+
SearchCriterionLocation location,
40+
[Parameter("id"), Description("Criterion id")]
41+
[MinMaxLength(2, 2)]
42+
string criterionId)
4243
{
4344
var culture = await _cultureService.GetCultureAsync(ctx.Interaction);
4445

4546
StringBuilder descriptionBuilder = new();
4647

4748
switch (location)
4849
{
49-
case SearchLocation.Item:
50-
foreach (var itemData in _dofusDatacenter.ItemsRepository.GetItemsDataWithEffectId(effectId))
50+
case SearchCriterionLocation.Item:
51+
foreach (var itemData in _dofusDatacenter.ItemsRepository.GetItemsDataWithCriterionId(criterionId))
5152
{
5253
descriptionBuilder.Append("- ");
5354
descriptionBuilder.Append(itemData.Name.ToString(culture));
@@ -56,8 +57,8 @@ public async Task EffectExecuteAsync(SlashCommandContext ctx,
5657
descriptionBuilder.Append(")\n");
5758
}
5859
break;
59-
case SearchLocation.Spell:
60-
foreach (var spellData in _dofusDatacenter.SpellsRepository.GetSpellsDataWithEffectId(effectId))
60+
case SearchCriterionLocation.Spell:
61+
foreach (var spellData in _dofusDatacenter.SpellsRepository.GetSpellsDataWithCriterionId(criterionId))
6162
{
6263
descriptionBuilder.Append("- ");
6364
descriptionBuilder.Append(spellData.Name.ToString(culture));
@@ -67,34 +68,34 @@ public async Task EffectExecuteAsync(SlashCommandContext ctx,
6768
}
6869
break;
6970
default:
70-
await ctx.RespondAsync($"Unknown {Formatter.Bold(location.ToString())}");
71+
await ctx.RespondAsync($"Unknown {Formatter.Bold(location.ToStringFast())}");
7172
return;
7273
}
7374

7475
var embed = _embedBuilderService.CreateEmbedBuilder(EmbedCategory.Tools, "Tools", culture)
75-
.WithTitle($"Search effect {effectId} in {location}")
76+
.WithTitle($"Search criterion {criterionId} in {location}")
7677
.WithDescription(descriptionBuilder.ToString().WithMaxLength(Constant.MaxEmbedDescriptionSize));
7778

7879
await ctx.RespondAsync(embed);
7980
}
8081

81-
[Command("criterion"), Description("Search where the criterion is used")]
82+
[Command("effect"), Description("Search where the effect is used")]
8283
[SlashCommandTypes(DiscordApplicationCommandType.SlashCommand)]
83-
public async Task CriterionExecuteAsync(SlashCommandContext ctx,
84-
[Parameter("where"), Description("Where to look for the criterion")]
85-
SearchLocation location,
86-
[Parameter("id"), Description("Criterion id")]
87-
[MinMaxLength(2, 2)]
88-
string criterionId)
84+
public async Task EffectExecuteAsync(SlashCommandContext ctx,
85+
[Parameter("where"), Description("Where to look for the effect")]
86+
SearchEffectLocation location,
87+
[Parameter("id"), Description("Effect id")]
88+
[MinMaxValue(-1, 999_999)]
89+
int effectId)
8990
{
9091
var culture = await _cultureService.GetCultureAsync(ctx.Interaction);
9192

9293
StringBuilder descriptionBuilder = new();
9394

9495
switch (location)
9596
{
96-
case SearchLocation.Item:
97-
foreach (var itemData in _dofusDatacenter.ItemsRepository.GetItemsDataWithCriterionId(criterionId))
97+
case SearchEffectLocation.Item:
98+
foreach (var itemData in _dofusDatacenter.ItemsRepository.GetItemsDataWithEffectId(effectId))
9899
{
99100
descriptionBuilder.Append("- ");
100101
descriptionBuilder.Append(itemData.Name.ToString(culture));
@@ -103,8 +104,8 @@ public async Task CriterionExecuteAsync(SlashCommandContext ctx,
103104
descriptionBuilder.Append(")\n");
104105
}
105106
break;
106-
case SearchLocation.Spell:
107-
foreach (var spellData in _dofusDatacenter.SpellsRepository.GetSpellsDataWithCriterionId(criterionId))
107+
case SearchEffectLocation.Spell:
108+
foreach (var spellData in _dofusDatacenter.SpellsRepository.GetSpellsDataWithEffectId(effectId))
108109
{
109110
descriptionBuilder.Append("- ");
110111
descriptionBuilder.Append(spellData.Name.ToString(culture));
@@ -114,12 +115,12 @@ public async Task CriterionExecuteAsync(SlashCommandContext ctx,
114115
}
115116
break;
116117
default:
117-
await ctx.RespondAsync($"Unknown {Formatter.Bold(location.ToString())}");
118+
await ctx.RespondAsync($"Unknown {Formatter.Bold(location.ToStringFast())}");
118119
return;
119120
}
120121

121122
var embed = _embedBuilderService.CreateEmbedBuilder(EmbedCategory.Tools, "Tools", culture)
122-
.WithTitle($"Search criterion {criterionId} in {location}")
123+
.WithTitle($"Search effect {effectId} in {location}")
123124
.WithDescription(descriptionBuilder.ToString().WithMaxLength(Constant.MaxEmbedDescriptionSize));
124125

125126
await ctx.RespondAsync(embed);
@@ -129,7 +130,7 @@ public async Task CriterionExecuteAsync(SlashCommandContext ctx,
129130
[SlashCommandTypes(DiscordApplicationCommandType.SlashCommand)]
130131
public async Task ItemSpriteExecuteAsync(SlashCommandContext ctx,
131132
[Parameter("item_type_id"), Description("Item type ID")]
132-
[MinMaxValue(0, 999)]
133+
[MinMaxValue(0, 999_999)]
133134
int itemTypeId,
134135
[Parameter("gfx_id"), Description("Gfx ID")]
135136
[MinMaxValue(-1, 999_999)]
@@ -157,4 +158,26 @@ public async Task ItemSpriteExecuteAsync(SlashCommandContext ctx,
157158

158159
await ctx.RespondAsync(embed);
159160
}
161+
162+
[Command("quest"), Description("Search the quest where the quest step ID is used")]
163+
[SlashCommandTypes(DiscordApplicationCommandType.SlashCommand)]
164+
public async Task QuestExecuteAsync(SlashCommandContext ctx,
165+
[Parameter("id"), Description("Quest step ID")]
166+
[MinMaxValue(0, 999_999)]
167+
int questStepId)
168+
{
169+
var culture = await _cultureService.GetCultureAsync(ctx.Interaction);
170+
171+
var questData = _dofusDatacenter.QuestsRepository.GetQuestDataByQuestStepId(questStepId, out var questStepIndex);
172+
if (questData is null)
173+
{
174+
await ctx.RespondAsync($"There is no quest with step ID {Formatter.Bold(questStepId.ToString())}.");
175+
return;
176+
}
177+
178+
var response = await new QuestMessageBuilder(_embedBuilderService, questData, questStepIndex, null, culture)
179+
.BuildAsync<DiscordInteractionResponseBuilder>();
180+
181+
await ctx.RespondAsync(response);
182+
}
160183
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
namespace Cyberia.Salamandra.Commands.Admin.Search;
2+
3+
public enum SearchCriterionLocation
4+
{
5+
Item,
6+
Spell
7+
}

Cyberia.Salamandra/Commands/Admin/Search/SearchLocation.cs renamed to Cyberia.Salamandra/Commands/Admin/Search/SearchEffectLocation.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
namespace Cyberia.Salamandra.Commands.Admin.Search;
22

3-
public enum SearchLocation
3+
public enum SearchEffectLocation
44
{
55
Item,
66
Spell
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
namespace Cyberia.Utils.Extensions;
2+
3+
/// <summary>
4+
/// Provides extension methods for enums.
5+
/// </summary>
6+
public static class EnumExtensions
7+
{
8+
/// <summary>
9+
/// Converts an enum value to its string representation using a fast method.
10+
/// </summary>
11+
/// <typeparam name="T">The type of the enum.</typeparam>
12+
/// <param name="value">The enum value to convert.</param>
13+
/// <returns>The string representation of the enum value.</returns>
14+
public static string ToStringFast<T>(this T value)
15+
where T : struct, Enum
16+
{
17+
return Enum.GetName(value) ?? value.ToString();
18+
}
19+
}

0 commit comments

Comments
 (0)