diff options
author | tom-overton <tom.overton@outlook.com> | 2022-06-10 05:06:06 -0700 |
---|---|---|
committer | rafa_99 <raroma09@gmail.com> | 2022-06-09 15:58:57 +0100 |
commit | e729b9b64c9009653e2e73c99e3f040191c18b70 (patch) | |
tree | cb781a1844b55a181acb0d70da7bfc7b29a01db5 /src/com/sneed/pkrandom | |
parent | 810b9dc324f0069c4db4e2d5866976b5a92bae5c (diff) |
BW2: Fix an issue where PWT trainers could have two Pokemon with the same item, causing an error (Fixes #454)
Diffstat (limited to 'src/com/sneed/pkrandom')
-rwxr-xr-x | src/com/sneed/pkrandom/pokemon/Trainer.java | 16 | ||||
-rwxr-xr-x | src/com/sneed/pkrandom/romhandlers/AbstractRomHandler.java | 5 | ||||
-rwxr-xr-x | src/com/sneed/pkrandom/romhandlers/Gen5RomHandler.java | 1 |
3 files changed, 22 insertions, 0 deletions
diff --git a/src/com/sneed/pkrandom/pokemon/Trainer.java b/src/com/sneed/pkrandom/pokemon/Trainer.java index a6a6a8a..8e8a76e 100755 --- a/src/com/sneed/pkrandom/pokemon/Trainer.java +++ b/src/com/sneed/pkrandom/pokemon/Trainer.java @@ -40,6 +40,8 @@ public class Trainer implements Comparable<Trainer> { public String fullDisplayName; public MultiBattleStatus multiBattleStatus = MultiBattleStatus.NEVER; public int forceStarterPosition = -1; + // Certain trainers (e.g., trainers in the PWT in BW2) require unique held items for all of their Pokemon to prevent a game crash. + public boolean requiresUniqueHeldItems; public String toString() { StringBuilder sb = new StringBuilder("["); @@ -127,6 +129,20 @@ public class Trainer implements Comparable<Trainer> { return (this.poketype & 1) == 1; } + public boolean pokemonHaveUniqueHeldItems() { + List<Integer> heldItemsForThisTrainer = new ArrayList<>(); + for (TrainerPokemon poke : this.pokemon) { + if (poke.heldItem > 0) { + if (heldItemsForThisTrainer.contains(poke.heldItem)) { + return false; + } else { + heldItemsForThisTrainer.add(poke.heldItem); + } + } + } + return true; + } + public enum MultiBattleStatus { NEVER, POTENTIAL, ALWAYS } diff --git a/src/com/sneed/pkrandom/romhandlers/AbstractRomHandler.java b/src/com/sneed/pkrandom/romhandlers/AbstractRomHandler.java index 4f289e9..f3471db 100755 --- a/src/com/sneed/pkrandom/romhandlers/AbstractRomHandler.java +++ b/src/com/sneed/pkrandom/romhandlers/AbstractRomHandler.java @@ -1962,6 +1962,11 @@ public abstract class AbstractRomHandler implements RomHandler { } else { for (TrainerPokemon tp : t.pokemon) { randomizeHeldItem(tp, settings, moves, movesets); + if (t.requiresUniqueHeldItems) { + while (!t.pokemonHaveUniqueHeldItems()) { + randomizeHeldItem(tp, settings, moves, movesets); + } + } } } } diff --git a/src/com/sneed/pkrandom/romhandlers/Gen5RomHandler.java b/src/com/sneed/pkrandom/romhandlers/Gen5RomHandler.java index 2743583..26a3aee 100755 --- a/src/com/sneed/pkrandom/romhandlers/Gen5RomHandler.java +++ b/src/com/sneed/pkrandom/romhandlers/Gen5RomHandler.java @@ -1468,6 +1468,7 @@ public class Gen5RomHandler extends AbstractDSRomHandler { tr.poketype = 3; // have held items and custom moves
int nameAndClassIndex = Gen5Constants.bw2DriftveilTrainerOffsets.get(trno);
tr.fullDisplayName = tclasses.get(Gen5Constants.normalTrainerClassLength + nameAndClassIndex) + " " + tnames.get(Gen5Constants.normalTrainerNameLength + nameAndClassIndex);
+ tr.requiresUniqueHeldItems = true;
int pokemonNum = 6;
if (trno < 2) {
pokemonNum = 3;
|