[Bug] Prevent being able to start with a hidden ability that's not unlocked for some Pokemon (#3663)

* prevent being able to start with a hidden ability that's not unlocked for some Pokemon

* fix starter ui for pokemon with a single ability and only ability 2 unlocked
This commit is contained in:
MokaStitcher 2024-08-25 17:25:40 +02:00 committed by GitHub
parent 3b4b45f83c
commit 163fadbd62
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -1795,15 +1795,17 @@ export default class StarterSelectUiHandler extends MessageUiHandler {
if (this.canCycleAbility) { if (this.canCycleAbility) {
const abilityCount = this.lastSpecies.getAbilityCount(); const abilityCount = this.lastSpecies.getAbilityCount();
const abilityAttr = this.scene.gameData.starterData[this.lastSpecies.speciesId].abilityAttr; const abilityAttr = this.scene.gameData.starterData[this.lastSpecies.speciesId].abilityAttr;
const hasAbility1 = abilityAttr & AbilityAttr.ABILITY_1;
let newAbilityIndex = this.abilityCursor; let newAbilityIndex = this.abilityCursor;
do { do {
newAbilityIndex = (newAbilityIndex + 1) % abilityCount; newAbilityIndex = (newAbilityIndex + 1) % abilityCount;
if (!newAbilityIndex) { if (newAbilityIndex === 0) {
if (abilityAttr & AbilityAttr.ABILITY_1) { if (hasAbility1) {
break; break;
} }
} else if (newAbilityIndex === 1) { } else if (newAbilityIndex === 1) {
if (this.lastSpecies.ability1 === this.lastSpecies.ability2) { // If ability 1 and 2 are the same and ability 1 is unlocked, skip over ability 2
if (this.lastSpecies.ability1 === this.lastSpecies.ability2 && hasAbility1) {
newAbilityIndex = (newAbilityIndex + 1) % abilityCount; newAbilityIndex = (newAbilityIndex + 1) % abilityCount;
} }
break; break;
@ -3045,7 +3047,20 @@ export default class StarterSelectUiHandler extends MessageUiHandler {
this.canCycleShiny = isVariantCaught || isVariant2Caught || isVariant3Caught; this.canCycleShiny = isVariantCaught || isVariant2Caught || isVariant3Caught;
this.canCycleGender = isMaleCaught && isFemaleCaught; this.canCycleGender = isMaleCaught && isFemaleCaught;
this.canCycleAbility = [ abilityAttr & AbilityAttr.ABILITY_1, (abilityAttr & AbilityAttr.ABILITY_2) && species.ability2, abilityAttr & AbilityAttr.ABILITY_HIDDEN ].filter(a => a).length > 1; const hasAbility1 = abilityAttr & AbilityAttr.ABILITY_1;
let hasAbility2 = abilityAttr & AbilityAttr.ABILITY_2;
const hasHiddenAbility = abilityAttr & AbilityAttr.ABILITY_HIDDEN;
/*
* Check for Pokemon with a single ability (at some point it was possible to catch them with their ability 2 attribute)
* This prevents cycling between ability 1 and 2 if they are both unlocked and the same
* but we still need to account for the possibility ability 1 was never unlocked and fallback on ability 2 in this case
*/
if (hasAbility1 && hasAbility2 && species.ability1 === species.ability2) {
hasAbility2 = 0;
}
this.canCycleAbility = [ hasAbility1, hasAbility2, hasHiddenAbility ].filter(a => a).length > 1;
this.canCycleForm = species.forms.filter(f => f.isStarterSelectable || !pokemonFormChanges[species.speciesId]?.find(fc => fc.formKey)) this.canCycleForm = species.forms.filter(f => f.isStarterSelectable || !pokemonFormChanges[species.speciesId]?.find(fc => fc.formKey))
.map((_, f) => dexEntry.caughtAttr & this.scene.gameData.getFormAttr(f)).filter(f => f).length > 1; .map((_, f) => dexEntry.caughtAttr & this.scene.gameData.getFormAttr(f)).filter(f => f).length > 1;
this.canCycleNature = this.scene.gameData.getNaturesForAttr(dexEntry.natureAttr).length > 1; this.canCycleNature = this.scene.gameData.getNaturesForAttr(dexEntry.natureAttr).length > 1;