Skip to content

Commit

Permalink
Merge pull request #45 from Zarel/master
Browse files Browse the repository at this point in the history
update from main
  • Loading branch information
FlamePrince-PS authored Oct 28, 2018
2 parents 317549a + 6643749 commit 6054f70
Show file tree
Hide file tree
Showing 26 changed files with 131 additions and 128 deletions.
2 changes: 1 addition & 1 deletion .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,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",
Expand Down
13 changes: 9 additions & 4 deletions chat-commands.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {

Expand Down Expand Up @@ -1769,7 +1772,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}`);
Expand Down Expand Up @@ -2043,7 +2046,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;
Expand Down Expand Up @@ -2643,7 +2646,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) {
Expand Down Expand Up @@ -2763,7 +2766,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));

Expand Down
6 changes: 3 additions & 3 deletions chat-plugins/mafia.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.");
}
Expand Down Expand Up @@ -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.");
}
Expand All @@ -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.");
}
Expand Down
2 changes: 1 addition & 1 deletion chat-plugins/roomsettings.js
Original file line number Diff line number Diff line change
Expand Up @@ -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}`);
}
Expand Down
2 changes: 1 addition & 1 deletion chat-plugins/scavengers.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
4 changes: 3 additions & 1 deletion chat-plugins/thing-of-the-day.js
Original file line number Diff line number Diff line change
Expand Up @@ -583,12 +583,14 @@ let commands = {
if (!this.runBroadcast()) return false;

const handler = selectHandler(this.message);
if (!handler.room) return this.errorReply(`The room for this -otd doesn't exist.`);

if (room !== handler.room) return this.errorReply(`This command can only be used in ${handler.room.title}.`);

handler.generateWinnerDisplay().then(text => {
if (!text) return this.errorReply("There is no winner yet.");
return this.sendReplyBox(text);
this.sendReplyBox(text);
this.room.update();
});
},
};
Expand Down
2 changes: 1 addition & 1 deletion chat-plugins/trivia.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
3 changes: 1 addition & 2 deletions chat.js
Original file line number Diff line number Diff line change
Expand Up @@ -1736,10 +1736,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 {
Expand Down
12 changes: 6 additions & 6 deletions data/moves.js
Original file line number Diff line number Diff line change
Expand Up @@ -5048,11 +5048,11 @@ let BattleMovedex = {
onModifyMove: function (move) {
if (move.sourceEffect === 'waterpledge') {
move.type = 'Water';
move.hasSTAB = true;
move.forceSTAB = true;
}
if (move.sourceEffect === 'grasspledge') {
move.type = 'Fire';
move.hasSTAB = true;
move.forceSTAB = true;
}
},
onHit: function (target, source, move) {
Expand Down Expand Up @@ -6466,11 +6466,11 @@ let BattleMovedex = {
onModifyMove: function (move) {
if (move.sourceEffect === 'waterpledge') {
move.type = 'Grass';
move.hasSTAB = true;
move.forceSTAB = true;
}
if (move.sourceEffect === 'firepledge') {
move.type = 'Fire';
move.hasSTAB = true;
move.forceSTAB = true;
}
},
onHit: function (target, source, move) {
Expand Down Expand Up @@ -18416,11 +18416,11 @@ let BattleMovedex = {
onModifyMove: function (move) {
if (move.sourceEffect === 'grasspledge') {
move.type = 'Grass';
move.hasSTAB = true;
move.forceSTAB = true;
}
if (move.sourceEffect === 'firepledge') {
move.type = 'Water';
move.hasSTAB = true;
move.forceSTAB = true;
}
},
onHit: function (target, source, move) {
Expand Down
6 changes: 3 additions & 3 deletions data/random-teams.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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,
Expand All @@ -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
Expand Down
3 changes: 1 addition & 2 deletions data/scripts.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
7 changes: 6 additions & 1 deletion dev-tools/globals.ts
Original file line number Diff line number Diff line change
Expand Up @@ -507,6 +507,7 @@ interface MoveData extends EffectData {
volatileStatus?: string
weather?: string
willCrit?: boolean
forceSTAB?: boolean
zMovePower?: number
zMoveEffect?: string
zMoveBoost?: SparseBoostsTable
Expand Down Expand Up @@ -537,7 +538,6 @@ interface ActiveMove extends Effect, MoveData {
hasAuraBreak?: boolean
hasBounced?: boolean
hasSheerForce?: boolean
hasSTAB?: boolean
isExternal?: boolean
lastHit?: boolean
magnitude?: number
Expand All @@ -552,6 +552,11 @@ interface ActiveMove extends Effect, MoveData {
statusRoll?: string
totalDamage?: number | false
willChangeForme?: boolean
/**
* Whether or not this move is a Z-Move that broke protect
* (affects damage calculation).
* @type {boolean}
*/
zBrokeProtect?: boolean
/**
* Has this move been boosted by a Z-crystal? Usually the same as
Expand Down
1 change: 1 addition & 0 deletions loginserver.js
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,7 @@ class LoginServerInstance {
if (data) {
resolve([data[i], res.statusCode, null]);
} else {
if (buffer.includes('<')) buffer = 'invalid response';
resolve([null, res.statusCode, new Error(buffer)]);
}
}
Expand Down
1 change: 0 additions & 1 deletion mods/gen1/random-teams.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down
3 changes: 1 addition & 2 deletions mods/gen2/scripts.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
4 changes: 2 additions & 2 deletions mods/gen3/random-teams.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
3 changes: 1 addition & 2 deletions mods/gen3/scripts.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
1 change: 0 additions & 1 deletion mods/gen4/random-teams.js
Original file line number Diff line number Diff line change
Expand Up @@ -545,7 +545,6 @@ class RandomGen4Teams extends RandomGen5Teams {
}
}

item = 'Leftovers';
if (template.requiredItems) {
item = this.sample(template.requiredItems);

Expand Down
5 changes: 2 additions & 3 deletions mods/gen4/scripts.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ let BattleScripts = {
baseDamage = this.randomizer(baseDamage);

// STAB
if (move.hasSTAB || type !== '???' && pokemon.hasType(type)) {
if (move.forceSTAB || type !== '???' && pokemon.hasType(type)) {
// The "???" type never gets STAB
// Not even if you Roost in Gen 4 and somehow manage to use
// Struggle in the same turn.
Expand Down Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion mods/gennext/moves.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion mods/stadium/scripts.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
5 changes: 3 additions & 2 deletions sim/battle-stream-example.js
Original file line number Diff line number Diff line change
Expand Up @@ -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())) {
Expand Down
3 changes: 1 addition & 2 deletions sim/battle.js
Original file line number Diff line number Diff line change
Expand Up @@ -2307,7 +2307,7 @@ class Battle extends Dex.ModdedDex {
baseDamage = this.randomizer(baseDamage);

// STAB
if (move.hasSTAB || (type !== '???' && pokemon.hasType(type))) {
if (move.forceSTAB || (type !== '???' && pokemon.hasType(type))) {
// The "???" type never gets STAB
// Not even if you Roost in Gen 4 and somehow manage to use
// Struggle in the same turn.
Expand Down Expand Up @@ -2730,7 +2730,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()) {
Expand Down
Loading

0 comments on commit 6054f70

Please sign in to comment.