New refactors of select-modifier-phase.ts

This commit is contained in:
Wlowscha 2025-05-29 11:56:45 +02:00
parent f849c0c8e7
commit 2a13e2ac5a
No known key found for this signature in database
GPG Key ID: 3C8F1AD330565D04
3 changed files with 101 additions and 78 deletions

View File

@ -1,3 +1,4 @@
/**
import { globalScene } from "#app/global-scene"; import { globalScene } from "#app/global-scene";
import { isNullOrUndefined, NumberHolder } from "#app/utils/common"; import { isNullOrUndefined, NumberHolder } from "#app/utils/common";
import type { RewardGenerator } from "./reward-generator"; import type { RewardGenerator } from "./reward-generator";
@ -13,7 +14,7 @@ export interface CustomRewardSettings {
guaranteedModifierTypeOptions?: ModifierTypeOption[]; guaranteedModifierTypeOptions?: ModifierTypeOption[];
guaranteedModifierTypeFuncs?: ModifierTypeFunc[]; guaranteedModifierTypeFuncs?: ModifierTypeFunc[];
fillRemaining?: boolean; fillRemaining?: boolean;
/** Set to negative value to disable rerolls completely in shop */ //Set to negative value to disable rerolls completely in shop
rerollMultiplier?: number; rerollMultiplier?: number;
allowLuckUpgrades?: boolean; allowLuckUpgrades?: boolean;
} }
@ -90,3 +91,4 @@ export class RewardPoolManager {
return modifierCount; return modifierCount;
} }
} }
*/

View File

@ -140,5 +140,4 @@ export class RewardManager {
} }
} }
*/ */

View File

