From 24571ea603cbd48a2c960ee4e312315bc759d73f Mon Sep 17 00:00:00 2001 From: Guangcong Luo Date: Sun, 28 Oct 2018 04:48:35 -0500 Subject: [PATCH] Fix misc errors found by LGTM --- .eslintrc | 2 +- chat-commands.js | 13 ++- chat-plugins/mafia.js | 6 +- chat-plugins/roomsettings.js | 2 +- chat-plugins/scavengers.js | 2 +- chat-plugins/trivia.js | 2 +- chat.js | 3 +- data/random-teams.js | 6 +- data/scripts.js | 3 +- mods/gen1/random-teams.js | 1 - mods/gen2/scripts.js | 3 +- mods/gen3/random-teams.js | 4 +- mods/gen3/scripts.js | 3 +- mods/gen4/random-teams.js | 1 - mods/gen4/scripts.js | 3 +- mods/gennext/moves.js | 2 +- mods/stadium/scripts.js | 2 +- sim/battle-stream-example.js | 5 +- sim/battle.js | 1 - sim/dex-data.js | 152 +++++++++++++++++------------------ sim/index.js | 3 +- sockets.js | 7 +- 22 files changed, 114 insertions(+), 112 deletions(-) diff --git a/.eslintrc b/.eslintrc index af9c5c587..e9cf44966 100644 --- a/.eslintrc +++ b/.eslintrc @@ -69,7 +69,7 @@ "no-sequences": "error", "no-throw-literal": "error", "no-unmodified-loop-condition": "error", - "no-unused-expressions": "error", + "no-unused-expressions": "off", "no-useless-call": "error", "no-useless-concat": "off", "no-void": "off", diff --git a/chat-commands.js b/chat-commands.js index 0635c881a..cf21e0bd4 100644 --- a/chat-commands.js +++ b/chat-commands.js @@ -26,6 +26,9 @@ const HOURMUTE_LENGTH = 60 * 60 * 1000; const MAX_CHATROOM_ID_LENGTH = 225; +/** Require reasons */ +const REQUIRE_REASONS = true; + /** @type {ChatCommands} */ const commands = { @@ -1703,7 +1706,7 @@ const commands = { if (!target) { return this.privateModAction(`(${targetUser.name} would be muted by ${user.name} ${problem}.)`); } - return this.addModAction(`${targetUser.name} would be muted by ${user.name} ${problem}.${(target ? ` (${target})` : ``)}`); + return this.addModAction(`${targetUser.name} would be muted by ${user.name} ${problem}. (${target})`); } if (targetUser in room.users) targetUser.popup(`|modal|${user.name} has muted you in ${room.id} for ${Chat.toDurationString(muteDuration)}. ${target}`); @@ -1977,7 +1980,7 @@ const commands = { if (target.length > MAX_REASON_LENGTH) { return this.errorReply(`The reason is too long. It cannot exceed ${MAX_REASON_LENGTH} characters.`); } - if (!target) { + if (!target && REQUIRE_REASONS) { return this.errorReply("Global bans require a reason."); } if (!this.can('ban', targetUser)) return false; @@ -2577,7 +2580,7 @@ const commands = { return this.errorReply(`This user is already blacklisted from this room.`); } - if (!target) { + if (!target && REQUIRE_REASONS) { return this.errorReply(`Blacklists require a reason.`); } if (target.length > MAX_REASON_LENGTH) { @@ -2697,7 +2700,9 @@ const commands = { } let [targetStr, reason] = target.split('|').map(val => val.trim()); - if (!(targetStr && reason)) return this.errorReply("Usage: /blacklistname name1, name2, ... | reason"); + if (!targetStr || (!reason && REQUIRE_REASONS)) { + return this.errorReply("Usage: /blacklistname name1, name2, ... | reason"); + } let targets = targetStr.split(',').map(s => toId(s)); diff --git a/chat-plugins/mafia.js b/chat-plugins/mafia.js index eb7dcf588..f497d84dc 100644 --- a/chat-plugins/mafia.js +++ b/chat-plugins/mafia.js @@ -2304,7 +2304,7 @@ const commands = { if (isNaN(num)) { if ((game.hostid === user.userid || game.cohosts.includes(user.userid)) && this.cmdToken === "!") { const broadcastMessage = this.message.toLowerCase().replace(/[^a-z0-9\s!,]/g, ''); - if (room && room.lastBroadcast === broadcastMessage && + if (room.lastBroadcast === broadcastMessage && room.lastBroadcastTime >= Date.now() - 20 * 1000) { return this.errorReply("You can't broadcast this because it was just broadcasted."); } @@ -2444,7 +2444,7 @@ const commands = { if (!game.started) return this.errorReply(`The game of mafia has not started yet.`); if ((game.hostid === user.userid || game.cohosts.includes(user.userid)) && this.cmdToken === "!") { const broadcastMessage = this.message.toLowerCase().replace(/[^a-z0-9\s!,]/g, ''); - if (room && room.lastBroadcast === broadcastMessage && + if (room.lastBroadcast === broadcastMessage && room.lastBroadcastTime >= Date.now() - 20 * 1000) { return this.errorReply("You can't broadcast this because it was just broadcasted."); } @@ -2465,7 +2465,7 @@ const commands = { const game = /** @type {MafiaTracker} */ (room.game); if ((game.hostid === user.userid || game.cohosts.includes(user.userid)) && this.cmdToken === "!") { const broadcastMessage = this.message.toLowerCase().replace(/[^a-z0-9\s!,]/g, ''); - if (room && room.lastBroadcast === broadcastMessage && + if (room.lastBroadcast === broadcastMessage && room.lastBroadcastTime >= Date.now() - 20 * 1000) { return this.errorReply("You can't broadcast this because it was just broadcasted."); } diff --git a/chat-plugins/roomsettings.js b/chat-plugins/roomsettings.js index e7d12e6d2..0c55a438b 100644 --- a/chat-plugins/roomsettings.js +++ b/chat-plugins/roomsettings.js @@ -547,7 +547,7 @@ exports.commands = { if (!user.can('makeroom')) return this.errorReply("Regex banwords are only allowed for leaders or above."); try { - let test = new RegExp(word); // eslint-disable-line no-unused-vars + new RegExp(word); // eslint-disable-line no-new } catch (e) { return this.errorReply(e.message.startsWith('Invalid regular expression: ') ? e.message : `Invalid regular expression: /${word}/: ${e.message}`); } diff --git a/chat-plugins/scavengers.js b/chat-plugins/scavengers.js index 3e062a5a7..fe264f73b 100644 --- a/chat-plugins/scavengers.js +++ b/chat-plugins/scavengers.js @@ -864,7 +864,7 @@ let commands = { room.game = new ScavengerHunt(room, user, hosts, gameType, params.result); } this.privateModAction(`(A new scavenger hunt was created by ${user.name}.)`); - this.modlog('SCAV NEW', null, `${gameType ? gameType.toUpperCase() : ''}: creators - ${hosts.map(h => h.userid)}`); + this.modlog('SCAV NEW', null, `${gameType.toUpperCase()}: creators - ${hosts.map(h => h.userid)}`); }, status: function (target, room, user) { diff --git a/chat-plugins/trivia.js b/chat-plugins/trivia.js index 54f68a841..ab8f83d9d 100644 --- a/chat-plugins/trivia.js +++ b/chat-plugins/trivia.js @@ -1710,7 +1710,7 @@ const commands = { name = Chat.escapeHTML(user.name); userid = user.userid; } else { - target = this.splitTarget(target, true); + this.splitTarget(target, true); name = Chat.escapeHTML(this.targetUsername); userid = toId(name); } diff --git a/chat.js b/chat.js index 14e81a5bb..a42a009e3 100644 --- a/chat.js +++ b/chat.js @@ -1663,10 +1663,9 @@ Chat.getImageDimensions = function (url) { Chat.fitImage = async function (url, maxHeight = 300, maxWidth = 300) { let {height, width} = await Chat.getImageDimensions(url); - let ratio = 1; - if (width <= maxWidth && height <= maxHeight) return [width, height]; + let ratio; if (height * (maxWidth / maxHeight) > width) { ratio = maxHeight / height; } else { diff --git a/data/random-teams.js b/data/random-teams.js index 2d78d40a3..862ef756b 100644 --- a/data/random-teams.js +++ b/data/random-teams.js @@ -1556,9 +1556,10 @@ class RandomTeams extends Dex.ModdedDex { item = 'Black Sludge'; } - let level = 75; + let level; if (!isDoubles) { + /** @type {{[tier: string]: number}} */ let levelScale = { LC: 88, 'LC Uber': 86, @@ -1575,6 +1576,7 @@ class RandomTeams extends Dex.ModdedDex { Uber: 73, AG: 71, }; + /** @type {{[species: string]: number}} */ let customScale = { // Banned Abilities Dugtrio: 77, Gothitelle: 77, Pelipper: 79, Politoed: 79, Wobbuffet: 77, @@ -1589,9 +1591,7 @@ class RandomTeams extends Dex.ModdedDex { if (tier.charAt(0) === '(') { tier = tier.slice(1, -1); } - // @ts-ignore level = levelScale[tier] || 75; - // @ts-ignore if (customScale[template.name]) level = customScale[template.name]; // Custom level based on moveset diff --git a/data/scripts.js b/data/scripts.js index 19e05ff00..a9bc97603 100644 --- a/data/scripts.js +++ b/data/scripts.js @@ -299,9 +299,8 @@ let BattleScripts = { tryMoveHit(target, pokemon, move) { this.setActiveMove(move, pokemon, target); move.zBrokeProtect = false; - let hitResult = true; - hitResult = this.singleEvent('PrepareHit', move, {}, target, pokemon, move); + let hitResult = this.singleEvent('PrepareHit', move, {}, target, pokemon, move); if (!hitResult) { if (hitResult === false) this.add('-fail', target); return false; diff --git a/mods/gen1/random-teams.js b/mods/gen1/random-teams.js index 861497b42..366f22edc 100644 --- a/mods/gen1/random-teams.js +++ b/mods/gen1/random-teams.js @@ -242,7 +242,6 @@ class RandomGen1Teams extends RandomGen2Teams { * @return {RandomTeamsTypes["RandomSet"]} */ randomSet(template, slot) { - if (slot === undefined) slot = 1; template = this.getTemplate(template); if (!template.exists) template = this.getTemplate('pikachu'); // Because Gen 1. diff --git a/mods/gen2/scripts.js b/mods/gen2/scripts.js index f6c7cde5e..c58f91f1a 100644 --- a/mods/gen2/scripts.js +++ b/mods/gen2/scripts.js @@ -121,13 +121,12 @@ let BattleScripts = { let doSelfDestruct = true; /**@type {number | false} */ let damage = 0; - let hitResult = true; if (move.selfdestruct && doSelfDestruct) { this.faint(pokemon, pokemon, move); } - hitResult = this.singleEvent('PrepareHit', move, {}, target, pokemon, move); + let hitResult = this.singleEvent('PrepareHit', move, {}, target, pokemon, move); if (!hitResult) { if (hitResult === false) this.add('-fail', target); return false; diff --git a/mods/gen3/random-teams.js b/mods/gen3/random-teams.js index 1d8e1641e..1b6012931 100644 --- a/mods/gen3/random-teams.js +++ b/mods/gen3/random-teams.js @@ -363,9 +363,9 @@ class RandomGen3Teams extends RandomGen4Teams { } if (reqMove) { // reject a move - for (let move of moves) { + for (let [i, move] of moves.entries()) { if (move === 'weatherball' || this.getMove(move).type in hasType) continue; - move = reqMove; + moves[i] = reqMove; let reqMoveIndex = movePool.indexOf(reqMove); if (reqMoveIndex !== -1) this.fastPop(movePool, reqMoveIndex); break; diff --git a/mods/gen3/scripts.js b/mods/gen3/scripts.js index 0b5efad31..148c5e5a3 100644 --- a/mods/gen3/scripts.js +++ b/mods/gen3/scripts.js @@ -21,11 +21,10 @@ let BattleScripts = { }, tryMoveHit(target, pokemon, move) { this.setActiveMove(move, pokemon, target); - let hitResult = true; let naturalImmunity = false; let accPass = true; - hitResult = this.singleEvent('PrepareHit', move, {}, target, pokemon, move); + let hitResult = this.singleEvent('PrepareHit', move, {}, target, pokemon, move); if (!hitResult) { if (hitResult === false) this.add('-fail', target); return false; diff --git a/mods/gen4/random-teams.js b/mods/gen4/random-teams.js index 4e9a88959..03e6472e8 100644 --- a/mods/gen4/random-teams.js +++ b/mods/gen4/random-teams.js @@ -545,7 +545,6 @@ class RandomGen4Teams extends RandomGen5Teams { } } - item = 'Leftovers'; if (template.requiredItems) { item = this.sample(template.requiredItems); diff --git a/mods/gen4/scripts.js b/mods/gen4/scripts.js index c202f2d2d..316284f9d 100644 --- a/mods/gen4/scripts.js +++ b/mods/gen4/scripts.js @@ -91,9 +91,8 @@ let BattleScripts = { }, tryMoveHit(target, pokemon, move) { this.setActiveMove(move, pokemon, target); - let hitResult = true; - hitResult = this.singleEvent('PrepareHit', move, {}, target, pokemon, move); + let hitResult = this.singleEvent('PrepareHit', move, {}, target, pokemon, move); if (!hitResult) { if (hitResult === false) this.add('-fail', target); return false; diff --git a/mods/gennext/moves.js b/mods/gennext/moves.js index bec623d4a..59024aa24 100644 --- a/mods/gennext/moves.js +++ b/mods/gennext/moves.js @@ -654,7 +654,7 @@ let BattleMovedex = { onDamage: function (damage, target, source, effect) { if (!effect || effect.effectType !== 'Move') return; if (!source || source.side === target.side) return; - if (effect && effect.effectType === 'Move' && damage >= target.hp) { + if (effect.effectType === 'Move' && damage >= target.hp) { damage = target.hp - 1; } this.effectData.totalDamage += damage; diff --git a/mods/stadium/scripts.js b/mods/stadium/scripts.js index 7d9bf2cc8..748d36fc4 100644 --- a/mods/stadium/scripts.js +++ b/mods/stadium/scripts.js @@ -290,7 +290,7 @@ let BattleScripts = { hitResult = this.singleEvent('TryHit', moveData, {}, target, pokemon, move); // Partial trapping moves still apply their volatile to Pokémon behind a Sub - let targetHadSub = (target && target.volatiles['substitute']); + const targetHadSub = !!target.volatiles['substitute']; if (targetHadSub && moveData.volatileStatus && moveData.volatileStatus === 'partiallytrapped') { target.addVolatile(moveData.volatileStatus, pokemon, move); } diff --git a/sim/battle-stream-example.js b/sim/battle-stream-example.js index 1bf9def18..51989132e 100644 --- a/sim/battle-stream-example.js +++ b/sim/battle-stream-example.js @@ -96,11 +96,12 @@ const p2spec = { team: Dex.packTeam(Dex.generateTeam('gen7randombattle')), }; -// eslint-disable-next-line no-unused-vars const p1 = new RandomPlayerAI(streams.p1); -// eslint-disable-next-line no-unused-vars const p2 = new RandomPlayerAI(streams.p2); +console.log("p1 is " + p1.constructor.name); +console.log("p2 is " + p2.constructor.name); + (async () => { let chunk; while ((chunk = await streams.omniscient.read())) { diff --git a/sim/battle.js b/sim/battle.js index fe4d539d5..7967211c6 100644 --- a/sim/battle.js +++ b/sim/battle.js @@ -2700,7 +2700,6 @@ class Battle extends Dex.ModdedDex { */ prioritizeAction(action, source, sourceEffect) { if (this.event) { - if (!source) source = this.event.source; if (!sourceEffect) sourceEffect = this.effect; } for (const [i, curAction] of this.queue.entries()) { diff --git a/sim/dex-data.js b/sim/dex-data.js index 89975d102..12c9d48c5 100644 --- a/sim/dex-data.js +++ b/sim/dex-data.js @@ -142,28 +142,28 @@ class Effect { * Whether or not the effect is ignored by Baton Pass. * @type {boolean} */ - this.noCopy = this.noCopy; + this.noCopy = !!this.noCopy; /** * Whether or not the effect affects fainted Pokemon. * @type {boolean} */ - this.affectsFainted = this.affectsFainted; + this.affectsFainted = !!this.affectsFainted; /** * The status that the effect may cause. - * @type {string} + * @type {string | undefined} */ - this.status = this.status; + this.status = this.status || undefined; /** * The weather that the effect may cause. - * @type {string} + * @type {string | undefined} */ - this.weather = this.weather; + this.weather = this.weather || undefined; /** * HP that the effect may drain. * @type {number[] | undefined} */ - this.drain = this.drain; + this.drain = this.drain || undefined; /** * @type {AnyObject} @@ -299,7 +299,7 @@ class Format extends Effect { * random/fixed teams. null if players can bring teams. * @type {string | undefined} */ - this.team = this.team; + this.team; /** @type {'Format' | 'Ruleset' | 'Rule' | 'ValidatorRule'} */ // @ts-ignore this.effectType = Tools.getString(this.effectType) || 'Format'; @@ -307,12 +307,12 @@ class Format extends Effect { * Whether or not debug battle messages should be shown. * @type {boolean} */ - this.debug = this.debug; + this.debug = !!this.debug; /** * Whether or not a format is played for ladder points. * @type {boolean} */ - this.rated = this.rated; + this.rated = !!this.rated; /** * Game type. * @type {GameType} @@ -354,12 +354,12 @@ class Format extends Effect { * the number that can actually be used. * @type {{battle?: number, validate?: [number, number]} | undefined} */ - this.teamLength = this.teamLength; + this.teamLength = this.teamLength || undefined; /** * An optional function that runs at the start of a battle. - * @type {(this: Battle) => void} + * @type {(this: Battle) => void | undefined} */ - this.onBegin = this.onBegin; + this.onBegin = this.onBegin || undefined; /** * If no team is selected, this format can generate a random team @@ -399,7 +399,7 @@ class Format extends Effect { * instead. * @type {number | undefined} */ - this.forcedLevel = this.forcedLevel; + this.forcedLevel = this.forcedLevel || undefined; /** * Forces all pokemon above this level down to this level. This * will allow e.g. level 50 Hydreigon in Gen 5, which is not @@ -407,7 +407,7 @@ class Format extends Effect { * 64. * @type {number | undefined} */ - this.maxForcedLevel = this.maxForcedLevel; + this.maxForcedLevel = this.maxForcedLevel || undefined; /** @type {boolean} */ this.noLog = !!this.noLog; @@ -441,33 +441,33 @@ class Item extends Effect { * this item. * @type {FlingData | undefined} */ - this.fling = this.fling; + this.fling = this.fling || undefined; /** * If this is a Drive: The type it turns Techno Blast into. * undefined, if not a Drive. * @type {string | undefined} */ - this.onDrive = this.onDrive; + this.onDrive = this.onDrive || undefined; /** * If this is a Memory: The type it turns Multi-Attack into. * undefined, if not a Memory. * @type {string | undefined} */ - this.onMemory = this.onMemory; + this.onMemory = this.onMemory || undefined; /** * If this is a mega stone: The name (e.g. Charizard-Mega-X) of the * forme this allows transformation into. * undefined, if not a mega stone. * @type {string | undefined} */ - this.megaStone = this.megaStone; + this.megaStone = this.megaStone || undefined; /** * If this is a mega stone: The name (e.g. Charizard) of the * forme this allows transformation from. * undefined, if not a mega stone. * @type {string | undefined} */ - this.megaEvolves = this.megaEvolves; + this.megaEvolves = this.megaEvolves || undefined; /** * If this is a Z crystal: true if the Z Crystal is generic * (e.g. Firium Z). If species-specific, the name @@ -476,14 +476,14 @@ class Item extends Effect { * undefined, if not a Z crystal. * @type {true | string | undefined} */ - this.zMove = this.zMove; + this.zMove = this.zMove || undefined; /** * If this is a generic Z crystal: The type (e.g. Fire) of the * Z Move this crystal allows the use of (e.g. Fire) * undefined, if not a generic Z crystal * @type {string | undefined} */ - this.zMoveType = this.zMoveType; + this.zMoveType = this.zMoveType || undefined; /** * If this is a species-specific Z crystal: The name * (e.g. Play Rough) of the move this crystal requires its @@ -491,7 +491,7 @@ class Item extends Effect { * undefined, if not a species-specific Z crystal * @type {string | undefined} */ - this.zMoveFrom = this.zMoveFrom; + this.zMoveFrom = this.zMoveFrom || undefined; /** * If this is a species-specific Z crystal: An array of the * species of Pokemon that can use this crystal's Z move. @@ -499,7 +499,7 @@ class Item extends Effect { * undefined, if not a species-specific Z crystal * @type {string[] | undefined} */ - this.zMoveUser = this.zMoveUser; + this.zMoveUser = this.zMoveUser || undefined; /** * Is this item a Berry? * @type {boolean} @@ -510,19 +510,19 @@ class Item extends Effect { * Whether or not this item ignores the Klutz ability. * @type {boolean} */ - this.ignoreKlutz = this.ignoreKlutz; + this.ignoreKlutz = !!this.ignoreKlutz; /** * The type the holder will change into if it is an Arceus. - * @type {string} + * @type {string | undefined} */ - this.onPlate = this.onPlate; + this.onPlate = this.onPlate || undefined; /** * Is this item a Gem? * @type {boolean} */ - this.isGem = this.isGem; + this.isGem = !!this.isGem; if (!this.gen) { if (this.num >= 689) { @@ -563,7 +563,7 @@ class Ability extends Effect { * Represents how useful or detrimental this ability is. * @type {number} */ - this.rating = this.rating; + this.rating; /** * Whether or not this ability suppresses weather. @@ -638,14 +638,14 @@ class Template extends Effect { * entry in `pokedex.js`. * @type {string[] | undefined} */ - this.otherForms = this.otherForms; + this.otherForms = this.otherForms || undefined; /** * Other formes. List of names of formes, appears only on the base * forme. Unlike forms, these have their own entry in `pokedex.js`. * @type {string[] | undefined} */ - this.otherFormes = this.otherFormes; + this.otherFormes = this.otherFormes || undefined; /** * Forme letter. One-letter version of the forme name. Usually the @@ -672,13 +672,13 @@ class Template extends Effect { * Types * @type {string[]} */ - this.types = this.types; + this.types; /** * Added type (used in OMs) * @type {string | undefined} */ - this.addedType = this.addedType; + this.addedType = this.addedType || undefined; /** * Pre-evolution. '' if nothing evolves into this Pokemon. @@ -710,7 +710,7 @@ class Template extends Effect { * Evolution level. falsy if doesn't evolve * @type {number | undefined} */ - this.evoLevel = this.evoLevel; + this.evoLevel = this.evoLevel || undefined; /** * Is NFE? True if this Pokemon can evolve (Mega evolution doesn't @@ -745,7 +745,7 @@ class Template extends Effect { * Required item. Do not use this directly; see requiredItems. * @type {string | undefined} */ - this.requiredItem = this.requiredItem; + this.requiredItem = this.requiredItem || undefined; /** * Required items. Items required to be in this forme, e.g. a mega @@ -759,19 +759,19 @@ class Template extends Effect { * Base stats * @type {StatsTable} */ - this.baseStats = this.baseStats; + this.baseStats; /** * Weight (in kg) * @type {number} */ - this.weightkg = this.weightkg; + this.weightkg; /** * Height (in m) * @type {number} */ - this.heightm = this.heightm; + this.heightm; /** * Color @@ -796,13 +796,13 @@ class Template extends Effect { * Max HP. Used in the battle engine * @type {number | undefined} */ - this.maxHP = this.maxHP; + this.maxHP = this.maxHP || undefined; /** * Keeps track of exactly how a pokemon might learn a move, in the form moveid:sources[] * @type {{[moveid: string]: MoveSource[]} | undefined} */ - this.learnset = this.learnset; + this.learnset = this.learnset || undefined; /** * True if the only way to get this pokemon is from events. * @type {boolean} @@ -812,7 +812,7 @@ class Template extends Effect { * List of event data for each event. * @type {EventInfo[] | undefined} */ - this.eventPokemon = this.eventPokemon; + this.eventPokemon = this.eventPokemon || undefined; if (!this.gen) { if (this.num >= 722 || this.forme.startsWith('Alola')) { @@ -895,13 +895,13 @@ class Move extends Effect { * Move base power. * @type {number} */ - this.basePower = this.basePower; + this.basePower; /** * Move base accuracy. True denotes a move that always hits * @type {true | number} */ - this.accuracy = this.accuracy; + this.accuracy; /** * Critical hit ratio. Defaults to 1. @@ -910,22 +910,22 @@ class Move extends Effect { this.critRatio = Number(this.critRatio) || 1; /** - * Will this move always be a critical hit? - * @type {boolean} + * Will this move always or never be a critical hit? + * @type {boolean | undefined} */ - this.willCrit = this.willCrit; + this.willCrit = this.willCrit || undefined; /** * Is this move a critical hit? - * @type {boolean} + * @type {boolean | undefined} */ - this.crit = this.crit; + this.crit = this.crit || undefined; /** * Can this move OHKO foes? - * @type {boolean | string} + * @type {boolean | string | undefined} */ - this.ohko = this.ohko; + this.ohko = this.ohko || undefined; /** * Base move type. This is the move type as specified by the games, @@ -960,50 +960,50 @@ class Move extends Effect { * Move category * @type {'Physical' | 'Special' | 'Status'} */ - this.category = this.category; + this.category; /** * Category that changes which defense to use when calculating * move damage. * @type {'Physical' | 'Special' | 'Status' | undefined} */ - this.defensiveCategory = this.defensiveCategory; + this.defensiveCategory = this.defensiveCategory || undefined; /** * Whether or not this move uses the target's boosts * @type {boolean} */ - this.useTargetOffensive = this.useTargetOffensive; + this.useTargetOffensive = !!this.useTargetOffensive; /** * Whether or not this move uses the user's boosts * @type {boolean} */ - this.useSourceDefensive = this.useSourceDefensive; + this.useSourceDefensive = !!this.useSourceDefensive; /** * Whether or not this move ignores negative attack boosts * @type {boolean} */ - this.ignoreNegativeOffensive = this.ignoreNegativeOffensive; + this.ignoreNegativeOffensive = !!this.ignoreNegativeOffensive; /** * Whether or not this move ignores positive defense boosts * @type {boolean} */ - this.ignorePositiveDefensive = this.ignorePositiveDefensive; + this.ignorePositiveDefensive = !!this.ignorePositiveDefensive; /** * Whether or not this move ignores attack boosts * @type {boolean} */ - this.ignoreOffensive = this.ignoreOffensive; + this.ignoreOffensive = !!this.ignoreOffensive; /** * Whether or not this move ignores defense boosts * @type {boolean} */ - this.ignoreDefensive = this.ignoreDefensive; + this.ignoreDefensive = !!this.ignoreDefensive; /** * Whether or not this move ignores type immunities. Defaults to @@ -1017,26 +1017,26 @@ class Move extends Effect { * Base move PP. * @type {number} */ - this.pp = this.pp; + this.pp; /** * Whether or not this move can receive PP boosts. * @type {boolean} */ - this.noPPBoosts = this.noPPBoosts; + this.noPPBoosts = !!this.noPPBoosts; /** * Is this move a Z-Move? - * @type {boolean | string | undefined} + * @type {boolean | string} */ - this.isZ = this.isZ; + this.isZ = this.isZ || false; /** * Whether or not this move is a Z-Move that broke protect * (affects damage calculation). * @type {boolean} */ - this.zBrokeProtect = this.zBrokeProtect; + this.zBrokeProtect = !!this.zBrokeProtect; /** * @type {MoveFlags} @@ -1046,9 +1046,9 @@ class Move extends Effect { /** * Whether or not the user must switch after using this move. - * @type {string | boolean} + * @type {string | true | undefined} */ - this.selfSwitch = this.selfSwitch; + this.selfSwitch = this.selfSwitch || undefined; /** * Move target only used by Pressure @@ -1057,7 +1057,7 @@ class Move extends Effect { this.pressureTarget = this.pressureTarget || ''; /** - * Move target used if the user is not a Ghost type + * Move target used if the user is not a Ghost type (for Curse) * @type {string} */ this.nonGhostTarget = this.nonGhostTarget || ''; @@ -1066,33 +1066,33 @@ class Move extends Effect { * Whether or not the move ignores abilities * @type {boolean} */ - this.ignoreAbility = this.ignoreAbility; + this.ignoreAbility = this.ignoreAbility || false; /** * Move damage against the current target - * @type {string | number | boolean} + * @type {string | number | boolean | undefined} */ - this.damage = this.damage; + this.damage = this.damage || undefined; /** * Whether or not this move hit multiple targets * @type {boolean} */ - this.spreadHit = this.spreadHit; + this.spreadHit = this.spreadHit || false; /** * Modifier that affects damage when multiple targets * are hit * @type {number | undefined} */ - this.spreadModifier = this.spreadModifier; + this.spreadModifier = this.spreadModifier || undefined; /** * Modifier that affects damage when this move is * a critical hit * @type {number | undefined} */ - this.critModifier = this.critModifier; + this.critModifier = this.critModifier || undefined; /** * Damage modifier based on the user's types @@ -1101,10 +1101,10 @@ class Move extends Effect { this.typeMod = this.typeMod || 0; /** - * Whether or not this move gets STAB + * Forces the move to get STAB even if the type doesn't match * @type {boolean} */ - this.hasSTAB = this.hasSTAB; + this.hasSTAB = !!this.hasSTAB; /** * True if it can't be copied with Sketch @@ -1113,10 +1113,10 @@ class Move extends Effect { this.noSketch = !!this.noSketch; /** - * STAB (can be modified by other effects) + * STAB multiplier (can be modified by other effects) (default 1.5) * @type {number | undefined} */ - this.stab = this.stab; + this.stab = this.stab || undefined; if (!this.gen) { if (this.num >= 622) { diff --git a/sim/index.js b/sim/index.js index 54d780813..a254614e8 100644 --- a/sim/index.js +++ b/sim/index.js @@ -17,7 +17,7 @@ const Side = require('./side'); const Pokemon = require('./pokemon'); const PRNG = require('./prng'); const {BattleStream} = require('./battle-stream'); -const Validator = require('./team-validator').Validator; // eslint-disable-line no-unused-vars +const TeamValidator = require('./team-validator'); module.exports = { Pokemon, @@ -25,6 +25,7 @@ module.exports = { Battle, PRNG, Dex, + TeamValidator, BattleStream, }; diff --git a/sockets.js b/sockets.js index c71ad27b0..f33aa02bd 100644 --- a/sockets.js +++ b/sockets.js @@ -99,8 +99,8 @@ if (cluster.isMaster) { }); /** - * @param {number} port - * @param {string} bindAddress + * @param {number} [port] + * @param {string} [bindAddress] * @param {number} [workerCount] */ exports.listen = function (port, bindAddress, workerCount) { @@ -122,6 +122,9 @@ if (cluster.isMaster) { if (bindAddress !== undefined) { Config.bindaddress = bindAddress; } + if (port !== undefined) { + Config.port = port; + } if (workerCount === undefined) { workerCount = (Config.workers !== undefined ? Config.workers : 1); }