Improve release logic

pull/1/head
Flashfyre 2023-04-11 09:41:11 -04:00
parent 53ab693bad
commit 50ce6c0791
4 changed files with 75 additions and 26 deletions

View File

@ -803,7 +803,7 @@ export class SwitchPhase extends BattlePhase {
start() { start() {
super.start(); super.start();
this.scene.ui.setMode(Mode.PARTY, this.isModal ? PartyUiMode.FAINT_SWITCH : PartyUiMode.SWITCH, (slotIndex: integer) => { this.scene.ui.setMode(Mode.PARTY, this.isModal ? PartyUiMode.FAINT_SWITCH : PartyUiMode.POST_BATTLE_SWITCH, (slotIndex: integer) => {
if (slotIndex && slotIndex < 6) if (slotIndex && slotIndex < 6)
this.scene.unshiftPhase(new SwitchSummonPhase(this.scene, slotIndex, this.doReturn)); this.scene.unshiftPhase(new SwitchSummonPhase(this.scene, slotIndex, this.doReturn));
this.scene.ui.setMode(Mode.MESSAGE).then(() => super.end()); this.scene.ui.setMode(Mode.MESSAGE).then(() => super.end());
@ -1114,10 +1114,9 @@ export class AttemptCapturePhase extends BattlePhase {
this.scene.ui.setMode(Mode.CONFIRM, () => { this.scene.ui.setMode(Mode.CONFIRM, () => {
this.scene.ui.setMode(Mode.PARTY, PartyUiMode.RELEASE, (slotIndex: integer) => { this.scene.ui.setMode(Mode.PARTY, PartyUiMode.RELEASE, (slotIndex: integer) => {
this.scene.ui.setMode(Mode.MESSAGE).then(() => { this.scene.ui.setMode(Mode.MESSAGE).then(() => {
if (slotIndex < 6) { if (slotIndex < 6)
this.scene.getParty().splice(slotIndex, 1);
addToParty(); addToParty();
} else else
promptRelease(); promptRelease();
}); });
}); });

View File

@ -5,7 +5,7 @@ import { EncounterPhase, SummonPhase, CommandPhase, NextEncounterPhase, SwitchBi
import { PlayerPokemon, EnemyPokemon } from './pokemon'; import { PlayerPokemon, EnemyPokemon } from './pokemon';
import PokemonSpecies, { allSpecies, getPokemonSpecies } from './pokemon-species'; import PokemonSpecies, { allSpecies, getPokemonSpecies } from './pokemon-species';
import * as Utils from './utils'; import * as Utils from './utils';
import { Modifier, ModifierBar, ConsumablePokemonModifier, ConsumableModifier, PartyShareModifier, PokemonHpRestoreModifier, HealingBoosterModifier, PersistentModifier } from './modifier'; import { Modifier, ModifierBar, ConsumablePokemonModifier, ConsumableModifier, PartyShareModifier, PokemonHpRestoreModifier, HealingBoosterModifier, PersistentModifier, PokemonHeldItemModifier } from './modifier';
import { PokeballType } from './pokeball'; import { PokeballType } from './pokeball';
import { Species } from './species'; import { Species } from './species';
import { initAutoPlay } from './auto-play'; import { initAutoPlay } from './auto-play';
@ -536,15 +536,18 @@ export default class BattleScene extends Phaser.Scene {
}); });
} }
updatePartyForModifiers(): Promise<void> { removePartyMemberModifiers(partyMemberIndex: integer): Promise<void> {
return new Promise(resolve => { return new Promise(resolve => {
Promise.allSettled(this.party.map(p => { const pokemonId = this.getParty()[partyMemberIndex].id;
p.calculateStats(); const modifiersToRemove = this.modifiers.filter(m => (m instanceof PokemonHeldItemModifier) && (m as PokemonHeldItemModifier).pokemonId === pokemonId);
return p.updateInfo(); for (let m of modifiersToRemove)
})).then(() => resolve()); this.modifiers.splice(this.modifiers.indexOf(m), 1);
this.updateModifiers().then(() => resolve());
}); });
} }
updateModifiers(): Promise<void> { updateModifiers(): Promise<void> {
return new Promise(resolve => { return new Promise(resolve => {
for (let modifier of this.modifiers) { for (let modifier of this.modifiers) {
@ -567,6 +570,15 @@ export default class BattleScene extends Phaser.Scene {
}); });
} }
updatePartyForModifiers(): Promise<void> {
return new Promise(resolve => {
Promise.allSettled(this.party.map(p => {
p.calculateStats();
return p.updateInfo();
})).then(() => resolve());
});
}
getModifier(modifierType: { new(...args: any[]): Modifier }): Modifier { getModifier(modifierType: { new(...args: any[]): Modifier }): Modifier {
return this.modifiers.find(m => m instanceof modifierType); return this.modifiers.find(m => m instanceof modifierType);
} }

View File

@ -151,19 +151,16 @@ export default class PartyUiHandler extends MessageUiHandler {
if (button === Button.ACTION) { if (button === Button.ACTION) {
const option = this.options[this.optionsCursor]; const option = this.options[this.optionsCursor];
const pokemon = this.scene.getParty()[this.cursor]; const pokemon = this.scene.getParty()[this.cursor];
if (option === PartyOption.SHIFT || option === PartyOption.SEND_OUT || option === PartyOption.APPLY || option === PartyOption.RELEASE) { if (option === PartyOption.SHIFT || option === PartyOption.SEND_OUT || option === PartyOption.APPLY
|| (this.partyUiMode === PartyUiMode.RELEASE && option === PartyOption.RELEASE)) {
let filterResult: string = this.selectFilter(pokemon); let filterResult: string = this.selectFilter(pokemon);
if (filterResult === null) { if (filterResult === null) {
this.clearOptions(); this.clearOptions();
if (this.selectCallback) { if (this.selectCallback) {
const selectCallback = this.selectCallback; if (option === PartyOption.RELEASE)
if (option === PartyOption.RELEASE) { this.doRelease(this.cursor);
this.partyMessageBox.setTexture('party_message'); else {
this.showText(this.getReleaseMessage(pokemon.name), null, () => { const selectCallback = this.selectCallback;
this.selectCallback = null;
selectCallback(this.cursor);
}, null, true);
} else {
this.selectCallback = null; this.selectCallback = null;
selectCallback(this.cursor); selectCallback(this.cursor);
} }
@ -185,6 +182,21 @@ export default class PartyUiHandler extends MessageUiHandler {
} else if (option === PartyOption.SUMMARY) { } else if (option === PartyOption.SUMMARY) {
ui.playSelect(); ui.playSelect();
ui.setModeWithoutClear(Mode.SUMMARY, pokemon).then(() => this.clearOptions()); ui.setModeWithoutClear(Mode.SUMMARY, pokemon).then(() => this.clearOptions());
} else if (option === PartyOption.RELEASE) {
this.clearOptions();
ui.playSelect();
if (this.cursor) {
this.showText(`Do you really want to release ${pokemon.name}?`, null, () => {
ui.setModeWithoutClear(Mode.CONFIRM, () => {
ui.setMode(Mode.PARTY);
this.doRelease(this.cursor);
}, () => {
ui.setMode(Mode.PARTY);
this.message.setText(defaultMessage);
});
});
} else
this.showText('You can\'t release a POKéMON that\'s in battle!', null, () => this.message.setText(defaultMessage), null, true);
} else if (option === PartyOption.CANCEL) } else if (option === PartyOption.CANCEL)
this.processInput(Button.CANCEL); this.processInput(Button.CANCEL);
} else if (button === Button.CANCEL) { } else if (button === Button.CANCEL) {
@ -331,7 +343,12 @@ export default class PartyUiHandler extends MessageUiHandler {
break; break;
} }
this.options.push(PartyOption.SUMMARY, PartyOption.CANCEL); this.options.push(PartyOption.SUMMARY);
if (this.partyUiMode === PartyUiMode.SWITCH)
this.options.push(PartyOption.RELEASE);
this.options.push(PartyOption.CANCEL);
for (let o = 0; o < this.options.length; o++) { for (let o = 0; o < this.options.length; o++) {
const yCoord = -6 - 16 * o; const yCoord = -6 - 16 * o;
@ -352,13 +369,34 @@ export default class PartyUiHandler extends MessageUiHandler {
this.setCursor(0); this.setCursor(0);
} }
doRelease(slotIndex: integer): void {
this.showText(this.getReleaseMessage(this.scene.getParty()[slotIndex].name), null, () => {
this.clearPartySlots();
this.scene.removePartyMemberModifiers(slotIndex);
this.scene.getParty().splice(slotIndex, 1);
this.populatePartySlots();
if (this.cursor >= this.scene.getParty().length)
this.setCursor(this.cursor - 1);
if (this.partyUiMode === PartyUiMode.RELEASE) {
const selectCallback = this.selectCallback;
this.selectCallback = null;
selectCallback(this.cursor);
} else
this.message.setText(defaultMessage);
}, null, true);
}
getReleaseMessage(pokemonName: string): string { getReleaseMessage(pokemonName: string): string {
const rand = Utils.randInt(128); const rand = Utils.randInt(128);
if (rand < 32) if (rand < 20)
return `Goodbye, ${pokemonName}!`; return `Goodbye, ${pokemonName}!`;
else if (rand < 64) else if (rand < 40)
return `Byebye, ${pokemonName}!`;
else if (rand < 60)
return `Farewell, ${pokemonName}!`; return `Farewell, ${pokemonName}!`;
else if (rand < 96) else if (rand < 80)
return `So long, ${pokemonName}!`;
else if (rand < 100)
return `This is where we part, ${pokemonName}!`; return `This is where we part, ${pokemonName}!`;
else if (rand < 108) else if (rand < 108)
return `I'll miss you, ${pokemonName}!`; return `I'll miss you, ${pokemonName}!`;

View File

@ -17,9 +17,9 @@ export enum Mode {
COMMAND, COMMAND,
FIGHT, FIGHT,
BALL, BALL,
CONFIRM,
MODIFIER_SELECT, MODIFIER_SELECT,
PARTY, PARTY,
CONFIRM,
SUMMARY, SUMMARY,
STARTER_SELECT, STARTER_SELECT,
EVOLUTION_SCENE EVOLUTION_SCENE
@ -52,9 +52,9 @@ export default class UI extends Phaser.GameObjects.Container {
new CommandUiHandler(scene), new CommandUiHandler(scene),
new FightUiHandler(scene), new FightUiHandler(scene),
new BallUiHandler(scene), new BallUiHandler(scene),
new ConfirmUiHandler(scene),
new ModifierSelectUiHandler(scene), new ModifierSelectUiHandler(scene),
new PartyUiHandler(scene), new PartyUiHandler(scene),
new ConfirmUiHandler(scene),
new SummaryUiHandler(scene), new SummaryUiHandler(scene),
new StarterSelectUiHandler(scene), new StarterSelectUiHandler(scene),
new EvolutionSceneHandler(scene) new EvolutionSceneHandler(scene)