From b75ca2bd563f9ca360f524873589c1ed43f031da Mon Sep 17 00:00:00 2001 From: Karthik99999 Date: Wed, 11 Oct 2023 11:22:59 -0700 Subject: [PATCH 1/5] Populate Tooltips with information from OTS --- src/battle-text-parser.ts | 2 +- src/battle.ts | 36 ++++++++++++++++++++++++++++++++++++ 2 files changed, 37 insertions(+), 1 deletion(-) diff --git a/src/battle-text-parser.ts b/src/battle-text-parser.ts index b64e399e04..11da55e34a 100644 --- a/src/battle-text-parser.ts +++ b/src/battle-text-parser.ts @@ -46,7 +46,7 @@ class BattleTextParser { case 'fieldhtml': case 'controlshtml': case 'bigerror': case 'debug': case 'tier': case 'challstr': case 'popup': case '': return [cmd, line.slice(index + 1)]; - case 'c': case 'chat': case 'uhtml': case 'uhtmlchange': case 'queryresponse': + case 'c': case 'chat': case 'uhtml': case 'uhtmlchange': case 'queryresponse': case 'showteam': // three parts const index2a = line.indexOf('|', index + 1); return [cmd, line.slice(index + 1, index2a), line.slice(index2a + 1)]; diff --git a/src/battle.ts b/src/battle.ts index 9f3985be78..f5e188a7c7 100644 --- a/src/battle.ts +++ b/src/battle.ts @@ -3571,6 +3571,42 @@ export class Battle { this.scene.teamPreview(); break; } + case 'showteam': { + if (this.turn !== 0) return; + // @ts-ignore + if (!window.Storage?.unpackTeam || !window.Storage?.exportTeam) return; + // @ts-ignore + const team: PokemonSet[] = Storage.unpackTeam(args[2]); + if (!team) return; + const side = this.getSide(args[1]); + side.clearPokemon(); + for (const set of team) { + const details = set.species + (set.level === 100 ? '' : ', L' + set.level) + + (set.gender === '' ? '' : ', ' + set.gender) + (set.shiny ? ', shiny' : ''); + const pokemon = side.addPokemon('', '', details); + if (set.item) pokemon.item = set.item; + if (set.ability) pokemon.rememberAbility(set.ability); + for (const move of set.moves) { + pokemon.rememberMove(move, 0); + } + if (set.teraType) pokemon.teraType = set.teraType; + } + const exportedTeam = team.map(set => { + // @ts-ignore + let buf = Storage.exportTeam([set], this.gen).replace(/\n/g, '
'); + if (set.name && set.name !== set.species) { + buf = buf.replace(set.name, BattleLog.sanitizeHTML(`
${set.name}`)); + } else { + buf = buf.replace(set.species, `
${set.species}`); + } + if (set.item) { + buf = buf.replace(set.item, `${set.item} `); + } + return buf; + }).join(''); + this.add(`|raw|
Open Team Sheet for ${side.name}${exportedTeam}
`); + break; + } case 'switch': case 'drag': case 'replace': { this.endLastTurn(); let poke = this.getSwitchedPokemon(args[1], args[2])!; From 12989cd3625dca713a00d298656b73dac4e9cbb3 Mon Sep 17 00:00:00 2001 From: Karthik99999 Date: Sat, 14 Oct 2023 21:22:03 -0700 Subject: [PATCH 2/5] Ensure abilities and moves aren't deleted on switch in --- src/battle.ts | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/battle.ts b/src/battle.ts index f5e188a7c7..ac1bc0d5a4 100644 --- a/src/battle.ts +++ b/src/battle.ts @@ -737,13 +737,17 @@ export class Side { } addPokemon(name: string, ident: string, details: string, replaceSlot = -1) { const oldItem = replaceSlot >= 0 ? this.pokemon[replaceSlot].item : undefined; + const oldAbility = replaceSlot >= 0 ? this.pokemon[replaceSlot].baseAbility : undefined; + const oldMoveTrack = replaceSlot >= 0 ? this.pokemon[replaceSlot].moveTrack : undefined; const data = this.battle.parseDetails(name, ident, details); const poke = new Pokemon(data, this); if (oldItem) poke.item = oldItem; + if (oldAbility) poke.baseAbility = oldAbility; if (!poke.ability && poke.baseAbility) poke.ability = poke.baseAbility; poke.reset(); + if (oldMoveTrack?.length) poke.moveTrack = oldMoveTrack.slice(); if (replaceSlot >= 0) { this.pokemon[replaceSlot] = poke; @@ -3582,7 +3586,7 @@ export class Battle { side.clearPokemon(); for (const set of team) { const details = set.species + (set.level === 100 ? '' : ', L' + set.level) + - (set.gender === '' ? '' : ', ' + set.gender) + (set.shiny ? ', shiny' : ''); + (!set.gender || set.gender === 'N' ? '' : ', ' + set.gender) + (set.shiny ? ', shiny' : ''); const pokemon = side.addPokemon('', '', details); if (set.item) pokemon.item = set.item; if (set.ability) pokemon.rememberAbility(set.ability); @@ -3604,7 +3608,7 @@ export class Battle { } return buf; }).join(''); - this.add(`|raw|
Open Team Sheet for ${side.name}${exportedTeam}
`); + this.add(`|raw|
Open Team Sheet for ${side.name}${exportedTeam}
`); break; } case 'switch': case 'drag': case 'replace': { From a40eb0910b5309634cfb36542def7b1621da187c Mon Sep 17 00:00:00 2001 From: Karthik99999 Date: Sat, 14 Oct 2023 21:59:19 -0700 Subject: [PATCH 3/5] Forgot about tera type --- src/battle.ts | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/battle.ts b/src/battle.ts index ac1bc0d5a4..bd65e8c696 100644 --- a/src/battle.ts +++ b/src/battle.ts @@ -739,11 +739,13 @@ export class Side { const oldItem = replaceSlot >= 0 ? this.pokemon[replaceSlot].item : undefined; const oldAbility = replaceSlot >= 0 ? this.pokemon[replaceSlot].baseAbility : undefined; const oldMoveTrack = replaceSlot >= 0 ? this.pokemon[replaceSlot].moveTrack : undefined; + const oldTeraType = replaceSlot >= 0 ? this.pokemon[replaceSlot].teraType : undefined; const data = this.battle.parseDetails(name, ident, details); const poke = new Pokemon(data, this); if (oldItem) poke.item = oldItem; if (oldAbility) poke.baseAbility = oldAbility; + if (oldTeraType) poke.teraType = oldTeraType; if (!poke.ability && poke.baseAbility) poke.ability = poke.baseAbility; poke.reset(); From 96de1da4fef47e33a7eeb6ba665c000a5ebc323e Mon Sep 17 00:00:00 2001 From: Karthik99999 Date: Sun, 15 Oct 2023 01:23:48 -0700 Subject: [PATCH 4/5] simplify code --- src/battle.ts | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/src/battle.ts b/src/battle.ts index bd65e8c696..f44238005b 100644 --- a/src/battle.ts +++ b/src/battle.ts @@ -736,20 +736,19 @@ export class Side { this.battle.scene.removeSideCondition(this.n, id); } addPokemon(name: string, ident: string, details: string, replaceSlot = -1) { - const oldItem = replaceSlot >= 0 ? this.pokemon[replaceSlot].item : undefined; - const oldAbility = replaceSlot >= 0 ? this.pokemon[replaceSlot].baseAbility : undefined; - const oldMoveTrack = replaceSlot >= 0 ? this.pokemon[replaceSlot].moveTrack : undefined; - const oldTeraType = replaceSlot >= 0 ? this.pokemon[replaceSlot].teraType : undefined; + const oldPokemon = replaceSlot >= 0 ? this.pokemon[replaceSlot] : undefined; const data = this.battle.parseDetails(name, ident, details); const poke = new Pokemon(data, this); - if (oldItem) poke.item = oldItem; - if (oldAbility) poke.baseAbility = oldAbility; - if (oldTeraType) poke.teraType = oldTeraType; + if (oldPokemon) { + poke.item = oldPokemon.item; + poke.baseAbility = oldPokemon.baseAbility; + poke.teraType = oldPokemon.teraType; + } if (!poke.ability && poke.baseAbility) poke.ability = poke.baseAbility; poke.reset(); - if (oldMoveTrack?.length) poke.moveTrack = oldMoveTrack.slice(); + if (oldPokemon?.moveTrack.length) poke.moveTrack = oldPokemon.moveTrack; if (replaceSlot >= 0) { this.pokemon[replaceSlot] = poke; From f577d46169df48eb140bf50968db2e87e18e64c4 Mon Sep 17 00:00:00 2001 From: Karthik99999 Date: Mon, 16 Oct 2023 22:02:10 -0700 Subject: [PATCH 5/5] Fix level in details --- src/battle.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/battle.ts b/src/battle.ts index f44238005b..f86564a45b 100644 --- a/src/battle.ts +++ b/src/battle.ts @@ -3586,7 +3586,7 @@ export class Battle { const side = this.getSide(args[1]); side.clearPokemon(); for (const set of team) { - const details = set.species + (set.level === 100 ? '' : ', L' + set.level) + + const details = set.species + (!set.level || set.level === 100 ? '' : ', L' + set.level) + (!set.gender || set.gender === 'N' ? '' : ', ' + set.gender) + (set.shiny ? ', shiny' : ''); const pokemon = side.addPokemon('', '', details); if (set.item) pokemon.item = set.item;