From 8bbd449dd203a65df2a128ffaeecaa243256e2e9 Mon Sep 17 00:00:00 2001 From: Spandan Date: Sun, 22 Jan 2017 15:33:30 +0530 Subject: [PATCH] movesearch: Add support for Z-status effects (#3105) --- chat-plugins/datasearch.js | 66 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 66 insertions(+) diff --git a/chat-plugins/datasearch.js b/chat-plugins/datasearch.js index 0f32872627..e00a1307e8 100644 --- a/chat-plugins/datasearch.js +++ b/chat-plugins/datasearch.js @@ -425,6 +425,24 @@ function runDexsearch(target, cmd, canAll, message) { break; } + if (target === 'zrecovery') { + if (parameters.length > 1) return {reply: "The parameter 'zrecovery' cannot have alternative parameters"}; + let recoveryMoves = ["aromatherapy", "bellydrum", "conversion2", "haze", "healbell", "mist", "psychup", "refresh", "spite", "stockpile", "teleport", "transform"]; + for (let k = 0; k < recoveryMoves.length; k++) { + let invalid = validParameter("moves", recoveryMoves[k], isNotSearch, target); + if (invalid) return {reply: invalid}; + if (isNotSearch) { + let bufferObj = {moves: {}}; + bufferObj.moves[recoveryMoves[k]] = false; + searches.push(bufferObj); + } else { + orGroup.moves[recoveryMoves[k]] = true; + } + } + if (isNotSearch) orGroup.skip = true; + break; + } + if (target === 'priority') { if (parameters.length > 1) return {reply: "The parameter 'priority' cannot have alternative parameters"}; for (let move in Tools.data.Movedex) { @@ -743,6 +761,15 @@ function runMovesearch(target, cmd, canAll, message) { continue; } + if (target === 'zrecovery') { + if (!searches['zrecovery']) { + searches['zrecovery'] = !isNotSearch; + } else if ((searches['zrecovery'] && isNotSearch) || (searches['zrecovery'] === false && !isNotSearch)) { + return {reply: 'A search cannot both exclude and include z-recovery moves.'}; + } + continue; + } + let template = Tools.getTemplate(target); if (template.exists) { if (Object.keys(lsetData).length) return {reply: "A search can only include one Pok\u00e9mon learnset."}; @@ -847,6 +874,26 @@ function runMovesearch(target, cmd, canAll, message) { continue; } + if (target.substr(0, 8) === 'zboosts ') { + switch (target.substr(8)) { + case 'attack': target = 'atk'; break; + case 'defense': target = 'def'; break; + case 'specialattack': target = 'spa'; break; + case 'spatk': target = 'spa'; break; + case 'specialdefense': target = 'spd'; break; + case 'spdef': target = 'spd'; break; + case 'speed': target = 'spe'; break; + case 'acc': target = 'accuracy'; break; + case 'evasiveness': target = 'evasion'; break; + default: target = target.substr(8); + } + if (!(target in allBoosts)) return {reply: "'" + escapeHTML(target.substr(8)) + "' is not a recognized stat."}; + if (!searches['boost']) searches['boost'] = {}; + if ((searches['boost'][target] && isNotSearch) || (searches['boost'][target] === false && !isNotSearch)) return {reply: 'A search cannot both exclude and include a stat boost.'}; + searches['boost'][target] = !isNotSearch; + continue; + } + let oldTarget = target; if (target.charAt(target.length - 1) === 's') target = target.substr(0, target.length - 1); switch (target) { @@ -930,6 +977,13 @@ function runMovesearch(target, cmd, canAll, message) { } break; + case 'zrecovery': + for (let move in dex) { + let hasRecovery = (dex[move].zMoveEffect === 'heal'); + if ((!hasRecovery && searches[search]) || (hasRecovery && !searches[search])) delete dex[move]; + } + break; + case 'property': for (let prop in searches[search]) { for (let move in dex) { @@ -972,6 +1026,18 @@ function runMovesearch(target, cmd, canAll, message) { } break; + case 'zboost': + for (let boost in searches[search]) { + for (let move in dex) { + if (dex[move].zMoveBoost) { + if ((dex[move].zMoveBoost[boost] > 0 && searches[search][boost]) || + (dex[move].zMoveBoost[boost] < 1 && !searches[search][boost])) continue; + } + delete dex[move]; + } + } + break; + case 'status': case 'volatileStatus': for (let searchStatus in searches[search]) {