Skip to content

Commit

Permalink
Refactor more things to use pokemon.allies/foes
Browse files Browse the repository at this point in the history
(This will make multi battles easier to implement.)
  • Loading branch information
Zarel committed Mar 29, 2021
1 parent d6e7df5 commit d18c0a4
Show file tree
Hide file tree
Showing 16 changed files with 68 additions and 111 deletions.
8 changes: 3 additions & 5 deletions config/formats.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1402,11 +1402,9 @@ export const Formats: FormatList = [
},
field: {
suppressingWeather() {
for (const side of this.battle.sides) {
for (const pokemon of side.active) {
if (pokemon && !pokemon.ignoringAbility() && pokemon.hasAbility('Cloud Nine')) {
return true;
}
for (const pokemon of this.battle.getAllActive()) {
if (pokemon && !pokemon.ignoringAbility() && pokemon.hasAbility('Cloud Nine')) {
return true;
}
}
return false;
Expand Down
48 changes: 13 additions & 35 deletions data/abilities.ts
Original file line number Diff line number Diff line change
Expand Up @@ -126,8 +126,7 @@ export const Abilities: {[abilityid: string]: AbilityData} = {
},
anticipation: {
onStart(pokemon) {
for (const target of pokemon.side.foe.active) {
if (!target || target.fainted) continue;
for (const target of pokemon.foes()) {
for (const moveSlot of target.moveSlots) {
const move = this.dex.getMove(moveSlot.move);
if (move.category === 'Status') continue;
Expand Down Expand Up @@ -227,8 +226,7 @@ export const Abilities: {[abilityid: string]: AbilityData} = {
onResidualSubOrder: 1,
onResidual(pokemon) {
if (!pokemon.hp) return;
for (const target of pokemon.side.foe.active) {
if (!target?.hp) continue;
for (const target of pokemon.foes()) {
if (target.status === 'slp' || target.hasAbility('comatose')) {
this.damage(target.baseMaxhp / 8, target, pokemon);
}
Expand Down Expand Up @@ -533,11 +531,9 @@ export const Abilities: {[abilityid: string]: AbilityData} = {
},
curiousmedicine: {
onStart(pokemon) {
for (const ally of pokemon.side.active) {
if (ally !== pokemon) {
ally.clearBoosts();
this.add('-clearboost', ally, '[from] ability: Curious Medicine', '[of] ' + pokemon);
}
for (const ally of pokemon.adjacentAllies()) {
ally.clearBoosts();
this.add('-clearboost', ally, '[from] ability: Curious Medicine', '[of] ' + pokemon);
}
},
name: "Curious Medicine",
Expand Down Expand Up @@ -771,8 +767,7 @@ export const Abilities: {[abilityid: string]: AbilityData} = {
onStart(pokemon) {
let totaldef = 0;
let totalspd = 0;
for (const target of pokemon.side.foe.active) {
if (!target || target.fainted) continue;
for (const target of pokemon.foes()) {
totaldef += target.getStat('def', false, true);
totalspd += target.getStat('spd', false, true);
}
Expand Down Expand Up @@ -1109,8 +1104,7 @@ export const Abilities: {[abilityid: string]: AbilityData} = {
onStart(pokemon) {
let warnMoves: (Move | Pokemon)[][] = [];
let warnBp = 1;
for (const target of pokemon.side.foe.active) {
if (target.fainted) continue;
for (const target of pokemon.foes()) {
for (const moveSlot of target.moveSlots) {
const move = this.dex.getMove(moveSlot.move);
let bp = move.basePower;
Expand Down Expand Up @@ -1147,8 +1141,7 @@ export const Abilities: {[abilityid: string]: AbilityData} = {
},
frisk: {
onStart(pokemon) {
for (const target of pokemon.side.foe.active) {
if (!target?.hp) continue;
for (const target of pokemon.foes()) {
if (target.item) {
this.add('-item', target, target.getItem().name, '[from] ability: Frisk', '[of] ' + pokemon, '[identify]');
}
Expand Down Expand Up @@ -1359,9 +1352,6 @@ export const Abilities: {[abilityid: string]: AbilityData} = {
onResidualOrder: 5,
onResidualSubOrder: 4,
onResidual(pokemon) {
if (pokemon.side.active.length === 1) {
return;
}
for (const allyActive of pokemon.adjacentAllies()) {
if (allyActive.status && this.randomChance(3, 10)) {
this.add('-activate', pokemon, 'ability: Healer');
Expand Down Expand Up @@ -2044,14 +2034,8 @@ export const Abilities: {[abilityid: string]: AbilityData} = {
minus: {
onModifySpAPriority: 5,
onModifySpA(spa, pokemon) {
if (pokemon.side.active.length === 1) {
return;
}
for (const allyActive of pokemon.side.active) {
if (
allyActive && allyActive.position !== pokemon.position &&
!allyActive.fainted && allyActive.hasAbility(['minus', 'plus'])
) {
for (const allyActive of pokemon.allies()) {
if (allyActive.hasAbility(['minus', 'plus'])) {
return this.chainModify(1.5);
}
}
Expand Down Expand Up @@ -2474,7 +2458,7 @@ export const Abilities: {[abilityid: string]: AbilityData} = {
},
pastelveil: {
onStart(pokemon) {
for (const ally of pokemon.allies()) {
for (const ally of pokemon.alliesAndSelf()) {
if (['psn', 'tox'].includes(ally.status)) {
this.add('-activate', pokemon, 'ability: Pastel Veil');
ally.cureStatus();
Expand Down Expand Up @@ -2593,14 +2577,8 @@ export const Abilities: {[abilityid: string]: AbilityData} = {
plus: {
onModifySpAPriority: 5,
onModifySpA(spa, pokemon) {
if (pokemon.side.active.length === 1) {
return;
}
for (const allyActive of pokemon.side.active) {
if (
allyActive && allyActive.position !== pokemon.position &&
!allyActive.fainted && allyActive.hasAbility(['minus', 'plus'])
) {
for (const allyActive of pokemon.allies()) {
if (allyActive.hasAbility(['minus', 'plus'])) {
return this.chainModify(1.5);
}
}
Expand Down
3 changes: 1 addition & 2 deletions data/mods/gen4/abilities.ts
Original file line number Diff line number Diff line change
Expand Up @@ -135,8 +135,7 @@ export const Abilities: {[k: string]: ModdedAbilityData} = {
onStart(pokemon) {
let warnMoves: Move[] = [];
let warnBp = 1;
for (const target of pokemon.side.foe.active) {
if (target.fainted) continue;
for (const target of pokemon.foes()) {
for (const moveSlot of target.moveSlots) {
const move = this.dex.getMove(moveSlot.move);
let bp = move.basePower;
Expand Down
7 changes: 3 additions & 4 deletions data/mods/gen4/moves.ts
Original file line number Diff line number Diff line change
Expand Up @@ -673,8 +673,7 @@ export const Moves: {[k: string]: ModdedMoveData} = {
inherit: true,
flags: {authentic: 1},
onTryHit(pokemon) {
for (const target of pokemon.side.foe.active) {
if (!target || target.fainted) continue;
for (const target of pokemon.foes()) {
for (const move of pokemon.moves) {
if (target.moves.includes(move)) return;
}
Expand Down Expand Up @@ -720,7 +719,7 @@ export const Moves: {[k: string]: ModdedMoveData} = {
if (target !== source && target.side === this.effectData.target && this.getCategory(move) === 'Special') {
if (!target.getMoveHitData(move).crit && !move.infiltrates) {
this.debug('Light Screen weaken');
if (target.allies().length > 1) return this.chainModify(2, 3);
if (target.alliesAndSelf().length > 1) return this.chainModify(2, 3);
return this.chainModify(0.5);
}
}
Expand Down Expand Up @@ -1031,7 +1030,7 @@ export const Moves: {[k: string]: ModdedMoveData} = {
if (target !== source && target.side === this.effectData.target && this.getCategory(move) === 'Physical') {
if (!target.getMoveHitData(move).crit && !move.infiltrates) {
this.debug('Reflect weaken');
if (target.allies().length > 1) return this.chainModify(2, 3);
if (target.alliesAndSelf().length > 1) return this.chainModify(2, 3);
return this.chainModify(0.5);
}
}
Expand Down
3 changes: 1 addition & 2 deletions data/mods/gen5/abilities.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@ export const Abilities: {[k: string]: ModdedAbilityData} = {
anticipation: {
inherit: true,
onStart(pokemon) {
for (const target of pokemon.side.foe.active) {
if (!target || target.fainted) continue;
for (const target of pokemon.foes()) {
for (const moveSlot of target.moveSlots) {
const move = this.dex.getMove(moveSlot.move);
if (move.category !== 'Status' && (
Expand Down
3 changes: 1 addition & 2 deletions data/mods/gennext/abilities.ts
Original file line number Diff line number Diff line change
Expand Up @@ -330,8 +330,7 @@ export const Abilities: {[k: string]: ModdedAbilityData} = {
}
let totaldef = 0;
let totalspd = 0;
for (const foe of pokemon.side.foe.active) {
if (!foe || foe.fainted) continue;
for (const foe of pokemon.foes()) {
totaldef += foe.storedStats.def;
totalspd += foe.storedStats.spd;
}
Expand Down
9 changes: 3 additions & 6 deletions data/mods/megasforall/abilities.ts
Original file line number Diff line number Diff line change
Expand Up @@ -301,8 +301,7 @@ export const Abilities: {[abilityid: string]: ModdedAbilityData} = {
shortDesc: "Summons hail on switch-in. If foe has a supereffective or OHKO move, summons rain.",
onStart(source) {
this.field.setWeather('hail');
for (const target of source.side.foe.active) {
if (!target || target.fainted) continue;
for (const target of source.foes()) {
for (const moveSlot of target.moveSlots) {
const move = this.dex.getMove(moveSlot.move);
if (move.category === 'Status') continue;
Expand All @@ -320,8 +319,7 @@ export const Abilities: {[abilityid: string]: ModdedAbilityData} = {
onAnySwitchIn(pokemon) {
const source = this.effectData.target;
if (pokemon === source) return;
for (const target of source.side.foe.active) {
if (!target || target.fainted) continue;
for (const target of source.foes()) {
for (const moveSlot of target.moveSlots) {
const move = this.dex.getMove(moveSlot.move);
if (move.category === 'Status') continue;
Expand Down Expand Up @@ -1266,8 +1264,7 @@ export const Abilities: {[abilityid: string]: ModdedAbilityData} = {
onStart(pokemon) {
let totalatk = 0;
let totalspa = 0;
for (const target of pokemon.side.foe.active) {
if (!target || target.fainted) continue;
for (const target of pokemon.foes()) {
totalatk += target.getStat('atk', false, true);
totalspa += target.getStat('spa', false, true);
}
Expand Down
7 changes: 3 additions & 4 deletions data/mods/megasforall/scripts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -159,11 +159,10 @@ export const Scripts: ModdedBattleScriptsData = {
runMegaEvo(pokemon) {
const speciesid = pokemon.canMegaEvo || pokemon.canUltraBurst;
if (!speciesid) return false;
const side = pokemon.side;

// Pokémon affected by Sky Drop cannot mega evolve. Enforce it here for now.
for (const foeActive of side.foe.active) {
if (foeActive.volatiles['skydrop'] && foeActive.volatiles['skydrop'].source === pokemon) {
for (const foeActive of pokemon.foes()) {
if (foeActive.volatiles['skydrop']?.source === pokemon) {
return false;
}
}
Expand All @@ -175,7 +174,7 @@ export const Scripts: ModdedBattleScriptsData = {

// Limit one mega evolution
const wasMega = pokemon.canMegaEvo;
for (const ally of side.pokemon) {
for (const ally of pokemon.alliesAndSelf()) {
if (wasMega) {
ally.canMegaEvo = null;
} else {
Expand Down
5 changes: 2 additions & 3 deletions data/mods/mixandmega/scripts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,10 @@ export const Scripts: ModdedBattleScriptsData = {

// @ts-ignore
const species: Species = this.getMixedSpecies(pokemon.m.originalSpecies, pokemon.canMegaEvo);
const side = pokemon.side;

// Pokémon affected by Sky Drop cannot Mega Evolve. Enforce it here for now.
for (const foeActive of side.foe.active) {
if (foeActive.volatiles['skydrop'] && foeActive.volatiles['skydrop'].source === pokemon) {
for (const foeActive of pokemon.foes()) {
if (foeActive.volatiles['skydrop']?.source === pokemon) {
return false;
}
}
Expand Down
5 changes: 2 additions & 3 deletions data/mods/mixandmega7/scripts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,10 @@ export const Scripts: ModdedBattleScriptsData = {
const isUltraBurst = !pokemon.canMegaEvo;
// @ts-ignore
const species: Species = this.getMixedSpecies(pokemon.m.originalSpecies, pokemon.canMegaEvo || pokemon.canUltraBurst);
const side = pokemon.side;

// Pokémon affected by Sky Drop cannot Mega Evolve. Enforce it here for now.
for (const foeActive of side.foe.active) {
if (foeActive.volatiles['skydrop'] && foeActive.volatiles['skydrop'].source === pokemon) {
for (const foeActive of pokemon.foes()) {
if (foeActive.volatiles['skydrop']?.source === pokemon) {
return false;
}
}
Expand Down
6 changes: 2 additions & 4 deletions data/mods/ssb/abilities.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1641,13 +1641,11 @@ export const Abilities: {[k: string]: ModdedAbilityData} = {
onStart(pokemon) {
let totalatk = 0;
let totalspa = 0;
for (const target of pokemon.side.foe.active) {
if (!target || target.fainted) continue;
for (const target of pokemon.foes()) {
totalatk += target.getStat('atk', false, true);
totalspa += target.getStat('spa', false, true);
}
for (const target of pokemon.side.foe.active) {
if (!target || target.fainted) continue;
for (const target of pokemon.foes()) {
this.add('-ability', pokemon, 'BURN IT DOWN!');
if (totalatk && totalatk >= totalspa) {
this.boost({atk: -1}, target, pokemon, null, true);
Expand Down
6 changes: 2 additions & 4 deletions data/mods/ssb/moves.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,7 @@ export const Moves: {[k: string]: ModdedMoveData} = {
},
onHit(target, source, move) {
if (this.randomChance(1, 10)) {
for (const foe of source.side.foe.active) {
if (!foe || foe.fainted) continue;
for (const foe of source.foes()) {
foe.trySetStatus('brn', source);
}
}
Expand Down Expand Up @@ -4207,8 +4206,7 @@ export const Moves: {[k: string]: ModdedMoveData} = {
onHit(source) {
let totalatk = 0;
let totalspa = 0;
for (const target of source.side.foe.active) {
if (!target || target.fainted) continue;
for (const target of source.foes()) {
totalatk += target.getStat('atk', false, true);
totalspa += target.getStat('spa', false, true);
if (totalatk && totalatk >= totalspa) {
Expand Down
8 changes: 3 additions & 5 deletions data/mods/ssb/scripts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,10 @@ export const Scripts: ModdedBattleScriptsData = {
if (pokemon.name === 'Raj.Shoot' && pokemon.species.name === 'Charizard') pokemon.canMegaEvo = 'Charizard-Mega-X';
const speciesid = pokemon.canMegaEvo || pokemon.canUltraBurst;
if (!speciesid) return false;
const side = pokemon.side;

// Pokémon affected by Sky Drop cannot mega evolve. Enforce it here for now.
for (const foeActive of side.foe.active) {
if (foeActive.volatiles['skydrop'] && foeActive.volatiles['skydrop'].source === pokemon) {
for (const foeActive of pokemon.foes()) {
if (foeActive.volatiles['skydrop']?.source === pokemon) {
return false;
}
}
Expand Down Expand Up @@ -1013,8 +1012,7 @@ export const Scripts: ModdedBattleScriptsData = {
// canceling switches would leak information
// if a foe might have a trapping ability
if (this.gen > 2) {
for (const source of pokemon.side.foe.active) {
if (!source || source.fainted) continue;
for (const source of pokemon.foes()) {
const species = (source.illusion || source).species;
if (!species.abilities) continue;
for (const abilitySlot in species.abilities) {
Expand Down
Loading

0 comments on commit d18c0a4

Please sign in to comment.