Merge pull request #4363 from PigeonBar/gts-infinite-loop

[Bug] [Beta] Fix game freeze from GTS infinite loop
This commit is contained in:
ImperialSympathizer 2024-09-21 17:24:20 -04:00 committed by GitHub
commit 0518cfd9d6
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 20 additions and 7 deletions

View File

@ -431,14 +431,13 @@ function getPokemonTradeOptions(scene: BattleScene): Map<number, EnemyPokemon[]>
function generateTradeOption(alreadyUsedSpecies: PokemonSpecies[], originalBst?: number): PokemonSpecies {
let newSpecies: PokemonSpecies | undefined;
let bstCap = 9999;
let bstMin = 0;
if (originalBst) {
bstCap = originalBst + 100;
bstMin = originalBst - 100;
}
while (isNullOrUndefined(newSpecies)) {
let bstCap = 9999;
let bstMin = 0;
if (originalBst) {
bstCap = originalBst + 100;
bstMin = originalBst - 100;
}
// Get all non-legendary species that fall within the Bst range requirements
let validSpecies = allSpecies
.filter(s => {

View File

@ -69,6 +69,20 @@ describe("Global Trade System - Mystery Encounter", () => {
expect(GlobalTradeSystemEncounter.options.length).toBe(4);
});
it("should not loop infinitely when generating trade options for extreme BST non-legendaries", async () => {
const extremeBstTeam = [Species.SLAKING, Species.WISHIWASHI, Species.SUNKERN];
await game.runToMysteryEncounter(MysteryEncounterType.GLOBAL_TRADE_SYSTEM, extremeBstTeam);
expect(GlobalTradeSystemEncounter.encounterType).toBe(MysteryEncounterType.GLOBAL_TRADE_SYSTEM);
expect(GlobalTradeSystemEncounter.encounterTier).toBe(MysteryEncounterTier.COMMON);
expect(GlobalTradeSystemEncounter.dialogue).toBeDefined();
expect(GlobalTradeSystemEncounter.dialogue.intro).toStrictEqual([{ text: `${namespace}.intro` }]);
expect(GlobalTradeSystemEncounter.dialogue.encounterOptionsDialogue?.title).toBe(`${namespace}.title`);
expect(GlobalTradeSystemEncounter.dialogue.encounterOptionsDialogue?.description).toBe(`${namespace}.description`);
expect(GlobalTradeSystemEncounter.dialogue.encounterOptionsDialogue?.query).toBe(`${namespace}.query`);
expect(GlobalTradeSystemEncounter.options.length).toBe(4);
});
it("should not spawn outside of CIVILIZATION_ENCOUNTER_BIOMES", async () => {
game.override.mysteryEncounterTier(MysteryEncounterTier.COMMON);
game.override.startingBiome(Biome.VOLCANO);