Skip to content

Commit

Permalink
Fix "Fix terrain seed activation timing (#5163)"
Browse files Browse the repository at this point in the history
Shouldn't of reverted this so quickly. Credit to the code goes to @MacChaeger
  • Loading branch information
HoeenCoder committed Feb 17, 2019
1 parent f8a1612 commit 9c9004c
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 15 deletions.
36 changes: 28 additions & 8 deletions data/items.js
Original file line number Diff line number Diff line change
Expand Up @@ -1504,11 +1504,16 @@ let BattleItems = {
fling: {
basePower: 10,
},
onUpdate(pokemon) {
if (this.isTerrain('electricterrain') && pokemon.useItem()) {
onStart(pokemon) {
if (!pokemon.ignoringItem() && this.isTerrain('electricterrain') && pokemon.useItem()) {
this.boost({def: 1});
}
},
onAnyTerrainStart() {
if (this.isTerrain('electricterrain') && this.effectData.target.useItem()) {
this.boost({def: 1}, this.effectData.target);

This comment has been minimized.

Copy link
@Zarel

Zarel Feb 17, 2019

Member

@MacChaeger

Yours just had this.boost({def: 1}), which boosts the Pokémon that starts Electric Terrain (i.e. Tapu Koko), rather than the item holder.

}
},
num: 881,
gen: 7,
desc: "If the terrain is Electric Terrain, raises holder's Defense by 1 stage. Single use.",
Expand Down Expand Up @@ -2165,11 +2170,16 @@ let BattleItems = {
fling: {
basePower: 10,
},
onUpdate(pokemon) {
if (this.isTerrain('grassyterrain') && pokemon.useItem()) {
onStart(pokemon) {
if (!pokemon.ignoringItem() && this.isTerrain('grassyterrain') && pokemon.useItem()) {
this.boost({def: 1});
}
},
onAnyTerrainStart() {
if (this.isTerrain('grassyterrain') && this.effectData.target.useItem()) {
this.boost({def: 1}, this.effectData.target);
}
},
num: 884,
gen: 7,
desc: "If the terrain is Grassy Terrain, raises holder's Defense by 1 stage. Single use.",
Expand Down Expand Up @@ -3609,11 +3619,16 @@ let BattleItems = {
fling: {
basePower: 10,
},
onUpdate(pokemon) {
if (this.isTerrain('mistyterrain') && pokemon.useItem()) {
onStart(pokemon) {
if (!pokemon.ignoringItem() && this.isTerrain('mistyterrain') && pokemon.useItem()) {
this.boost({spd: 1});
}
},
onAnyTerrainStart() {
if (this.isTerrain('mistyterrain') && this.effectData.target.useItem()) {
this.boost({spd: 1}, this.effectData.target);
}
},
num: 883,
gen: 7,
desc: "If the terrain is Misty Terrain, raises holder's Sp. Def by 1 stage. Single use.",
Expand Down Expand Up @@ -4411,11 +4426,16 @@ let BattleItems = {
fling: {
basePower: 10,
},
onUpdate(pokemon) {
if (this.isTerrain('psychicterrain') && pokemon.useItem()) {
onStart(pokemon) {
if (!pokemon.ignoringItem() && this.isTerrain('psychicterrain') && pokemon.useItem()) {
this.boost({spd: 1});
}
},
onAnyTerrainStart() {
if (this.isTerrain('psychicterrain') && this.effectData.target.useItem()) {
this.boost({spd: 1}, this.effectData.target);
}
},
num: 882,
gen: 7,
desc: "If the terrain is Psychic Terrain, raises holder's Sp. Def by 1 stage. Single use.",
Expand Down
1 change: 1 addition & 0 deletions data/mods/ssb/scripts.js
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,7 @@ let BattleScripts = {
}
// Always run a terrain end event to prevent a visual glitch with custom terrains
if (prevTerrain) this.singleEvent('End', this.getEffect(prevTerrain), prevTerrainData, this);
this.runEvent('TerrainStart', source, source, status);
return true;
},
pokemon: {
Expand Down
1 change: 1 addition & 0 deletions dev-tools/globals.ts
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,7 @@ interface EventMethods {
onAnyDamage?: (this: Battle, damage: number, target: Pokemon, source: Pokemon, effect: Effect) => void
onAnyBasePower?: (this: Battle, basePower: number, source: Pokemon, target: Pokemon, move: ActiveMove) => void
onAnySetWeather?: (this: Battle, target: Pokemon, source: Pokemon, weather: PureEffect) => void
onAnyTerrainStart?: (this: Battle) => void
onAnyModifyDamage?: (this: Battle, damage: number, source: Pokemon, target: Pokemon, move: ActiveMove) => void
onAnyRedirectTarget?: (this: Battle, target: Pokemon, source: Pokemon, source2: Pokemon, move: ActiveMove) => void
onAnyAccuracy?: (this: Battle, accuracy: number, target: Pokemon, source: Pokemon, move: ActiveMove) => void
Expand Down
1 change: 1 addition & 0 deletions sim/battle.js
Original file line number Diff line number Diff line change
Expand Up @@ -321,6 +321,7 @@ class Battle extends Dex.ModdedDex {
this.terrainData = prevTerrainData;
return false;
}
this.runEvent('TerrainStart', source, source, status);
return true;
}

Expand Down
24 changes: 17 additions & 7 deletions test/simulator/items/seeds.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,24 @@ describe('Seeds', function () {
});

it('should activate even in a double-switch-in', function () {
battle = common.createBattle();
const p1 = battle.join('p1', 'Guest 1', 1, [
{species: 'tapukoko', ability: 'electricsurge', item: 'grassyseed', moves: ['protect']},
battle = common.createBattle([
[{species: 'Tapu Koko', ability: 'electricsurge', item: 'grassyseed', moves: ['protect']}],
[{species: 'Tapu Bulu', ability: 'grassysurge', item: 'electricseed', moves: ['protect']}],
]);
const p2 = battle.join('p2', 'Guest 2', 1, [
{species: 'tapubulu', ability: 'grassysurge', item: 'electricseed', moves: ['protect']},
assert.false(battle.p1.active[0].item);
assert.false(battle.p2.active[0].item);
});

it('should not activate when Magic Room ends', function () {
battle = common.createBattle([
[
{species: 'Tapu Koko', ability: 'electricsurge', item: 'terrainextender', moves: ['protect']},
{species: 'Hawlucha', ability: 'unburden', item: 'electricseed', moves: ['protect']},
],
[{species: 'Alakazam', ability: 'magicguard', moves: ['magicroom']}],
]);
assert.false(p1.active[0].item);
assert.false(p2.active[0].item);
battle.makeChoices('move protect', 'move magicroom');
battle.makeChoices('switch 2', 'move magicroom');
assert.strictEqual(battle.p1.active[0].item, 'electricseed');
});
});

1 comment on commit 9c9004c

@pyuk-bot
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What was the problem

Please sign in to comment.