From 6607d1c53b8265d9b9b348e2bc7ef1210a1cf936 Mon Sep 17 00:00:00 2001 From: Ivo Julca Date: Fri, 30 Jan 2015 20:54:34 -0500 Subject: [PATCH] =?UTF-8?q?Pok=C3=A9mon=20cannot=20megaevolve=20to=20thems?= =?UTF-8?q?elves=20-=20Rename=20randbats=20helper=20function=20`canMegaEvo?= =?UTF-8?q?`=20to=20`hasMegaEvo`.=20-=20Move=20duplicate=20mega=20evolutio?= =?UTF-8?q?n=20possibility=20checks=20from=20`runMegaEvo`=20and=20BattlePo?= =?UTF-8?q?kemon=20constructor=20to=20`canMegaEvo`=20battle=20script.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- battle-engine.js | 9 ++++----- data/moves.js | 11 +++++++---- data/scripts.js | 45 ++++++++++++++++++++------------------------- 3 files changed, 31 insertions(+), 34 deletions(-) diff --git a/battle-engine.js b/battle-engine.js index 679ac680e6..e3f85edb0a 100644 --- a/battle-engine.js +++ b/battle-engine.js @@ -202,9 +202,6 @@ BattlePokemon = (function () { this.baseAbility = toId(set.ability); this.ability = this.baseAbility; this.item = toId(set.item); - var forme; - if (this.baseTemplate.otherFormes) forme = this.battle.getTemplate(this.baseTemplate.otherFormes[0]); - this.canMegaEvo = ((this.battle.getItem(this.item).megaEvolves === this.baseTemplate.baseSpecies) || (forme && forme.isMega && forme.requiredMove && this.set.moves.indexOf(toId(forme.requiredMove)) > -1)); this.abilityData = {id: this.ability}; this.itemData = {id: this.item}; this.speciesData = {id: this.speciesid}; @@ -243,6 +240,8 @@ BattlePokemon = (function () { } } + this.canMegaEvo = this.battle.canMegaEvo(this); + if (!this.set.evs) { this.set.evs = {hp: 84, atk: 84, def: 84, spa: 84, spd: 84, spe: 84}; } @@ -1333,7 +1332,7 @@ BattleSide = (function () { baseAbility: pokemon.baseAbility, item: pokemon.item, pokeball: pokemon.pokeball, - canMegaEvo: pokemon.canMegaEvo + canMegaEvo: !!pokemon.canMegaEvo }); } return data; @@ -3355,7 +3354,7 @@ Battle = (function () { this.runMove(decision.move, decision.pokemon, this.getTarget(decision), decision.sourceEffect); break; case 'megaEvo': - if (this.runMegaEvo) this.runMegaEvo(decision.pokemon); + if (decision.pokemon.canMegaEvo) this.runMegaEvo(decision.pokemon); break; case 'beforeTurnMove': if (!decision.pokemon.isActive) return false; diff --git a/data/moves.js b/data/moves.js index 90a75b3f06..efeff58acf 100644 --- a/data/moves.js +++ b/data/moves.js @@ -10673,11 +10673,14 @@ exports.BattleMovedex = { this.cancelMove(sources[i]); // Run through each decision in queue to check if the Pursuit user is supposed to mega evolve this turn. // If it is, then mega evolve before moving. - var willMegaEvo = false; - for (var j = 0; j < this.queue.length; j++) { - if (this.queue[j].pokemon === sources[i] && this.queue[j].choice === 'megaEvo') willMegaEvo = true; + if (sources[i].canMegaEvo) { + for (var j = 0; j < this.queue.length; j++) { + if (this.queue[j].pokemon === sources[i] && this.queue[j].choice === 'megaEvo') { + this.runMegaEvo(sources[i]); + break; + } + } } - if (willMegaEvo) this.runMegaEvo(sources[i]); this.runMove('pursuit', sources[i], pokemon); } } diff --git a/data/scripts.js b/data/scripts.js index d83b7c1b4a..7f5bcb8ae7 100644 --- a/data/scripts.js +++ b/data/scripts.js @@ -532,25 +532,19 @@ exports.BattleScripts = { return damage; }, + canMegaEvo: function (pokemon) { + var altForme = pokemon.baseTemplate.otherFormes && this.getTemplate(pokemon.baseTemplate.otherFormes[0]); + if (altForme && altForme.isMega && altForme.requiredMove && pokemon.moves.indexOf(toId(altForme.requiredMove)) > -1) return altForme.species; + var item = pokemon.getItem(); + if (item.megaEvolves !== pokemon.baseTemplate.baseSpecies || item.megaStone === pokemon.species) return false; + return item.megaStone; + }, + runMegaEvo: function (pokemon) { - if (!pokemon.canMegaEvo) return false; - - var otherForme; - var template; - var item; - if (pokemon.baseTemplate.otherFormes) otherForme = this.getTemplate(pokemon.baseTemplate.otherFormes[0]); - if (otherForme && otherForme.isMega && otherForme.requiredMove) { - if (pokemon.moves.indexOf(toId(otherForme.requiredMove)) < 0) return false; - template = otherForme; - } else { - item = this.getItem(pokemon.item); - if (!item.megaStone) return false; - template = this.getTemplate(item.megaStone); - if (pokemon.baseTemplate.baseSpecies !== template.baseSpecies) return false; - } - if (!template.isMega) return false; - + var template = this.getTemplate(pokemon.canMegaEvo); var side = pokemon.side; + + // Pokémon affected by Sky Drop cannot mega evolve. Enforce it here for now. var foeActive = side.foe.active; for (var i = 0; i < foeActive.length; i++) { if (foeActive[i].volatiles['skydrop'] && foeActive[i].volatiles['skydrop'].source === pokemon) { @@ -558,17 +552,18 @@ exports.BattleScripts = { } } - // okay, mega evolution is possible pokemon.formeChange(template); - pokemon.baseTemplate = template; // mega evolution is permanent :o + pokemon.baseTemplate = template; // mega evolution is permanent pokemon.details = template.species + (pokemon.level === 100 ? '' : ', L' + pokemon.level) + (pokemon.gender === '' ? '' : ', ' + pokemon.gender) + (pokemon.set.shiny ? ', shiny' : ''); this.add('detailschange', pokemon, pokemon.details); - this.add('-mega', pokemon, template.baseSpecies, item); - var oldAbility = pokemon.ability; + this.add('-mega', pokemon, template.baseSpecies, template.requiredItem); pokemon.setAbility(template.abilities['0']); pokemon.baseAbility = pokemon.ability; - for (var i = 0; i < side.pokemon.length; i++) side.pokemon[i].canMegaEvo = false; + // Limit one mega evolution + for (var i = 0; i < side.pokemon.length; i++) { + side.pokemon[i].canMegaEvo = false; + } return true; }, @@ -594,7 +589,7 @@ exports.BattleScripts = { if (!isValid) selectedAbilities.push(selectedAbility); return isValid; }, - canMegaEvo: function (template) { + hasMegaEvo: function (template) { if (template.otherFormes) { var forme = this.getTemplate(template.otherFormes[0]); if (forme.requiredItem) { @@ -900,7 +895,7 @@ exports.BattleScripts = { } // Decide if the Pokemon can mega evolve early, so viable moves for the mega can be generated - if (!noMega && this.canMegaEvo(template)) { + if (!noMega && this.hasMegaEvo(template)) { // If there's more than one mega evolution, randomly pick one template = this.getTemplate(template.otherFormes[(template.otherFormes[1]) ? Math.round(Math.random()) : 0]); } @@ -1984,7 +1979,7 @@ exports.BattleScripts = { } // Decide if the Pokemon can mega evolve early, so viable moves for the mega can be generated - if (!noMega && this.canMegaEvo(template)) { + if (!noMega && this.hasMegaEvo(template)) { // If there's more than one mega evolution, randomly pick one template = this.getTemplate(template.otherFormes[(template.otherFormes[1]) ? Math.round(Math.random()) : 0]); }