From 52ab0ed0ca395cd3fb3fca0bfcdff75dc96e8d69 Mon Sep 17 00:00:00 2001 From: John Tur Date: Sat, 11 May 2024 04:41:13 -0400 Subject: [PATCH] Improve trade embed --- DiscordMonies/Game/PrettyColors.cs | 2 ++ DiscordMonies/Game/Trade/TradeCommands.cs | 6 ++-- DiscordMonies/Game/Trade/TradeService.cs | 43 ++++++++--------------- DiscordMonies/Game/Trade/TradeTable.cs | 19 +++++----- 4 files changed, 29 insertions(+), 41 deletions(-) diff --git a/DiscordMonies/Game/PrettyColors.cs b/DiscordMonies/Game/PrettyColors.cs index 64d90c9..ac16a5e 100644 --- a/DiscordMonies/Game/PrettyColors.cs +++ b/DiscordMonies/Game/PrettyColors.cs @@ -12,6 +12,8 @@ public static class PrettyColors public static readonly Color Gold = Color.FromArgb(0xF1C40F); + public static readonly Color Purple = Color.FromArgb(0x9B59B6); + public static readonly ImmutableArray ColorList = [ new("red", Color.FromArgb(255, 70, 70)), diff --git a/DiscordMonies/Game/Trade/TradeCommands.cs b/DiscordMonies/Game/Trade/TradeCommands.cs index 0d514ef..0c0337d 100644 --- a/DiscordMonies/Game/Trade/TradeCommands.cs +++ b/DiscordMonies/Game/Trade/TradeCommands.cs @@ -18,7 +18,6 @@ public class TradeCommands(GameState gameState, IInteractionCommandContext ctx, [Command("open")] [RequiresPlayer(PlayerType.Player)] [Description("Set up a new trade with a player")] - [Ephemeral] public async Task Open([Description("The player to trade with")] GamePlayer otherPlayer) { var player = gameState.GetById(ctx.GetUserId()); @@ -35,8 +34,9 @@ public async Task Open([Description("The player to trade with")] GamePla To = otherPlayer, CopyOf = null }; - - await feedback.SendContextualAsync($"Opened a new trade table. Add items to the trade table, and then offer it to {Mention.User(otherPlayer)} when you're ready."); + + await feedback.SendContextualAsync($"{player} is creating a trade...", options: MessageOptions.SuppressNotifications); + await feedback.SendContextualAsync($"Opened a new trade table. Add items to the trade table, and then offer it to {Mention.User(otherPlayer)} when you're ready.", options: MessageOptions.Ephemeral); return Result.Success; } diff --git a/DiscordMonies/Game/Trade/TradeService.cs b/DiscordMonies/Game/Trade/TradeService.cs index 8e728dd..d302537 100644 --- a/DiscordMonies/Game/Trade/TradeService.cs +++ b/DiscordMonies/Game/Trade/TradeService.cs @@ -63,7 +63,7 @@ public async Task Toggle(IOwnable ownable, bool giving) } entry.Add(ownable); - await feedback.SendContextualAsync($"Added {ownable} to the trade table.", embeds: new([tradeTable.PrintTradeTable(true)])); + await feedback.SendContextualAsync($"Added {ownable} to the trade table.", embeds: new([tradeTable.PrintTradeTable()])); } public async Task SetMoney(int money, bool giving) @@ -93,7 +93,7 @@ public async Task SetMoney(int money, bool giving) { tradeTable.Money = -money; } - await feedback.SendContextualAsync($"Added {money.MoneyString()} to the trade table.", embeds: new([tradeTable.PrintTradeTable(true)])); + await feedback.SendContextualAsync($"Added {money.MoneyString()} to the trade table.", embeds: new([tradeTable.PrintTradeTable()])); } public async Task Offer() @@ -105,7 +105,7 @@ public async Task Offer() { await feedback.SendContextualAsync( $"Unable to offer this trade table as it is empty. Please add items to the trade table.", - embeds: new([tradeTable.PrintTradeTable(true)])); + embeds: new([tradeTable.PrintTradeTable()])); return; } @@ -113,7 +113,7 @@ await feedback.SendContextualAsync( { await feedback.SendContextualAsync( $"Unable to offer this trade table as it is now invalid. Please check the trade table and ensure that each player has the required assets in order to trade.", - embeds: new([tradeTable.PrintTradeTable(true)])); + embeds: new([tradeTable.PrintTradeTable()])); return; } @@ -127,7 +127,7 @@ await feedback.SendContextualAsync( await feedback.SendAsync(gameState.ThreadId, tradeTable.CopyOf is not null ? $"{Mention.User(tradeTable.To)}, **{tradeTable.From}** offers you a counter trade." : $"{Mention.User(tradeTable.To)}, **{tradeTable.From}** wants to trade with you.", - embeds: new([tradeTable.PrintTradeTable(false)]), options: new() + embeds: new([tradeTable.PrintTradeTable()]), options: new() { MessageComponents = new([ new ActionRowComponent([ @@ -184,20 +184,14 @@ public async Task AcceptTradeTable(TradeTable tradeTable) { if (tradeTable.State != TradeTable.TradeTableState.Offered) { - await feedback.SendContextualAsync("You can't accept this trade table because it's not currently open.", options: new() - { - MessageFlags = new(MessageFlags.Ephemeral) - }); + await feedback.SendContextualAsync("You can't accept this trade table because it's not currently open.", options: MessageOptions.Ephemeral); return; } var player = gameState.GetById(ctx.GetUserId()); if (tradeTable.To != player) { - await feedback.SendContextualAsync("You can't accept this trade table because it's not addressed to you.", options: new() - { - MessageFlags = new(MessageFlags.Ephemeral) - }); + await feedback.SendContextualAsync("You can't accept this trade table because it's not addressed to you.", options: MessageOptions.Ephemeral); return; } @@ -205,7 +199,7 @@ public async Task AcceptTradeTable(TradeTable tradeTable) { await feedback.SendContextualAsync( "Unable to accept this trade table as it is now invalid. Please check the trade table and ensure that each player has the required assets in order to trade. You can counter the trade table in order to edit it.", - embeds: new([tradeTable.PrintTradeTable(true)])); + embeds: new([tradeTable.PrintTradeTable()])); return; } @@ -218,28 +212,22 @@ await feedback.SendContextualAsync( await gameControllerService.TryPay(tradeTable.From, tradeTable.To, tradeTable.Money); await feedback.SendAsync(gameState.ThreadId, - $"{tradeTable.To} has completed a trade with **{tradeTable.From}**.", - embeds: new([tradeTable.PrintTradeTable(true)])); + $"{tradeTable.To} has accepted {tradeTable.From}'s trade.", + embeds: new([tradeTable.PrintTradeTable()])); } public async Task CounterTradeTable(TradeTable tradeTable) { if (tradeTable.State != TradeTable.TradeTableState.Offered) { - await feedback.SendContextualAsync("You can't counter this trade table because it's not currently open.", options: new() - { - MessageFlags = new(MessageFlags.Ephemeral) - }); + await feedback.SendContextualAsync("You can't counter this trade table because it's not currently open.", options: MessageOptions.Ephemeral); return; } var player = gameState.GetById(ctx.GetUserId()); if (tradeTable.To != player) { - await feedback.SendContextualAsync("You can't counter this trade table because it's not addressed to you.", options: new() - { - MessageFlags = new(MessageFlags.Ephemeral) - }); + await feedback.SendContextualAsync("You can't counter this trade table because it's not addressed to you.", options: MessageOptions.Ephemeral); return; } @@ -247,7 +235,7 @@ public async Task CounterTradeTable(TradeTable tradeTable) player.ConfiguringTradeTable = tradeTable.Copy(); await feedback.SendContextualAsync("You can now edit the trade. Once you're done, offer the trade with /trade offer again.", - embeds: new([tradeTable.PrintTradeTable(true)]), options: new() + embeds: new([tradeTable.PrintTradeTable()]), options: new() { MessageFlags = new(MessageFlags.Ephemeral) }); @@ -257,10 +245,7 @@ public async Task RejectTradeTable(TradeTable tradeTable) { if (tradeTable.State != TradeTable.TradeTableState.Offered) { - await feedback.SendContextualAsync("You can't reject this trade table because it's not currently open.", options: new() - { - MessageFlags = new(MessageFlags.Ephemeral) - }); + await feedback.SendContextualAsync("You can't reject this trade table because it's not currently open.", options: MessageOptions.Ephemeral); return; } diff --git a/DiscordMonies/Game/Trade/TradeTable.cs b/DiscordMonies/Game/Trade/TradeTable.cs index 0f9b632..edc607b 100644 --- a/DiscordMonies/Game/Trade/TradeTable.cs +++ b/DiscordMonies/Game/Trade/TradeTable.cs @@ -43,12 +43,18 @@ public TradeTable Copy() }; } - public Embed PrintTradeTable(bool asGiving) + public Embed PrintTradeTable() { + static string OwnableEntry(IOwnable ownable) + { + return ownable is Space { IsMortgaged: true } ? $"- {Emoji.CircledM} {ownable}" : $"- {ownable}"; + } + var builder = new EmbedBuilder() - .WithTitle("Trade") - .AddField($"{From} gives", string.Join("\n", Giving.Select(OwnableEntry).Append(Money > 0 ? Money.MoneyString() : string.Empty))).Get() - .AddField($"{To} gives", string.Join("\n", Receiving.Select(OwnableEntry).Append(Money < 0 ? (-Money).MoneyString() : string.Empty))).Get(); + .WithTitle($"Trade {Emoji.TwistedArrows}") + .WithColour(PrettyColors.Purple) + .AddField($"{From.DisplayName} gives:", string.Join("\n", Giving.Select(OwnableEntry).Append(Money > 0 ? $"- {Money.MoneyString()}" : string.Empty)), true).Get() + .AddField($"{To.DisplayName} gives:", string.Join("\n", Receiving.Select(OwnableEntry).Append(Money < 0 ? $"- {(-Money).MoneyString()}" : string.Empty)), true).Get(); if (Giving.Concat(Receiving).Any(x => x is Space { IsMortgaged: true })) { @@ -58,9 +64,4 @@ public Embed PrintTradeTable(bool asGiving) return builder.Build().Get(); } - - private static string OwnableEntry(IOwnable ownable) - { - return ownable is Space { IsMortgaged: true } ? $"{Emoji.CircledM} {ownable.ToString()}" : ownable.ToString(); - } } \ No newline at end of file