From 2f0be453cccaf73647e2c1d6cda04966974f6410 Mon Sep 17 00:00:00 2001 From: Guangcong Luo Date: Tue, 16 Oct 2018 20:53:33 -0500 Subject: [PATCH] Gen 3: Fix Pressure PP tracking This commit makes it so players are always informed about their own Pressure activations. This fixes Pressure PP tracking for players. PP tracking for spectators will still be wrong; there's no fix for that. Fixes https://github.com/Zarel/Pokemon-Showdown-Client/issues/766 --- mods/gen3/abilities.js | 11 ++++++++++- roomlogs.js | 5 +++-- sim/battle-stream.js | 6 +++--- sockets.js | 6 +++--- 4 files changed, 19 insertions(+), 9 deletions(-) diff --git a/mods/gen3/abilities.js b/mods/gen3/abilities.js index add776a4b4..12829f5018 100644 --- a/mods/gen3/abilities.js +++ b/mods/gen3/abilities.js @@ -113,7 +113,16 @@ let BattleAbilities = { }, "pressure": { inherit: true, - onStart: function () { }, + onStart: function (pokemon) { + this.add('split'); + for (const line of [false, this.sides[0], this.sides[1], true]) { + if (line === true || line === pokemon.side) { + this.add('-ability', pokemon, 'Pressure', '[silent]'); + } else { + this.log.push(''); + } + } + }, }, "roughskin": { inherit: true, diff --git a/roomlogs.js b/roomlogs.js index e7c616973d..e05ec97b45 100644 --- a/roomlogs.js +++ b/roomlogs.js @@ -88,9 +88,10 @@ class Roomlog { } log = []; for (let i = 0; i < this.log.length; ++i) { - let line = this.log[i]; + const line = this.log[i]; if (line === '|split') { - log.push(this.log[i + channel + 1]); + const ownLine = this.log[i + channel + 1]; + if (ownLine) log.push(ownLine); i += 4; } else { log.push(line); diff --git a/sim/battle-stream.js b/sim/battle-stream.js index ca6b0fde1b..71e8a5aa2e 100644 --- a/sim/battle-stream.js +++ b/sim/battle-stream.js @@ -192,11 +192,11 @@ function getPlayerStreams(stream) { const [type, data] = splitFirst(chunk, `\n`); switch (type) { case 'update': - const p1Update = data.replace(/\n\|split\n[^\n]*\n([^\n]*)\n[^\n]*\n[^\n]*/g, '\n$1'); + const p1Update = data.replace(/\n\|split\n[^\n]*\n([^\n]*)\n[^\n]*\n[^\n]*/g, '\n$1').replace(/\n\n/g, '\n'); p1.push(p1Update); - const p2Update = data.replace(/\n\|split\n[^\n]*\n[^\n]*\n([^\n]*)\n[^\n]*/g, '\n$1'); + const p2Update = data.replace(/\n\|split\n[^\n]*\n[^\n]*\n([^\n]*)\n[^\n]*/g, '\n$1').replace(/\n\n/g, '\n'); p2.push(p2Update); - const specUpdate = data.replace(/\n\|split\n([^\n]*)\n[^\n]*\n[^\n]*\n[^\n]*/g, '\n$1'); + const specUpdate = data.replace(/\n\|split\n([^\n]*)\n[^\n]*\n[^\n]*\n[^\n]*/g, '\n$1').replace(/\n\n/g, '\n'); spectator.push(specUpdate); const omniUpdate = data.replace(/\n\|split\n[^\n]*\n[^\n]*\n[^\n]*/g, ''); omniscient.push(omniUpdate); diff --git a/sockets.js b/sockets.js index 8a0a0f5dff..c71ad27b01 100644 --- a/sockets.js +++ b/sockets.js @@ -546,19 +546,19 @@ if (cluster.isMaster) { switch (subchannel ? subchannel.get(socketid) : '0') { case '1': if (!messages[1]) { - messages[1] = message.replace(/\n\|split\n[^\n]*\n([^\n]*)\n[^\n]*\n[^\n]*/g, '\n$1'); + messages[1] = message.replace(/\n\|split\n[^\n]*\n([^\n]*)\n[^\n]*\n[^\n]*/g, '\n$1').replace(/\n\n/g, '\n'); } socket.write(messages[1]); break; case '2': if (!messages[2]) { - messages[2] = message.replace(/\n\|split\n[^\n]*\n[^\n]*\n([^\n]*)\n[^\n]*/g, '\n$1'); + messages[2] = message.replace(/\n\|split\n[^\n]*\n[^\n]*\n([^\n]*)\n[^\n]*/g, '\n$1').replace(/\n\n/g, '\n'); } socket.write(messages[2]); break; default: if (!messages[0]) { - messages[0] = message.replace(/\n\|split\n([^\n]*)\n[^\n]*\n[^\n]*\n[^\n]*/g, '\n$1'); + messages[0] = message.replace(/\n\|split\n([^\n]*)\n[^\n]*\n[^\n]*\n[^\n]*/g, '\n$1').replace(/\n\n/g, '\n'); } socket.write(messages[0]); break;