Removed unnecessary else statement

This commit is contained in:
Wlowscha 2025-03-11 22:43:23 +01:00
parent 2c360b30c9
commit e05082167e
No known key found for this signature in database
GPG Key ID: 3C8F1AD330565D04
6 changed files with 105 additions and 94 deletions

@ -1 +1 @@
Subproject commit 6b3f37cb351552721232f4dabefa17bddb5b9004 Subproject commit b4534f03ba8eb8709486ee967257b6f3725702dd

View File

@ -285,11 +285,7 @@ export abstract class Challenge {
* @param _dexAttr {@link DexAttrProps} The dex attributes of the pokemon. * @param _dexAttr {@link DexAttrProps} The dex attributes of the pokemon.
* @returns {@link boolean} Whether this function did anything. * @returns {@link boolean} Whether this function did anything.
*/ */
applyStarterChoice( applyStarterChoice(_pokemon: PokemonSpecies, _valid: Utils.BooleanHolder, _dexAttr: DexAttrProps): boolean {
_pokemon: PokemonSpecies,
_valid: Utils.BooleanHolder,
_dexAttr: DexAttrProps,
): boolean {
return false; return false;
} }
@ -441,10 +437,7 @@ export class SingleGenerationChallenge extends Challenge {
super(Challenges.SINGLE_GENERATION, 9); super(Challenges.SINGLE_GENERATION, 9);
} }
applyStarterChoice( applyStarterChoice(pokemon: PokemonSpecies, valid: Utils.BooleanHolder): boolean {
pokemon: PokemonSpecies,
valid: Utils.BooleanHolder,
): boolean {
if (pokemon.generation !== this.value) { if (pokemon.generation !== this.value) {
valid.value = false; valid.value = false;
return true; return true;
@ -725,13 +718,9 @@ export class SingleTypeChallenge extends Challenge {
super(Challenges.SINGLE_TYPE, 18); super(Challenges.SINGLE_TYPE, 18);
} }
override applyStarterChoice( override applyStarterChoice(pokemon: PokemonSpecies, valid: Utils.BooleanHolder, dexAttr: DexAttrProps): boolean {
pokemon: PokemonSpecies,
valid: Utils.BooleanHolder,
dexAttr: DexAttrProps,
): boolean {
const speciesForm = getPokemonSpeciesForm(pokemon.speciesId, dexAttr.formIndex); const speciesForm = getPokemonSpeciesForm(pokemon.speciesId, dexAttr.formIndex);
const types = [ speciesForm.type1, speciesForm.type2 ]; const types = [speciesForm.type1, speciesForm.type2];
if (!types.includes(this.value - 1)) { if (!types.includes(this.value - 1)) {
valid.value = false; valid.value = false;
return true; return true;

View File

@ -1569,53 +1569,52 @@ export default class StarterSelectUiHandler extends MessageUiHandler {
Challenge.ChallengeType.STARTER_CHOICE, Challenge.ChallengeType.STARTER_CHOICE,
species, species,
isValidForChallenge, isValidForChallenge,
props props,
); );
return isValidForChallenge.value; return isValidForChallenge.value;
} else {
// We check the validity of every evolution and battle form separately,
// and require that at least one is valid
const allValidities: boolean[] = [];
const speciesToCheck = [ species.speciesId ];
while (speciesToCheck.length) {
const checking = speciesToCheck.pop();
const checkingSpecies = getPokemonSpecies(checking ?? Species.BULBASAUR);
const isEvoValidForChallenge = new BooleanHolder(true);
Challenge.applyChallenges(
globalScene.gameMode,
Challenge.ChallengeType.STARTER_CHOICE,
checkingSpecies,
isEvoValidForChallenge,
props // This might be wrong, in principle we need to pass the right formIndex
);
allValidities.push(isEvoValidForChallenge.value);
if (checking && pokemonEvolutions.hasOwnProperty(checking)) {
pokemonEvolutions[checking].forEach(e => {
speciesToCheck.push(e.speciesId);
});
}
if (checking && pokemonFormChanges.hasOwnProperty(checking)) {
pokemonFormChanges[checking].forEach(f1 => {
checkingSpecies.forms.forEach((f2, formIndex) => {
if (f1.formKey === f2.formKey) {
const formProps = { ...props };
formProps.formIndex = formIndex;
const isFormValidForChallenge = new BooleanHolder(true);
Challenge.applyChallenges(
globalScene.gameMode,
Challenge.ChallengeType.STARTER_CHOICE,
checkingSpecies,
isFormValidForChallenge,
formProps
);
allValidities.push(isFormValidForChallenge.value);
}
});
});
}
}
return allValidities.filter(v => v).length > 0;
} }
// We check the validity of every evolution and battle form separately,
// and require that at least one is valid
const allValidities: boolean[] = [];
const speciesToCheck = [species.speciesId];
while (speciesToCheck.length) {
const checking = speciesToCheck.pop();
const checkingSpecies = getPokemonSpecies(checking ?? Species.BULBASAUR);
const isEvoValidForChallenge = new BooleanHolder(true);
Challenge.applyChallenges(
globalScene.gameMode,
Challenge.ChallengeType.STARTER_CHOICE,
checkingSpecies,
isEvoValidForChallenge,
props, // This might be wrong, in principle we need to pass the right formIndex
);
allValidities.push(isEvoValidForChallenge.value);
if (checking && pokemonEvolutions.hasOwnProperty(checking)) {
pokemonEvolutions[checking].forEach(e => {
speciesToCheck.push(e.speciesId);
});
}
if (checking && pokemonFormChanges.hasOwnProperty(checking)) {
pokemonFormChanges[checking].forEach(f1 => {
checkingSpecies.forms.forEach((f2, formIndex) => {
if (f1.formKey === f2.formKey) {
const formProps = { ...props };
formProps.formIndex = formIndex;
const isFormValidForChallenge = new BooleanHolder(true);
Challenge.applyChallenges(
globalScene.gameMode,
Challenge.ChallengeType.STARTER_CHOICE,
checkingSpecies,
isFormValidForChallenge,
formProps,
);
allValidities.push(isFormValidForChallenge.value);
}
});
});
}
}
return allValidities.filter(v => v).length > 0;
} }
processInput(button: Button): boolean { processInput(button: Button): boolean {
@ -1831,10 +1830,7 @@ export default class StarterSelectUiHandler extends MessageUiHandler {
); );
const isCaught = globalScene.gameData.dexData[species.speciesId].caughtAttr; const isCaught = globalScene.gameData.dexData[species.speciesId].caughtAttr;
return ( return (
!isDupe && !isDupe && isValidForChallenge && currentPartyValue + starterCost <= this.getValueLimit() && isCaught
isValidForChallenge &&
currentPartyValue + starterCost <= this.getValueLimit() &&
isCaught
); );
}); });
if (validStarters.length === 0) { if (validStarters.length === 0) {
@ -1926,7 +1922,10 @@ export default class StarterSelectUiHandler extends MessageUiHandler {
const isPartyValid = this.isPartyValid(); const isPartyValid = this.isPartyValid();
const isValidForChallenge = this.checkValidForChallenge( const isValidForChallenge = this.checkValidForChallenge(
this.lastSpecies, this.lastSpecies,
globalScene.gameData.getSpeciesDexAttrProps(this.lastSpecies, this.getCurrentDexProps(this.lastSpecies.speciesId)), globalScene.gameData.getSpeciesDexAttrProps(
this.lastSpecies,
this.getCurrentDexProps(this.lastSpecies.speciesId),
),
isPartyValid, isPartyValid,
); );
@ -3046,11 +3045,22 @@ export default class StarterSelectUiHandler extends MessageUiHandler {
* Since some pokemon rely on forms to be valid (i.e. blaze tauros for fire challenges), we make a fake form and dex props to use in the challenge * Since some pokemon rely on forms to be valid (i.e. blaze tauros for fire challenges), we make a fake form and dex props to use in the challenge
*/ */
const tempFormProps = BigInt(Math.pow(2, i)) * DexAttr.DEFAULT_FORM; const tempFormProps = BigInt(Math.pow(2, i)) * DexAttr.DEFAULT_FORM;
const isValidForChallenge = this.checkValidForChallenge(container.species, globalScene.gameData.getSpeciesDexAttrProps(species, tempFormProps), true); const isValidForChallenge = this.checkValidForChallenge(
container.species,
globalScene.gameData.getSpeciesDexAttrProps(species, tempFormProps),
true,
);
allFormsValid = allFormsValid || isValidForChallenge; allFormsValid = allFormsValid || isValidForChallenge;
} }
} else { } else {
const isValidForChallenge = this.checkValidForChallenge(container.species, globalScene.gameData.getSpeciesDexAttrProps(species, globalScene.gameData.getSpeciesDefaultDexAttr(container.species, false, true)), true); const isValidForChallenge = this.checkValidForChallenge(
container.species,
globalScene.gameData.getSpeciesDexAttrProps(
species,
globalScene.gameData.getSpeciesDefaultDexAttr(container.species, false, true),
),
true,
);
allFormsValid = isValidForChallenge; allFormsValid = isValidForChallenge;
} }
if (allFormsValid) { if (allFormsValid) {
@ -3884,7 +3894,9 @@ export default class StarterSelectUiHandler extends MessageUiHandler {
this.pokemonSprite.setVisible(!this.statsMode); this.pokemonSprite.setVisible(!this.statsMode);
} }
const currentFilteredContainer = this.filteredStarterContainers.find(p => p.species.speciesId === species.speciesId); const currentFilteredContainer = this.filteredStarterContainers.find(
p => p.species.speciesId === species.speciesId,
);
if (currentFilteredContainer) { if (currentFilteredContainer) {
const starterSprite = currentFilteredContainer.icon as Phaser.GameObjects.Sprite; const starterSprite = currentFilteredContainer.icon as Phaser.GameObjects.Sprite;
starterSprite.setTexture( starterSprite.setTexture(
@ -4259,7 +4271,11 @@ export default class StarterSelectUiHandler extends MessageUiHandler {
if (addingToParty) { if (addingToParty) {
// this does a check to see if the pokemon being added is valid; if so, it will update the isPartyValid boolean // this does a check to see if the pokemon being added is valid; if so, it will update the isPartyValid boolean
const species = this.filteredStarterContainers[this.cursor].species; const species = this.filteredStarterContainers[this.cursor].species;
const isNewPokemonValid = this.checkValidForChallenge(species, globalScene.gameData.getSpeciesDexAttrProps(species, this.getCurrentDexProps(species.speciesId)), false); const isNewPokemonValid = this.checkValidForChallenge(
species,
globalScene.gameData.getSpeciesDexAttrProps(species, this.getCurrentDexProps(species.speciesId)),
false,
);
isPartyValid = isPartyValid || isNewPokemonValid; isPartyValid = isPartyValid || isNewPokemonValid;
} }
@ -4284,7 +4300,14 @@ export default class StarterSelectUiHandler extends MessageUiHandler {
* If speciesStarterDexEntry?.caughtAttr is true, this species registered in stater. * If speciesStarterDexEntry?.caughtAttr is true, this species registered in stater.
* we change to can AddParty value to true since the user has enough cost to choose this pokemon and this pokemon registered too. * we change to can AddParty value to true since the user has enough cost to choose this pokemon and this pokemon registered too.
*/ */
const isValidForChallenge = this.checkValidForChallenge(this.allSpecies[s], globalScene.gameData.getSpeciesDexAttrProps(this.allSpecies[s], this.getCurrentDexProps(this.allSpecies[s].speciesId)), isPartyValid); const isValidForChallenge = this.checkValidForChallenge(
this.allSpecies[s],
globalScene.gameData.getSpeciesDexAttrProps(
this.allSpecies[s],
this.getCurrentDexProps(this.allSpecies[s].speciesId),
),
isPartyValid,
);
const canBeChosen = remainValue >= speciesStarterValue && isValidForChallenge; const canBeChosen = remainValue >= speciesStarterValue && isValidForChallenge;
@ -4421,7 +4444,11 @@ export default class StarterSelectUiHandler extends MessageUiHandler {
let canStart = false; let canStart = false;
for (let s = 0; s < this.starterSpecies.length; s++) { for (let s = 0; s < this.starterSpecies.length; s++) {
const species = this.starterSpecies[s]; const species = this.starterSpecies[s];
const isValidForChallenge = this.checkValidForChallenge(species, globalScene.gameData.getSpeciesDexAttrProps(species, this.getCurrentDexProps(species.speciesId)), false); const isValidForChallenge = this.checkValidForChallenge(
species,
globalScene.gameData.getSpeciesDexAttrProps(species, this.getCurrentDexProps(species.speciesId)),
false,
);
canStart = canStart || isValidForChallenge; canStart = canStart || isValidForChallenge;
} }
return canStart; return canStart;

View File

@ -24,7 +24,7 @@ describe("Abilities - Lightningrod", () => {
beforeEach(() => { beforeEach(() => {
game = new GameManager(phaserGame); game = new GameManager(phaserGame);
game.override game.override
.moveset([ Moves.SPLASH, Moves.SHOCK_WAVE ]) .moveset([Moves.SPLASH, Moves.SHOCK_WAVE])
.ability(Abilities.BALL_FETCH) .ability(Abilities.BALL_FETCH)
.battleType("double") .battleType("double")
.disableCrits() .disableCrits()
@ -34,7 +34,7 @@ describe("Abilities - Lightningrod", () => {
}); });
it("should redirect electric type moves", async () => { it("should redirect electric type moves", async () => {
await game.classicMode.startBattle([ Species.FEEBAS, Species.MAGIKARP ]); await game.classicMode.startBattle([Species.FEEBAS, Species.MAGIKARP]);
const enemy1 = game.scene.getEnemyField()[0]; const enemy1 = game.scene.getEnemyField()[0];
const enemy2 = game.scene.getEnemyField()[1]; const enemy2 = game.scene.getEnemyField()[1];
@ -49,8 +49,8 @@ describe("Abilities - Lightningrod", () => {
}); });
it("should not redirect non-electric type moves", async () => { it("should not redirect non-electric type moves", async () => {
game.override.moveset([ Moves.SPLASH, Moves.AERIAL_ACE ]); game.override.moveset([Moves.SPLASH, Moves.AERIAL_ACE]);
await game.classicMode.startBattle([ Species.FEEBAS, Species.MAGIKARP ]); await game.classicMode.startBattle([Species.FEEBAS, Species.MAGIKARP]);
const enemy1 = game.scene.getEnemyField()[0]; const enemy1 = game.scene.getEnemyField()[0];
const enemy2 = game.scene.getEnemyField()[1]; const enemy2 = game.scene.getEnemyField()[1];
@ -65,7 +65,7 @@ describe("Abilities - Lightningrod", () => {
}); });
it("should boost the user's spatk without damaging", async () => { it("should boost the user's spatk without damaging", async () => {
await game.classicMode.startBattle([ Species.FEEBAS, Species.MAGIKARP ]); await game.classicMode.startBattle([Species.FEEBAS, Species.MAGIKARP]);
const enemy2 = game.scene.getEnemyField()[1]; const enemy2 = game.scene.getEnemyField()[1];
@ -81,7 +81,7 @@ describe("Abilities - Lightningrod", () => {
it("should not redirect moves changed from electric type via ability", async () => { it("should not redirect moves changed from electric type via ability", async () => {
game.override.ability(Abilities.NORMALIZE); game.override.ability(Abilities.NORMALIZE);
await game.classicMode.startBattle([ Species.FEEBAS, Species.MAGIKARP ]); await game.classicMode.startBattle([Species.FEEBAS, Species.MAGIKARP]);
const enemy1 = game.scene.getEnemyField()[0]; const enemy1 = game.scene.getEnemyField()[0];
const enemy2 = game.scene.getEnemyField()[1]; const enemy2 = game.scene.getEnemyField()[1];
@ -96,9 +96,8 @@ describe("Abilities - Lightningrod", () => {
}); });
it("should redirect moves changed to electric type via ability", async () => { it("should redirect moves changed to electric type via ability", async () => {
game.override.ability(Abilities.GALVANIZE) game.override.ability(Abilities.GALVANIZE).moveset(Moves.TACKLE);
.moveset(Moves.TACKLE); await game.classicMode.startBattle([Species.FEEBAS, Species.MAGIKARP]);
await game.classicMode.startBattle([ Species.FEEBAS, Species.MAGIKARP ]);
const enemy1 = game.scene.getEnemyField()[0]; const enemy1 = game.scene.getEnemyField()[0];
const enemy2 = game.scene.getEnemyField()[1]; const enemy2 = game.scene.getEnemyField()[1];

View File

@ -158,11 +158,8 @@ describe("Abilities - Neutralizing Gas", () => {
}); });
it("should not activate abilities of pokemon no longer on the field", async () => { it("should not activate abilities of pokemon no longer on the field", async () => {
game.override game.override.battleType("single").ability(Abilities.NEUTRALIZING_GAS).enemyAbility(Abilities.DELTA_STREAM);
.battleType("single") await game.classicMode.startBattle([Species.MAGIKARP]);
.ability(Abilities.NEUTRALIZING_GAS)
.enemyAbility(Abilities.DELTA_STREAM);
await game.classicMode.startBattle([ Species.MAGIKARP ]);
const enemy = game.scene.getEnemyPokemon()!; const enemy = game.scene.getEnemyPokemon()!;
const weatherChangeAttr = enemy.getAbilityAttrs(PostSummonWeatherChangeAbAttr, false)[0]; const weatherChangeAttr = enemy.getAbilityAttrs(PostSummonWeatherChangeAbAttr, false)[0];

View File

@ -24,7 +24,7 @@ describe("Abilities - Storm Drain", () => {
beforeEach(() => { beforeEach(() => {
game = new GameManager(phaserGame); game = new GameManager(phaserGame);
game.override game.override
.moveset([ Moves.SPLASH, Moves.WATER_GUN ]) .moveset([Moves.SPLASH, Moves.WATER_GUN])
.ability(Abilities.BALL_FETCH) .ability(Abilities.BALL_FETCH)
.battleType("double") .battleType("double")
.disableCrits() .disableCrits()
@ -34,7 +34,7 @@ describe("Abilities - Storm Drain", () => {
}); });
it("should redirect water type moves", async () => { it("should redirect water type moves", async () => {
await game.classicMode.startBattle([ Species.FEEBAS, Species.MAGIKARP ]); await game.classicMode.startBattle([Species.FEEBAS, Species.MAGIKARP]);
const enemy1 = game.scene.getEnemyField()[0]; const enemy1 = game.scene.getEnemyField()[0];
const enemy2 = game.scene.getEnemyField()[1]; const enemy2 = game.scene.getEnemyField()[1];
@ -49,8 +49,8 @@ describe("Abilities - Storm Drain", () => {
}); });
it("should not redirect non-water type moves", async () => { it("should not redirect non-water type moves", async () => {
game.override.moveset([ Moves.SPLASH, Moves.AERIAL_ACE ]); game.override.moveset([Moves.SPLASH, Moves.AERIAL_ACE]);
await game.classicMode.startBattle([ Species.FEEBAS, Species.MAGIKARP ]); await game.classicMode.startBattle([Species.FEEBAS, Species.MAGIKARP]);
const enemy1 = game.scene.getEnemyField()[0]; const enemy1 = game.scene.getEnemyField()[0];
const enemy2 = game.scene.getEnemyField()[1]; const enemy2 = game.scene.getEnemyField()[1];
@ -65,7 +65,7 @@ describe("Abilities - Storm Drain", () => {
}); });
it("should boost the user's spatk without damaging", async () => { it("should boost the user's spatk without damaging", async () => {
await game.classicMode.startBattle([ Species.FEEBAS, Species.MAGIKARP ]); await game.classicMode.startBattle([Species.FEEBAS, Species.MAGIKARP]);
const enemy2 = game.scene.getEnemyField()[1]; const enemy2 = game.scene.getEnemyField()[1];
@ -81,7 +81,7 @@ describe("Abilities - Storm Drain", () => {
it("should not redirect moves changed from water type via ability", async () => { it("should not redirect moves changed from water type via ability", async () => {
game.override.ability(Abilities.NORMALIZE); game.override.ability(Abilities.NORMALIZE);
await game.classicMode.startBattle([ Species.FEEBAS, Species.MAGIKARP ]); await game.classicMode.startBattle([Species.FEEBAS, Species.MAGIKARP]);
const enemy1 = game.scene.getEnemyField()[0]; const enemy1 = game.scene.getEnemyField()[0];
const enemy2 = game.scene.getEnemyField()[1]; const enemy2 = game.scene.getEnemyField()[1];
@ -96,9 +96,8 @@ describe("Abilities - Storm Drain", () => {
}); });
it("should redirect moves changed to water type via ability", async () => { it("should redirect moves changed to water type via ability", async () => {
game.override.ability(Abilities.LIQUID_VOICE) game.override.ability(Abilities.LIQUID_VOICE).moveset(Moves.PSYCHIC_NOISE);
.moveset(Moves.PSYCHIC_NOISE); await game.classicMode.startBattle([Species.FEEBAS, Species.MAGIKARP]);
await game.classicMode.startBattle([ Species.FEEBAS, Species.MAGIKARP ]);
const enemy1 = game.scene.getEnemyField()[0]; const enemy1 = game.scene.getEnemyField()[0];
const enemy2 = game.scene.getEnemyField()[1]; const enemy2 = game.scene.getEnemyField()[1];