@ -68,7 +68,7 @@ export class SelectModifierPhase extends BattlePhase {
} }
const modifierCount = this.getModifierCount(); const modifierCount = this.getModifierCount();
this.typeOptions = this.getModifierTypeOptions(modifierCount.value); this.typeOptions = this.getModifierTypeOptions(modifierCount);
const modifierSelectCallback = (rowCursor: number, cursor: number) => { const modifierSelectCallback = (rowCursor: number, cursor: number) => {
if (rowCursor < 0 || cursor < 0) { if (rowCursor < 0 || cursor < 0) {
@ -146,11 +146,31 @@ export class SelectModifierPhase extends BattlePhase {
} }
private playBottomRowOption(cursor: number, modifierSelectCallback): boolean { private playBottomRowOption(cursor: number, modifierSelectCallback): boolean {
const party = globalScene.getPlayerParty(); let success = false;
const rerollCost = this.getRerollCost(globalScene.lockModifierTiers);
switch (cursor) { switch (cursor) {
// Reroll rewards
case 0: case 0:
success = this.rerollModifiers();
break;
case 1:
success = this.openModifierTransferScreen(modifierSelectCallback);
break;
// Check the party, pass a callback to restore the modifier select screen.
case 2:
globalScene.ui.setModeWithoutClear(UiMode.PARTY, PartyUiMode.CHECK, -1, () => {
this.resetModifierSelect(modifierSelectCallback);
});
success = true;
break;
case 3:
success = this.toggleRerollLock();
break;
}
return success;
}
// Reroll rewards
private rerollModifiers() {
const rerollCost = this.getRerollCost(globalScene.lockModifierTiers);
if (rerollCost < 0 || globalScene.money < rerollCost) { if (rerollCost < 0 || globalScene.money < rerollCost) {
globalScene.ui.playError(); globalScene.ui.playError();
return false; return false;
@ -170,9 +190,12 @@ export class SelectModifierPhase extends BattlePhase {
globalScene.animateMoneyChanged(false); globalScene.animateMoneyChanged(false);
} }
globalScene.playSound("se/buy"); globalScene.playSound("se/buy");
break; return true;
}
// Transfer modifiers among party pokemon // Transfer modifiers among party pokemon
case 1: private openModifierTransferScreen(modifierSelectCallback) {
const party = globalScene.getPlayerParty();
globalScene.ui.setModeWithoutClear( globalScene.ui.setModeWithoutClear(
UiMode.PARTY, UiMode.PARTY,
PartyUiMode.MODIFIER_TRANSFER, PartyUiMode.MODIFIER_TRANSFER,
@ -186,8 +209,7 @@ export class SelectModifierPhase extends BattlePhase {
itemIndex > -1 itemIndex > -1
) { ) {
const itemModifiers = globalScene.findModifiers( const itemModifiers = globalScene.findModifiers(
m => m => m instanceof PokemonHeldItemModifier && m.isTransferable && m.pokemonId === party[fromSlotIndex].id,
m instanceof PokemonHeldItemModifier && m.isTransferable && m.pokemonId === party[fromSlotIndex].id,
) as PokemonHeldItemModifier[]; ) as PokemonHeldItemModifier[];
const itemModifier = itemModifiers[itemIndex]; const itemModifier = itemModifiers[itemIndex];
globalScene.tryTransferHeldItemModifier( globalScene.tryTransferHeldItemModifier(
@ -205,15 +227,12 @@ export class SelectModifierPhase extends BattlePhase {
}, },
PartyUiHandler.FilterItemMaxStacks, PartyUiHandler.FilterItemMaxStacks,
); );
break; return true;
// Check the party, pass a callback to restore the modifier select screen. }
case 2:
globalScene.ui.setModeWithoutClear(UiMode.PARTY, PartyUiMode.CHECK, -1, () => {
this.resetModifierSelect(modifierSelectCallback);
});
break;
// Toggle reroll lock // Toggle reroll lock
case 3: private toggleRerollLock() {
const rerollCost = this.getRerollCost(globalScene.lockModifierTiers);
if (rerollCost < 0) { if (rerollCost < 0) {
// Reroll lock button is also disabled when reroll is disabled // Reroll lock button is also disabled when reroll is disabled
globalScene.ui.playError(); globalScene.ui.playError();
@ -226,9 +245,8 @@ export class SelectModifierPhase extends BattlePhase {
uiHandler.updateRerollCostText(); uiHandler.updateRerollCostText();
return false; return false;
} }
return true;
}
// Applies the effects of the chosen modifier
private applyModifier(modifier: Modifier, cost = 0, playSound = false) { private applyModifier(modifier: Modifier, cost = 0, playSound = false) {
const result = globalScene.addModifier(modifier, false, playSound, undefined, undefined, cost); const result = globalScene.addModifier(modifier, false, playSound, undefined, undefined, cost);
// Queue a copy of this phase when applying a TM or Memory Mushroom. // Queue a copy of this phase when applying a TM or Memory Mushroom.
@ -257,6 +275,7 @@ export class SelectModifierPhase extends BattlePhase {
} }
} }
// Opens the party menu specifically for fusions
private openFusionMenu(modifierType, cost, modifierSelectCallback) { private openFusionMenu(modifierType, cost, modifierSelectCallback) {
const party = globalScene.getPlayerParty(); const party = globalScene.getPlayerParty();
globalScene.ui.setModeWithoutClear( globalScene.ui.setModeWithoutClear(
@ -282,6 +301,7 @@ export class SelectModifierPhase extends BattlePhase {
); );
} }
// Opens the party menu to apply one of various modifiers
private openModifierMenu(modifierType, cost, modifierSelectCallback) { private openModifierMenu(modifierType, cost, modifierSelectCallback) {
const party = globalScene.getPlayerParty(); const party = globalScene.getPlayerParty();
const pokemonModifierType = modifierType as PokemonModifierType; const pokemonModifierType = modifierType as PokemonModifierType;
@ -326,11 +346,11 @@ export class SelectModifierPhase extends BattlePhase {
} }
// Function that determines how many reward slots are available // Function that determines how many reward slots are available
private getModifierCount() { private getModifierCount(): number {
const modifierCount = new NumberHolder(3); const modifierCountHolder = new NumberHolder(3);
if (this.isPlayer()) { if (this.isPlayer()) {
globalScene.applyModifiers(ExtraModifierModifier, true, modifierCount); globalScene.applyModifiers(ExtraModifierModifier, true, modifierCountHolder);
globalScene.applyModifiers(TempExtraModifierModifier, true, modifierCount); globalScene.applyModifiers(TempExtraModifierModifier, true, modifierCountHolder);
} }
// If custom modifiers are specified, overrides default item count // If custom modifiers are specified, overrides default item count
@ -340,16 +360,18 @@ export class SelectModifierPhase extends BattlePhase {
(this.customModifierSettings.guaranteedModifierTypeOptions?.length || 0) + (this.customModifierSettings.guaranteedModifierTypeOptions?.length || 0) +
(this.customModifierSettings.guaranteedModifierTypeFuncs?.length || 0); (this.customModifierSettings.guaranteedModifierTypeFuncs?.length || 0);
if (this.customModifierSettings.fillRemaining) { if (this.customModifierSettings.fillRemaining) {
const originalCount = modifierCount.value; const originalCount = modifierCountHolder.value;
modifierCount.value = originalCount > newItemCount ? originalCount : newItemCount; modifierCountHolder.value = originalCount > newItemCount ? originalCount : newItemCount;
} else { } else {
modifierCount.value = newItemCount; modifierCountHolder.value = newItemCount;
} }
} }
return modifierCount; return modifierCountHolder.value;
} }
// Function that resets the reward selection screen,
// e.g. after pressing cancel in the party ui or while learning a move
private resetModifierSelect(modifierSelectCallback) { private resetModifierSelect(modifierSelectCallback) {
globalScene.ui.setMode( globalScene.ui.setMode(
UiMode.MODIFIER_SELECT, UiMode.MODIFIER_SELECT,