From 8b36160e2123eb3fafdb0d195526449836ff43f2 Mon Sep 17 00:00:00 2001 From: urkerab Date: Fri, 1 Feb 2019 20:39:45 +0000 Subject: [PATCH 1/6] Fix some OMotM crashes --- config/formats.js | 2 +- mods/pokebilities/abilities.js | 7 +++---- mods/pokebilities/scripts.js | 14 +++++++++++--- 3 files changed, 15 insertions(+), 8 deletions(-) diff --git a/config/formats.js b/config/formats.js index 08b92d8740698..0a5c8f44021b9 100644 --- a/config/formats.js +++ b/config/formats.js @@ -530,7 +530,7 @@ let Formats = [ mod: 'gen7', ruleset: ['[Gen 7] OU'], onModifyTemplate: function (template, pokemon) { - if (template.types.includes(pokemon.hpType)) return; + if (!pokemon || template.types.includes(pokemon.hpType)) return; let dex = this && this.deepClone ? this : Dex; let newTemplate = dex.deepClone(template); newTemplate.addedType = pokemon.hpType; diff --git a/mods/pokebilities/abilities.js b/mods/pokebilities/abilities.js index 5cc2b8f84117b..02811a858e6b4 100644 --- a/mods/pokebilities/abilities.js +++ b/mods/pokebilities/abilities.js @@ -8,9 +8,8 @@ exports.BattleAbilities = { let isAbility = this.effect.effectType === "Ability"; let possibleInnates = []; let possibleTargets = []; - for (let i = 0; i < pokemon.side.foe.active.length; i++) { - let target = pokemon.side.foe.active[i]; - if (target && !target.fainted) { + for (let target of pokemon.side.foe.active) { + if (target && !target.fainted && target.innates) { possibleInnates = possibleInnates.concat(target.innates); possibleTargets = possibleTargets.concat(target.innates.map(innate => target)); } @@ -30,7 +29,7 @@ exports.BattleAbilities = { if (isAbility) { pokemon.setAbility(ability); } else { - pokemon.removeVolatile("abilitytrace", pokemon); + pokemon.removeVolatile("abilitytrace"); pokemon.addVolatile("ability" + innate, pokemon); } return; diff --git a/mods/pokebilities/scripts.js b/mods/pokebilities/scripts.js index eaabf78e97056..7b1e66c06422b 100644 --- a/mods/pokebilities/scripts.js +++ b/mods/pokebilities/scripts.js @@ -77,9 +77,17 @@ exports.BattleScripts = { } else { this.battle.add('-transform', this, pokemon); } - this.setAbility(pokemon.ability, this, {id: 'transform'}); - this.innates.forEach(innate => this.removeVolatile('ability' + innate, this)); - pokemon.innates.forEach(innate => this.addVolatile('ability' + innate, this)); + this.setAbility(pokemon.ability, this, true); + if (this.innates) { + for (let innate of this.innates) { + this.removeVolatile('ability' + innate); + } + } + if (pokemon.innates) { + for (let innate of pokemon.innates) { + this.addVolatile('ability' + innate, this); + } + } return true; }, }, From 48252d2da145618ebb13cd19ffb2c086a30a1719 Mon Sep 17 00:00:00 2001 From: urkerab Date: Fri, 1 Feb 2019 23:51:12 +0000 Subject: [PATCH 2/6] Typescript mods/pokebilities --- dev-tools/globals.ts | 3 +++ mods/pokebilities/abilities.js | 3 +++ mods/pokebilities/scripts.js | 8 +++++--- tsconfig.json | 3 +-- 4 files changed, 12 insertions(+), 5 deletions(-) diff --git a/dev-tools/globals.ts b/dev-tools/globals.ts index 37cd31bb7cc0f..49a1a14312725 100644 --- a/dev-tools/globals.ts +++ b/dev-tools/globals.ts @@ -757,6 +757,7 @@ interface ModdedBattlePokemon { getActionSpeed?: (this: Pokemon) => number getStat?: (this: Pokemon, statName: string, unboosted?: boolean, unmodified?: boolean) => number getWeight?: (this: Pokemon) => number + hasAbility?: (this: Pokemon, ability: string | string[]) => boolean isGrounded?: (this: Pokemon, negateImmunity: boolean | undefined) => boolean | null modifyStat?: (this: Pokemon, statName: string, modifier: number) => void moveUsed?: (this: Pokemon, move: Move, targetLoc?: number) => void @@ -772,11 +773,13 @@ interface ModdedBattleScriptsData extends Partial { boost?: (this: Battle, boost: SparseBoostsTable, target: Pokemon, source?: Pokemon | null, effect?: Effect | string | null, isSecondary?: boolean, isSelf?: boolean) => boolean | null | 0 debug?: (this: Battle, activity: string) => void getDamage?: (this: Battle, pokemon: Pokemon, target: Pokemon, move: string | number | ActiveMove, suppressMessages: boolean) => number + getEffect?: (this: Battle, name: string | Effect | null) => Effect init?: (this: Battle) => void modifyDamage?: (this: Battle, baseDamage: number, pokemon: Pokemon, target: Pokemon, move: ActiveMove, suppressMessages?: boolean) => void natureModify?: (this: Battle, stats: StatsTable, set: PokemonSet) => StatsTable setTerrain?: (this: Battle, status: string | Effect, source: Pokemon | null | 'debug', sourceEffect: Effect | null) => boolean spreadModify?: (this: Battle, baseStats: StatsTable, set: PokemonSet) => StatsTable + suppressingWeather?: (this: Battle) => boolean // oms doGetMixedTemplate?: (this: Battle, template: Template, deltas: AnyObject) => Template diff --git a/mods/pokebilities/abilities.js b/mods/pokebilities/abilities.js index 02811a858e6b4..e7f3e663f9974 100644 --- a/mods/pokebilities/abilities.js +++ b/mods/pokebilities/abilities.js @@ -1,12 +1,15 @@ 'use strict'; +/**@type {{[k: string]: ModdedAbilityData}} */ exports.BattleAbilities = { trace: { inherit: true, onUpdate: function (pokemon) { if (!pokemon.isStarted) return; let isAbility = this.effect.effectType === "Ability"; + /**@type {string[]} */ let possibleInnates = []; + /**@type {Pokemon[]} */ let possibleTargets = []; for (let target of pokemon.side.foe.active) { if (target && !target.fainted && target.innates) { diff --git a/mods/pokebilities/scripts.js b/mods/pokebilities/scripts.js index 7b1e66c06422b..6400fcb96d10f 100644 --- a/mods/pokebilities/scripts.js +++ b/mods/pokebilities/scripts.js @@ -1,7 +1,8 @@ 'use strict'; +/**@type {ModdedBattleScriptsData} */ exports.BattleScripts = { - getEffect: function (name) { + getEffect(name) { if (name && typeof name !== 'string') { return name; } @@ -22,13 +23,13 @@ exports.BattleScripts = { return false; }, pokemon: { - hasAbility: function (ability) { + hasAbility(ability) { if (this.ignoringAbility()) return false; if (Array.isArray(ability)) return ability.some(ability => this.hasAbility(ability)); ability = toId(ability); return this.ability === ability || !!this.volatiles['ability' + ability]; }, - transformInto: function (pokemon, effect) { + transformInto(pokemon, effect) { let template = pokemon.template; if (pokemon.fainted || pokemon.illusion || (pokemon.volatiles['substitute'] && this.battle.gen >= 5)) { return false; @@ -70,6 +71,7 @@ exports.BattleScripts = { }); } for (let j in pokemon.boosts) { + // @ts-ignore this.boosts[j] = pokemon.boosts[j]; } if (effect) { diff --git a/tsconfig.json b/tsconfig.json index 0af4d324a3aa1..16ef830148c33 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -12,8 +12,7 @@ "types": ["node"], "exclude": [ "./mods/gen1/pokedex.js", - "./mods/pic/*.js", - "./mods/pokebilities/*.js" + "./mods/pic/*.js" ], "include": [ "./config/formats.js", From 3b93b6fca714140deaea13f521b6affbc2ab422c Mon Sep 17 00:00:00 2001 From: urkerab Date: Fri, 1 Feb 2019 23:52:59 +0000 Subject: [PATCH 3/6] Typescript mods/pic --- dev-tools/globals.ts | 2 ++ mods/pic/moves.js | 5 +++-- mods/pic/scripts.js | 9 +++++---- tsconfig.json | 3 +-- 4 files changed, 11 insertions(+), 8 deletions(-) diff --git a/dev-tools/globals.ts b/dev-tools/globals.ts index 49a1a14312725..98eb7b23874d4 100644 --- a/dev-tools/globals.ts +++ b/dev-tools/globals.ts @@ -755,6 +755,7 @@ interface ModdedBattlePokemon { boostBy?: (this: Pokemon, boost: SparseBoostsTable) => boolean calculateStat?: (this: Pokemon, statName: string, boost: number, modifier?: number) => number getActionSpeed?: (this: Pokemon) => number + getRequestData?: (this: Pokemon) => {moves: {move: string, id: string, target?: string, disabled?: boolean}[], maybeDisabled?: boolean, trapped?: boolean, maybeTrapped?: boolean, canMegaEvo?: boolean, canUltraBurst?: boolean, canZMove?: AnyObject | null} getStat?: (this: Pokemon, statName: string, unboosted?: boolean, unmodified?: boolean) => number getWeight?: (this: Pokemon) => number hasAbility?: (this: Pokemon, ability: string | string[]) => boolean @@ -762,6 +763,7 @@ interface ModdedBattlePokemon { modifyStat?: (this: Pokemon, statName: string, modifier: number) => void moveUsed?: (this: Pokemon, move: Move, targetLoc?: number) => void recalculateStats?: (this: Pokemon) => void + setAbility?: (this: Pokemon, ability: string | Ability, source: Pokemon | null, isFromFormeChange: boolean) => string | false transformInto?: (this: Pokemon, pokemon: Pokemon, effect: Effect | null) => boolean } diff --git a/mods/pic/moves.js b/mods/pic/moves.js index 27d0411bb04e6..8657727232935 100644 --- a/mods/pic/moves.js +++ b/mods/pic/moves.js @@ -1,5 +1,6 @@ 'use strict'; +/**@type {{[k: string]: ModdedMoveData}} */ exports.BattleMovedex = { "skillswap": { inherit: true, @@ -26,8 +27,8 @@ exports.BattleMovedex = { if (targetAbility.id !== sourceAbility.id) { source.ability = targetAbility.id; target.ability = sourceAbility.id; - source.abilityData = {id: source.ability.id, target: source}; - target.abilityData = {id: target.ability.id, target: target}; + source.abilityData = {id: source.ability, target: source}; + target.abilityData = {id: target.ability, target: target}; } if (sourceAlly && sourceAlly.ability !== source.ability) { let volatile = sourceAlly.innate = 'ability' + source.ability; diff --git a/mods/pic/scripts.js b/mods/pic/scripts.js index 2aed4151e8246..fac3a58f38b7f 100644 --- a/mods/pic/scripts.js +++ b/mods/pic/scripts.js @@ -1,7 +1,8 @@ 'use strict'; +/**@type {ModdedBattleScriptsData} */ exports.BattleScripts = { - getEffect: function (name) { + getEffect(name) { if (name && typeof name !== 'string') { return name; } @@ -10,7 +11,7 @@ exports.BattleScripts = { return Object.getPrototypeOf(this).getEffect.call(this, name); }, pokemon: { - setAbility: function (ability, source, isFromFormechange) { + setAbility(ability, source, isFromFormechange) { if (!this.hp) return false; ability = this.battle.getAbility(ability); let oldAbility = this.ability; @@ -36,7 +37,7 @@ exports.BattleScripts = { this.abilityOrder = this.battle.abilityOrder++; return oldAbility; }, - hasAbility: function (ability) { + hasAbility(ability) { if (!this.ignoringAbility()) { if (Array.isArray(ability) ? ability.map(toId).includes(this.ability) : toId(ability) === this.ability) { return true; @@ -47,7 +48,7 @@ exports.BattleScripts = { if (Array.isArray(ability)) return ability.map(toId).includes(ally.ability); return toId(ability) === ally.ability; }, - getRequestData: function () { + getRequestData() { let ally = this.side.active.find(ally => ally && ally !== this && !ally.fainted); this.moveSlots = this.baseMoveSlots.concat(ally ? ally.baseMoveSlots : []); for (const moveSlot of this.moveSlots) { diff --git a/tsconfig.json b/tsconfig.json index 16ef830148c33..2c9697497b663 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -11,8 +11,7 @@ }, "types": ["node"], "exclude": [ - "./mods/gen1/pokedex.js", - "./mods/pic/*.js" + "./mods/gen1/pokedex.js" ], "include": [ "./config/formats.js", From 2f9f2f8a86d198cbed367812d92f45fa4e03fe53 Mon Sep 17 00:00:00 2001 From: urkerab Date: Fri, 1 Feb 2019 23:58:54 +0000 Subject: [PATCH 4/6] Revert "Remove Pokebilities format" This reverts commit b3d3f4419e8a3db2501bb0b8786f4d0b84bfe830. --- config/formats.js | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/config/formats.js b/config/formats.js index 0a5c8f44021b9..d54a461175d60 100644 --- a/config/formats.js +++ b/config/formats.js @@ -520,6 +520,36 @@ let Formats = [ section: "OM of the Month", column: 2, }, + { + name: "[Gen 7] Pokebilities", + desc: `Pokémon have all of their Abilities simultaneously, excluding unreleased or banned Abilities.`, + threads: [ + `• Pokébilities`, + ], + + mod: 'pokebilities', + ruleset: ['[Gen 7] OU', 'Evasion Abilities Clause'], + banlist: ['Excadrill'], + onBegin: function () { + let ruleTable = this.getRuleTable(this.getFormat()); + let allPokemon = this.p1.pokemon.concat(this.p2.pokemon); + for (let pokemon of allPokemon) { + if (pokemon.ability === pokemon.template.abilities['S']) { + continue; + } + // @ts-ignore + pokemon.innates = Object.keys(pokemon.template.abilities).filter(key => key !== 'S' && (key !== 'H' || !pokemon.template.unreleasedHidden)).map(key => toId(pokemon.template.abilities[key])).filter(ability => ability !== pokemon.ability && !ruleTable.get('-ability:' + ability)); + } + }, + onSwitchInPriority: 2, + onSwitchIn: function (pokemon) { + if (pokemon.innates) pokemon.innates.forEach(innate => pokemon.addVolatile("ability" + innate, pokemon)); + }, + onAfterMega: function (pokemon) { + Object.keys(pokemon.volatiles).filter(innate => innate.startsWith('ability')).forEach(innate => pokemon.removeVolatile(innate)); + pokemon.innates = undefined; + }, + }, { name: "[Gen 7] Hidden Type", desc: `Pokémon have an added type determined by their IVs. Same as the Hidden Power type.`, From 011e04f416b110746f93d27c7a1026774275614c Mon Sep 17 00:00:00 2001 From: The Immortal Date: Sat, 2 Feb 2019 04:12:47 +0400 Subject: [PATCH 5/6] Update formats.js --- config/formats.js | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/config/formats.js b/config/formats.js index d54a461175d60..505f29ec8b0c2 100644 --- a/config/formats.js +++ b/config/formats.js @@ -528,17 +528,16 @@ let Formats = [ ], mod: 'pokebilities', - ruleset: ['[Gen 7] OU', 'Evasion Abilities Clause'], - banlist: ['Excadrill'], + ruleset: ['[Gen 7] OU'], + banlist: ['Diglett', 'Dugtrio', 'Excadrill', 'Gothita', 'Gothitelle', 'Gothorita', 'Trapinch', 'Wobbuffet', 'Wynaut'], onBegin: function () { - let ruleTable = this.getRuleTable(this.getFormat()); let allPokemon = this.p1.pokemon.concat(this.p2.pokemon); for (let pokemon of allPokemon) { if (pokemon.ability === pokemon.template.abilities['S']) { continue; } // @ts-ignore - pokemon.innates = Object.keys(pokemon.template.abilities).filter(key => key !== 'S' && (key !== 'H' || !pokemon.template.unreleasedHidden)).map(key => toId(pokemon.template.abilities[key])).filter(ability => ability !== pokemon.ability && !ruleTable.get('-ability:' + ability)); + pokemon.innates = Object.keys(pokemon.template.abilities).filter(key => key !== 'S' && (key !== 'H' || !pokemon.template.unreleasedHidden)).map(key => toId(pokemon.template.abilities[key])).filter(ability => ability !== pokemon.ability); } }, onSwitchInPriority: 2, From 07bb5016f8e582180c395959142c601481a54d1f Mon Sep 17 00:00:00 2001 From: The Immortal Date: Sat, 2 Feb 2019 04:18:00 +0400 Subject: [PATCH 6/6] Update formats.js --- config/formats.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/config/formats.js b/config/formats.js index 505f29ec8b0c2..9aae232c50477 100644 --- a/config/formats.js +++ b/config/formats.js @@ -522,7 +522,7 @@ let Formats = [ }, { name: "[Gen 7] Pokebilities", - desc: `Pokémon have all of their Abilities simultaneously, excluding unreleased or banned Abilities.`, + desc: `Pokémon have all of their released Abilities simultaneously.`, threads: [ `• Pokébilities`, ],