From 9e0a8a30301b69bf7e23a68d0c1e835bd3b70133 Mon Sep 17 00:00:00 2001 From: Flashfyre Date: Mon, 3 Jul 2023 10:59:56 -0400 Subject: [PATCH] Fix hanging after catching Pokemon without releasing --- package-lock.json | 34 +++++++++++++++++----------------- src/battle-phases.ts | 20 ++++++++++++-------- 2 files changed, 29 insertions(+), 25 deletions(-) diff --git a/package-lock.json b/package-lock.json index 9395668b56a..1a333c8b4e5 100644 --- a/package-lock.json +++ b/package-lock.json @@ -19,6 +19,15 @@ "vite-plugin-fs": "^1.0.0-beta.6" } }, + "node_modules/@aashutoshrathi/word-wrap": { + "version": "1.2.6", + "resolved": "https://registry.npmjs.org/@aashutoshrathi/word-wrap/-/word-wrap-1.2.6.tgz", + "integrity": "sha512-1Yjs2SvM8TflER/OD3cOjhWWOZb58A2t7wpE2S9XfBYTiIl+XFhQG2bjy4Pu1I+EAlCNUzRDYDdFwFYUKvXcIA==", + "dev": true, + "engines": { + "node": ">=0.10.0" + } + }, "node_modules/@babel/runtime": { "version": "7.21.0", "resolved": "https://registry.npmjs.org/@babel/runtime/-/runtime-7.21.0.tgz", @@ -1817,17 +1826,17 @@ "dev": true }, "node_modules/optionator": { - "version": "0.9.1", - "resolved": "https://registry.npmjs.org/optionator/-/optionator-0.9.1.tgz", - "integrity": "sha512-74RlY5FCnhq4jRxVUPKDaRwrVNXMqsGsiW6AJw4XK8hmtm10wC0ypZBLw5IIp85NZMr91+qd1RvvENwg7jjRFw==", + "version": "0.9.3", + "resolved": "https://registry.npmjs.org/optionator/-/optionator-0.9.3.tgz", + "integrity": "sha512-JjCoypp+jKn1ttEFExxhetCKeJt9zhAgAve5FXHixTvFDW/5aEktX9bufBKLRRMdU7bNtpLfcGu94B3cdEJgjg==", "dev": true, "dependencies": { + "@aashutoshrathi/word-wrap": "^1.2.3", "deep-is": "^0.1.3", "fast-levenshtein": "^2.0.6", "levn": "^0.4.1", "prelude-ls": "^1.2.1", - "type-check": "^0.4.0", - "word-wrap": "^1.2.3" + "type-check": "^0.4.0" }, "engines": { "node": ">= 0.8.0" @@ -2411,9 +2420,9 @@ } }, "node_modules/vite": { - "version": "3.2.5", - "resolved": "https://registry.npmjs.org/vite/-/vite-3.2.5.tgz", - "integrity": "sha512-4mVEpXpSOgrssFZAOmGIr85wPHKvaDAcXqxVxVRZhljkJOMZi1ibLibzjLHzJvcok8BMguLc7g1W6W/GqZbLdQ==", + "version": "3.2.7", + "resolved": "https://registry.npmjs.org/vite/-/vite-3.2.7.tgz", + "integrity": "sha512-29pdXjk49xAP0QBr0xXqu2s5jiQIXNvE/xwd0vUizYT2Hzqe4BksNNoWllFVXJf4eLZ+UlVQmXfB4lWrc+t18g==", "dev": true, "dependencies": { "esbuild": "^0.15.9", @@ -2512,15 +2521,6 @@ "node": ">= 8" } }, - "node_modules/word-wrap": { - "version": "1.2.3", - "resolved": "https://registry.npmjs.org/word-wrap/-/word-wrap-1.2.3.tgz", - "integrity": "sha512-Hz/mrNwitNRh/HUAtM/VT/5VH+ygD6DV7mYKZAtHOrbs8U7lvPS6xf7EJKMF0uW1KJCl0H701g3ZGus+muE5vQ==", - "dev": true, - "engines": { - "node": ">=0.10.0" - } - }, "node_modules/wrappy": { "version": "1.0.2", "resolved": "https://registry.npmjs.org/wrappy/-/wrappy-1.0.2.tgz", diff --git a/src/battle-phases.ts b/src/battle-phases.ts index 13cb3da59d8..07733276e35 100644 --- a/src/battle-phases.ts +++ b/src/battle-phases.ts @@ -2316,15 +2316,18 @@ export class AttemptCapturePhase extends PokemonPhase { this.removePb(); this.end(); }; + const removePokemon = () => { + this.scene.getPlayerField().forEach(playerPokemon => playerPokemon.removeTagsBySourceId(pokemon.id)); + pokemon.hp = 0; + pokemon.trySetStatus(StatusEffect.FAINT); + this.scene.clearEnemyModifiers(); + this.scene.field.remove(pokemon, true); + }; const addToParty = () => { const newPokemon = pokemon.addToParty(); const modifiers = this.scene.findModifiers(m => m instanceof PokemonHeldItemModifier, false); Promise.all(modifiers.map(m => this.scene.addModifier(m))).then(() => { - this.scene.getPlayerField().forEach(playerPokemon => playerPokemon.removeTagsBySourceId(pokemon.id)); - pokemon.hp = 0; - pokemon.trySetStatus(StatusEffect.FAINT); - this.scene.clearEnemyModifiers(); - this.scene.field.remove(pokemon, true); + removePokemon(); if (newPokemon) newPokemon.loadAssets().then(end); else @@ -2345,9 +2348,10 @@ export class AttemptCapturePhase extends PokemonPhase { }); }); }, () => { - this.scene.ui.setMode(Mode.MESSAGE); - pokemon.hp = 0; - end(); + this.scene.ui.setMode(Mode.MESSAGE).then(() => { + removePokemon(); + end(); + }); }); }); };