Revert "[WIP] Client changes for multi battle (#1631)"

It's causing problems in double battles.

This reverts commit 8bd57951e5.
This commit is contained in:
Guangcong Luo
2020-10-20 08:56:37 -04:00
parent 76799f3f77
commit 70e35b7599
8 changed files with 49 additions and 95 deletions

View File

@@ -381,7 +381,7 @@
if (this.request.forceSwitch !== true) {
var faintedLength = _.filter(this.request.forceSwitch, function (fainted) {return fainted;}).length;
var freedomDegrees = faintedLength - _.filter(switchables.slice(this.battle.mySide.active.length), function (mon) {return !mon.fainted && !mon.notMine;}).length;
var freedomDegrees = faintedLength - _.filter(switchables.slice(this.battle.mySide.active.length), function (mon) {return !mon.fainted;}).length;
this.choice.freedomDegrees = Math.max(freedomDegrees, 0);
this.choice.canSwitch = faintedLength - this.choice.freedomDegrees;
}
@@ -402,9 +402,6 @@
done: 0,
count: 1
};
if (this.battle.gameType === 'multi') {
this.choice.count = 1;
}
if (this.battle.gameType === 'doubles') {
this.choice.count = 2;
}
@@ -517,8 +514,7 @@
}
var moveTarget = this.choice ? this.choice.moveTarget : '';
var pos = this.choice.choices.length;
if (type === 'movetarget') pos--;
var pos = this.choice.choices.length - (type === 'movetarget' ? 1 : 0);
var hpRatio = switchables[pos].hp / switchables[pos].maxhp;
@@ -555,10 +551,6 @@
if (type === 'movetarget') {
requestTitle += 'At who? ';
if (this.request && this.request.side) {
pos += Math.floor((parseInt(this.side.charAt(1), 10) - 1) / 2);
}
var targetMenus = ['', ''];
var myActive = this.battle.mySide.active;
var yourActive = this.battle.yourSide.active;
@@ -792,9 +784,8 @@
for (var i = 0; i < switchables.length; i++) {
var pokemon = switchables[i];
var tooltipArgs = 'switchpokemon|' + i;
if (pokemon.fainted || i < (this.battle.pokemonControlled || this.battle.mySide.active.length) || pokemon.notMine || this.choice.switchFlags[i]) {
var disabledReason = pokemon.notMine ? ',notMine' : pokemon.fainted ? ',fainted' : i < (this.battle.pokemonControlled || this.battle.mySide.active.length) ? ',active' : '';
switchMenu += '<button class="disabled has-tooltip" name="chooseDisabled" value="' + BattleLog.escapeHTML(pokemon.name) + disabledReason + '" data-tooltip="' + BattleLog.escapeHTML(tooltipArgs) + '">';
if (pokemon.fainted || i < this.battle.mySide.active.length || this.choice.switchFlags[i]) {
switchMenu += '<button class="disabled has-tooltip" name="chooseDisabled" value="' + BattleLog.escapeHTML(pokemon.name) + (pokemon.fainted ? ',fainted' : i < this.battle.mySide.active.length ? ',active' : '') + '" data-tooltip="' + BattleLog.escapeHTML(tooltipArgs) + '">';
} else {
switchMenu += '<button name="chooseSwitch" value="' + i + '" class="has-tooltip" data-tooltip="' + BattleLog.escapeHTML(tooltipArgs) + '">';
}
@@ -874,14 +865,14 @@
buf += '<small>';
if (this.choice.teamPreview) {
var myPokemon = this.battle.myPokemon;
var myPokemon = this.battle.mySide.pokemon;
var leads = [];
for (var i = 0; i < this.choice.count; i++) {
leads.push(myPokemon[this.choice.teamPreview[i] - 1].speciesForme);
}
buf += leads.join(', ') + ' will be sent out first.<br />';
} else if (this.choice.choices && this.request) {
var myActive = this.battle.myPokemon;
var myActive = this.battle.mySide.active;
for (var i = 0; i < this.choice.choices.length; i++) {
var parts = this.choice.choices[i].split(' ');
switch (parts[0]) {
@@ -1008,7 +999,7 @@
updateSideLocation: function (sideData) {
if (!sideData.id) return;
this.side = sideData.id;
if (this.battle.sidesSwitched !== !(parseInt(this.side.charAt(1), 10) % 2)) {
if (this.battle.sidesSwitched !== !!(this.side === 'p2')) {
this.battle.switchSides();
this.$chat = this.$chatFrame.find('.inner');
}
@@ -1215,17 +1206,13 @@
chooseDisabled: function (data) {
this.tooltips.hideTooltip();
data = data.split(',');
switch (data[1]) {
case 'notMine':
app.addPopupMessage("You cannot decide for your partner!");
break;
case 'fainted':
if (data[1] === 'fainted') {
app.addPopupMessage("" + data[0] + " has no energy left to battle!");
break;
case 'active':
} else if (data[1] === 'trapped') {
app.addPopupMessage("You are trapped and cannot select " + data[0] + "!");
} else if (data[1] === 'active') {
app.addPopupMessage("" + data[0] + " is already in battle!");
break;
default:
} else {
app.addPopupMessage("" + data[0] + " is already selected!");
}
},
@@ -1241,23 +1228,23 @@
},
nextChoice: function () {
var choices = this.choice.choices;
var myActive = this.request.active || this.battle.mySide.active;
var myActive = this.battle.mySide.active;
if (this.request.requestType === 'switch' && this.request.forceSwitch !== true) {
while (choices.length < (this.battle.pokemonControlled || myActive.length) && !this.request.forceSwitch[choices.length]) {
while (choices.length < myActive.length && !this.request.forceSwitch[choices.length]) {
choices.push('pass');
}
if (choices.length < (this.battle.pokemonControlled || myActive.length)) {
if (choices.length < myActive.length) {
this.choice.type = 'switch2';
this.updateControlsForPlayer();
return true;
}
} else if (this.request.requestType === 'move') {
while (choices.length < (this.battle.pokemonControlled || myActive.length) && !myActive[choices.length]) {
while (choices.length < myActive.length && !myActive[choices.length]) {
choices.push('pass');
}
if (choices.length < (this.battle.pokemonControlled || myActive.length)) {
if (choices.length < myActive.length) {
this.choice.type = 'move2';
this.updateControlsForPlayer();
return true;
@@ -1278,12 +1265,12 @@
if (act === 'switch') {
// Assert that the remaining Pokémon won't switch, even though
// the player could have decided otherwise.
for (var i = 0; i < (this.battle.pokemonControlled || this.battle.mySide.active.length); i++) {
for (var i = 0; i < this.battle.mySide.active.length; i++) {
if (!this.choice.choices[i]) this.choice.choices[i] = 'pass';
}
}
if (this.choice.choices.length >= (this.choice.count || this.battle.pokemonControlled || (this.request.active || this.battle.mySide.active).length)) {
if (this.choice.choices.length >= (this.choice.count || this.battle.mySide.active.length)) {
this.sendDecision(this.choice.choices);
}
@@ -1393,8 +1380,9 @@
var self = this;
app.addPopupPrompt("Replacement player's username", "Replace player", function (target) {
if (!target) return;
var side = (room.battle.mySide.id === room.battle.p1.id ? 'p1' : 'p2');
room.leaveBattle();
room.send('/addplayer ' + target + ', ' + self.side);
room.send('/addplayer ' + target + ', ' + side);
self.close();
});
},

View File

@@ -443,14 +443,15 @@
for (var i = 0; i < targets.length; i++) {
targets[i] = $.trim(targets[i]);
}
var self = this;
var challenge = function (targets) {
target = toID(targets[0]);
self.challengeData = {userid: target, format: targets.length > 1 ? targets.slice(1).join(',') : '', team: ''};
app.on('response:userdetails', self.challengeUserdetails, self);
app.send('/cmd userdetails ' + targets[0]);
if (self.challengeData.teammate) app.send('/cmd userdetails ' + targets[3]);
app.send('/cmd userdetails ' + target);
};
if (!targets[0]) {
app.addPopupPrompt("Who would you like to challenge?", "Challenge user", function (target) {
if (!target) return;
@@ -462,7 +463,7 @@
return false;
case 'accept':
var userid = toID(targets[0]);
var userid = toID(target);
if (userid) {
var $challenge = $('.pm-window').filter('div[data-userid="' + userid + '"]').find('button[name="acceptChallenge"]');
if (!$challenge.length) {
@@ -1110,10 +1111,6 @@
// if foe has changed name, challengeData.userid will be wrong, so defer to data
var name = data.name || data.userid;
if (/^[a-z0-9]/i.test(name)) name = ' ' + name;
if (this.challengeData.teammate) {
app.rooms[''].challenge(name, this.challengeData.format, this.challengeData.team, this.challengeData.teammate);
return;
}
app.rooms[''].challenge(name, this.challengeData.format, this.challengeData.team);
},

View File

@@ -677,7 +677,6 @@
var challenge = data.challengeTo;
var name = challenge.to;
var userid = toID(name);
var teammate = challenge.teammate;
var $challenge = this.openChallenge(name);
var buf = '<form class="battleform"><p>Waiting for ' + BattleLog.escapeHTML(name) + '...</p>';
@@ -786,7 +785,7 @@
},
// challenge buttons
challenge: function (name, format, team, teammate) {
challenge: function (name, format, team) {
var userid = toID(name);
var $challenge = this.$('.pm-window-' + userid + ' .challenge');
if ($challenge.length && !$challenge.find('button[name=dismissChallenge]').length) {
@@ -817,26 +816,11 @@
var teamIndex = $pmWindow.find('button[name=team]').val();
var privacy = this.adjustPrivacy($pmWindow.find('input[name=private]').is(':checked'));
var team = null;
var teammate = null;
if (Storage.teams[teamIndex]) team = Storage.teams[teamIndex];
if (format.indexOf('@@@') === -1 && !window.BattleFormats[format].team && !team) {
app.addPopupMessage("You need to go into the Teambuilder and build a team for this format.");
return;
}
if (BattleFormats[toID(format)].isMultiBattle) {
app.addPopupPrompt("Invite a user:", "Invite user", function (target) {
if (!target) return;
teammate = ', ' + target;
});
if (!teammate) {
app.addPopupMessage("This is a multi battle format. You need one more player");
return;
}
target.disabled = true;
app.sendTeam(team);
app.send('/accept ' + userid + teammate);
return;
}
target.disabled = true;
app.sendTeam(team);

View File

@@ -656,7 +656,6 @@ class BattleScene {
sidebarIcons.push(['empty', null]);
}
let sliceCount = 0;
let pokemonhtml = '';
for (let i = 0; i < sidebarIcons.length; i++) {
const [iconType, pokeIndex] = sidebarIcons[i];
@@ -685,10 +684,6 @@ class BattleScene {
const details = this.getDetailsText(poke);
pokemonhtml += `<span${tooltipCode} style="` + Dex.getPokemonIcon(poke, !side.n) + `" aria-label="${details}"></span>`;
}
if (i === side.teamSliceIndicies[sliceCount]) {
sliceCount++;
pokemonhtml += `</div><div class="teamicons">`;
}
if (i % 3 === 2) pokemonhtml += `</div><div class="teamicons">`;
}
pokemonhtml = '<div class="teamicons">' + pokemonhtml + '</div>';

View File

@@ -234,8 +234,8 @@ class BattleTextParser {
if (!pokemon) return '';
let side;
switch (pokemon.slice(0, 2)) {
case 'p1': case 'p3': side = 0; break;
case 'p2': case 'p4': side = 1; break;
case 'p1': side = 0; break;
case 'p2': side = 1; break;
default: return `???pokemon:${pokemon}???`;
}
const name = this.pokemonName(pokemon);

View File

@@ -684,7 +684,7 @@ class BattleTooltips {
text += '' + (move.desc || move.shortDesc) + '</p>';
if (this.battle.gameType === 'doubles' || this.battle.gameType === 'multi') {
if (this.battle.gameType === 'doubles') {
if (move.target === 'allAdjacent') {
text += '<p>&#x25ce; Hits both foes and ally.</p>';
} else if (move.target === 'allAdjacentFoes') {

View File

@@ -592,7 +592,6 @@ class Side {
active = [null] as (Pokemon | null)[];
lastPokemon = null as Pokemon | null;
pokemon = [] as Pokemon[];
teamSliceIndicies = [] as number[];
/** [effectName, levels, minDuration, maxDuration] */
sideConditions: {[id: string]: [string, number, number, number]} = {};
@@ -1052,7 +1051,6 @@ class Battle {
p1: Side = null!;
p2: Side = null!;
myPokemon: ServerPokemon[] | null = null;
pokemonControlled = 0;
sides: [Side, Side] = [null!, null!];
lastMove = '';
@@ -1061,7 +1059,7 @@ class Battle {
teamPreviewCount = 0;
speciesClause = false;
tier = '';
gameType: 'singles' | 'doubles' | 'multi' | 'triples' = 'singles';
gameType: 'singles' | 'doubles' | 'triples' = 'singles';
rated: string | boolean = false;
isBlitz = false;
endLastTurnPending = false;
@@ -2953,20 +2951,22 @@ class Battle {
let siden = -1;
let slot = -1; // if there is an explicit slot for this pokemon
let slotChart: {[k: string]: number} = {a: 0, b: 1, c: 2, d: 3, e: 4, f: 5};
if (name.match(/^p[0-9]$|p[0-9]: |p[0-9][a-f]: /)) {
const serverSideN = parseInt(name.charAt(1), 10) - 1;
if (this.sidesSwitched) {
siden = serverSideN + ((serverSideN % 2) ? -1 : 1);
} else {
siden = serverSideN;
}
if (name.match(/^p[0-9]$|p[0-9]: /)) {
name = name.substr(4);
} else {
slot = slotChart[name.charAt(2)];
name = name.substr(5);
pokemonid = 'p' + (serverSideN + 1) + ': ' + name;
}
if (name.substr(0, 4) === 'p2: ' || name === 'p2') {
siden = this.p2.n;
name = name.substr(4);
} else if (name.substr(0, 4) === 'p1: ' || name === 'p1') {
siden = this.p1.n;
name = name.substr(4);
} else if (name.substr(0, 2) === 'p2' && name.substr(3, 2) === ': ') {
slot = slotChart[name.substr(2, 1)];
siden = this.p2.n;
name = name.substr(5);
pokemonid = 'p2: ' + name;
} else if (name.substr(0, 2) === 'p1' && name.substr(3, 2) === ': ') {
slot = slotChart[name.substr(2, 1)];
siden = this.p1.n;
name = name.substr(5);
pokemonid = 'p1: ' + name;
}
return {name, siden, slot, pokemonid};
}
@@ -2974,10 +2974,9 @@ class Battle {
if (pokemonid === '??') throw new Error(`pokemonid not passed`);
const {name, siden, slot, pokemonid: parsedPokemonid} = this.parsePokemonId(pokemonid);
pokemonid = parsedPokemonid;
const teamn = siden % 2;
const searchid = `${pokemonid}|${details}`;
const side = this.sides[teamn];
const side = this.sides[siden];
// search inactive revealed pokemon
for (let i = 0; i < side.pokemon.length; i++) {
@@ -3028,10 +3027,9 @@ class Battle {
const {siden, slot, pokemonid: parsedPokemonid} = this.parsePokemonId(pokemonid);
pokemonid = parsedPokemonid;
const teamn = siden % 2;
/** if true, don't match an active pokemon */
const isInactive = (slot < 0);
const side = this.sides[teamn];
const side = this.sides[siden];
// search player's pokemon
if (!isInactive && side.active[slot]) return side.active[slot];
@@ -3126,10 +3124,6 @@ class Battle {
this.mySide.active = [null];
this.yourSide.active = [null];
break;
case 'multi':
case 'free-for-all':
this.pokemonControlled = 1;
// falls through
case 'doubles':
this.mySide.active = [null, null];
this.yourSide.active = [null, null];

View File

@@ -10,8 +10,6 @@ type BattleDesc = {
minElo?: number | string,
p1?: string,
p2?: string,
p3?: string,
p4?: string,
};
class BattlesRoom extends PSRoom {
@@ -46,12 +44,10 @@ class BattlesPanel extends PSRoomPanel<BattlesRoom> {
renderBattleLink(battle: BattleDesc) {
const format = battle.id.split('-')[1];
const minEloMessage = typeof battle.minElo === 'number' ? `rated ${battle.minElo}` : battle.minElo;
const p1 = battle.p1 + (battle.p3 ? " & " + battle.p3 : "");
const p2 = battle.p2 + (battle.p4 ? " & " + battle.p4 : "");
return <div><a href={`/${battle.id}`} class="blocklink">
{minEloMessage && <small style="float:right">({minEloMessage})</small>}
<small>[{format}]</small><br />
<em class="p1">{p1}</em> <small class="vs">vs.</small> <em class="p2">{p2}</em>
<em class="p1">{battle.p1}</em> <small class="vs">vs.</small> <em class="p2">{battle.p2}</em>
</a></div>;
}
render() {