Skip to content

Commit

Permalink
Merge pull request #79 from Bia10/expandDebugCommand
Browse files Browse the repository at this point in the history
Add option to output debug into chat
  • Loading branch information
Kaioru authored Sep 30, 2023
2 parents 5072bdd + 3f97f9b commit 1a4d0da
Showing 1 changed file with 43 additions and 15 deletions.
58 changes: 43 additions & 15 deletions src/plugin/Edelstein.Plugin.Rue/Commands/Admin/DebugCommand.cs
Original file line number Diff line number Diff line change
@@ -1,14 +1,22 @@
using Edelstein.Common.Gameplay.Game.Objects.User.Messages;
using Edelstein.Protocol.Gameplay.Game.Objects.User;
using PowerArgs;

namespace Edelstein.Plugin.Rue.Commands.Admin;

public class DebugCommand : AbstractCommand
public class DebugCommandArgs : CommandArgs
{
[ArgPosition(0)]
[ArgDescription("Output to chat window?")]
public bool ToChat { get; set; } = false;
}

public class DebugCommand : AbstractCommand<DebugCommandArgs>
{
public override string Name => "Debug";
public override string Description => "Testing command for debugging purposes";

public override async Task Execute(IFieldUser user, string[] args)
protected override async Task Execute(IFieldUser user, DebugCommandArgs args)
{
await user.Message(new IncEXPMessage(1000, true));
await user.Message(new IncMoneyMessage(1000));
Expand All @@ -22,15 +30,23 @@ public override async Task Execute(IFieldUser user, string[] args)
[3] = "ExtendedSP Records",
[4] = "Quest Records",
[5] = "QuestEx Records",
[6] = "QuestCompletes Records",
[6] = "QuestCompleted Records",
}), -1);

if (answer == -1) return;

switch (answer)
{
case 0:
await user.Prompt(s => s.Say(user.Stats.ToString() ?? string.Empty), default);
var userStats = user.Stats.ToString() ?? string.Empty;

if (args.ToChat)
{
await user.Message(userStats);
break;
}

await user.Prompt(s => s.Say(userStats), default);
break;
case 1:
await DisplayRecordsToUser(
Expand All @@ -39,21 +55,24 @@ await DisplayRecordsToUser(
user.Character.TemporaryStats.Records.ToDictionary(
kvp => kvp.Key.ToString(),
kvp => kvp.Value.ToString() ?? string.Empty),
kvp => $"Type: {kvp.Key} Record: {kvp.Value}");
kvp => $"Type: {kvp.Key} Record: {kvp.Value}",
args.ToChat);
break;
case 2:
await DisplayRecordsToUser(
user,
"Skill",
user.Stats.SkillLevels.Records,
kvp => $"Id: {kvp.Key} Level: {kvp.Value}");
kvp => $"Id: {kvp.Key} Level: {kvp.Value}",
args.ToChat);
break;
case 3:
await DisplayRecordsToUser(
user,
"ExtendSP",
user.Character.ExtendSP.Records,
kvp => $"Id: {kvp.Key} Level: {kvp.Value}");
kvp => $"Id: {kvp.Key} Level: {kvp.Value}",
args.ToChat);
break;
case 4:
await DisplayRecordsToUser(
Expand All @@ -62,7 +81,8 @@ await DisplayRecordsToUser(
user.Character.QuestRecords.Records.ToDictionary(
kvp => kvp.Key.ToString(),
kvp => kvp.Value.ToString() ?? string.Empty),
kvp => $"Id: {kvp.Key} Value: {kvp.Value}");
kvp => $"Id: {kvp.Key} Value: {kvp.Value}",
args.ToChat);
break;
case 5:
await DisplayRecordsToUser(
Expand All @@ -71,16 +91,18 @@ await DisplayRecordsToUser(
user.Character.QuestRecordsEx.Records.ToDictionary(
kvp => kvp.Key.ToString(),
kvp => kvp.Value.ToString() ?? string.Empty),
kvp => $"Id: {kvp.Key} Value: {kvp.Value}");
kvp => $"Id: {kvp.Key} Value: {kvp.Value}",
args.ToChat);
break;
case 6:
await DisplayRecordsToUser(
user,
"QuestCompletes",
"QuestCompleted",
user.Character.QuestCompletes.Records.ToDictionary(
kvp => kvp.Key.ToString(),
kvp => kvp.Value.ToString() ?? string.Empty),
kvp => $"Id: {kvp.Key} Value: {kvp.Value}");
kvp => $"Id: {kvp.Key} Value: {kvp.Value}",
args.ToChat);
break;
}
}
Expand All @@ -89,16 +111,22 @@ private static async Task DisplayRecordsToUser<T>(
IFieldUser user,
string header,
IDictionary<T, T> record,
Func<KeyValuePair<T, T>, string> formatting)
Func<KeyValuePair<T, T>, string> formatting,
bool outputToChat = false)
{
var recordText = $"{header} records for player #e#b#h #:\\n";
var characterName = outputToChat ? user.Character.Name : "#e#b#h #";
var newline = outputToChat ? string.Empty : "\\n";
var recordText = $"{header} records for player {characterName}: {newline}";

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

await user.Prompt(s => s.Say(recordText), default);
if (outputToChat)
await user.Message(recordText);
else if (!outputToChat)
await user.Prompt(s => s.Say(recordText), default);
}
}

0 comments on commit 1a4d0da

Please sign in to comment.