From 326918a5f1a83d7eeaefcef2affff9548030c595 Mon Sep 17 00:00:00 2001 From: Flashfyre Date: Thu, 4 Apr 2024 15:22:05 -0400 Subject: [PATCH] Add retry option (easy mode) --- src/battle-scene.ts | 1 + src/phases.ts | 32 ++++++++++++++++++++++ src/system/settings.ts | 18 ++++++++---- src/ui/abstact-option-select-ui-handler.ts | 16 +++++++++++ src/ui/biome-select-ui-handler.ts | 12 ++++++++ src/ui/confirm-ui-handler.ts | 3 +- 6 files changed, 75 insertions(+), 7 deletions(-) diff --git a/src/battle-scene.ts b/src/battle-scene.ts index abf347b18..13545263e 100644 --- a/src/battle-scene.ts +++ b/src/battle-scene.ts @@ -116,6 +116,7 @@ export default class BattleScene extends SceneBase { public damageNumbersMode: integer = 0; public showLevelUpStats: boolean = true; public enableTutorials: boolean = import.meta.env.VITE_BYPASS_TUTORIAL === "1"; + public enableRetries: boolean = false; public uiTheme: UiTheme = UiTheme.DEFAULT; public windowType: integer = 0; public experimentalSprites: boolean = false; diff --git a/src/phases.ts b/src/phases.ts index 4fb7517e3..13762ae4b 100644 --- a/src/phases.ts +++ b/src/phases.ts @@ -3175,6 +3175,38 @@ export class GameOverPhase extends BattlePhase { start() { super.start(); + if (this.victory || !this.scene.enableRetries) + this.handleClearSession(); + else { + this.scene.ui.showText(`Would you like to retry from the start of the battle?`, null, () => { + this.scene.ui.setMode(Mode.CONFIRM, () => { + this.scene.ui.fadeOut(1250).then(() => { + this.scene.reset(); + this.scene.clearPhaseQueue(); + this.scene.gameData.loadSession(this.scene, this.scene.sessionSlotId).then(() => { + this.scene.pushPhase(new EncounterPhase(this.scene, true)); + + const availablePartyMembers = this.scene.getParty().filter(p => !p.isFainted()).length; + + this.scene.pushPhase(new SummonPhase(this.scene, 0)); + if (this.scene.currentBattle.double && availablePartyMembers > 1) + this.scene.pushPhase(new SummonPhase(this.scene, 1)); + if (this.scene.currentBattle.waveIndex > 1 && this.scene.currentBattle.battleType !== BattleType.TRAINER) { + this.scene.pushPhase(new CheckSwitchPhase(this.scene, 0, this.scene.currentBattle.double)); + if (this.scene.currentBattle.double && availablePartyMembers > 1) + this.scene.pushPhase(new CheckSwitchPhase(this.scene, 1, this.scene.currentBattle.double)); + } + + this.scene.ui.fadeIn(1250); + this.end(); + }); + }); + }, () => this.handleClearSession(), false, 0, 0, 1000); + }); + } + } + + handleClearSession(): void { this.scene.gameData.tryClearSession(this.scene, this.scene.sessionSlotId).then((success: boolean | [boolean, boolean]) => { this.scene.time.delayedCall(1000, () => { let firstClear = false; diff --git a/src/system/settings.ts b/src/system/settings.ts index 3da3c46a5..adeddd367 100644 --- a/src/system/settings.ts +++ b/src/system/settings.ts @@ -9,11 +9,12 @@ export enum Setting { BGM_Volume = "BGM_VOLUME", SE_Volume = "SE_VOLUME", Damage_Numbers = "DAMAGE_NUMBERS", - Show_Stats_on_Level_Up = "SHOW_LEVEL_UP_STATS", UI_Theme = "UI_THEME", Window_Type = "WINDOW_TYPE", Tutorials = "TUTORIALS", + Enable_Retries = "ENABLE_RETRIES", Sprite_Set = "SPRITE_SET", + Show_Stats_on_Level_Up = "SHOW_LEVEL_UP_STATS", Fusion_Palette_Swaps = "FUSION_PALETTE_SWAPS", Player_Gender = "PLAYER_GENDER", Touch_Controls = "TOUCH_CONTROLS", @@ -34,11 +35,12 @@ export const settingOptions: SettingOptions = { [Setting.BGM_Volume]: new Array(11).fill(null).map((_, i) => i ? (i * 10).toString() : 'Mute'), [Setting.SE_Volume]: new Array(11).fill(null).map((_, i) => i ? (i * 10).toString() : 'Mute'), [Setting.Damage_Numbers]: [ 'Off', 'Simple', 'Fancy' ], - [Setting.Show_Stats_on_Level_Up]: [ 'Off', 'On' ], [Setting.UI_Theme]: [ 'Default', 'Legacy' ], [Setting.Window_Type]: new Array(5).fill(null).map((_, i) => (i + 1).toString()), [Setting.Tutorials]: [ 'Off', 'On' ], + [Setting.Enable_Retries]: [ 'Off', 'On' ], [Setting.Sprite_Set]: [ 'Consistent', 'Prioritize Animation' ], + [Setting.Show_Stats_on_Level_Up]: [ 'Off', 'On' ], [Setting.Fusion_Palette_Swaps]: [ 'Off', 'On' ], [Setting.Player_Gender]: [ 'Boy', 'Girl' ], [Setting.Touch_Controls]: [ 'Auto', 'Disabled' ], @@ -51,11 +53,12 @@ export const settingDefaults: SettingDefaults = { [Setting.BGM_Volume]: 10, [Setting.SE_Volume]: 10, [Setting.Damage_Numbers]: 0, - [Setting.Show_Stats_on_Level_Up]: 1, [Setting.UI_Theme]: 0, [Setting.Window_Type]: 0, [Setting.Tutorials]: 1, + [Setting.Enable_Retries]: 0, [Setting.Sprite_Set]: 0, + [Setting.Show_Stats_on_Level_Up]: 1, [Setting.Fusion_Palette_Swaps]: 1, [Setting.Player_Gender]: 0, [Setting.Touch_Controls]: 0, @@ -84,9 +87,6 @@ export function setSetting(scene: BattleScene, setting: Setting, value: integer) case Setting.Damage_Numbers: scene.damageNumbersMode = value; break; - case Setting.Show_Stats_on_Level_Up: - scene.showLevelUpStats = settingOptions[setting][value] === 'On'; - break; case Setting.UI_Theme: scene.uiTheme = value; break; @@ -96,11 +96,17 @@ export function setSetting(scene: BattleScene, setting: Setting, value: integer) case Setting.Tutorials: scene.enableTutorials = settingOptions[setting][value] === 'On'; break; + case Setting.Enable_Retries: + scene.enableRetries = settingOptions[setting][value] === 'On'; + break; case Setting.Sprite_Set: scene.experimentalSprites = !!value; if (value) scene.initExpSprites(); break; + case Setting.Show_Stats_on_Level_Up: + scene.showLevelUpStats = settingOptions[setting][value] === 'On'; + break; case Setting.Fusion_Palette_Swaps: scene.fusionPaletteSwaps = !!value; break; diff --git a/src/ui/abstact-option-select-ui-handler.ts b/src/ui/abstact-option-select-ui-handler.ts index 910f490a9..92a1963f3 100644 --- a/src/ui/abstact-option-select-ui-handler.ts +++ b/src/ui/abstact-option-select-ui-handler.ts @@ -3,12 +3,14 @@ import { TextStyle, addTextObject } from "./text"; import { Mode } from "./ui"; import UiHandler from "./ui-handler"; import { addWindow } from "./ui-theme"; +import * as Utils from "../utils"; export interface OptionSelectConfig { xOffset?: number; yOffset?: number; options: OptionSelectItem[]; maxOptions?: integer; + delay?: integer; noCancel?: boolean; } @@ -29,6 +31,8 @@ export default abstract class AbstractOptionSelectUiHandler extends UiHandler { protected config: OptionSelectConfig; + protected blockInput: boolean; + protected scrollCursor: integer = 0; private cursorObj: Phaser.GameObjects.Image; @@ -93,10 +97,22 @@ export default abstract class AbstractOptionSelectUiHandler extends UiHandler { this.scrollCursor = 0; this.setCursor(0); + if (this.config.delay) { + this.blockInput = true; + this.optionSelectText.setAlpha(0.5); + this.scene.time.delayedCall(Utils.fixedInt(this.config.delay), () => { + this.blockInput = false; + this.optionSelectText.setAlpha(1); + }); + } + return true; } processInput(button: Button): boolean { + if (this.blockInput) + return false; + const ui = this.getUi(); let success = false; diff --git a/src/ui/biome-select-ui-handler.ts b/src/ui/biome-select-ui-handler.ts index 8321488c4..ff0a6a882 100644 --- a/src/ui/biome-select-ui-handler.ts +++ b/src/ui/biome-select-ui-handler.ts @@ -15,6 +15,8 @@ export default class BiomeSelectUiHandler extends UiHandler { private cursorObj: Phaser.GameObjects.Image; + private blockInput: boolean; + private biomeSelectHandler: Function; constructor(scene: BattleScene) { @@ -59,12 +61,22 @@ export default class BiomeSelectUiHandler extends UiHandler { this.biomeSelectContainer.setVisible(true); this.setCursor(0); + + this.blockInput = true; + this.biomesText.setAlpha(0.5); + this.scene.time.delayedCall(Utils.fixedInt(1000), () => { + this.blockInput = false; + this.biomesText.setAlpha(1); + }); } return true; } processInput(button: Button): boolean { + if (this.blockInput) + return false; + const ui = this.getUi(); let success = false; diff --git a/src/ui/confirm-ui-handler.ts b/src/ui/confirm-ui-handler.ts index b7ac2ff77..7f0efb6ca 100644 --- a/src/ui/confirm-ui-handler.ts +++ b/src/ui/confirm-ui-handler.ts @@ -26,7 +26,8 @@ export default class ConfirmUiHandler extends AbstractOptionSelectUiHandler { label: 'No', handler: args[1] } - ] + ], + delay: args.length >= 6 && args[5] !== null ? args[5] as integer : 0 }; super.show([ config ]);