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 { isNullOrUndefined, NumberHolder } from "#app/utils/common";
import type { RewardGenerator } from "./reward-generator";
@ -13,7 +14,7 @@ export interface CustomRewardSettings {
guaranteedModifierTypeOptions?: ModifierTypeOption[];
guaranteedModifierTypeFuncs?: ModifierTypeFunc[];
fillRemaining?: boolean;
/** Set to negative value to disable rerolls completely in shop */
//Set to negative value to disable rerolls completely in shop
rerollMultiplier?: number;
allowLuckUpgrades?: boolean;
}
@ -90,3 +91,4 @@ export class RewardPoolManager {
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();
this.typeOptions = this.getModifierTypeOptions(modifierCount.value);
this.typeOptions = this.getModifierTypeOptions(modifierCount);
const modifierSelectCallback = (rowCursor: number, cursor: number) => {
if (rowCursor < 0 || cursor < 0) {
@ -146,11 +146,31 @@ export class SelectModifierPhase extends BattlePhase {
}
private playBottomRowOption(cursor: number, modifierSelectCallback): boolean {
const party = globalScene.getPlayerParty();
const rerollCost = this.getRerollCost(globalScene.lockModifierTiers);
let success = false;
switch (cursor) {
// Reroll rewards
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) {
globalScene.ui.playError();
return false;
@ -170,9 +190,12 @@ export class SelectModifierPhase extends BattlePhase {
globalScene.animateMoneyChanged(false);
}
globalScene.playSound("se/buy");
break;
return true;
}
// Transfer modifiers among party pokemon
case 1:
private openModifierTransferScreen(modifierSelectCallback) {
const party = globalScene.getPlayerParty();
globalScene.ui.setModeWithoutClear(
UiMode.PARTY,
PartyUiMode.MODIFIER_TRANSFER,
@ -186,8 +209,7 @@ export class SelectModifierPhase extends BattlePhase {
itemIndex > -1
) {
const itemModifiers = globalScene.findModifiers(
m =>
m instanceof PokemonHeldItemModifier && m.isTransferable && m.pokemonId === party[fromSlotIndex].id,
m => m instanceof PokemonHeldItemModifier && m.isTransferable && m.pokemonId === party[fromSlotIndex].id,
) as PokemonHeldItemModifier[];
const itemModifier = itemModifiers[itemIndex];
globalScene.tryTransferHeldItemModifier(
@ -205,15 +227,12 @@ export class SelectModifierPhase extends BattlePhase {
},
PartyUiHandler.FilterItemMaxStacks,
);
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);
});
break;
return true;
}
// Toggle reroll lock
case 3:
private toggleRerollLock() {
const rerollCost = this.getRerollCost(globalScene.lockModifierTiers);
if (rerollCost < 0) {
// Reroll lock button is also disabled when reroll is disabled
globalScene.ui.playError();
@ -226,9 +245,8 @@ export class SelectModifierPhase extends BattlePhase {
uiHandler.updateRerollCostText();
return false;
}
return true;
}
// Applies the effects of the chosen modifier
private applyModifier(modifier: Modifier, cost = 0, playSound = false) {
const result = globalScene.addModifier(modifier, false, playSound, undefined, undefined, cost);
// 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) {
const party = globalScene.getPlayerParty();
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) {
const party = globalScene.getPlayerParty();
const pokemonModifierType = modifierType as PokemonModifierType;
@ -326,11 +346,11 @@ export class SelectModifierPhase extends BattlePhase {
}
// Function that determines how many reward slots are available
private getModifierCount() {
const modifierCount = new NumberHolder(3);
private getModifierCount(): number {
const modifierCountHolder = new NumberHolder(3);
if (this.isPlayer()) {
globalScene.applyModifiers(ExtraModifierModifier, true, modifierCount);
globalScene.applyModifiers(TempExtraModifierModifier, true, modifierCount);
globalScene.applyModifiers(ExtraModifierModifier, true, modifierCountHolder);
globalScene.applyModifiers(TempExtraModifierModifier, true, modifierCountHolder);
}
// 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.guaranteedModifierTypeFuncs?.length || 0);
if (this.customModifierSettings.fillRemaining) {
const originalCount = modifierCount.value;
modifierCount.value = originalCount > newItemCount ? originalCount : newItemCount;
const originalCount = modifierCountHolder.value;
modifierCountHolder.value = originalCount > newItemCount ? originalCount : newItemCount;
} 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) {
globalScene.ui.setMode(
UiMode.MODIFIER_SELECT,