Replace magic numbers, add/update various comments

This commit is contained in:
NightKev 2024-09-10 02:41:29 -07:00
parent a04e0d431d
commit ae8fecb7fd
5 changed files with 61 additions and 34 deletions

View File

@ -15,7 +15,7 @@ import { TextStyle, addTextObject, getTextColor } from "./ui/text";
import { allMoves } from "./data/move"; import { allMoves } from "./data/move";
import { ModifierPoolType, getDefaultModifierTypeForTier, getEnemyModifierTypesForWave, getLuckString, getLuckTextTint, getModifierPoolForType, getModifierType, getPartyLuckValue, modifierTypes } from "./modifier/modifier-type"; import { ModifierPoolType, getDefaultModifierTypeForTier, getEnemyModifierTypesForWave, getLuckString, getLuckTextTint, getModifierPoolForType, getModifierType, getPartyLuckValue, modifierTypes } from "./modifier/modifier-type";
import AbilityBar from "./ui/ability-bar"; import AbilityBar from "./ui/ability-bar";
import { BlockItemTheftAbAttr, BonusItemChanceAbAttr, DoubleBattleChanceAbAttr, ChangeMovePriorityAbAttr, PostBattleInitAbAttr, applyAbAttrs, applyPostBattleInitAbAttrs } from "./data/ability"; import { BlockItemTheftAbAttr, BonusItemChanceAbAttr, DoubleBattleChanceAbAttr, ChangeMovePriorityAbAttr, PostBattleInitAbAttr, applyAbAttrs, applyPostBattleInitAbAttrs, applyPreEncounterAbAttrs } from "./data/ability";
import { allAbilities } from "./data/ability"; import { allAbilities } from "./data/ability";
import Battle, { BattleType, FixedBattleConfig } from "./battle"; import Battle, { BattleType, FixedBattleConfig } from "./battle";
import { GameMode, GameModes, getGameMode } from "./game-mode"; import { GameMode, GameModes, getGameMode } from "./game-mode";
@ -84,6 +84,7 @@ import { TitlePhase } from "./phases/title-phase";
import { ToggleDoublePositionPhase } from "./phases/toggle-double-position-phase"; import { ToggleDoublePositionPhase } from "./phases/toggle-double-position-phase";
import { TurnInitPhase } from "./phases/turn-init-phase"; import { TurnInitPhase } from "./phases/turn-init-phase";
import { ShopCursorTarget } from "./enums/shop-cursor-target"; import { ShopCursorTarget } from "./enums/shop-cursor-target";
import { BOSS_BONUS_ENEMY_ITEM_CHANCE_MULTIPLIER } from "#app/constants";
export const bypassLogin = import.meta.env.VITE_BYPASS_LOGIN === "1"; export const bypassLogin = import.meta.env.VITE_BYPASS_LOGIN === "1";
@ -2478,17 +2479,20 @@ export default class BattleScene extends SceneBase {
generateEnemyModifiers(): Promise<void> { generateEnemyModifiers(): Promise<void> {
return new Promise(resolve => { return new Promise(resolve => {
if (this.currentBattle.battleSpec === BattleSpec.FINAL_BOSS) { if (this.currentBattle.battleSpec === BattleSpec.FINAL_BOSS) { // Classic mode final boss
return resolve(); return resolve();
} }
const difficultyWaveIndex = this.gameMode.getWaveForDifficulty(this.currentBattle.waveIndex); const difficultyWaveIndex = this.gameMode.getWaveForDifficulty(this.currentBattle.waveIndex);
const isFinalBoss = this.gameMode.isWaveFinal(this.currentBattle.waveIndex); const isFinalBoss = this.gameMode.isWaveFinal(this.currentBattle.waveIndex);
let chances = Math.ceil(difficultyWaveIndex / 10);
if (this.getPlayerPokemon()?.hasAbilityWithAttr(BonusItemChanceAbAttr)) { const chances = new Utils.NumberHolder(Math.ceil(difficultyWaveIndex / 10));
chances += Math.floor(chances * 1.2);
} applyPreEncounterAbAttrs(BonusItemChanceAbAttr, this.getPlayerPokemon()!, false, chances);
chances.value = Math.ceil(chances.value);
if (isFinalBoss) { if (isFinalBoss) {
chances = Math.ceil(chances * 2.5); chances.value = Math.ceil(chances.value * BOSS_BONUS_ENEMY_ITEM_CHANCE_MULTIPLIER);
} }
const party = this.getEnemyParty(); const party = this.getEnemyParty();
@ -2510,17 +2514,19 @@ export default class BattleScene extends SceneBase {
upgradeChance /= 8; upgradeChance /= 8;
} }
const modifierChance = this.gameMode.getEnemyModifierChance(isBoss); const modifierChance = this.gameMode.getEnemyModifierChance(isBoss);
let pokemonModifierChance = modifierChance; // TODO: Is this supposed to be used?
if (this.currentBattle.battleType === BattleType.TRAINER && this.currentBattle.trainer) /* let pokemonModifierChance = modifierChance;
pokemonModifierChance = Math.ceil(pokemonModifierChance * this.currentBattle.trainer.getPartyMemberModifierChanceMultiplier(i)); // eslint-disable-line if (this.currentBattle.battleType === BattleType.TRAINER && this.currentBattle.trainer) {
pokemonModifierChance = Math.ceil(pokemonModifierChance * this.currentBattle.trainer.getPartyMemberModifierChanceMultiplier(i));
} */
let count = 0; let count = 0;
for (let c = 0; c < chances; c++) { for (let c = 0; c < chances.value; c++) {
if (!Utils.randSeedInt(modifierChance)) { if (!Utils.randSeedInt(modifierChance)) {
count++; count++;
} }
} }
if (isBoss) { if (isBoss) {
count = Math.max(count, Math.floor(chances / 2)); count = Math.max(count, Math.floor(chances.value / 2));
} }
getEnemyModifierTypesForWave(difficultyWaveIndex, count, [ enemyPokemon ], this.currentBattle.battleType === BattleType.TRAINER ? ModifierPoolType.TRAINER : ModifierPoolType.WILD, upgradeChance) getEnemyModifierTypesForWave(difficultyWaveIndex, count, [ enemyPokemon ], this.currentBattle.battleType === BattleType.TRAINER ? ModifierPoolType.TRAINER : ModifierPoolType.WILD, upgradeChance)
.map(mt => mt.newModifier(enemyPokemon).add(this.enemyModifiers, false, this)); .map(mt => mt.newModifier(enemyPokemon).add(this.enemyModifiers, false, this));

View File

@ -1 +1,2 @@
export const PLAYER_PARTY_MAX_SIZE = 6; export const PLAYER_PARTY_MAX_SIZE = 6;
export const BOSS_BONUS_ENEMY_ITEM_CHANCE_MULTIPLIER = 2.5;

View File

@ -2815,16 +2815,27 @@ export class BonusCritAbAttr extends AbAttr {
} }
} }
export class PreEncounterAbAttr extends AbAttr {
applyPreEncounter(pokemon: Pokemon, passive: boolean, simulated: boolean, args: any[]): boolean {
return false;
}
}
/** /**
* If an ability has this tag, it will increase the chance of items by 20%. * If an ability has this tag, it will increase the chance of enemy pokemon having items by {@linkcode chanceMultiplier} (default 1.2x).
* This is used in battle-scene.ts in generateEnemyModifiers. * This is used in `battle-scene.ts` in `generateEnemyModifiers`.
*/ */
export class BonusItemChanceAbAttr extends AbAttr { export class BonusItemChanceAbAttr extends PreEncounterAbAttr {
constructor() { constructor(protected chanceMultiplier: number = 1.2) {
super(false); super(false);
} }
apply(pokemon: Pokemon, passive: boolean, simulated: boolean, cancelled: Utils.BooleanHolder | null, args: any[]): boolean | Promise<boolean> { override apply(pokemon: Pokemon, passive: boolean, simulated: boolean, cancelled: Utils.BooleanHolder | null, args: any[]): boolean | Promise<boolean> {
return true;
}
override applyPreEncounter(pokemon: Pokemon, passive: boolean, simulated: boolean, args: any[]): boolean {
(args[0] as Utils.NumberHolder).value *= this.chanceMultiplier;
return true; return true;
} }
} }
@ -4764,6 +4775,11 @@ export function applyPostFaintAbAttrs(attrType: Constructor<PostFaintAbAttr>,
return applyAbAttrsInternal<PostFaintAbAttr>(attrType, pokemon, (attr, passive) => attr.applyPostFaint(pokemon, passive, simulated, attacker, move, hitResult, args), args, false, simulated); return applyAbAttrsInternal<PostFaintAbAttr>(attrType, pokemon, (attr, passive) => attr.applyPostFaint(pokemon, passive, simulated, attacker, move, hitResult, args), args, false, simulated);
} }
export function applyPreEncounterAbAttrs(attrType: Constructor<PreEncounterAbAttr>,
pokemon: Pokemon, simulated: boolean = false, ...args: any[]): Promise<void> {
return applyAbAttrsInternal<PreEncounterAbAttr>(attrType, pokemon, (attr, passive) => attr.applyPreEncounter(pokemon, passive, simulated, args), args, false, simulated);
}
function queueShowAbility(pokemon: Pokemon, passive: boolean): void { function queueShowAbility(pokemon: Pokemon, passive: boolean): void {
pokemon.scene.unshiftPhase(new ShowAbilityPhase(pokemon.scene, pokemon.id, passive)); pokemon.scene.unshiftPhase(new ShowAbilityPhase(pokemon.scene, pokemon.id, passive));
pokemon.scene.clearPhaseQueueSplice(); pokemon.scene.clearPhaseQueueSplice();

View File

@ -1,4 +1,8 @@
export enum BattleSpec { export enum BattleSpec {
DEFAULT, DEFAULT,
/**
* This is currently only used for the wave 200 Eternatus fight in Classic mode
* @see `Battle.initBattleSpec` in `src/battle.ts`
*/
FINAL_BOSS FINAL_BOSS
} }

View File

@ -215,38 +215,38 @@ export class GameMode implements GameModeConfig {
} }
/** /**
* Every 10 waves is a boss battle * Every 10 waves is a boss battle
* @returns true if waveIndex is a multiple of 10 * @returns true if waveIndex is a multiple of 10
*/ */
isBoss(waveIndex: integer): boolean { isBoss(waveIndex: integer): boolean {
return waveIndex % 10 === 0; return waveIndex % 10 === 0;
} }
/** /**
* Every 50 waves of an Endless mode is a boss * Every 50 waves of an Endless mode is a boss
* At this time it is paradox pokemon * At this time it is paradox pokemon
* @returns true if waveIndex is a multiple of 50 in Endless * @returns true if waveIndex is a multiple of 50 in Endless
*/ */
isEndlessBoss(waveIndex: integer): boolean { isEndlessMiniBoss(waveIndex: integer): boolean {
return !!(waveIndex % 50) && return (waveIndex % 50 === 0) &&
(this.modeId === GameModes.ENDLESS || this.modeId === GameModes.SPLICED_ENDLESS); (this.modeId === GameModes.ENDLESS || this.modeId === GameModes.SPLICED_ENDLESS);
} }
/** /**
* Every 250 waves of an Endless mode is a minor boss * Every 250 waves of an Endless mode is a minor boss
* At this time it is Eternatus * At this time it is Eternatus
* @returns true if waveIndex is a multiple of 250 in Endless * @returns true if waveIndex is a multiple of 250 in Endless
*/ */
isEndlessMinorBoss(waveIndex: integer): boolean { isEndlessMinorBoss(waveIndex: integer): boolean {
return waveIndex % 250 === 0 && return waveIndex % 250 === 0 &&
(this.modeId === GameModes.ENDLESS || this.modeId === GameModes.SPLICED_ENDLESS); (this.modeId === GameModes.ENDLESS || this.modeId === GameModes.SPLICED_ENDLESS);
} }
/** /**
* Every 1000 waves of an Endless mode is a major boss * Every 1000 waves of an Endless mode is a major boss
* At this time it is Eternamax Eternatus * At this time it is Eternamax Eternatus
* @returns true if waveIndex is a multiple of 1000 in Endless * @returns true if waveIndex is a multiple of 1000 in Endless
*/ */
isEndlessMajorBoss(waveIndex: integer): boolean { isEndlessMajorBoss(waveIndex: integer): boolean {
return waveIndex % 1000 === 0 && return waveIndex % 1000 === 0 &&
(this.modeId === GameModes.ENDLESS || this.modeId === GameModes.SPLICED_ENDLESS); (this.modeId === GameModes.ENDLESS || this.modeId === GameModes.SPLICED_ENDLESS);