Shiny and variant also cycle correctly again

This commit is contained in:
Wlowscha 2025-09-08 19:39:03 +02:00
parent 690b88989c
commit 8a6284b035
No known key found for this signature in database
GPG Key ID: 3C8F1AD330565D04
4 changed files with 28 additions and 24 deletions

View File

@ -2106,10 +2106,18 @@ export class GameData {
}
getSpeciesDefaultDexAttrProps(species: PokemonSpecies): DexAttrProps {
const shiny = false;
const dexAttr = this.dexData[species.speciesId].caughtAttr;
// Default shiny is true if caught
const shiny = !!(dexAttr & DexAttr.SHINY);
// Default is female only for species where malePercent is not null but 0
const female = species.malePercent === 0;
const variant = 0;
// Default is the highest variant
let variant: Variant = 0;
if (dexAttr & DexAttr.VARIANT_3) {
variant = 2;
} else if (dexAttr & DexAttr.VARIANT_2) {
variant = 1;
}
const formIndex = 0;
return {

View File

@ -514,8 +514,6 @@ export class StarterSummary extends Phaser.GameObjects.Container {
this.pokemonHatchedCountText.setText(`${dexEntry.hatchedCount}`);
const defaultDexAttr = getDexAttrFromPreferences(species.speciesId, starterPreferences);
const defaultProps = globalScene.gameData.getSpeciesDexAttrProps(species, defaultDexAttr);
this.setShinyIcon(defaultProps.shiny, defaultProps.variant);
if (pokemonPrevolutions.hasOwnProperty(species.speciesId)) {
this.pokemonCaughtHatchedContainer.setVisible(false);
@ -653,6 +651,8 @@ export class StarterSummary extends Phaser.GameObjects.Container {
getTextColor(shiny ? TextStyle.SUMMARY_DEX_NUM_GOLD : TextStyle.SUMMARY_DEX_NUM, true),
);
this.setShinyIcon(shiny, variant);
const assetLoadCancelled = new BooleanHolder(false);
this.assetLoadCancelled = assetLoadCancelled;

View File

@ -1381,14 +1381,15 @@ export class StarterSelectUiHandler extends MessageUiHandler {
switch (button) {
case Button.CYCLE_SHINY:
if (this.canCycleShiny) {
console.log(starterPreferences);
if (starterPreferences.shiny === false) {
// If not shiny, we change to shiny and get the proper default variant
const newVariant = starterPreferences.variant ? (starterPreferences.variant as Variant) : props.variant;
const newVariant = (starterPreferences.variant as Variant) ?? props.variant;
this.setShinyAndVariant(speciesId, true, newVariant);
globalScene.playSound("se/sparkle");
} else {
// If shiny, we update the variant
let newVariant = props.variant;
let newVariant = starterPreferences.variant ?? props.variant;
do {
newVariant = (newVariant + 1) % 3;
if (newVariant === 0) {
@ -1416,6 +1417,7 @@ export class StarterSelectUiHandler extends MessageUiHandler {
success = true;
}
}
console.log("AFTER", starterPreferences);
}
break;
case Button.CYCLE_FORM:
@ -1491,9 +1493,7 @@ export class StarterSelectUiHandler extends MessageUiHandler {
break;
}
if (success) {
this.setSpeciesDetails(this.lastSpecies);
}
return success;
}

View File

@ -18,7 +18,7 @@ import type { Variant } from "#sprites/variant";
import type { DexAttrProps, StarterDataEntry, StarterPreferences } from "#system/game-data";
import type { DexEntry } from "#types/dex-data";
import { applyChallenges, checkStarterValidForChallenge } from "#utils/challenge-utils";
import { NumberHolder } from "#utils/common";
import { isNullOrUndefined, NumberHolder } from "#utils/common";
import i18next from "i18next";
export interface SpeciesDetails {
@ -281,18 +281,13 @@ export function getDexAttrFromPreferences(speciesId: number, starterPreferences:
props += DexAttr.SHINY;
if (starterPreferences[speciesId]?.variant !== undefined) {
props += BigInt(Math.pow(2, starterPreferences[speciesId]?.variant)) * DexAttr.DEFAULT_VARIANT;
} else {
/* This calculates the correct variant if there's no starter preferences for it.
* This gets the highest tier variant that you've caught and adds it to the temp props
*/
if ((caughtAttr & DexAttr.VARIANT_3) > 0) {
} else if ((caughtAttr & DexAttr.VARIANT_3) > 0) {
props += DexAttr.VARIANT_3;
} else if ((caughtAttr & DexAttr.VARIANT_2) > 0) {
props += DexAttr.VARIANT_2;
} else {
props += DexAttr.DEFAULT_VARIANT;
}
}
} else {
props += DexAttr.NON_SHINY;
props += DexAttr.DEFAULT_VARIANT; // we add the default variant here because non shiny versions are listed as default variant
@ -312,11 +307,12 @@ export function getSpeciesPropsFromPreferences(
species: PokemonSpecies,
starterPreferences: StarterPreferences = {},
): DexAttrProps {
const defaults = globalScene.gameData.getSpeciesDefaultDexAttrProps(species);
return {
shiny: !!starterPreferences.shiny,
variant: (starterPreferences.variant as Variant) ?? 0,
female: starterPreferences.female ?? species.malePercent === 0,
formIndex: starterPreferences.formIndex ?? 0,
shiny: isNullOrUndefined(starterPreferences.shiny) ? defaults.shiny : starterPreferences.shiny,
variant: isNullOrUndefined(starterPreferences.variant) ? defaults.variant : (starterPreferences.variant as Variant),
female: starterPreferences.female ?? defaults.female,
formIndex: starterPreferences.formIndex ?? defaults.formIndex,
};
}