summaryrefslogtreecommitdiff
path: root/src/com/dabomstew/pkrandom/romhandlers/Gen4RomHandler.java
diff options
context:
space:
mode:
authortom-overton <tom.overton@outlook.com>2021-05-05 19:26:10 -0700
committertom-overton <tom.overton@outlook.com>2021-05-06 13:58:06 -0700
commita2c77186061df860ba6ae2415aad755076879ed5 (patch)
tree05b7f6ac689044a04070c2e77c201010592b0dde /src/com/dabomstew/pkrandom/romhandlers/Gen4RomHandler.java
parentc6ae0aa0fdf0b7dab1681dbf525c9d9e0135eef8 (diff)
Randomize trainer ability slots and add functionality to get the ability for a given trainer Pokemon
Diffstat (limited to 'src/com/dabomstew/pkrandom/romhandlers/Gen4RomHandler.java')
-rwxr-xr-xsrc/com/dabomstew/pkrandom/romhandlers/Gen4RomHandler.java38
1 files changed, 34 insertions, 4 deletions
diff --git a/src/com/dabomstew/pkrandom/romhandlers/Gen4RomHandler.java b/src/com/dabomstew/pkrandom/romhandlers/Gen4RomHandler.java
index 9126f63..a785237 100755
--- a/src/com/dabomstew/pkrandom/romhandlers/Gen4RomHandler.java
+++ b/src/com/dabomstew/pkrandom/romhandlers/Gen4RomHandler.java
@@ -2098,7 +2098,12 @@ public class Gen4RomHandler extends AbstractDSRomHandler {
tpk.level = level;
tpk.pokemon = pokes[species];
tpk.AILevel = ailevel;
- tpk.ability = (trpoke[pokeOffs + 1] >>> 4) & 0xF;
+ int abilitySlot = (trpoke[pokeOffs + 1] >>> 4) & 0xF;
+ if (abilitySlot == 0) {
+ // All Gen 4 games represent the first ability as ability 0.
+ abilitySlot = 1;
+ }
+ tpk.abilitySlot = abilitySlot;
tpk.forme = formnum;
tpk.formeSuffix = Gen4Constants.getFormeSuffixByBaseForme(species,formnum);
tpk.absolutePokeNumber = Gen4Constants.getAbsolutePokeNumByBaseForme(species,formnum);
@@ -2202,7 +2207,13 @@ public class Gen4RomHandler extends AbstractDSRomHandler {
Iterator<TrainerPokemon> tpokes = tr.pokemon.iterator();
for (int poke = 0; poke < numPokes; poke++) {
TrainerPokemon tp = tpokes.next();
+ int ability = tp.abilitySlot << 4;
+ if (tp.abilitySlot == 1) {
+ // All Gen 4 games represent the first ability as ability 0.
+ ability = 0;
+ }
writeWord(trpoke, pokeOffs, tp.AILevel);
+ writeWord(trpoke, pokeOffs + 1, ability);
writeWord(trpoke, pokeOffs + 2, tp.level);
writeWord(trpoke, pokeOffs + 4, tp.pokemon.number);
trpoke[pokeOffs + 5] |= (tp.forme << 2);
@@ -3656,6 +3667,23 @@ public class Gen4RomHandler extends AbstractDSRomHandler {
}
@Override
+ public int getAbilityForTrainerPokemon(TrainerPokemon tp) {
+ // In Gen 4, alt formes for Trainer Pokemon use the base forme's ability
+ Pokemon pkmn = tp.pokemon;
+ while (pkmn.baseForme != null) {
+ pkmn = pkmn.baseForme;
+ }
+
+ if (romEntry.romType == Gen4Constants.Type_DP || romEntry.romType == Gen4Constants.Type_Plat) {
+ // In DPPt, Trainer Pokemon *always* use the first Ability, no matter what
+ return pkmn.ability1;
+ } else {
+ // In HGSS, Trainer Pokemon can specify which ability they want to use.
+ return tp.abilitySlot == 2 ? pkmn.ability2 : pkmn.ability1;
+ }
+ }
+
+ @Override
public boolean hasMegaEvolutions() {
return false;
}
@@ -4361,13 +4389,15 @@ public class Gen4RomHandler extends AbstractDSRomHandler {
if (byType.get(Type.NORMAL) == Effectiveness.NEUTRAL) {
items.add(Gen4Constants.chilanBerry);
}
- if (tp.ability == Abilities.levitate) {
+
+ int ability = this.getAbilityForTrainerPokemon(tp);
+ if (ability == Abilities.levitate) {
items.removeAll(Arrays.asList(Gen4Constants.shucaBerry));
}
if (!consumableOnly) {
- if (Gen4Constants.abilityBoostingItems.containsKey(tp.ability)) {
- items.addAll(Gen4Constants.abilityBoostingItems.get(tp.ability));
+ if (Gen4Constants.abilityBoostingItems.containsKey(ability)) {
+ items.addAll(Gen4Constants.abilityBoostingItems.get(ability));
}
if (tp.pokemon.primaryType == Type.POISON || tp.pokemon.secondaryType == Type.POISON) {
items.add(Gen4Constants.blackSludge);