Re-Add MovePriorityModifier

This commit is contained in:
Dean 2025-10-30 18:58:06 -07:00
parent 90ade594a0
commit 9a4381c776
6 changed files with 54 additions and 10 deletions

View File

@ -34,6 +34,7 @@ import { MoveCategory } from "#enums/move-category";
import { MoveFlags } from "#enums/move-flags";
import { MoveId } from "#enums/move-id";
import { MovePhaseTimingModifier } from "#enums/move-phase-timing-modifier";
import { MovePriorityModifier } from "#enums/move-priority-modifier";
import { MoveResult } from "#enums/move-result";
import { MoveTarget } from "#enums/move-target";
import { MoveUseMode } from "#enums/move-use-mode";
@ -4142,6 +4143,25 @@ export class ChangeMovePriorityAbAttr extends AbAttr {
}
}
export class ChangeMovePriorityModifierAbAttr extends AbAttr {
private readonly newModifier: MovePriorityModifier;
private readonly moveFunc: (pokemon: Pokemon, move: Move) => boolean;
constructor(moveFunc: (pokemon: Pokemon, move: Move) => boolean, newModifier: MovePriorityModifier) {
super(false);
this.newModifier = newModifier;
this.moveFunc = moveFunc;
}
override canApply({ pokemon, move }: ChangeMovePriorityAbAttrParams): boolean {
return this.moveFunc(pokemon, move);
}
override apply({ priority }: ChangeMovePriorityAbAttrParams): void {
priority.value = this.newModifier;
}
}
export class IgnoreContactAbAttr extends AbAttr {
private declare readonly _: never;
}
@ -6721,6 +6741,7 @@ const AbilityAttrs = Object.freeze({
BlockStatusDamageAbAttr,
BlockOneHitKOAbAttr,
ChangeMovePriorityAbAttr,
ChangeMovePriorityModifierAbAttr,
IgnoreContactAbAttr,
PreWeatherEffectAbAttr,
PreWeatherDamageAbAttr,
@ -7238,7 +7259,7 @@ export function initAbilities() {
.attr(DoubleBattleChanceAbAttr)
.build(),
new AbBuilder(AbilityId.STALL, 4)
.attr(ChangeMovePriorityAbAttr, (_pokemon, _move: Move) => true, -0.2)
.attr(ChangeMovePriorityModifierAbAttr, (_pokemon, _move: Move) => true, MovePriorityModifier.LAST_IN_BRACKET)
.build(),
new AbBuilder(AbilityId.TECHNICIAN, 4)
.attr(MovePowerBoostAbAttr, (user, target, move) => {
@ -8185,7 +8206,7 @@ export function initAbilities() {
.ignorable()
.build(),
new AbBuilder(AbilityId.MYCELIUM_MIGHT, 9)
.attr(ChangeMovePriorityAbAttr, (_pokemon, move) => move.category === MoveCategory.STATUS, -0.2)
.attr(ChangeMovePriorityModifierAbAttr, (_pokemon, move) => move.category === MoveCategory.STATUS, MovePriorityModifier.LAST_IN_BRACKET)
.attr(PreventBypassSpeedChanceAbAttr, (_pokemon, move) => move.category === MoveCategory.STATUS)
.attr(MoveAbilityBypassAbAttr, (_pokemon, move: Move) => move.category === MoveCategory.STATUS)
.build(),

View File

@ -101,6 +101,7 @@ import { MovePhaseTimingModifier } from "#enums/move-phase-timing-modifier";
import { inSpeedOrder } from "#utils/speed-order-generator";
import { canSpeciesTera, willTerastallize } from "#utils/pokemon-utils";
import type { ReadonlyGenericUint8Array } from "#types/typed-arrays";
import { MovePriorityModifier } from "#enums/move-priority-modifier";
/**
* A function used to conditionally determine execution of a given {@linkcode MoveAttr}.
@ -1060,17 +1061,19 @@ export abstract class Move implements Localizable {
getPriority(user: Pokemon, simulated: boolean = true) {
const priority = new NumberHolder(this.priority);
applyMoveAttrs("IncrementMovePriorityAttr", user, null, this, priority);
applyAbAttrs("ChangeMovePriorityAbAttr", {pokemon: user, simulated, move: this, priority});
if (user.getTag(BattlerTagType.BYPASS_SPEED)) {
priority.value += 0.2;
}
return priority.value;
}
public getPriorityModifier(user: Pokemon, simulated = true) {
const modifierHolder = new NumberHolder(MovePriorityModifier.NORMAL);
applyAbAttrs("ChangeMovePriorityModifierAbAttr", {pokemon: user, simulated: simulated, move: this, priority: modifierHolder});
modifierHolder.value = user.getTag(BattlerTagType.BYPASS_SPEED) ? MovePriorityModifier.FIRST_IN_BRACKET : modifierHolder.value;
return modifierHolder.value;
}
/**
* Calculate the [Expected Power](https://en.wikipedia.org/wiki/Expected_value) per turn
* of this move, taking into account multi hit moves, accuracy, and the number of turns it

View File

@ -67,7 +67,7 @@ export class Terrain {
return (
!isFieldTargeted(move)
&& !isSpreadMove(move)
&& move.getPriority(user) > 0.2 // fractional priority is used by quick claw etc and is not blocked by terrain
&& move.getPriority(user) > 0
&& user.getOpponents(true).some(o => targets.includes(o.getBattlerIndex()) && o.isGrounded())
);
}

View File

@ -0,0 +1,13 @@
import type { ObjectValues } from "#types/type-helpers";
/**
* Enum representing modifiers for Move priorities.
*/
export const MovePriorityModifier = Object.freeze({
/** Used when moves go last in their priority bracket, but before moves of lower priority. */
LAST_IN_BRACKET: 0,
NORMAL: 1,
/** Used when moves go first in their priority bracket, but before moves of lower priority. */
FIRST_IN_BRACKET: 2,
});
export type MovePriorityModifier = ObjectValues<typeof MovePriorityModifier>;

View File

@ -92,11 +92,18 @@ export class MovePhasePriorityQueue extends PokemonPhasePriorityQueue<MovePhase>
});
const timingModifiers = [a, b].map(movePhase => movePhase.timingModifier);
const priorityModifiers = [a, b].map(movePhase =>
movePhase.move.getMove().getPriorityModifier(movePhase.pokemon),
);
if (timingModifiers[0] !== timingModifiers[1]) {
return timingModifiers[1] - timingModifiers[0];
}
if (priority[0] === priority[1] && priorityModifiers[0] !== priorityModifiers[1]) {
return priorityModifiers[1] - priorityModifiers[0];
}
return priority[1] - priority[0];
});
}

View File

@ -72,7 +72,7 @@ describe("Arena - Psychic Terrain", () => {
await game.phaseInterceptor.to("MovePhase", false);
const feebas = game.field.getPlayerPokemon();
expect(allMoves[MoveId.POUND].getPriority(feebas)).toBe(0.2);
expect(allMoves[MoveId.POUND].getPriority(feebas)).toBe(0);
await game.toEndOfTurn();
@ -93,7 +93,7 @@ describe("Arena - Psychic Terrain", () => {
await game.phaseInterceptor.to("MovePhase", false);
const feebas = game.field.getPlayerPokemon();
expect(allMoves[MoveId.QUICK_ATTACK].getPriority(feebas)).toBe(1.2);
expect(allMoves[MoveId.QUICK_ATTACK].getPriority(feebas)).toBe(1);
await game.toEndOfTurn();