Skip to content

Commit

Permalink
Fixes bug with metronome/copycat/assist/sleep talk targeting ally
Browse files Browse the repository at this point in the history
  • Loading branch information
schmidtc1 committed Aug 28, 2024
1 parent b854a37 commit 1e64ef0
Showing 1 changed file with 32 additions and 42 deletions.
74 changes: 32 additions & 42 deletions src/data/move.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5280,6 +5280,29 @@ export class FirstMoveTypeAttr extends MoveEffectAttr {
}
}

function callMove(user: Pokemon, target: Pokemon, moveId: number): Promise<boolean> {
return new Promise(resolve => {
// replaces MoveTarget.NEAR_OTHER with MoveTarget.NEAR_ENEMY to prevent ally being targetted
const replaceMoveTarget = allMoves[moveId].moveTarget === MoveTarget.NEAR_OTHER ? MoveTarget.NEAR_ENEMY : undefined;
const moveTargets = getMoveTargets(user, moveId, replaceMoveTarget);
if (moveTargets.targets.length === 0) {
resolve(false);
return;
}
const targets = moveTargets.multiple || moveTargets.targets.length === 1
? moveTargets.targets
: moveTargets.targets.indexOf(target.getBattlerIndex()) > -1
? [ target.getBattlerIndex() ]
: [ moveTargets.targets[user.randSeedInt(moveTargets.targets.length)] ];
user.getMoveQueue().push({ move: moveId, targets: targets, ignorePP: true });
user.scene.unshiftPhase(new MovePhase(user.scene, user, targets, new PokemonMove(moveId, 0, 0, true), true));
initMoveAnim(user.scene, moveId).then(() => {
loadMoveAnimAssets(user.scene, [ moveId ], true)
.then(() => resolve(true));
});
});
}

/**
* Attribute used to call a random move
* Used for {@linkcode Moves.METRONOME}
Expand All @@ -5305,28 +5328,7 @@ export class RandomMoveAttr extends OverrideMoveEffectAttr {
apply(user: Pokemon, target: Pokemon, move: Move, args: any[]): Promise<boolean> {
const moveIds = Utils.getEnumValues(Moves).filter(m => !this.invalidMoves.includes(m) && !allMoves[m].name.endsWith(" (N)"));
const moveId = moveIds[user.randSeedInt(moveIds.length)];
return this.callMove(user, target, moveId);
}

callMove(user: Pokemon, target: Pokemon, moveId: number): Promise<boolean> {
return new Promise(resolve => {
const moveTargets = getMoveTargets(user, moveId);
if (moveTargets.targets.length === 0) {
resolve(false);
return;
}
const targets = moveTargets.multiple || moveTargets.targets.length === 1
? moveTargets.targets
: moveTargets.targets.indexOf(target.getBattlerIndex()) > -1
? [ target.getBattlerIndex() ]
: [ moveTargets.targets[user.randSeedInt(moveTargets.targets.length)] ];
user.getMoveQueue().push({ move: moveId, targets: targets, ignorePP: true });
user.scene.unshiftPhase(new MovePhase(user.scene, user, targets, new PokemonMove(moveId, 0, 0, true), true));
initMoveAnim(user.scene, moveId).then(() => {
loadMoveAnimAssets(user.scene, [ moveId ], true)
.then(() => resolve(true));
});
});
return callMove(user, target, moveId);
}
}

Expand Down Expand Up @@ -5355,7 +5357,7 @@ export class RandomMovesetMoveAttr extends RandomMoveAttr {
* @returns {Promise<boolean>}
*/
apply(user: Pokemon, target: Pokemon, move: Move, args: any[]): Promise<boolean> {
return this.callMove(user, target, this.moveId);
return callMove(user, target, this.moveId);
}

getCondition(): MoveConditionFunc {
Expand Down Expand Up @@ -5769,24 +5771,9 @@ const lastMoveCopiableCondition: MoveConditionFunc = (user, target, move) => {
};

export class CopyMoveAttr extends OverrideMoveEffectAttr {
apply(user: Pokemon, target: Pokemon, move: Move, args: any[]): boolean {
apply(user: Pokemon, target: Pokemon, move: Move, args: any[]): Promise<boolean> {
const lastMove = user.scene.currentBattle.lastMove;

const moveTargets = getMoveTargets(user, lastMove);
if (!moveTargets.targets.length) {
return false;
}

const targets = moveTargets.multiple || moveTargets.targets.length === 1
? moveTargets.targets
: moveTargets.targets.indexOf(target.getBattlerIndex()) > -1
? [ target.getBattlerIndex() ]
: [ moveTargets.targets[user.randSeedInt(moveTargets.targets.length)] ];
user.getMoveQueue().push({ move: lastMove, targets: targets, ignorePP: true });

user.scene.unshiftPhase(new MovePhase(user.scene, user as PlayerPokemon, targets, new PokemonMove(lastMove, 0, 0, true), true));

return true;
return callMove(user, target, lastMove);
}

getCondition(): MoveConditionFunc {
Expand Down Expand Up @@ -6509,11 +6496,14 @@ export type MoveTargetSet = {
multiple: boolean;
};

export function getMoveTargets(user: Pokemon, move: Moves): MoveTargetSet {
export function getMoveTargets(user: Pokemon, move: Moves, replaceTarget?: MoveTarget): MoveTargetSet {
const variableTarget = new Utils.NumberHolder(0);
user.getOpponents().forEach(p => applyMoveAttrs(VariableTargetAttr, user, p, allMoves[move], variableTarget));

const moveTarget = allMoves[move].hasAttr(VariableTargetAttr) ? variableTarget.value : move ? allMoves[move].moveTarget : move === undefined ? MoveTarget.NEAR_ENEMY : [];
const moveTarget = allMoves[move].hasAttr(VariableTargetAttr) ? variableTarget.value :
replaceTarget !== undefined ? replaceTarget :
move ? allMoves[move].moveTarget :
move === undefined ? MoveTarget.NEAR_ENEMY : [];
const opponents = user.getOpponents();

let set: Pokemon[] = [];
Expand Down

0 comments on commit 1e64ef0

Please sign in to comment.