Splitting up methods in select-modifier-phase.ts

This commit is contained in:
Wlowscha 2025-05-28 00:14:51 +02:00
parent 9769cfbc9c
commit 82e24bf4bc
No known key found for this signature in database
GPG Key ID: 3C8F1AD330565D04

View File

@ -66,25 +66,7 @@ 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
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); this.typeOptions = this.getModifierTypeOptions(modifierCount.value);
@ -98,24 +80,76 @@ 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 modifierType: ModifierType;
let cost: number; let cost = 0;
const rerollCost = this.getRerollCost(globalScene.lockModifierTiers);
switch (rowCursor) { switch (rowCursor) {
// Execute option from the bottom row
case 0: case 0:
return this.playBottomRowOption(cursor, modifierSelectCallback);
// Pick an option from the rewards
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;
// Pick an option from the shop
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) {
globalScene.ui.playError();
return false;
}
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!; // TODO: is the bang correct?
};
this.resetModifierSelect(modifierSelectCallback);
}
private playBottomRowOption(cursor: number, modifierSelectCallback): boolean {
const party = globalScene.getPlayerParty();
const rerollCost = this.getRerollCost(globalScene.lockModifierTiers);
switch (cursor) { switch (cursor) {
// Reroll rewards
case 0: case 0:
if (rerollCost < 0 || globalScene.money < rerollCost) { if (rerollCost < 0 || globalScene.money < rerollCost) {
globalScene.ui.playError(); globalScene.ui.playError();
@ -137,6 +171,7 @@ export class SelectModifierPhase extends BattlePhase {
} }
globalScene.playSound("se/buy"); globalScene.playSound("se/buy");
break; break;
// Transfer modifiers among party pokemon
case 1: case 1:
globalScene.ui.setModeWithoutClear( globalScene.ui.setModeWithoutClear(
UiMode.PARTY, UiMode.PARTY,
@ -152,9 +187,7 @@ export class SelectModifierPhase extends BattlePhase {
) { ) {
const itemModifiers = globalScene.findModifiers( const itemModifiers = globalScene.findModifiers(
m => m =>
m instanceof PokemonHeldItemModifier && m instanceof PokemonHeldItemModifier && m.isTransferable && m.pokemonId === party[fromSlotIndex].id,
m.isTransferable &&
m.pokemonId === party[fromSlotIndex].id,
) as PokemonHeldItemModifier[]; ) as PokemonHeldItemModifier[];
const itemModifier = itemModifiers[itemIndex]; const itemModifier = itemModifiers[itemIndex];
globalScene.tryTransferHeldItemModifier( globalScene.tryTransferHeldItemModifier(
@ -167,29 +200,19 @@ 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; break;
// Check the party, pass a callback to restore the modifier select screen.
case 2: case 2:
globalScene.ui.setModeWithoutClear(UiMode.PARTY, PartyUiMode.CHECK, -1, () => { globalScene.ui.setModeWithoutClear(UiMode.PARTY, PartyUiMode.CHECK, -1, () => {
globalScene.ui.setMode( this.resetModifierSelect(modifierSelectCallback);
UiMode.MODIFIER_SELECT,
this.isPlayer(),
this.typeOptions,
modifierSelectCallback,
this.getRerollCost(globalScene.lockModifierTiers),
);
}); });
break; break;
// Toggle reroll lock
case 3: 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
@ -204,43 +227,9 @@ export class SelectModifierPhase extends BattlePhase {
return false; return false;
} }
return true; 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) { private applyModifier(modifier: Modifier, cost = 0, playSound = false) {
// TODO: is the bang on cost correct?
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 +255,10 @@ export class SelectModifierPhase extends BattlePhase {
globalScene.ui.setMode(UiMode.MESSAGE); globalScene.ui.setMode(UiMode.MESSAGE);
super.end(); super.end();
} }
}; }
if (modifierType! instanceof PokemonModifierType) { private openFusionMenu(modifierType, cost, modifierSelectCallback) {
//TODO: is the bang correct? const party = globalScene.getPlayerParty();
if (modifierType instanceof FusePokemonModifierType) {
globalScene.ui.setModeWithoutClear( globalScene.ui.setModeWithoutClear(
UiMode.PARTY, UiMode.PARTY,
PartyUiMode.SPLICE, PartyUiMode.SPLICE,
@ -284,21 +272,18 @@ 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 { }
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 +310,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 +324,33 @@ 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() {
const modifierCount = new NumberHolder(3);
if (this.isPlayer()) {
globalScene.applyModifiers(ExtraModifierModifier, true, modifierCount);
globalScene.applyModifiers(TempExtraModifierModifier, true, modifierCount);
} }
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 = modifierCount.value;
modifierCount.value = originalCount > newItemCount ? originalCount : newItemCount;
} else {
modifierCount.value = newItemCount;
}
}
return modifierCount;
}
private resetModifierSelect(modifierSelectCallback) {
globalScene.ui.setMode( globalScene.ui.setMode(
UiMode.MODIFIER_SELECT, UiMode.MODIFIER_SELECT,
this.isPlayer(), this.isPlayer(),