Skip to content

Commit

Permalink
Fix some OMotM crashes (#5132)
Browse files Browse the repository at this point in the history
  • Loading branch information
urkerab authored and Zarel committed Feb 2, 2019
1 parent 94849bf commit 5863284
Show file tree
Hide file tree
Showing 7 changed files with 66 additions and 20 deletions.
31 changes: 30 additions & 1 deletion config/formats.js
Original file line number Diff line number Diff line change
Expand Up @@ -498,6 +498,35 @@ let Formats = [
section: "OM of the Month",
column: 2,
},
{
name: "[Gen 7] Pokebilities",
desc: `Pokémon have all of their released Abilities simultaneously.`,
threads: [
`&bullet; <a href="https://www.smogon.com/forums/threads/3588652/">Pok&eacute;bilities</a>`,
],

mod: 'pokebilities',
ruleset: ['[Gen 7] OU'],
banlist: ['Diglett', 'Dugtrio', 'Excadrill', 'Gothita', 'Gothitelle', 'Gothorita', 'Trapinch', 'Wobbuffet', 'Wynaut'],
onBegin: function () {
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);
}
},
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&eacute;mon have an added type determined by their IVs. Same as the Hidden Power type.`,
Expand All @@ -508,7 +537,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;
Expand Down
5 changes: 5 additions & 0 deletions dev-tools/globals.ts
Original file line number Diff line number Diff line change
Expand Up @@ -755,12 +755,15 @@ 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
isGrounded?: (this: Pokemon, negateImmunity: boolean | undefined) => boolean | null
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
}

Expand All @@ -772,11 +775,13 @@ interface ModdedBattleScriptsData extends Partial<BattleScriptsData> {
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
Expand Down
5 changes: 3 additions & 2 deletions mods/pic/moves.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
'use strict';

/**@type {{[k: string]: ModdedMoveData}} */
exports.BattleMovedex = {
"skillswap": {
inherit: true,
Expand All @@ -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;
Expand Down
9 changes: 5 additions & 4 deletions mods/pic/scripts.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
'use strict';

/**@type {ModdedBattleScriptsData} */
exports.BattleScripts = {
getEffect: function (name) {
getEffect(name) {
if (name && typeof name !== 'string') {
return name;
}
Expand All @@ -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;
Expand All @@ -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;
Expand All @@ -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) {
Expand Down
10 changes: 6 additions & 4 deletions mods/pokebilities/abilities.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
'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 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));
}
Expand All @@ -30,7 +32,7 @@ exports.BattleAbilities = {
if (isAbility) {
pokemon.setAbility(ability);
} else {
pokemon.removeVolatile("abilitytrace", pokemon);
pokemon.removeVolatile("abilitytrace");
pokemon.addVolatile("ability" + innate, pokemon);
}
return;
Expand Down
22 changes: 16 additions & 6 deletions mods/pokebilities/scripts.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
'use strict';

/**@type {ModdedBattleScriptsData} */
exports.BattleScripts = {
getEffect: function (name) {
getEffect(name) {
if (name && typeof name !== 'string') {
return name;
}
Expand All @@ -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;
Expand Down Expand Up @@ -70,16 +71,25 @@ exports.BattleScripts = {
});
}
for (let j in pokemon.boosts) {
// @ts-ignore
this.boosts[j] = pokemon.boosts[j];
}
if (effect) {
this.battle.add('-transform', this, pokemon, '[from] ' + effect.fullname);
} 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;
},
},
Expand Down
4 changes: 1 addition & 3 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,7 @@
},
"types": ["node"],
"exclude": [
"./mods/gen1/pokedex.js",
"./mods/pic/*.js",
"./mods/pokebilities/*.js"
"./mods/gen1/pokedex.js"
],
"include": [
"./config/formats.js",
Expand Down

0 comments on commit 5863284

Please sign in to comment.