Skip to content

Commit

Permalink
Few modifications to trading steps/notifs
Browse files Browse the repository at this point in the history
  • Loading branch information
bdawg1989 committed Oct 31, 2024
1 parent 97388d7 commit d361507
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 25 deletions.
26 changes: 15 additions & 11 deletions SysBot.Pokemon.Discord/Helpers/DiscordTradeNotifier.cs
Original file line number Diff line number Diff line change
Expand Up @@ -113,32 +113,36 @@ public void TradeFinished(PokeRoutineExecutor<T> routine, PokeTradeDetail<T> inf
{
OnFinish?.Invoke(routine);
var tradedToUser = Data.Species;
string tradedSpeciesName = result.Species != 0 ? Enum.GetName(typeof(Species), result.Species) ?? "Unknown" : "";

if (info.TotalBatchTrades > 1)
{
// For batch trades, just send each Pokemon
if (Hub.Config.Discord.ReturnPKMs && result.Species != 0)
Trader.SendPKMAsync(result, "Here's what you traded me!").ConfigureAwait(false);

// Only send completion message on last trade
if (info.BatchTradeNumber == info.TotalBatchTrades)
// Send the embed only on the first trade of the batch
if (info.BatchTradeNumber == 1)
{
var message = tradedToUser != 0 ?
(info.IsMysteryEgg ? "Enjoy your **Mystery Eggs**!" : $"Enjoy your **{(Species)tradedToUser}** and other Pokémon!") :
"Batch trades finished!";

(info.IsMysteryEgg ? "Enjoy your **Mystery Eggs**!" :
info.IsMysteryMon ? "Enjoy your **Mystery Pokemon**!" :
$"Enjoy your **{(Species)tradedToUser}** and other Pokémon!") :
"Batch trades started!";
EmbedHelper.SendTradeFinishedEmbedAsync(Trader, message, Data, info.IsMysteryMon, info.IsMysteryEgg).ConfigureAwait(false);
}

// send each Pokemon file as they come in
if (Hub.Config.Discord.ReturnPKMs && result.Species != 0)
Trader.SendPKMAsync(result, $"Here's the {tradedSpeciesName} you traded me!").ConfigureAwait(false);
}
else
{
// Original single trade logic
var message = tradedToUser != 0 ?
(info.IsMysteryEgg ? "Enjoy your **Mystery Egg**!" : $"Enjoy your **{(Species)tradedToUser}**!") :
(info.IsMysteryEgg ? "Enjoy your **Mystery Egg**!" :
info.IsMysteryMon ? "Enjoy your **Mystery Pokemon**!" :
$"Enjoy your **{(Species)tradedToUser}**!") :
"Trade finished!";
EmbedHelper.SendTradeFinishedEmbedAsync(Trader, message, Data, info.IsMysteryMon, info.IsMysteryEgg).ConfigureAwait(false);
if (result.Species != 0 && Hub.Config.Discord.ReturnPKMs)
Trader.SendPKMAsync(result, "Here's what you traded me!").ConfigureAwait(false);
Trader.SendPKMAsync(result, $"Here's the {tradedSpeciesName} you traded me!").ConfigureAwait(false);
}
}

Expand Down
9 changes: 4 additions & 5 deletions SysBot.Pokemon/BDSP/BotTrade/PokeTradeBotBS.cs
Original file line number Diff line number Diff line change
Expand Up @@ -897,8 +897,6 @@ private async Task<PokeTradeResult> PerformLinkCodeTrade(SAV8BS sav, PokeTradeDe
var tradePartner = await GetTradePartnerInfo(token).ConfigureAwait(false);
var trainerNID = GetFakeNID(tradePartner.TrainerName, tradePartner.TrainerID);
RecordUtil<PokeTradeBotSWSH>.Record($"Initiating\t{trainerNID:X16}\t{tradePartner.TrainerName}\t{poke.Trainer.TrainerName}\t{poke.Trainer.ID}\t{poke.ID}\t{toSend.EncryptionConstant:X8}");
Log($"Found Link Trade partner: {tradePartner.TrainerName}-{tradePartner.TID7} (ID: {trainerNID})");
poke.SendNotification(this, $"Found Link Trade partner: {tradePartner.TrainerName}. **TID**: {tradePartner.TID7} **SID**: {tradePartner.SID7}. Waiting for a Pokémon...");

var tradeCodeStorage = new TradeCodeStorage();
var existingTradeDetails = tradeCodeStorage.GetTradeDetails(poke.Trainer.ID);
Expand Down Expand Up @@ -1095,8 +1093,6 @@ private async Task<PokeTradeResult> PerformBatchTrade(SAV8BS sav, PokeTradeDetai

var tradePartner = await GetTradePartnerInfo(token).ConfigureAwait(false);
var trainerNID = GetFakeNID(tradePartner.TrainerName, tradePartner.TrainerID);
Log($"Found Link Trade partner: {tradePartner.TrainerName}-{tradePartner.TID7} (ID: {trainerNID})");
poke.SendNotification(this, $"Found Link Trade partner: {tradePartner.TrainerName}. **TID**: {tradePartner.TID7} **SID**: {tradePartner.SID7}. Waiting for a Pokémon...");

// Handle trainer data
var tradeCodeStorage = new TradeCodeStorage();
Expand Down Expand Up @@ -1131,6 +1127,10 @@ private async Task<PokeTradeResult> PerformBatchTrade(SAV8BS sav, PokeTradeDetai
return PokeTradeResult.SuspiciousActivity;
}

Log($"Found Link Trade partner: {tradePartner.TrainerName}-{tradePartner.TID7} (ID: {trainerNID})");
if (completedTrades == 0 || startingDetail.TotalBatchTrades == 1)
poke.SendNotification(this, $"Found Link Trade partner: {tradePartner.TrainerName}. **TID**: {tradePartner.TID7} **SID**: {tradePartner.SID7}. Waiting for a Pokémon...");

if (Hub.Config.Legality.UseTradePartnerInfo && !poke.IgnoreAutoOT)
{
toSend = await ApplyAutoOT(toSend, sav, tradePartner.TrainerName, (uint)tid, (uint)sid, token);
Expand All @@ -1139,7 +1139,6 @@ private async Task<PokeTradeResult> PerformBatchTrade(SAV8BS sav, PokeTradeDetai
await Task.Delay(2_000, token).ConfigureAwait(false);

// Begin trade
poke.SendNotification(this, $"Found Link Trade partner: {tradePartner.TrainerName}. **TID**: {tradePartner.TID7} **SID**: {tradePartner.SID7} Waiting for a Pokémon...");
LinkTradePokemonOffset = await SwitchConnection.PointerAll(Offsets.LinkTradePartnerPokemonPointer, token).ConfigureAwait(false);

var offered = await ReadUntilPresent(LinkTradePokemonOffset, 25_000, 1_000, BoxFormatSlotSize, token).ConfigureAwait(false);
Expand Down
5 changes: 2 additions & 3 deletions SysBot.Pokemon/LA/BotTrade/PokeTradeBotLA.cs
Original file line number Diff line number Diff line change
Expand Up @@ -433,8 +433,6 @@ private async Task<PokeTradeResult> PerformBatchTrade(SAV8LA sav, PokeTradeDetai
var trainerNID = await GetTradePartnerNID(TradePartnerNIDOffset, token).ConfigureAwait(false);
tradePartner.NID = trainerNID;
RecordUtil<PokeTradeBotSWSH>.Record($"Initiating\t{trainerNID:X16}\t{tradePartner.TrainerName}\t{poke.Trainer.TrainerName}\t{poke.Trainer.ID}\t{poke.ID}\t{toSend.EncryptionConstant:X8}");
Log($"Found Link Trade partner: {tradePartner.TrainerName}-{tradePartner.TID7} (ID: {trainerNID})");
poke.SendNotification(this, $"Found Link Trade partner: {tradePartner.TrainerName}. **TID**: {tradePartner.TID7} **SID**: {tradePartner.SID7}. Waiting for a Pokémon...");

var tradeCodeStorage = new TradeCodeStorage();
var existingTradeDetails = tradeCodeStorage.GetTradeDetails(poke.Trainer.ID);
Expand Down Expand Up @@ -462,8 +460,9 @@ private async Task<PokeTradeResult> PerformBatchTrade(SAV8LA sav, PokeTradeDetai
}

// Only send the "Found partner" notification on the first trade of a batch or for single trades
Log($"Found Link Trade partner: {tradePartner.TrainerName}-{tradePartner.TID7} (ID: {trainerNID})");
if (completedTrades == 0 || startingDetail.TotalBatchTrades == 1)
poke.SendNotification(this, $"Found Link Trade partner: {tradePartner.TrainerName}. TID: {tradePartner.TID7} SID: {tradePartner.SID7} Waiting for a Pokémon...");
poke.SendNotification(this, $"Found Link Trade partner: {tradePartner.TrainerName}. **TID**: {tradePartner.TID7} **SID**: {tradePartner.SID7}. Waiting for a Pokémon...");

// Watch their status to indicate they have offered a Pokémon as well.
var offering = await ReadUntilChanged(TradePartnerOfferedOffset, [0x3], 25_000, 1_000, true, true, token).ConfigureAwait(false);
Expand Down
6 changes: 2 additions & 4 deletions SysBot.Pokemon/SV/BotTrade/PokeTradeBotSV.cs
Original file line number Diff line number Diff line change
Expand Up @@ -881,8 +881,6 @@ private async Task<PokeTradeResult> PerformBatchTrade(SAV9SV sav, PokeTradeDetai
var tradePartner = new TradePartnerSV(tradePartnerFullInfo);
var trainerNID = await GetTradePartnerNID(TradePartnerNIDOffset, token).ConfigureAwait(false);
RecordUtil<PokeTradeBotSWSH>.Record($"Initiating\t{trainerNID:X16}\t{tradePartner.TrainerName}\t{poke.Trainer.TrainerName}\t{poke.Trainer.ID}\t{poke.ID}\t{toSend.EncryptionConstant:X8}");
Log($"Found Link Trade partner: {tradePartner.TrainerName}-{tradePartner.TID7} (ID: {trainerNID})");
poke.SendNotification(this, $"Found Link Trade partner: {tradePartner.TrainerName}. **TID**: {tradePartner.TID7} **SID**: {tradePartner.SID7}. Waiting for a Pokémon...");

var tradeCodeStorage = new TradeCodeStorage();
var existingTradeDetails = tradeCodeStorage.GetTradeDetails(poke.Trainer.ID);
Expand Down Expand Up @@ -926,9 +924,9 @@ private async Task<PokeTradeResult> PerformBatchTrade(SAV9SV sav, PokeTradeDetai
return PokeTradeResult.TrainerTooSlow;
}

// Only send the "Found partner" notification on the first trade of a batch or for single trades
Log($"Found Link Trade partner: {tradePartner.TrainerName}-{tradePartner.TID7} (ID: {trainerNID})");
if (completedTrades == 0 || startingDetail.TotalBatchTrades == 1)
poke.SendNotification(this, $"Found Link Trade partner: {tradePartner.TrainerName}. **TID**: {tradePartner.TID7} **SID**: {tradePartner.SID7} Waiting for a Pokémon...");
poke.SendNotification(this, $"Found Link Trade partner: {tradePartner.TrainerName}. **TID**: {tradePartner.TID7} **SID**: {tradePartner.SID7}. Waiting for a Pokémon...");

if (Hub.Config.Legality.UseTradePartnerInfo && !poke.IgnoreAutoOT)
{
Expand Down
6 changes: 4 additions & 2 deletions SysBot.Pokemon/SWSH/BotTrade/PokeTradeBotSWSH.cs
Original file line number Diff line number Diff line change
Expand Up @@ -359,8 +359,6 @@ private async Task<PokeTradeResult> PerformBatchTrade(SAV8SWSH sav, PokeTradeDet
var trainerSID = await GetTradePartnerSID7(TradeMethod.LinkTrade, token).ConfigureAwait(false);
var trainerNID = await GetTradePartnerNID(token).ConfigureAwait(false);
RecordUtil<PokeTradeBotSWSH>.Record($"Initiating\t{trainerNID:X16}\t{trainerName}\t{poke.Trainer.TrainerName}\t{poke.Trainer.ID}\t{poke.ID}\t{toSend.EncryptionConstant:X8}");
Log($"Found Link Trade partner: {trainerName}-{trainerTID} (ID: {trainerNID})");
poke.SendNotification(this, $"Found Link Trade partner: {trainerName}. **TID**: {trainerTID} **SID**: {trainerSID}. Waiting for a Pokémon...");

var tradeCodeStorage = new TradeCodeStorage();
var existingTradeDetails = tradeCodeStorage.GetTradeDetails(poke.Trainer.ID);
Expand Down Expand Up @@ -398,6 +396,10 @@ private async Task<PokeTradeResult> PerformBatchTrade(SAV8SWSH sav, PokeTradeDet
return PokeTradeResult.RecoverOpenBox;
}

Log($"Found Link Trade partner: {trainerName}-{trainerTID} (ID: {trainerNID})");
if (completedTrades == 0 || startingDetail.TotalBatchTrades == 1)
poke.SendNotification(this, $"Found Link Trade partner: {trainerName}. **TID**: {trainerTID} **SID**: {trainerSID}. Waiting for a Pokémon...");

if (Hub.Config.Legality.UseTradePartnerInfo && !poke.IgnoreAutoOT)
{
toSend = await ApplyAutoOT(toSend, trainerName, sav, token);
Expand Down

0 comments on commit d361507

Please sign in to comment.