[Bug] Fix multi-hit early stopping (#2648)

This commit is contained in:
innerthunder 2024-06-26 21:41:31 -07:00 committed by GitHub
parent 996568ef5b
commit e477fccaab
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 32 additions and 14 deletions

View File

@ -900,8 +900,7 @@ export class ProtectedTag extends BattlerTag {
// Stop multi-hit moves early // Stop multi-hit moves early
const effectPhase = pokemon.scene.getCurrentPhase(); const effectPhase = pokemon.scene.getCurrentPhase();
if (effectPhase instanceof MoveEffectPhase) { if (effectPhase instanceof MoveEffectPhase) {
const attacker = effectPhase.getPokemon(); effectPhase.stopMultiHit(pokemon);
attacker.stopMultiHit();
} }
return true; return true;
} }

View File

@ -1800,7 +1800,7 @@ export default abstract class Pokemon extends Phaser.GameObjects.Container {
} }
if (cancelled.value) { if (cancelled.value) {
source.stopMultiHit(); source.stopMultiHit(this);
result = HitResult.NO_EFFECT; result = HitResult.NO_EFFECT;
} else { } else {
const typeBoost = source.findTag(t => t instanceof TypeBoostTag && t.boostedType === move.type) as TypeBoostTag; const typeBoost = source.findTag(t => t instanceof TypeBoostTag && t.boostedType === move.type) as TypeBoostTag;
@ -2261,15 +2261,14 @@ export default abstract class Pokemon extends Phaser.GameObjects.Container {
} }
/** /**
* If this Pokemon is using a multi-hit move, stop the move * If this Pokemon is using a multi-hit move, cancels all subsequent strikes
* after the next hit resolves. * @param {Pokemon} target If specified, this only cancels subsequent strikes against this Pokemon
*/ */
stopMultiHit(): void { stopMultiHit(target?: Pokemon): void {
if (!this.turnData) { const effectPhase = this.scene.getCurrentPhase();
return; if (effectPhase instanceof MoveEffectPhase) {
effectPhase.stopMultiHit(target);
} }
this.turnData.hitCount = 1;
this.turnData.hitsLeft = 1;
} }
changeForm(formChange: SpeciesFormChange): Promise<void> { changeForm(formChange: SpeciesFormChange): Promise<void> {

View File

@ -2890,8 +2890,7 @@ export class MoveEffectPhase extends PokemonPhase {
const targetHitChecks = Object.fromEntries(targets.map(p => [p.getBattlerIndex(), this.hitCheck(p)])); const targetHitChecks = Object.fromEntries(targets.map(p => [p.getBattlerIndex(), this.hitCheck(p)]));
const activeTargets = targets.map(t => t.isActive(true)); const activeTargets = targets.map(t => t.isActive(true));
if (!activeTargets.length || (!move.hasAttr(VariableTargetAttr) && !move.isMultiTarget() && !targetHitChecks[this.targets[0]])) { if (!activeTargets.length || (!move.hasAttr(VariableTargetAttr) && !move.isMultiTarget() && !targetHitChecks[this.targets[0]])) {
user.turnData.hitCount = 1; this.stopMultiHit();
user.turnData.hitsLeft = 1;
if (activeTargets.length) { if (activeTargets.length) {
this.scene.queueMessage(getPokemonMessage(user, "'s\nattack missed!")); this.scene.queueMessage(getPokemonMessage(user, "'s\nattack missed!"));
moveHistoryEntry.result = MoveResult.MISS; moveHistoryEntry.result = MoveResult.MISS;
@ -2910,8 +2909,7 @@ export class MoveEffectPhase extends PokemonPhase {
new MoveAnim(move.id as Moves, user, this.getTarget()?.getBattlerIndex()).play(this.scene, () => { new MoveAnim(move.id as Moves, user, this.getTarget()?.getBattlerIndex()).play(this.scene, () => {
for (const target of targets) { for (const target of targets) {
if (!targetHitChecks[target.getBattlerIndex()]) { if (!targetHitChecks[target.getBattlerIndex()]) {
user.turnData.hitCount = 1; this.stopMultiHit(target);
user.turnData.hitsLeft = 1;
this.scene.queueMessage(getPokemonMessage(user, "'s\nattack missed!")); this.scene.queueMessage(getPokemonMessage(user, "'s\nattack missed!"));
if (moveHistoryEntry.result === MoveResult.PENDING) { if (moveHistoryEntry.result === MoveResult.PENDING) {
moveHistoryEntry.result = MoveResult.MISS; moveHistoryEntry.result = MoveResult.MISS;
@ -3116,6 +3114,28 @@ export class MoveEffectPhase extends PokemonPhase {
return this.getTargets().find(() => true); return this.getTargets().find(() => true);
} }
removeTarget(target: Pokemon): void {
const targetIndex = this.targets.findIndex(ind => ind === target.getBattlerIndex());
if (targetIndex !== -1) {
this.targets.splice(this.targets.findIndex(ind => ind === target.getBattlerIndex()), 1);
}
}
stopMultiHit(target?: Pokemon): void {
/** If given a specific target, remove the target from subsequent strikes */
if (target) {
this.removeTarget(target);
}
/**
* If no target specified, or the specified target was the last of this move's
* targets, completely cancel all subsequent strikes.
*/
if (!target || this.targets.length === 0 ) {
this.getUserPokemon().turnData.hitCount = 1;
this.getUserPokemon().turnData.hitsLeft = 1;
}
}
getNewHitPhase() { getNewHitPhase() {
return new MoveEffectPhase(this.scene, this.battlerIndex, this.targets, this.move); return new MoveEffectPhase(this.scene, this.battlerIndex, this.targets, this.move);
} }