From d234466d61aa1be076d92945bc9ee2c31849228b Mon Sep 17 00:00:00 2001 From: NightKev <34855794+DayKev@users.noreply.github.com> Date: Mon, 26 Aug 2024 14:05:16 -0700 Subject: [PATCH] =?UTF-8?q?[Balance]=20Make=20sure=20trainers=20are=20usin?= =?UTF-8?q?g=20fully=20evolved=20Pok=C3=A9mon=20by=20gym=203=20(#3499)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Make sure trainers are using fully evolved Pokemon by gym 3 * Expand comment info Co-authored-by: Mumble * Implement suggestions * Update `getPokemonSpecies()` to throw an error if passed `undefined` --------- Co-authored-by: Mumble --- src/data/daily-run.ts | 3 ++- src/data/pokemon-species.ts | 50 ++++++++++++++++++++++--------------- src/data/trainer-config.ts | 6 ++--- src/field/trainer.ts | 8 +++--- 4 files changed, 39 insertions(+), 28 deletions(-) diff --git a/src/data/daily-run.ts b/src/data/daily-run.ts index b875877f99e..0a02defe052 100644 --- a/src/data/daily-run.ts +++ b/src/data/daily-run.ts @@ -49,7 +49,8 @@ export function getDailyRunStarters(scene: BattleScene, seed: string): Starter[] const costSpecies = Object.keys(speciesStarters) .map(s => parseInt(s) as Species) .filter(s => speciesStarters[s] === cost); - const starterSpecies = getPokemonSpecies(getPokemonSpecies(Utils.randSeedItem(costSpecies)).getTrainerSpeciesForLevel(startingLevel, true, PartyMemberStrength.STRONGER)); + const randPkmSpecies = getPokemonSpecies(Utils.randSeedItem(costSpecies)); + const starterSpecies = getPokemonSpecies(randPkmSpecies.getTrainerSpeciesForLevel(startingLevel, true, PartyMemberStrength.STRONGER)); starters.push(getDailyRunStarter(scene, starterSpecies, startingLevel)); } }, 0, seed); diff --git a/src/data/pokemon-species.ts b/src/data/pokemon-species.ts index dc12ca402cd..14779688fc2 100644 --- a/src/data/pokemon-species.ts +++ b/src/data/pokemon-species.ts @@ -1,24 +1,21 @@ - +import { Localizable } from "#app/interfaces/locales"; +import { Abilities } from "#enums/abilities"; +import { PartyMemberStrength } from "#enums/party-member-strength"; +import { Species } from "#enums/species"; +import { QuantizerCelebi, argbFromRgba, rgbaFromArgb } from "@material/material-color-utilities"; +import i18next from "i18next"; import BattleScene, { AnySound } from "../battle-scene"; -import { Variant, variantColorCache } from "./variant"; -import { variantData } from "./variant"; +import { GameMode } from "../game-mode"; +import { StarterMoveset } from "../system/game-data"; +import * as Utils from "../utils"; +import { uncatchableSpecies } from "./biomes"; +import { speciesEggMoves } from "./egg-moves"; import { GrowthRate } from "./exp"; import { EvolutionLevel, SpeciesWildEvolutionDelay, pokemonEvolutions, pokemonPrevolutions } from "./pokemon-evolutions"; import { Type } from "./type"; import { LevelMoves, pokemonFormLevelMoves, pokemonFormLevelMoves as pokemonSpeciesFormLevelMoves, pokemonSpeciesLevelMoves } from "./pokemon-level-moves"; -import { uncatchableSpecies } from "./biomes"; -import * as Utils from "../utils"; -import { StarterMoveset } from "../system/game-data"; -import { speciesEggMoves } from "./egg-moves"; -import { GameMode } from "../game-mode"; -import { QuantizerCelebi, argbFromRgba, rgbaFromArgb } from "@material/material-color-utilities"; -import { VariantSet } from "./variant"; -import i18next from "i18next"; -import { Localizable } from "#app/interfaces/locales"; import { Stat } from "./pokemon-stat"; -import { Abilities } from "#enums/abilities"; -import { PartyMemberStrength } from "#enums/party-member-strength"; -import { Species } from "#enums/species"; +import { Variant, VariantSet, variantColorCache, variantData } from "./variant"; export enum Region { NORMAL, @@ -28,7 +25,15 @@ export enum Region { PALDEA } -export function getPokemonSpecies(species: Species | Species[]): PokemonSpecies { +/** + * Gets the {@linkcode PokemonSpecies} object associated with the {@linkcode Species} enum given + * @param species The species to fetch + * @returns The associated {@linkcode PokemonSpecies} object + */ +export function getPokemonSpecies(species: Species | Species[] | undefined): PokemonSpecies { + if (!species) { + throw new Error("`species` must not be undefined in `getPokemonSpecies()`"); + } // If a special pool (named trainers) is used here it CAN happen that they have a array as species (which means choose one of those two). So we catch that with this code block if (Array.isArray(species)) { // Pick a random species from the list @@ -648,8 +653,8 @@ export default class PokemonSpecies extends PokemonSpeciesForm implements Locali return this.getSpeciesForLevel(level, allowEvolving, false, (isBoss ? PartyMemberStrength.WEAKER : PartyMemberStrength.AVERAGE) + (gameMode?.isEndless ? 1 : 0)); } - getTrainerSpeciesForLevel(level: integer, allowEvolving: boolean = false, strength: PartyMemberStrength): Species { - return this.getSpeciesForLevel(level, allowEvolving, true, strength); + getTrainerSpeciesForLevel(level: integer, allowEvolving: boolean = false, strength: PartyMemberStrength, currentWave: number = 0): Species { + return this.getSpeciesForLevel(level, allowEvolving, true, strength, currentWave); } private getStrengthLevelDiff(strength: PartyMemberStrength): integer { @@ -669,7 +674,7 @@ export default class PokemonSpecies extends PokemonSpeciesForm implements Locali } } - getSpeciesForLevel(level: integer, allowEvolving: boolean = false, forTrainer: boolean = false, strength: PartyMemberStrength = PartyMemberStrength.WEAKER): Species { + getSpeciesForLevel(level: integer, allowEvolving: boolean = false, forTrainer: boolean = false, strength: PartyMemberStrength = PartyMemberStrength.WEAKER, currentWave: number = 0): Species { const prevolutionLevels = this.getPrevolutionLevels(); if (prevolutionLevels.length) { @@ -730,6 +735,11 @@ export default class PokemonSpecies extends PokemonSpeciesForm implements Locali evolutionChance = Math.min(0.65 * easeInFunc(Math.min(Math.max(level - evolutionLevel, 0), preferredMinLevel) / preferredMinLevel) + 0.35 * easeOutFunc(Math.min(Math.max(level - evolutionLevel, 0), preferredMinLevel * 2.5) / (preferredMinLevel * 2.5)), 1); } } + /* (Most) Trainers shouldn't be using unevolved Pokemon by the third gym leader / wave 80. Exceptions to this include Breeders, whose large teams are balanced by the use of weaker pokemon */ + if (currentWave >= 80 && forTrainer && strength > PartyMemberStrength.WEAKER) { + evolutionChance = 1; + noEvolutionChance = 0; + } if (evolutionChance > 0) { if (isRegionalEvolution) { @@ -754,7 +764,7 @@ export default class PokemonSpecies extends PokemonSpeciesForm implements Locali for (const weight of evolutionPool.keys()) { if (randValue < weight) { - return getPokemonSpecies(evolutionPool.get(weight)!).getSpeciesForLevel(level, true, forTrainer, strength); // TODO: is the bang correct? + return getPokemonSpecies(evolutionPool.get(weight)).getSpeciesForLevel(level, true, forTrainer, strength, currentWave); } } diff --git a/src/data/trainer-config.ts b/src/data/trainer-config.ts index 5f47ce42a62..36f75a60c49 100644 --- a/src/data/trainer-config.ts +++ b/src/data/trainer-config.ts @@ -142,7 +142,7 @@ export const trainerPartyTemplates = { FIVE_WEAK_BALANCED: new TrainerPartyTemplate(5, PartyMemberStrength.WEAK, false, true), SIX_WEAKER: new TrainerPartyTemplate(6, PartyMemberStrength.WEAKER), SIX_WEAKER_SAME: new TrainerPartyTemplate(6, PartyMemberStrength.WEAKER, true), - SIX_WEAK_SAME: new TrainerPartyTemplate(6, PartyMemberStrength.WEAKER, true), + SIX_WEAK_SAME: new TrainerPartyTemplate(6, PartyMemberStrength.WEAK, true), SIX_WEAK_BALANCED: new TrainerPartyTemplate(6, PartyMemberStrength.WEAK, false, true), GYM_LEADER_1: new TrainerPartyCompoundTemplate(new TrainerPartyTemplate(1, PartyMemberStrength.AVERAGE), new TrainerPartyTemplate(1, PartyMemberStrength.STRONG)), @@ -965,7 +965,7 @@ function getRandomPartyMemberFunc(speciesPool: Species[], trainerSlot: TrainerSl return (scene: BattleScene, level: integer, strength: PartyMemberStrength) => { let species = Utils.randSeedItem(speciesPool); if (!ignoreEvolution) { - species = getPokemonSpecies(species).getTrainerSpeciesForLevel(level, true, strength); + species = getPokemonSpecies(species).getTrainerSpeciesForLevel(level, true, strength, scene.currentBattle.waveIndex); } return scene.addEnemyPokemon(getPokemonSpecies(species), level, trainerSlot, undefined, undefined, postProcess); }; @@ -975,7 +975,7 @@ function getSpeciesFilterRandomPartyMemberFunc(speciesFilter: PokemonSpeciesFilt const originalSpeciesFilter = speciesFilter; speciesFilter = (species: PokemonSpecies) => (allowLegendaries || (!species.legendary && !species.subLegendary && !species.mythical)) && !species.isTrainerForbidden() && originalSpeciesFilter(species); return (scene: BattleScene, level: integer, strength: PartyMemberStrength) => { - const ret = scene.addEnemyPokemon(getPokemonSpecies(scene.randomSpecies(scene.currentBattle.waveIndex, level, false, speciesFilter).getTrainerSpeciesForLevel(level, true, strength)), level, trainerSlot, undefined, undefined, postProcess); + const ret = scene.addEnemyPokemon(getPokemonSpecies(scene.randomSpecies(scene.currentBattle.waveIndex, level, false, speciesFilter).getTrainerSpeciesForLevel(level, true, strength, scene.currentBattle.waveIndex)), level, trainerSlot, undefined, undefined, postProcess); return ret; }; } diff --git a/src/field/trainer.ts b/src/field/trainer.ts index 68ebabbbe23..02827d0d69d 100644 --- a/src/field/trainer.ts +++ b/src/field/trainer.ts @@ -359,12 +359,12 @@ export default class Trainer extends Phaser.GameObjects.Container { let species = useNewSpeciesPool ? getPokemonSpecies(newSpeciesPool[Math.floor(Math.random() * newSpeciesPool.length)]) : template.isSameSpecies(index) && index > offset - ? getPokemonSpecies(battle.enemyParty[offset].species.getTrainerSpeciesForLevel(level, false, template.getStrength(offset))) + ? getPokemonSpecies(battle.enemyParty[offset].species.getTrainerSpeciesForLevel(level, false, template.getStrength(offset), this.scene.currentBattle.waveIndex)) : this.genNewPartyMemberSpecies(level, strength); // If the species is from newSpeciesPool, we need to adjust it based on the level and strength if (newSpeciesPool) { - species = getPokemonSpecies(species.getSpeciesForLevel(level, true, true, strength)); + species = getPokemonSpecies(species.getSpeciesForLevel(level, true, true, strength, this.scene.currentBattle.waveIndex)); } ret = this.scene.addEnemyPokemon(species, level, !this.isDouble() || !(index % 2) ? TrainerSlot.TRAINER : TrainerSlot.TRAINER_PARTNER); @@ -393,7 +393,7 @@ export default class Trainer extends Phaser.GameObjects.Container { species = this.scene.randomSpecies(battle.waveIndex, level, false, this.config.speciesFilter); } - let ret = getPokemonSpecies(species.getTrainerSpeciesForLevel(level, true, strength)); + let ret = getPokemonSpecies(species.getTrainerSpeciesForLevel(level, true, strength, this.scene.currentBattle.waveIndex)); let retry = false; console.log(ret.getName()); @@ -412,7 +412,7 @@ export default class Trainer extends Phaser.GameObjects.Container { console.log("Attempting reroll of species evolution to fit specialty type..."); let evoAttempt = 0; while (retry && evoAttempt++ < 10) { - ret = getPokemonSpecies(species.getTrainerSpeciesForLevel(level, true, strength)); + ret = getPokemonSpecies(species.getTrainerSpeciesForLevel(level, true, strength, this.scene.currentBattle.waveIndex)); console.log(ret.name); if (this.config.specialtyTypes.find(t => ret.isOfType(t))) { retry = false;