refactored, increased PostAttackApplyBattlerTagAbAttr robustness

This commit is contained in:
Luc 2024-04-19 01:14:36 -04:00
parent ab884e0dfc
commit e81dcb191e

View File

@ -998,10 +998,11 @@ export class PostAttackContactApplyStatusEffectAbAttr extends PostAttackApplySta
export class PostAttackApplyBattlerTagAbAttr extends PostAttackAbAttr {
private contactRequired: boolean;
private chance: integer;
private chance: (user: Pokemon, target: Pokemon, move: PokemonMove) => integer;
private effects: BattlerTagType[];
constructor(contactRequired: boolean, chance: integer, ...effects: BattlerTagType[]) {
constructor(contactRequired: boolean, chance: (user: Pokemon, target: Pokemon, move: PokemonMove) => integer, ...effects: BattlerTagType[]) {
super();
this.contactRequired = contactRequired;
@ -1010,7 +1011,7 @@ export class PostAttackApplyBattlerTagAbAttr extends PostAttackAbAttr {
}
applyPostAttack(pokemon: Pokemon, passive: boolean, attacker: Pokemon, move: PokemonMove, hitResult: HitResult, args: any[]): boolean {
if (pokemon != attacker && (!this.contactRequired || move.getMove().checkFlag(MoveFlags.MAKES_CONTACT, attacker, pokemon)) && pokemon.randSeedInt(100) < this.chance && !pokemon.status) {
if (pokemon != attacker && (!this.contactRequired || move.getMove().checkFlag(MoveFlags.MAKES_CONTACT, attacker, pokemon)) && pokemon.randSeedInt(100) < this.chance(attacker, pokemon, move) && !pokemon.status) {
const effect = this.effects.length === 1 ? this.effects[0] : this.effects[pokemon.randSeedInt(this.effects.length)];
@ -1021,32 +1022,6 @@ export class PostAttackApplyBattlerTagAbAttr extends PostAttackAbAttr {
}
}
export class StenchAbAttr extends PostAttackAbAttr {
private contactRequired: boolean;
private chance: integer;
constructor(contactRequired: boolean, chance: integer) {
super();
this.contactRequired = contactRequired;
this.chance = chance;
}
applyPostAttack(pokemon: Pokemon, passive: boolean, attacker: Pokemon, move: PokemonMove, hitResult: HitResult, args: any[]): boolean {
if (pokemon != attacker && (!this.contactRequired || move.getMove().checkFlag(MoveFlags.MAKES_CONTACT, attacker, pokemon)) && pokemon.randSeedInt(100) < this.chance && !pokemon.status) {
const flinchAttr = move.getMove().findAttr(attr => attr instanceof FlinchAttr);
if (!flinchAttr)
return attacker.addTag(BattlerTagType.FLINCHED);
}
return false;
}
}
export class PostDefendStealHeldItemAbAttr extends PostDefendAbAttr {
private condition: PokemonDefendCondition;
@ -2342,7 +2317,7 @@ export const allAbilities = [ new Ability(Abilities.NONE, "-", "", 3) ];
export function initAbilities() {
allAbilities.push(
new Ability(Abilities.STENCH, "Stench", "By releasing stench when attacking, this Pokémon may cause the target to flinch.", 3)
.attr(StenchAbAttr, false, 10),
.attr(PostAttackApplyBattlerTagAbAttr, false, (user, target, move) => move.getMove().findAttr(attr => attr instanceof FlinchAttr) == undefined ? 10 : 0, BattlerTagType.FLINCHED),
new Ability(Abilities.DRIZZLE, "Drizzle", "The Pokémon makes it rain when it enters a battle.", 3)
.attr(PostSummonWeatherChangeAbAttr, WeatherType.RAIN)
.attr(PostBiomeChangeWeatherChangeAbAttr, WeatherType.RAIN),