Skip to content

Commit

Permalink
Add basic ribbon check for Wonder Trade bots
Browse files Browse the repository at this point in the history
  • Loading branch information
drgoku282 committed Mar 25, 2017
1 parent f3d3832 commit fd60369
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 20 deletions.
41 changes: 39 additions & 2 deletions PKMN-NTR/Bot/Bot.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,15 @@ public static void Report(string message)

public static bool IsLegal(PKM poke)
{
if (poke.GenNumber >= 6)
if (Program.gCmdWindow.enableillegal)
{
Report("Bot: Illegal mode enabled, skip check");
return true;
}

LegalityAnalysis Legal = new LegalityAnalysis(poke);
if (Legal.Parsed)
{
LegalityAnalysis Legal = new LegalityAnalysis(poke);
return Legal.Valid;
}
else
Expand All @@ -27,6 +33,37 @@ public static bool IsLegal(PKM poke)
}
}

public static bool IsTradeable(PKM poke)
{
if (!IsLegal(poke))
{ // Don't trade illegal pokemon
return false;
}

if (poke.IsEgg)
{ // Don't trade eggs
return false;
}

if (poke.Format == 6)
{
var poke6 = new PK6(poke.Data);
if (poke6.RibbonCountry || poke6.RibbonWorld || poke6.RibbonClassic || poke6.RibbonPremier || poke6.RibbonEvent || poke6.RibbonBirthday || poke6.RibbonSpecial || poke6.RibbonSouvenir || poke6.RibbonWishing || poke6.RibbonChampionBattle || poke6.RibbonChampionRegional || poke6.RibbonChampionNational || poke6.RibbonChampionWorld)
{ // Check for Special Ribbons
return false;
}
}
if (poke.Format == 7)
{
var poke7 = new PK7(poke.Data);
if (poke7.RibbonCountry || poke7.RibbonWorld || poke7.RibbonClassic || poke7.RibbonPremier || poke7.RibbonEvent || poke7.RibbonBirthday || poke7.RibbonSpecial || poke7.RibbonSouvenir || poke7.RibbonWishing || poke7.RibbonChampionBattle || poke7.RibbonChampionRegional || poke7.RibbonChampionNational || poke7.RibbonChampionWorld)
{ // Check for Special Ribbons
return false;
}
}
return true;
}

public static uint GetBoxOff(uint startOff, NumericUpDown boxSource, NumericUpDown slotSource)
{
return startOff + (uint)(boxSource.Value - 1) * 30 * 232 + (uint)(slotSource.Value - 1) * 232;
Expand Down
21 changes: 12 additions & 9 deletions PKMN-NTR/Bot/Bot_WonderTrade6.cs
Original file line number Diff line number Diff line change
Expand Up @@ -250,19 +250,22 @@ public async void RunBot()
else
{ // Valid pkm, check legality
attempts = 0;
if (IsLegal(WTpoke) || Program.gCmdWindow.enableillegal)
if (IsTradeable(WTpoke))
{
if (Program.gCmdWindow.enableillegal)
{
Report("Bot: Illegal pokémon, will trade it anyways");
}
currentCHK = WTpoke.Checksum;
Report("Bot: Pokémon found - 0x" + currentCHK.ToString("X4"));
botstate = botstates.pressWTbutton;
}
else
{
Report("Bot: Illegal pokémon");
if (Program.gCmdWindow.enableillegal)
{
Report("Bot: Pokémon cannot be traded, is an egg or have special ribbons.");
}
else
{
Report("Bot: Pokémon cannot be traded, is illegal or is an egg or have special ribbons.");
}
getNextSlot();
}
}
Expand All @@ -279,14 +282,14 @@ public async void RunBot()
if (temp.Length == 232)
{
PK6 pkmn = new PK6(temp);
if (IsLegal(pkmn) || Program.gCmdWindow.enableillegal)
if (IsTradeable(pkmn))
{ // Legal pkm
Report("Bot: Illegal pokémon, will write it anyways");
Report("Bot: Valid PK6 file");
pklist.Add(pkmn);
}
else
{ // Illegal pkm
Report("Bot: File " + pkf + " is illegal, will not be traded");
Report("Bot: File " + pkf + " cannot be traded");
}
}
else
Expand Down
21 changes: 12 additions & 9 deletions PKMN-NTR/Bot/Bot_WonderTrade7.cs
Original file line number Diff line number Diff line change
Expand Up @@ -266,19 +266,22 @@ public async void RunBot()
else
{ // Valid pkm, check legality
attempts = 0;
if (IsLegal(WTpoke) || Program.gCmdWindow.enableillegal)
if (IsTradeable(WTpoke))
{
if (Program.gCmdWindow.enableillegal)
{
Report("Bot: Illegal pokémon, will trade it anyways");
}
currentCHK = WTpoke.Checksum;
Report("Bot: Pokémon found - 0x" + currentCHK.ToString("X4"));
botstate = botstates.writelastbox;
}
else
{
Report("Bot: Illegal pokémon");
if (Program.gCmdWindow.enableillegal)
{
Report("Bot: Pokémon cannot be traded, is an egg or have special ribbons.");
}
else
{
Report("Bot: Pokémon cannot be traded, is illegal or is an egg or have special ribbons.");
}
getNextSlot();
}
}
Expand All @@ -295,14 +298,14 @@ public async void RunBot()
if (temp.Length == 232)
{
PK7 pkmn = new PK7(temp);
if (IsLegal(pkmn))
if (IsTradeable(pkmn))
{ // Legal pkm
Report("Bot: Illegal pokémon, will write it anyways");
Report("Bot: Valid PK7 ifle");
pklist.Add(pkmn);
}
else
{ // Illegal pkm
Report("Bot: File " + pkf + " is illegal, will not be traded");
Report("Bot: File " + pkf + " cannot be traded");
}
}
else
Expand Down

0 comments on commit fd60369

Please sign in to comment.