Skip to content

Commit

Permalink
Fix some OMotM crashes
Browse files Browse the repository at this point in the history
  • Loading branch information
urkerab committed Feb 1, 2019
1 parent 8d57bd1 commit 0c276e6
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 7 deletions.
2 changes: 1 addition & 1 deletion config/formats.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
3 changes: 3 additions & 0 deletions dev-tools/globals.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -772,11 +773,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
3 changes: 2 additions & 1 deletion mods/pokebilities/abilities.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
'use strict';

/**@type {{[k: string]: ModdedAbilityData}} */
exports.BattleAbilities = {
trace: {
inherit: true,
Expand All @@ -10,7 +11,7 @@ exports.BattleAbilities = {
let possibleTargets = [];
for (let i = 0; i < pokemon.side.foe.active.length; i++) {
let target = pokemon.side.foe.active[i];
if (target && !target.fainted) {
if (target && !target.fainted && target.innates) {
possibleInnates = possibleInnates.concat(target.innates);
possibleTargets = possibleTargets.concat(target.innates.map(innate => target));
}
Expand Down
8 changes: 5 additions & 3 deletions mods/pokebilities/scripts.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
'use strict';

/**@type {ModdedBattleScriptsData} */
exports.BattleScripts = {
getEffect: function (name) {
if (name && typeof name !== 'string') {
Expand Down Expand Up @@ -70,16 +71,17 @@ 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) this.innates.forEach(innate => this.removeVolatile('ability' + innate));
if (pokemon.innates) pokemon.innates.forEach(innate => this.addVolatile('ability' + innate, this));
return true;
},
},
Expand Down
3 changes: 1 addition & 2 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@
"types": ["node"],
"exclude": [
"./mods/gen1/pokedex.js",
"./mods/pic/*.js",
"./mods/pokebilities/*.js"
"./mods/pic/*.js"
],
"include": [
"./config/formats.js",
Expand Down

0 comments on commit 0c276e6

Please sign in to comment.