Support new ability flags (#2210)

This commit is contained in:
Karthik 2024-01-08 17:10:58 -07:00 committed by GitHub
parent 8820a14f54
commit 17eef20bcf
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 30 additions and 10 deletions

View File

@ -1063,7 +1063,7 @@ process.stdout.write("Building `data/teambuilder-tables.js`... ");
// Client relevant data that should be overriden by past gens and mods
const overrideSpeciesKeys = ['abilities', 'baseStats', 'cosmeticFormes', 'isNonstandard', 'requiredItems', 'types', 'unreleasedHidden'];
const overrideMoveKeys = ['accuracy', 'basePower', 'category', 'desc', 'flags', 'isNonstandard', 'noSketch', 'pp', 'priority', 'shortDesc', 'target', 'type'];
const overrideAbilityKeys = ['desc', 'isNonstandard', 'rating', 'shortDesc'];
const overrideAbilityKeys = ['desc', 'flags', 'isNonstandard', 'rating', 'shortDesc'];
//
// Past gen table

View File

@ -1372,6 +1372,25 @@ class Move implements Effect {
}
}
interface AbilityFlags {
/** Can be suppressed by Mold Breaker and related effects */
breakable?: 1;
/** Ability can't be suppressed by e.g. Gastro Acid or Neutralizing Gas */
cantsuppress?: 1;
/** Role Play fails if target has this Ability */
failroleplay?: 1;
/** Skill Swap fails if either the user or target has this Ability */
failskillswap?: 1;
/** Entrainment fails if user has this Ability */
noentrain?: 1;
/** Receiver and Power of Alchemy will not activate if an ally faints with this Ability */
noreceiver?: 1;
/** Trace cannot copy this Ability */
notrace?: 1;
/** Disables the Ability if the user is Transformed */
notransform?: 1;
}
class Ability implements Effect {
// effect
readonly effectType = 'Ability';
@ -1385,7 +1404,7 @@ class Ability implements Effect {
readonly desc: string;
readonly rating: number;
readonly isPermanent: boolean;
readonly flags: AbilityFlags;
readonly isNonstandard: boolean;
constructor(id: ID, name: string, data: any) {
@ -1399,7 +1418,7 @@ class Ability implements Effect {
this.shortDesc = data.shortDesc || data.desc || '';
this.desc = data.desc || data.shortDesc || '';
this.rating = data.rating || 1;
this.isPermanent = !!data.isPermanent;
this.flags = data.flags || {};
this.isNonstandard = !!data.isNonstandard;
if (!this.gen) {
if (this.num >= 234) {

View File

@ -521,11 +521,14 @@ export class Pokemon implements PokemonDetails, PokemonHealth {
return !this.getTypeList(serverPokemon).includes('Flying');
}
effectiveAbility(serverPokemon?: ServerPokemon) {
if (this.fainted || this.volatiles['gastroacid']) return '';
const ability = this.side.battle.dex.abilities.get(
serverPokemon?.ability || this.ability || serverPokemon?.baseAbility || ''
);
if (this.side.battle.ngasActive() && !ability.isPermanent) {
if (
this.fainted ||
(this.volatiles['transform'] && ability.flags['notransform']) ||
(!ability.flags['cantsuppress'] && (this.side.battle.ngasActive() || this.volatiles['gastroacid']))
) {
return '';
}
return ability.name;
@ -1224,6 +1227,7 @@ export class Battle {
}
return pokemonList;
}
// Used in Pokemon#effectiveAbility over abilityActive to prevent infinite recursion
ngasActive() {
for (const active of this.getAllActive()) {
if (active.ability === 'Neutralizing Gas' && !active.volatiles['gastroacid']) {
@ -1234,12 +1238,9 @@ export class Battle {
}
abilityActive(abilities: string | string[]) {
if (typeof abilities === 'string') abilities = [abilities];
if (this.ngasActive()) {
abilities = abilities.filter(a => this.dex.abilities.get(a).isPermanent);
if (!abilities.length) return false;
}
abilities = abilities.map(toID);
for (const active of this.getAllActive()) {
if (abilities.includes(active.ability) && !active.volatiles['gastroacid']) {
if (abilities.includes(toID(active.effectiveAbility()))) {
return true;
}
}