Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Expand debug command #78

Merged
merged 4 commits into from
Sep 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ public class StartPluginBootstrap<TContext> : IBootstrap
private readonly IPluginManager<TContext> _manager;

public StartPluginBootstrap(
ILogger<StartPluginBootstrap<TContext>> logger,
ILoggerFactory loggerFactory,
TContext context,
ILogger<StartPluginBootstrap<TContext>> logger,
ILoggerFactory loggerFactory,
TContext context,
IPluginManager<TContext> manager
)
{
Expand All @@ -24,26 +24,27 @@ IPluginManager<TContext> manager
_context = context;
_manager = manager;
}

public int Priority => BootstrapPriority.Start;

public async Task Start()
{
var plugins = await _manager.RetrieveAll();
var hosted = plugins
.Select(p =>
.Select(p =>
Tuple.Create(p, new PluginHost(_loggerFactory.CreateLogger(p.GetType()))))
.ToImmutableList();

foreach (var host in hosted)
{
await host.Item1.OnInit(host.Item2, _context);
_logger.LogDebug("{Context} plugin {ID} initialised", typeof(TContext).Name, host.Item1.ID);
_logger.LogInformation("{Context} plugin {ID} initialised", typeof(TContext).Name, host.Item1.ID);
}

foreach (var host in hosted)
{
await host.Item1.OnStart(host.Item2, _context);
_logger.LogDebug("{Context} plugin {ID} started", typeof(TContext).Name, host.Item1.ID);
_logger.LogInformation("{Context} plugin {ID} started", typeof(TContext).Name, host.Item1.ID);
}
}

Expand All @@ -54,7 +55,7 @@ public async Task Stop()
foreach (var plugin in plugins)
{
await plugin.OnStop();
_logger.LogDebug("{Context} plugin {ID} stopped", typeof(TContext).Name, plugin.ID);
_logger.LogInformation("{Context} plugin {ID} stopped", typeof(TContext).Name, plugin.ID);
}
}
}
91 changes: 89 additions & 2 deletions src/plugin/Edelstein.Plugin.Rue/Commands/Admin/DebugCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,98 @@ public class DebugCommand : AbstractCommand
{
public override string Name => "Debug";
public override string Description => "Testing command for debugging purposes";

public override async Task Execute(IFieldUser user, string[] args)
{
await user.Message(new IncEXPMessage(1000, true));
await user.Message(new IncMoneyMessage(1000));
await user.Prompt(s => s.Say(user.Stats.ToString()!), default);

var answer = await user.Prompt(target => target.AskMenu(
"What would you like to debug?", new Dictionary<int, string>
{
[0] = "Stats",
[1] = "Temporary Stats Records",
[2] = "Skill Records",
[3] = "ExtendedSP Records",
[4] = "Quest Records",
[5] = "QuestEx Records",
[6] = "QuestCompletes Records",
}), -1);

if (answer == -1) return;

switch (answer)
{
case 0:
await user.Prompt(s => s.Say(user.Stats.ToString() ?? string.Empty), default);
break;
case 1:
await DisplayRecordsToUser(
user,
"Temporary stats",
user.Character.TemporaryStats.Records.ToDictionary(
kvp => kvp.Key.ToString(),
kvp => kvp.Value.ToString() ?? string.Empty),
kvp => $"Type: {kvp.Key} Record: {kvp.Value}");
break;
case 2:
await DisplayRecordsToUser(
user,
"Skill",
user.Stats.SkillLevels.Records,
kvp => $"Id: {kvp.Key} Level: {kvp.Value}");
break;
case 3:
await DisplayRecordsToUser(
user,
"ExtendSP",
user.Character.ExtendSP.Records,
kvp => $"Id: {kvp.Key} Level: {kvp.Value}");
break;
case 4:
await DisplayRecordsToUser(
user,
"Quest",
user.Character.QuestRecords.Records.ToDictionary(
kvp => kvp.Key.ToString(),
kvp => kvp.Value.ToString() ?? string.Empty),
kvp => $"Id: {kvp.Key} Value: {kvp.Value}");
break;
case 5:
await DisplayRecordsToUser(
user,
"QuestEx",
user.Character.QuestRecordsEx.Records.ToDictionary(
kvp => kvp.Key.ToString(),
kvp => kvp.Value.ToString() ?? string.Empty),
kvp => $"Id: {kvp.Key} Value: {kvp.Value}");
break;
case 6:
await DisplayRecordsToUser(
user,
"QuestCompletes",
user.Character.QuestCompletes.Records.ToDictionary(
kvp => kvp.Key.ToString(),
kvp => kvp.Value.ToString() ?? string.Empty),
kvp => $"Id: {kvp.Key} Value: {kvp.Value}");
break;
}
}

private static async Task DisplayRecordsToUser<T>(
IFieldUser user,
string header,
IDictionary<T, T> record,
Func<KeyValuePair<T, T>, string> formatting)
{
var recordText = $"{header} records for player #e#b#h #:\\n";

for (var i = 0; i < record.Count; i++)
{
KeyValuePair<T, T> kvp = record.ElementAt(i);
recordText += $"[{i}] {formatting(kvp)}\\n";
}

await user.Prompt(s => s.Say(recordText), default);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ public class EquipCommand : AbstractCommand
{
public override string Name => "Equip";
public override string Description => "Modifies equipment stats";

public override async Task Execute(IFieldUser user, string[] args)
{
var equipped = user.Character.Inventories[ItemInventoryType.Equip]?.Items.ToList() ?? new List<KeyValuePair<short, IItemSlot>>();
Expand All @@ -21,9 +21,10 @@ public override async Task Execute(IFieldUser user, string[] args)
)), -1);

if (slot == -1) return;

var item = user.Character.Inventories[ItemInventoryType.Equip]?.Items[(short)slot];
if (item is not IItemSlotEquip equip) return;

var sel = await user.Prompt(target => target.AskMenu("Which equipment stat?", new Dictionary<int, string>
{
[0] = "Grade",
Expand All @@ -41,7 +42,7 @@ public override async Task Execute(IFieldUser user, string[] args)
equip.Grade = (byte)await user.Prompt(target => target.AskNumber("What value?"), 0);
break;
case 4:
equip.Grade = (byte)-await user.Prompt(target => target.AskNumber("What value?"), 0);
equip.Grade = (byte) -await user.Prompt(target => target.AskNumber("What value?"), 0);
break;
case 1:
equip.Option1 = (short)await user.Prompt(target => target.AskNumber("What value?"), 0);
Expand Down