Skip to content
This repository was archived by the owner on Jul 14, 2025. It is now read-only.
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
20 changes: 16 additions & 4 deletions SysBot.Pokemon/Helpers/AutoLegalityWrapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using System;
using System.IO;
using System.Linq;
using System.Runtime.ConstrainedExecution;
using System.Threading;

namespace SysBot.Pokemon;
Expand Down Expand Up @@ -40,7 +41,13 @@ private static void InitializeSettings(LegalitySettings cfg)
APILegality.AllowTrainerOverride = cfg.AllowTrainerDataOverride;
APILegality.AllowBatchCommands = cfg.AllowBatchCommands;
APILegality.PrioritizeGame = cfg.PrioritizeGame;
APILegality.PrioritizeGameVersion = cfg.PrioritizeGameVersion;
GameVersion[] validVersions = [.. Enum.GetValues<GameVersion>().Where(ver => ver <= (GameVersion)51 && ver > GameVersion.Any)];
foreach (var ver in validVersions)
{
if (!cfg.PriorityOrder.Contains(ver))
cfg.PriorityOrder.Add(ver);
}
APILegality.PriorityOrder = cfg.PriorityOrder;
APILegality.SetBattleVersion = cfg.SetBattleVersion;
APILegality.Timeout = cfg.Timeout;
var settings = ParseSettings.Settings;
Expand Down Expand Up @@ -78,6 +85,7 @@ private static void InitializeTrainerDatabase(LegalitySettings cfg)
RegisterIfNoneExist(fallback, 7, GameVersion.GP);
RegisterIfNoneExist(fallback, 7, GameVersion.GE);
}

private static SimpleTrainerInfo GetDefaultTrainer(LegalitySettings cfg)
{
var OT = cfg.GenerateOT;
Expand All @@ -93,6 +101,7 @@ private static SimpleTrainerInfo GetDefaultTrainer(LegalitySettings cfg)
};
return fallback;
}

private static void RegisterIfNoneExist(SimpleTrainerInfo fallback, byte generation, GameVersion version)
{
fallback = new SimpleTrainerInfo(version)
Expand All @@ -107,6 +116,7 @@ private static void RegisterIfNoneExist(SimpleTrainerInfo fallback, byte generat
if (exist is SimpleTrainerInfo) // not anything from files; this assumes ALM returns SimpleTrainerInfo for non-user-provided fake templates.
TrainerSettings.Register(fallback);
}

private static void InitializeCoreStrings()
{
var lang = Thread.CurrentThread.CurrentCulture.TwoLetterISOLanguageName[..2];
Expand Down Expand Up @@ -162,16 +172,18 @@ public static PKM GetLegal(this ITrainerInfo sav, IBattleTemplate set, out strin
var result = sav.GetLegalFromSet(set);
res = result.Status switch
{
LegalizationResult.Regenerated => "Regenerated",
LegalizationResult.Failed => "Failed",
LegalizationResult.Timeout => "Timeout",
LegalizationResult.Regenerated => "Regenerated",
LegalizationResult.Failed => "Failed",
LegalizationResult.Timeout => "Timeout",
LegalizationResult.VersionMismatch => "VersionMismatch",
_ => "",
};
return result.Created;
}

public static string GetLegalizationHint(IBattleTemplate set, ITrainerInfo sav, PKM pk) => set.SetAnalysis(sav, pk);

public static PKM LegalizePokemon(this PKM pk) => pk.Legalize();

public static IBattleTemplate GetTemplate(ShowdownSet set) => new RegenTemplate(set);
}
11 changes: 7 additions & 4 deletions SysBot.Pokemon/Settings/LegalitySettings.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
using PKHeX.Core;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;

namespace SysBot.Pokemon;

Expand All @@ -9,6 +11,7 @@ public class LegalitySettings
private string DefaultTrainerName = "SysBot";
private const string Generate = nameof(Generate);
private const string Misc = nameof(Misc);

public override string ToString() => "Legality Generating Settings";

// Generate
Expand Down Expand Up @@ -42,10 +45,10 @@ public string GenerateOT
public byte GenerateGenderOT { get; set; } = 0;

[Category(Generate), Description("If PrioritizeGame is set to \"True\", uses PrioritizeGameVersion to start looking for encounters. If \"False\", uses newest game as the version. It is recommended to leave this as \"True\".")]
public bool PrioritizeGame { get; set; } = true;
public bool PrioritizeGame { get; set; } = false;

[Category(Generate), Description("Specifies the first game to use to generate encounters, or current game if this field is set to \"Any\". Set PrioritizeGame to \"true\" to enable. It is recommended to leave this as \"Any\".")]
public GameVersion PrioritizeGameVersion { get; set; } = GameVersion.Any;
[Category(Generate), Description("The order of GameVersions ALM will attempt to legalize from.")]
public List<GameVersion> PriorityOrder { get; set; } = [.. Enum.GetValues<GameVersion>().Where(ver => ver > GameVersion.Any && ver <= (GameVersion)51)];

[Category(Generate), Description("Set all possible legal ribbons for any generated Pokémon.")]
public bool SetAllLegalRibbons { get; set; }
Expand All @@ -64,7 +67,7 @@ public string GenerateOT

[Category(Generate), Description("Prevents trading Pokémon that require a HOME Tracker, even if the file has one already."), DisplayName("Disallow Non-Native Pokémon")]
public bool DisallowNonNatives { get; set; } = false;

[Category(Generate), Description("Prevents trading Pokémon that already have a HOME Tracker."), DisplayName("Disallow Home Tracked Pokémon")]
public bool DisallowTracked { get; set; } = false;

Expand Down
Binary file modified SysBot.Pokemon/deps/PKHeX.Core.AutoMod.dll
Binary file not shown.
Binary file modified SysBot.Pokemon/deps/PKHeX.Core.dll
Binary file not shown.