diff --git a/battle-engine.js b/battle-engine.js index 64a5439f67..960a499757 100644 --- a/battle-engine.js +++ b/battle-engine.js @@ -1119,7 +1119,10 @@ BattlePokemon = (function () { BattlePokemon.prototype.setItem = function (item, source, effect) { if (!this.hp || !this.isActive) return false; item = this.battle.getItem(item); - if (item.id === 'leppaberry') this.isStale = 2; + if (item.id === 'leppaberry') { + this.isStale = 2; + this.isStaleSource = 'getleppa'; + } this.lastItem = this.item; this.item = item.id; this.itemData = {id: item.id, target: this}; @@ -2838,6 +2841,7 @@ Battle = (function () { for (var i = 0; i < side.foe.active.length; i++) { if (side.foe.active[i].isStale >= 2) { oldActive.isStaleCon++; + oldActive.isStaleSource = 'drag'; break; } } @@ -2912,19 +2916,43 @@ Battle = (function () { if (pokemon.fainted) continue; if (pokemon.isStale < 2) { if (pokemon.isStaleCon >= 2) { - if (pokemon.hp >= pokemon.isStaleHP - pokemon.maxhp / 100) pokemon.isStale++; + if (pokemon.hp >= pokemon.isStaleHP - pokemon.maxhp / 100) { + pokemon.isStale++; + if (this.firstStaleWarned && pokemon.isStale < 2) { + switch (pokemon.isStaleSource) { + case 'struggle': + this.add('html', '
' + this.escapeHTML(pokemon.name) + ' isn\'t losing HP from Struggle. If this continues, it will be classified as being in an endless loop.
'); + break; + case 'drag': + this.add('html', '
' + this.escapeHTML(pokemon.name) + ' isn\'t losing PP or HP from being forced to switch. If this continues, it will be classified as being in an endless loop.
'); + break; + case 'switch': + this.add('html', '
' + this.escapeHTML(pokemon.name) + ' isn\'t losing PP or HP from repeatedly switching. If this continues, it will be classified as being in an endless loop.
'); + break; + } + } + } pokemon.isStaleCon = 0; pokemon.isStalePPTurns = 0; pokemon.isStaleHP = pokemon.hp; } if (pokemon.isStalePPTurns >= 5) { - if (pokemon.hp >= pokemon.isStaleHP - pokemon.maxhp / 100) pokemon.isStale++; + if (pokemon.hp >= pokemon.isStaleHP - pokemon.maxhp / 100) { + pokemon.isStale++; + pokemon.isStaleSource = 'ppstall'; + if (this.firstStaleWarned && pokemon.isStale < 2) { + this.add('html', '
' + this.escapeHTML(pokemon.name) + ' isn\'t losing PP or HP. If it keeps on not losing PP or HP, it will be classified as being in an endless loop.
'); + } + } pokemon.isStaleCon = 0; pokemon.isStalePPTurns = 0; pokemon.isStaleHP = pokemon.hp; } } - pokemon.isStaleCon += (pokemon.getMoves().length === 0 ? 1 : 0); + if (pokemon.getMoves().length === 0) { + pokemon.isStaleCon++; + pokemon.isStaleSource = 'struggle'; + } if (pokemon.isStale < 2) { allStale = false; } else if (pokemon.isStale && !pokemon.staleWarned) { @@ -2942,15 +2970,45 @@ Battle = (function () { this.sides[i].faintedLastTurn = this.sides[i].faintedThisTurn; this.sides[i].faintedThisTurn = false; } - this.add('turn', this.turn); var banlistTable = this.getFormat().banlistTable; if (banlistTable && 'Rule:endlessbattleclause' in banlistTable) { + if (oneStale) { + var activationWarning = '
If all active Pokémon go in an endless loop, Endless Battle Clause will activate.'; + if (allStale) activationWarning = ''; + var loopReason = ''; + switch (oneStale.isStaleSource) { + case 'struggle': + loopReason = ": it isn't losing HP from Struggle"; + break; + case 'drag': + loopReason = ": it isn't losing PP or HP from being forced to switch"; + break; + case 'switch': + loopReason = ": it isn't losing PP or HP from repeatedly switching"; + break; + case 'getleppa': + loopReason = ": it got a Leppa Berry it didn't start with"; + break; + case 'useleppa': + loopReason = ": it used a Leppa Berry it didn't start with"; + break; + case 'ppstall': + loopReason = ": it isn't losing PP or HP"; + break; + case 'ppoverflow': + loopReason = ": its PP overflowed"; + break; + } + this.add('html', '
' + this.escapeHTML(oneStale.name) + ' is in an endless loop' + loopReason + '.' + activationWarning + '
'); + oneStale.staleWarned = true; + this.firstStaleWarned = true; + } if (allStale) { this.add('message', "All active Pok\u00e9mon are in an endless loop. Endless Battle Clause activated!"); var leppaPokemon = null; for (var i = 0; i < this.sides.length; i++) { - for (var j = 0; j < this.sides[i].active.length; j++) { - var pokemon = this.sides[i].active[j]; + for (var j = 0; j < this.sides[i].pokemon.length; j++) { + var pokemon = this.sides[i].pokemon[j]; if (toId(pokemon.set.item) === 'leppaberry') { if (leppaPokemon) { leppaPokemon = null; // both sides have Leppa @@ -2969,9 +3027,6 @@ Battle = (function () { } this.win(); return; - } else if (oneStale) { - this.add('html', '
' + this.escapeHTML(oneStale.name) + ' is in an endless loop. If all active Pokémon go in an endless loop, Endless Battle Clause will activate.
'); - oneStale.staleWarned = true; } } else { if (allStale && !this.staleWarned) { @@ -2983,6 +3038,8 @@ Battle = (function () { } } + this.add('turn', this.turn); + if (this.gameType === 'triples' && this.sides.map('pokemonLeft').count(1) === this.sides.length) { // If both sides have one Pokemon left in triples and they are not adjacent, they are both moved to the center. var center = false; @@ -3874,6 +3931,7 @@ Battle = (function () { for (var i = 0; i < foeActive.length; i++) { if (foeActive[i].isStale >= 2) { decision.pokemon.isStaleCon++; + decision.pokemon.isStaleSource = 'switch'; break; } } @@ -3899,6 +3957,7 @@ Battle = (function () { for (var i = 0; i < foeActive.length; i++) { if (foeActive[i].isStale >= 2) { decision.pokemon.isStaleCon++; + decision.pokemon.isStaleSource = 'switch'; break; } } diff --git a/data/items.js b/data/items.js index 44a2d6451b..d671e82f7d 100644 --- a/data/items.js +++ b/data/items.js @@ -2327,7 +2327,10 @@ exports.BattleItems = { move.pp += 10; if (move.pp > move.maxpp) move.pp = move.maxpp; this.add('-activate', pokemon, 'item: Leppa Berry', move.move); - if (pokemon.item === 'leppaberry') pokemon.isStale = 2; + if (pokemon.item === 'leppaberry') { + pokemon.isStale = 2; + pokemon.isStaleSource = 'useleppa'; + } }, num: 154, gen: 3, diff --git a/mods/gen1/scripts.js b/mods/gen1/scripts.js index 3e642ef91b..83eb5845e9 100644 --- a/mods/gen1/scripts.js +++ b/mods/gen1/scripts.js @@ -142,6 +142,8 @@ exports.BattleScripts = { if (usedMovePos > -1 && pokemon.moveset[usedMovePos].pp === 0) { // If we were on the middle of the 0 PP sequence, the PPs get reset to 63. pokemon.moveset[usedMovePos].pp = 63; + pokemon.isStale = 2; + pokemon.isStaleSource = 'ppoverflow'; } } }