Extracted logic from modifierSelectCallback

This commit is contained in:
Wlowscha 2025-05-29 12:59:19 +02:00
parent 2a13e2ac5a
commit d769bd7f11
No known key found for this signature in database
GPG Key ID: 3C8F1AD330565D04

View File

@ -85,26 +85,53 @@ export class SelectModifierPhase extends BattlePhase {
});
return false;
}
let modifierType: ModifierType;
let cost = 0;
switch (rowCursor) {
// Execute option from the bottom row
// Execute one of the options from the bottom row
case 0:
return this.playBottomRowOption(cursor, modifierSelectCallback);
switch (cursor) {
case 0:
return this.rerollModifiers();
case 1:
return this.openModifierTransferScreen(modifierSelectCallback);
// 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);
});
return true;
case 3:
return this.toggleRerollLock();
default:
return false;
}
// Pick an option from the rewards
case 1:
return this.selectRewardModifierOption(cursor, modifierSelectCallback);
// Pick an option from the shop
default: {
return this.selectShopModifierOption(rowCursor, cursor, modifierSelectCallback);
}
}
};
this.resetModifierSelect(modifierSelectCallback);
}
// Pick a modifier from among the rewards and apply it
private selectRewardModifierOption(cursor: number, modifierSelectCallback): boolean {
if (this.typeOptions.length === 0) {
globalScene.ui.clearText();
globalScene.ui.setMode(UiMode.MESSAGE);
super.end();
return true;
}
if (this.typeOptions[cursor].type) {
modifierType = this.typeOptions[cursor].type;
const modifierType = this.typeOptions[cursor].type;
return this.applyChosenModifier(modifierType, 0, modifierSelectCallback);
}
break;
// Pick an option from the shop
default: {
// Pick a modifier from the shop and apply it
private selectShopModifierOption(rowCursor: number, cursor: number, modifierSelectCallback): boolean {
const shopOptions = getPlayerShopModifierTypeOptionsForWave(
globalScene.currentBattle.waveIndex,
globalScene.getWaveMoneyAmount(1),
@ -113,22 +140,22 @@ export class SelectModifierPhase extends BattlePhase {
shopOptions[
rowCursor > 2 || shopOptions.length <= SHOP_OPTIONS_ROW_LIMIT ? cursor : cursor + SHOP_OPTIONS_ROW_LIMIT
];
if (shopOption.type) {
modifierType = shopOption.type;
}
const modifierType = shopOption.type;
// Apply Black Sludge to healing item cost
const healingItemCost = new NumberHolder(shopOption.cost);
globalScene.applyModifier(HealShopCostModifier, true, healingItemCost);
cost = healingItemCost.value;
break;
}
}
const cost = healingItemCost.value;
if (cost! && globalScene.money < cost && !Overrides.WAIVE_ROLL_FEE_OVERRIDE) {
if (globalScene.money < cost && !Overrides.WAIVE_ROLL_FEE_OVERRIDE) {
globalScene.ui.playError();
return false;
}
return this.applyChosenModifier(modifierType, cost, modifierSelectCallback);
}
// Apply a chosen modifier: do an effect or open the party menu
private applyChosenModifier(modifierType: ModifierType, cost: number, modifierSelectCallback): boolean {
if (modifierType! instanceof PokemonModifierType) {
//TODO: is the bang correct?
if (modifierType instanceof FusePokemonModifierType) {
@ -139,33 +166,7 @@ export class SelectModifierPhase extends BattlePhase {
} else {
this.applyModifier(modifierType!.newModifier()!); // TODO: is the bang correct?
}
return !cost!; // TODO: is the bang correct?
};
this.resetModifierSelect(modifierSelectCallback);
}
private playBottomRowOption(cursor: number, modifierSelectCallback): boolean {
let success = false;
switch (cursor) {
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;
return !cost;
}
// Reroll rewards