Skip to content

Commit

Permalink
Add quest search command
Browse files Browse the repository at this point in the history
  • Loading branch information
Kaioru committed Sep 23, 2023
1 parent 3394bfc commit 2423f25
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ namespace Edelstein.Common.Gameplay.Models.Characters.Quests.Templates;
public record QuestTemplate : IQuestTemplate
{
public int ID { get; }

public string Name { get; }

public bool IsAutoAccept { get; }
public bool IsAutoStart { get; }
Expand All @@ -21,10 +23,14 @@ public QuestTemplate(int id, IDataProperty property)
{
ID = id;

IsAutoAccept = (property.Resolve<int>("autoAccept") ?? 0) > 0;
IsAutoStart = (property.Resolve<int>("autoStart") ?? 0) > 0;
IsAutoComplete = (property.Resolve<int>("autoComplete") ?? 0) > 0;
IsAutoPreComplete = (property.Resolve<int>("autoPreComplete") ?? 0) > 0;
var info = property.Resolve("QuestInfo")?.ResolveAll();

Name = info?.ResolveOrDefault<string>("name") ?? "NO-NAME";

IsAutoAccept = (info?.Resolve<int>("autoAccept") ?? 0) > 0;
IsAutoStart = (info?.Resolve<int>("autoStart") ?? 0) > 0;
IsAutoComplete = (info?.Resolve<int>("autoComplete") ?? 0) > 0;
IsAutoPreComplete = (info?.Resolve<int>("autoPreComplete") ?? 0) > 0;

var act = property.Resolve("Act")?.ResolveAll();

Expand Down
35 changes: 35 additions & 0 deletions src/plugin/Edelstein.Plugin.Rue/Commands/Admin/QuestCommand.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
using Edelstein.Protocol.Gameplay.Game.Objects.User;
using Edelstein.Protocol.Gameplay.Models.Characters.Quests.Templates;
using Edelstein.Protocol.Gameplay.Models.Inventories.Templates;
using Edelstein.Protocol.Utilities.Templates;

namespace Edelstein.Plugin.Rue.Commands.Admin;

public class QuestCommand : AbstractTemplateCommand<IQuestTemplate>
{
public override string Name => "Quest";
public override string Description => "Searches a specified quest";

private readonly ITemplateManager<IQuestTemplate> _strings;

public QuestCommand(
ITemplateManager<IQuestTemplate> templates
) : base(templates)
{
_strings = templates;
}

protected override async Task<IEnumerable<TemplateCommandIndex>> Indices()
{
var result = new List<TemplateCommandIndex>();
var strings = (await _strings.RetrieveAll()).ToList();

result.AddRange(strings.Select(s => new TemplateCommandIndex(s.ID, s.ID.ToString(), s.Name)));
result.AddRange(strings.Select(s => new TemplateCommandIndex(s.ID, s.Name, s.Name)));

return result;
}

protected override Task Execute(IFieldUser user, IQuestTemplate template, TemplateCommandArgs args)
=> Task.CompletedTask;
}
3 changes: 3 additions & 0 deletions src/plugin/Edelstein.Plugin.Rue/RueGamePlugin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@ public Task OnStart(IPluginHost host, GameContext ctx)
ctx.Templates.Skill,
ctx.Templates.SkillString
));
commandManager.Insert(new QuestCommand(
ctx.Templates.Quest
));
commandManager.Insert(new EquipCommand());
commandManager.Insert(new StatCommand());
commandManager.Insert(new TemporaryStatCommand());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using Edelstein.Protocol.Gameplay.Game.Objects.Mob.Templates;
using Edelstein.Protocol.Gameplay.Game.Objects.NPC.Templates;
using Edelstein.Protocol.Gameplay.Game.Templates;
using Edelstein.Protocol.Gameplay.Models.Characters.Quests.Templates;
using Edelstein.Protocol.Gameplay.Models.Characters.Skills.Templates;
using Edelstein.Protocol.Gameplay.Models.Inventories.Templates;
using Edelstein.Protocol.Gameplay.Models.Inventories.Templates.Options;
Expand All @@ -15,6 +16,7 @@ public record GameContextTemplates(
ITemplateManager<IItemOptionTemplate> ItemOption,
ITemplateManager<ISkillTemplate> Skill,
ITemplateManager<ISkillStringTemplate> SkillString,
ITemplateManager<IQuestTemplate> Quest,
ITemplateManager<IFieldTemplate> Field,
ITemplateManager<IFieldStringTemplate> FieldString,
ITemplateManager<INPCTemplate> NPC,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ namespace Edelstein.Protocol.Gameplay.Models.Characters.Quests.Templates;

public interface IQuestTemplate : ITemplate
{
string Name { get; }

bool IsAutoAccept { get; }
bool IsAutoStart { get; }
bool IsAutoComplete { get; }
Expand Down

0 comments on commit 2423f25

Please sign in to comment.