From d6ceb30d86c9a30fc375b2795501bc1b48c97e49 Mon Sep 17 00:00:00 2001 From: Dread134 Date: Wed, 15 May 2024 13:06:37 -0400 Subject: [PATCH] Fix Simulated Trigger Issue: Corrosion triggers when moves use getTargetBenefitScore even if the move is not actually used by the opponent. Fix: Moved IgnoreTypeStatusEffectImunity to extend from PreSetStatusAbAttr instead of AbAttr so I can use the existing implemented quiet arg. Extras: I changed simulated to just use the first arg which is how the current checks pass the quiet arg. I was able to remove effect from args and have it as a set parameter being passed --- src/data/ability.ts | 52 ++++++++++++++++++++++---------------------- src/field/pokemon.ts | 3 ++- 2 files changed, 28 insertions(+), 27 deletions(-) diff --git a/src/data/ability.ts b/src/data/ability.ts index a257525ef..004614357 100644 --- a/src/data/ability.ts +++ b/src/data/ability.ts @@ -1736,6 +1736,30 @@ export class PreSetStatusAbAttr extends AbAttr { } } +/** + * Ignores the type immunity to Status Effects of the defender if the defender is of a certain type + */ +export class IgnoreTypeStatusEffectImmunityAbAttr extends PreSetStatusAbAttr { + private statusEffect: StatusEffect[]; + private defenderType: Type[]; + + constructor(statusEffect: StatusEffect[], defenderType: Type[]) { + super(true); + + this.statusEffect = statusEffect; + this.defenderType = defenderType; + } + + applyPreSetStatus(pokemon: Pokemon, passive: boolean, effect: StatusEffect,cancelled: Utils.BooleanHolder, args: any[]): boolean { + if (this.statusEffect.includes(effect) && this.defenderType.includes(args[1] as Type)) { + cancelled.value = true; + return true; + } + + return false; + } +} + export class StatusEffectImmunityAbAttr extends PreSetStatusAbAttr { private immuneEffects: StatusEffect[]; @@ -2666,30 +2690,6 @@ export class IgnoreTypeImmunityAbAttr extends AbAttr { } } -/** - * Ignores the type immunity to Status Effects of the defender if the defender is of a certain type - */ -export class IgnoreTypeStatusEffectImmunityAbAttr extends AbAttr { - private statusEffect: StatusEffect[]; - private defenderType: Type[]; - - constructor(statusEffect: StatusEffect[], defenderType: Type[]) { - super(true); - - this.statusEffect = statusEffect; - this.defenderType = defenderType; - } - - apply(pokemon: Pokemon, passive: boolean, cancelled: Utils.BooleanHolder, args: any[]): boolean { - if (this.statusEffect.includes(args[0] as StatusEffect) && this.defenderType.includes(args[1] as Type)) { - cancelled.value = true; - return true; - } - - return false; - } -} - function applyAbAttrsInternal(attrType: { new(...args: any[]): TAttr }, pokemon: Pokemon, applyFunc: AbAttrApplyFunc, args: any[], isAsync: boolean = false, showAbilityInstant: boolean = false, quiet: boolean = false, passive: boolean = false): Promise { return new Promise(resolve => { @@ -2824,8 +2824,8 @@ export function applyPostStatChangeAbAttrs(attrType: { new(...args: any[]): Post export function applyPreSetStatusAbAttrs(attrType: { new(...args: any[]): PreSetStatusAbAttr }, pokemon: Pokemon, effect: StatusEffect, cancelled: Utils.BooleanHolder, ...args: any[]): Promise { - const simulated = args.length > 1 && args[1]; - return applyAbAttrsInternal(attrType, pokemon, (attr, passive) => attr.applyPreSetStatus(pokemon, passive, effect, cancelled, args), args, false, false, !simulated); + const simulated = args[0]; + return applyAbAttrsInternal(attrType, pokemon, (attr, passive) => attr.applyPreSetStatus(pokemon, passive, effect, cancelled, args), args, false, false, simulated); } export function applyPreApplyBattlerTagAbAttrs(attrType: { new(...args: any[]): PreApplyBattlerTagAbAttr }, diff --git a/src/field/pokemon.ts b/src/field/pokemon.ts index eb08af3da..9c163ee26 100644 --- a/src/field/pokemon.ts +++ b/src/field/pokemon.ts @@ -2052,6 +2052,7 @@ export default abstract class Pokemon extends Phaser.GameObjects.Container { switch (effect) { case StatusEffect.POISON: case StatusEffect.TOXIC: + console.log('checking poison immunity', this.name, types, sourcePokemon?.name, sourcePokemon?.id) // Check if the Pokemon is immune to Poison/Toxic or if the source pokemon is canceling the immunity let poisonImmunity = types.map(defType => { // Check if the Pokemon is not immune to Poison/Toxic @@ -2061,7 +2062,7 @@ export default abstract class Pokemon extends Phaser.GameObjects.Container { // Check if the source Pokemon has an ability that cancels the Poison/Toxic immunity const cancelImmunity = new Utils.BooleanHolder(false); if (sourcePokemon) { - applyAbAttrs(IgnoreTypeStatusEffectImmunityAbAttr, sourcePokemon, cancelImmunity, effect, defType); + applyPreSetStatusAbAttrs(IgnoreTypeStatusEffectImmunityAbAttr, sourcePokemon, effect, cancelImmunity, quiet, defType); if (cancelImmunity.value) return false; }