Fix crashing issues

This commit is contained in:
Flashfyre 2023-06-06 10:14:53 -04:00
parent ffa4c60011
commit f7ca13d96e
5 changed files with 19 additions and 10 deletions

View File

@ -222,7 +222,7 @@ export class EncounterPhase extends BattlePhase {
this.scene.field.add(enemyPokemon); this.scene.field.add(enemyPokemon);
const playerPokemon = this.scene.getPlayerPokemon(); const playerPokemon = this.scene.getPlayerPokemon();
if (playerPokemon.visible) if (playerPokemon.visible)
this.scene.field.moveBelow(enemyPokemon, playerPokemon); this.scene.field.moveBelow(enemyPokemon as Pokemon, playerPokemon);
enemyPokemon.tint(0, 0.5); enemyPokemon.tint(0, 0.5);
if (battle.enemyField.length > 1) if (battle.enemyField.length > 1)
enemyPokemon.setFieldPosition(e ? FieldPosition.RIGHT : FieldPosition.LEFT); enemyPokemon.setFieldPosition(e ? FieldPosition.RIGHT : FieldPosition.LEFT);
@ -2128,18 +2128,20 @@ export class PokemonHealPhase extends CommonAnimPhase {
private message: string; private message: string;
private showFullHpMessage: boolean; private showFullHpMessage: boolean;
private skipAnim: boolean; private skipAnim: boolean;
private revive: boolean;
constructor(scene: BattleScene, battlerIndex: BattlerIndex, hpHealed: integer, message: string, showFullHpMessage: boolean, skipAnim?: boolean) { constructor(scene: BattleScene, battlerIndex: BattlerIndex, hpHealed: integer, message: string, showFullHpMessage: boolean, skipAnim?: boolean, revive?: boolean) {
super(scene, battlerIndex, undefined, CommonAnim.HEALTH_UP); super(scene, battlerIndex, undefined, CommonAnim.HEALTH_UP);
this.hpHealed = hpHealed; this.hpHealed = hpHealed;
this.message = message; this.message = message;
this.showFullHpMessage = showFullHpMessage; this.showFullHpMessage = showFullHpMessage;
this.skipAnim = !!skipAnim; this.skipAnim = !!skipAnim;
this.revive = !!revive;
} }
start() { start() {
if (!this.skipAnim && this.getPokemon().hp && this.getPokemon().getHpRatio() < 1) if (!this.skipAnim && (this.revive || this.getPokemon().hp) && this.getPokemon().getHpRatio() < 1)
super.start(); super.start();
else else
this.end(); this.end();
@ -2148,7 +2150,7 @@ export class PokemonHealPhase extends CommonAnimPhase {
end() { end() {
const pokemon = this.getPokemon(); const pokemon = this.getPokemon();
if (!this.getPokemon().isActive(true)) { if (!pokemon.isOnField() || (!this.revive && !pokemon.isActive())) {
super.end(); super.end();
return; return;
} }
@ -2157,6 +2159,7 @@ export class PokemonHealPhase extends CommonAnimPhase {
if (!fullHp) { if (!fullHp) {
const hpRestoreMultiplier = new Utils.IntegerHolder(1); const hpRestoreMultiplier = new Utils.IntegerHolder(1);
if (!this.revive)
this.scene.applyModifiers(HealingBoosterModifier, this.player, hpRestoreMultiplier); this.scene.applyModifiers(HealingBoosterModifier, this.player, hpRestoreMultiplier);
pokemon.hp = Math.min(pokemon.hp + this.hpHealed * hpRestoreMultiplier.value, pokemon.getMaxHp()); pokemon.hp = Math.min(pokemon.hp + this.hpHealed * hpRestoreMultiplier.value, pokemon.getMaxHp());
pokemon.updateInfo().then(() => super.end()); pokemon.updateInfo().then(() => super.end());
@ -2212,7 +2215,7 @@ export class AttemptCapturePhase extends PokemonPhase {
this.scene.sound.play('pb_throw'); this.scene.sound.play('pb_throw');
this.scene.time.delayedCall(300, () => { this.scene.time.delayedCall(300, () => {
this.scene.field.moveBelow(this.pokeball, pokemon); this.scene.field.moveBelow(this.pokeball as Phaser.GameObjects.GameObject, pokemon);
}); });
this.scene.tweens.add({ this.scene.tweens.add({
targets: this.pokeball, targets: this.pokeball,

View File

@ -668,13 +668,13 @@ export default class BattleScene extends Phaser.Scene {
} }
playBgm(bgmName?: string, loopPoint?: number): void { playBgm(bgmName?: string, loopPoint?: number): void {
if (!bgmName && this.bgm) { if (!bgmName && this.bgm && !this.bgm.pendingRemove) {
this.bgm.play({ this.bgm.play({
volume: 1 volume: 1
}); });
return; return;
} }
if (this.bgm && this.bgm.isPlaying) if (this.bgm && !this.bgm.pendingRemove && this.bgm.isPlaying)
this.bgm.stop(); this.bgm.stop();
this.bgm = this.sound.add(bgmName, { loop: true }); this.bgm = this.sound.add(bgmName, { loop: true });
this.bgm.play(); this.bgm.play();

View File

@ -760,6 +760,7 @@ const enemyModifierPool = {
new WeightedModifierType(modifierTypes.BASE_STAT_BOOSTER, 1) new WeightedModifierType(modifierTypes.BASE_STAT_BOOSTER, 1)
].map(m => { m.setTier(ModifierTier.GREAT); return m; }), ].map(m => { m.setTier(ModifierTier.GREAT); return m; }),
[ModifierTier.ULTRA]: [ [ModifierTier.ULTRA]: [
new WeightedModifierType(modifierTypes.REVIVER_SEED, 2),
new WeightedModifierType(modifierTypes.ATTACK_TYPE_BOOSTER, 10), new WeightedModifierType(modifierTypes.ATTACK_TYPE_BOOSTER, 10),
new WeightedModifierType(modifierTypes.FOCUS_BAND, 2), new WeightedModifierType(modifierTypes.FOCUS_BAND, 2),
new WeightedModifierType(modifierTypes.LUCKY_EGG, 4), new WeightedModifierType(modifierTypes.LUCKY_EGG, 4),

View File

@ -682,7 +682,8 @@ export class PokemonInstantReviveModifier extends PokemonHeldItemModifier {
apply(args: any[]): boolean { apply(args: any[]): boolean {
const pokemon = args[0] as Pokemon; const pokemon = args[0] as Pokemon;
pokemon.scene.unshiftPhase(new PokemonHealPhase(pokemon.scene, pokemon.getBattlerIndex(), Math.max(Math.floor(pokemon.getMaxHp() / 2)), getPokemonMessage(pokemon, ` was revived\nby its ${this.type.name}!`), false)); pokemon.scene.unshiftPhase(new PokemonHealPhase(pokemon.scene, pokemon.getBattlerIndex(),
Math.max(Math.floor(pokemon.getMaxHp() / 2), 1),getPokemonMessage(pokemon, ` was revived\nby its ${this.type.name}!`), false, false, true));
return true; return true;
} }

View File

@ -188,12 +188,16 @@ export default abstract class Pokemon extends Phaser.GameObjects.Container {
} }
} }
isOnField(): boolean {
return this.scene.field.getIndex(this) > -1;
}
isFainted(checkStatus?: boolean): boolean { isFainted(checkStatus?: boolean): boolean {
return !this.hp && (!checkStatus || this.status?.effect === StatusEffect.FAINT); return !this.hp && (!checkStatus || this.status?.effect === StatusEffect.FAINT);
} }
isActive(onField?: boolean): boolean { isActive(onField?: boolean): boolean {
return !this.isFainted() && !!this.scene && (!onField || this.scene.field.getIndex(this) > -1); return !this.isFainted() && !!this.scene && (!onField || this.isOnField());
} }
abstract isPlayer(): boolean; abstract isPlayer(): boolean;