Refactored select-modifier-phase.ts

This commit is contained in:
Wlowscha 2025-05-29 13:13:14 +02:00
parent f9e6785c35
commit d4de55e6f0
No known key found for this signature in database
GPG Key ID: 3C8F1AD330565D04

View File

@ -66,27 +66,9 @@ export class SelectModifierPhase extends BattlePhase {
if (!this.isCopy) { if (!this.isCopy) {
regenerateModifierPoolThresholds(party, this.getPoolType(), this.rerollCount); regenerateModifierPoolThresholds(party, this.getPoolType(), this.rerollCount);
} }
const modifierCount = new NumberHolder(3); const modifierCount = this.getModifierCount();
if (this.isPlayer()) {
globalScene.applyModifiers(ExtraModifierModifier, true, modifierCount);
globalScene.applyModifiers(TempExtraModifierModifier, true, modifierCount);
}
// If custom modifiers are specified, overrides default item count this.typeOptions = this.getModifierTypeOptions(modifierCount);
if (this.customModifierSettings) {
const newItemCount =
(this.customModifierSettings.guaranteedModifierTiers?.length || 0) +
(this.customModifierSettings.guaranteedModifierTypeOptions?.length || 0) +
(this.customModifierSettings.guaranteedModifierTypeFuncs?.length || 0);
if (this.customModifierSettings.fillRemaining) {
const originalCount = modifierCount.value;
modifierCount.value = originalCount > newItemCount ? originalCount : newItemCount;
} else {
modifierCount.value = newItemCount;
}
}
this.typeOptions = this.getModifierTypeOptions(modifierCount.value);
const modifierSelectCallback = (rowCursor: number, cursor: number) => { const modifierSelectCallback = (rowCursor: number, cursor: number) => {
if (rowCursor < 0 || cursor < 0) { if (rowCursor < 0 || cursor < 0) {
@ -98,25 +80,98 @@ export class SelectModifierPhase extends BattlePhase {
globalScene.ui.setMode(UiMode.MESSAGE); globalScene.ui.setMode(UiMode.MESSAGE);
super.end(); super.end();
}, },
() => () => this.resetModifierSelect(modifierSelectCallback),
globalScene.ui.setMode(
UiMode.MODIFIER_SELECT,
this.isPlayer(),
this.typeOptions,
modifierSelectCallback,
this.getRerollCost(globalScene.lockModifierTiers),
),
); );
}); });
return false; return false;
} }
let modifierType: ModifierType;
let cost: number;
const rerollCost = this.getRerollCost(globalScene.lockModifierTiers);
switch (rowCursor) { switch (rowCursor) {
// Execute one of the options from the bottom row
case 0: case 0:
switch (cursor) { switch (cursor) {
case 0: 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;
}
const modifierType = this.typeOptions[cursor].type;
return this.applyChosenModifier(modifierType, 0, modifierSelectCallback);
}
// 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),
);
const shopOption =
shopOptions[
rowCursor > 2 || shopOptions.length <= SHOP_OPTIONS_ROW_LIMIT ? cursor : cursor + SHOP_OPTIONS_ROW_LIMIT
];
const modifierType = shopOption.type;
// Apply Black Sludge to healing item cost
const healingItemCost = new NumberHolder(shopOption.cost);
globalScene.applyModifier(HealShopCostModifier, true, healingItemCost);
const cost = healingItemCost.value;
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) {
this.openFusionMenu(modifierType, cost, modifierSelectCallback);
} else {
this.openModifierMenu(modifierType, cost, modifierSelectCallback);
}
} else {
this.applyModifier(modifierType!.newModifier()!); // TODO: is the bang correct?
}
return !cost;
}
// 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;
@ -136,8 +191,12 @@ export class SelectModifierPhase extends BattlePhase {
globalScene.animateMoneyChanged(false); globalScene.animateMoneyChanged(false);
} }
globalScene.playSound("se/buy"); globalScene.playSound("se/buy");
break; return true;
case 1: }
// Transfer modifiers among party pokemon
private openModifierTransferScreen(modifierSelectCallback) {
const party = globalScene.getPlayerParty();
globalScene.ui.setModeWithoutClear( globalScene.ui.setModeWithoutClear(
UiMode.PARTY, UiMode.PARTY,
PartyUiMode.MODIFIER_TRANSFER, PartyUiMode.MODIFIER_TRANSFER,
@ -151,10 +210,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(
@ -167,30 +223,17 @@ export class SelectModifierPhase extends BattlePhase {
false, false,
); );
} else { } else {
globalScene.ui.setMode( this.resetModifierSelect(modifierSelectCallback);
UiMode.MODIFIER_SELECT,
this.isPlayer(),
this.typeOptions,
modifierSelectCallback,
this.getRerollCost(globalScene.lockModifierTiers),
);
} }
}, },
PartyUiHandler.FilterItemMaxStacks, PartyUiHandler.FilterItemMaxStacks,
); );
break; return true;
case 2: }
globalScene.ui.setModeWithoutClear(UiMode.PARTY, PartyUiMode.CHECK, -1, () => {
globalScene.ui.setMode( // Toggle reroll lock
UiMode.MODIFIER_SELECT, private toggleRerollLock() {
this.isPlayer(), const rerollCost = this.getRerollCost(globalScene.lockModifierTiers);
this.typeOptions,
modifierSelectCallback,
this.getRerollCost(globalScene.lockModifierTiers),
);
});
break;
case 3:
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();
@ -203,44 +246,9 @@ export class SelectModifierPhase extends BattlePhase {
uiHandler.updateRerollCostText(); uiHandler.updateRerollCostText();
return false; return false;
} }
return true;
case 1:
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;
}
break;
default:
const shopOptions = getPlayerShopModifierTypeOptionsForWave(
globalScene.currentBattle.waveIndex,
globalScene.getWaveMoneyAmount(1),
);
const shopOption =
shopOptions[
rowCursor > 2 || shopOptions.length <= SHOP_OPTIONS_ROW_LIMIT ? cursor : cursor + SHOP_OPTIONS_ROW_LIMIT
];
if (shopOption.type) {
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;
}
if (cost! && globalScene.money < cost && !Overrides.WAIVE_ROLL_FEE_OVERRIDE) { // Applies the effects of the chosen modifier
// TODO: is the bang on cost correct? private applyModifier(modifier: Modifier, cost = 0, playSound = false) {
globalScene.ui.playError();
return false;
}
const applyModifier = (modifier: Modifier, 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.
// If the player selects either of these, then escapes out of consuming them, // If the player selects either of these, then escapes out of consuming them,
@ -266,11 +274,11 @@ export class SelectModifierPhase extends BattlePhase {
globalScene.ui.setMode(UiMode.MESSAGE); globalScene.ui.setMode(UiMode.MESSAGE);
super.end(); super.end();
} }
}; }
if (modifierType! instanceof PokemonModifierType) { // Opens the party menu specifically for fusions
//TODO: is the bang correct? private openFusionMenu(modifierType, cost, modifierSelectCallback) {
if (modifierType instanceof FusePokemonModifierType) { const party = globalScene.getPlayerParty();
globalScene.ui.setModeWithoutClear( globalScene.ui.setModeWithoutClear(
UiMode.PARTY, UiMode.PARTY,
PartyUiMode.SPLICE, PartyUiMode.SPLICE,
@ -284,21 +292,19 @@ export class SelectModifierPhase extends BattlePhase {
) { ) {
globalScene.ui.setMode(UiMode.MODIFIER_SELECT, this.isPlayer()).then(() => { globalScene.ui.setMode(UiMode.MODIFIER_SELECT, this.isPlayer()).then(() => {
const modifier = modifierType.newModifier(party[fromSlotIndex], party[spliceSlotIndex])!; //TODO: is the bang correct? const modifier = modifierType.newModifier(party[fromSlotIndex], party[spliceSlotIndex])!; //TODO: is the bang correct?
applyModifier(modifier, true); this.applyModifier(modifier, cost, true);
}); });
} else { } else {
globalScene.ui.setMode( this.resetModifierSelect(modifierSelectCallback);
UiMode.MODIFIER_SELECT,
this.isPlayer(),
this.typeOptions,
modifierSelectCallback,
this.getRerollCost(globalScene.lockModifierTiers),
);
} }
}, },
modifierType.selectFilter, modifierType.selectFilter,
); );
} else { }
// Opens the party menu to apply one of various modifiers
private openModifierMenu(modifierType, cost, modifierSelectCallback) {
const party = globalScene.getPlayerParty();
const pokemonModifierType = modifierType as PokemonModifierType; const pokemonModifierType = modifierType as PokemonModifierType;
const isMoveModifier = modifierType instanceof PokemonMoveModifierType; const isMoveModifier = modifierType instanceof PokemonMoveModifierType;
const isTmModifier = modifierType instanceof TmModifierType; const isTmModifier = modifierType instanceof TmModifierType;
@ -325,16 +331,10 @@ export class SelectModifierPhase extends BattlePhase {
? modifierType.newModifier(party[slotIndex]) ? modifierType.newModifier(party[slotIndex])
: modifierType.newModifier(party[slotIndex], option as number) : modifierType.newModifier(party[slotIndex], option as number)
: modifierType.newModifier(party[slotIndex], option - PartyOption.MOVE_1); : modifierType.newModifier(party[slotIndex], option - PartyOption.MOVE_1);
applyModifier(modifier!, true); // TODO: is the bang correct? this.applyModifier(modifier!, cost, true); // TODO: is the bang correct?
}); });
} else { } else {
globalScene.ui.setMode( this.resetModifierSelect(modifierSelectCallback);
UiMode.MODIFIER_SELECT,
this.isPlayer(),
this.typeOptions,
modifierSelectCallback,
this.getRerollCost(globalScene.lockModifierTiers),
);
} }
}, },
pokemonModifierType.selectFilter, pokemonModifierType.selectFilter,
@ -345,12 +345,35 @@ export class SelectModifierPhase extends BattlePhase {
isPpRestoreModifier, isPpRestoreModifier,
); );
} }
} else {
applyModifier(modifierType!.newModifier()!); // TODO: is the bang correct? // Function that determines how many reward slots are available
private getModifierCount(): number {
const modifierCountHolder = new NumberHolder(3);
if (this.isPlayer()) {
globalScene.applyModifiers(ExtraModifierModifier, true, modifierCountHolder);
globalScene.applyModifiers(TempExtraModifierModifier, true, modifierCountHolder);
} }
return !cost!; // TODO: is the bang correct? // If custom modifiers are specified, overrides default item count
}; if (this.customModifierSettings) {
const newItemCount =
(this.customModifierSettings.guaranteedModifierTiers?.length || 0) +
(this.customModifierSettings.guaranteedModifierTypeOptions?.length || 0) +
(this.customModifierSettings.guaranteedModifierTypeFuncs?.length || 0);
if (this.customModifierSettings.fillRemaining) {
const originalCount = modifierCountHolder.value;
modifierCountHolder.value = originalCount > newItemCount ? originalCount : newItemCount;
} else {
modifierCountHolder.value = newItemCount;
}
}
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( globalScene.ui.setMode(
UiMode.MODIFIER_SELECT, UiMode.MODIFIER_SELECT,
this.isPlayer(), this.isPlayer(),