diff --git a/src/modifier/modifier-type.ts b/src/modifier/modifier-type.ts index 9c361f2ec22..5bfc4a823a8 100644 --- a/src/modifier/modifier-type.ts +++ b/src/modifier/modifier-type.ts @@ -59,6 +59,20 @@ export class ModifierType { this.tier = tier; } + getOrInferTier(): ModifierTier { + if (this.tier) + return this.tier; + if (!this.id) + return null; + for (let tier of Utils.getEnumValues(ModifierTier)) { + if (!modifierPool.hasOwnProperty(tier)) + continue; + if (modifierPool[tier].find(m => (m as WeightedModifierType).modifierType.id === (this.generatorId || this.id))) + return (this.tier = tier); + } + return null; + } + withIdFromFunc(func: ModifierTypeFunc): ModifierType { this.id = Object.keys(modifierTypes).find(k => modifierTypes[k] === func); return this; diff --git a/src/modifier/modifier.ts b/src/modifier/modifier.ts index 8438ea012b7..8f5861437c5 100644 --- a/src/modifier/modifier.ts +++ b/src/modifier/modifier.ts @@ -18,6 +18,7 @@ import { MoneyAchv, achvs } from '../system/achv'; import { VoucherType } from '../system/voucher'; import { PreventBerryUseAbAttr, applyAbAttrs } from '../data/ability'; import { FormChangeItem, SpeciesFormChangeItemTrigger } from '../data/pokemon-forms'; +import { ModifierTier } from './modifier-tier'; type ModifierType = ModifierTypes.ModifierType; export type ModifierPredicate = (modifier: Modifier) => boolean; @@ -1648,12 +1649,18 @@ export abstract class HeldItemTransferModifier extends PokemonHeldItemModifier { const transferredModifierTypes: ModifierTypes.ModifierType[] = []; const itemModifiers = pokemon.scene.findModifiers(m => m instanceof PokemonHeldItemModifier && (m as PokemonHeldItemModifier).pokemonId === targetPokemon.id && m.getTransferrable(withinParty), targetPokemon.isPlayer()) as PokemonHeldItemModifier[]; + let highestItemTier = itemModifiers.map(m => m.type.getOrInferTier()).reduce((highestTier, tier) => Math.max(tier, highestTier), 0); + let tierItemModifiers = itemModifiers.filter(m => m.type.getOrInferTier() === highestItemTier); let heldItemTransferPromises: Promise[] = []; for (let i = 0; i < transferredItemCount; i++) { - if (!itemModifiers.length) - break; + if (!tierItemModifiers.length) { + while (highestItemTier-- && !tierItemModifiers.length) + tierItemModifiers = itemModifiers.filter(m => m.type.tier === highestItemTier); + if (!tierItemModifiers.length) + break; + } const randItemIndex = pokemon.randSeedInt(itemModifiers.length); const randItem = itemModifiers[randItemIndex]; heldItemTransferPromises.push(pokemon.scene.tryTransferHeldItemModifier(randItem, pokemon, false, false, true).then(success => { diff --git a/src/phases.ts b/src/phases.ts index c71882b6742..a9b1c70bd9c 100644 --- a/src/phases.ts +++ b/src/phases.ts @@ -2885,8 +2885,9 @@ export class GameOverPhase extends BattlePhase { this.scene.gameData.clearSession().then(() => { this.scene.time.delayedCall(1000, () => { + let firstClear = false; if (this.victory) { - this.scene.validateAchv(achvs.CLASSIC_VICTORY); + firstClear = this.scene.validateAchv(achvs.CLASSIC_VICTORY); this.scene.gameData.gameStats.sessionsWon++; } this.scene.gameData.saveSystem(); @@ -2896,6 +2897,8 @@ export class GameOverPhase extends BattlePhase { this.scene.clearPhaseQueue(); this.scene.ui.clearText(); this.handleUnlocks(this.scene.getParty()); + if (!firstClear) + this.scene.unshiftPhase(new ModifierRewardPhase(this.scene, modifierTypes.VOUCHER_PREMIUM)); this.scene.reset(); this.scene.unshiftPhase(new CheckLoadPhase(this.scene)); this.end();