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
pull/919/head
Dread134 2024-05-15 13:06:37 -04:00
parent 78f7965304
commit d6ceb30d86
2 changed files with 28 additions and 27 deletions

View File

@ -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 { export class StatusEffectImmunityAbAttr extends PreSetStatusAbAttr {
private immuneEffects: StatusEffect[]; 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<TAttr extends AbAttr>(attrType: { new(...args: any[]): TAttr }, function applyAbAttrsInternal<TAttr extends AbAttr>(attrType: { new(...args: any[]): TAttr },
pokemon: Pokemon, applyFunc: AbAttrApplyFunc<TAttr>, args: any[], isAsync: boolean = false, showAbilityInstant: boolean = false, quiet: boolean = false, passive: boolean = false): Promise<void> { pokemon: Pokemon, applyFunc: AbAttrApplyFunc<TAttr>, args: any[], isAsync: boolean = false, showAbilityInstant: boolean = false, quiet: boolean = false, passive: boolean = false): Promise<void> {
return new Promise(resolve => { return new Promise(resolve => {
@ -2824,8 +2824,8 @@ export function applyPostStatChangeAbAttrs(attrType: { new(...args: any[]): Post
export function applyPreSetStatusAbAttrs(attrType: { new(...args: any[]): PreSetStatusAbAttr }, export function applyPreSetStatusAbAttrs(attrType: { new(...args: any[]): PreSetStatusAbAttr },
pokemon: Pokemon, effect: StatusEffect, cancelled: Utils.BooleanHolder, ...args: any[]): Promise<void> { pokemon: Pokemon, effect: StatusEffect, cancelled: Utils.BooleanHolder, ...args: any[]): Promise<void> {
const simulated = args.length > 1 && args[1]; const simulated = args[0];
return applyAbAttrsInternal<PreSetStatusAbAttr>(attrType, pokemon, (attr, passive) => attr.applyPreSetStatus(pokemon, passive, effect, cancelled, args), args, false, false, !simulated); return applyAbAttrsInternal<PreSetStatusAbAttr>(attrType, pokemon, (attr, passive) => attr.applyPreSetStatus(pokemon, passive, effect, cancelled, args), args, false, false, simulated);
} }
export function applyPreApplyBattlerTagAbAttrs(attrType: { new(...args: any[]): PreApplyBattlerTagAbAttr }, export function applyPreApplyBattlerTagAbAttrs(attrType: { new(...args: any[]): PreApplyBattlerTagAbAttr },

View File

@ -2052,6 +2052,7 @@ export default abstract class Pokemon extends Phaser.GameObjects.Container {
switch (effect) { switch (effect) {
case StatusEffect.POISON: case StatusEffect.POISON:
case StatusEffect.TOXIC: 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 // Check if the Pokemon is immune to Poison/Toxic or if the source pokemon is canceling the immunity
let poisonImmunity = types.map(defType => { let poisonImmunity = types.map(defType => {
// Check if the Pokemon is not immune to Poison/Toxic // 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 // Check if the source Pokemon has an ability that cancels the Poison/Toxic immunity
const cancelImmunity = new Utils.BooleanHolder(false); const cancelImmunity = new Utils.BooleanHolder(false);
if (sourcePokemon) { if (sourcePokemon) {
applyAbAttrs(IgnoreTypeStatusEffectImmunityAbAttr, sourcePokemon, cancelImmunity, effect, defType); applyPreSetStatusAbAttrs(IgnoreTypeStatusEffectImmunityAbAttr, sourcePokemon, effect, cancelImmunity, quiet, defType);
if (cancelImmunity.value) if (cancelImmunity.value)
return false; return false;
} }