mirror of
https://github.com/pagefaultgames/pokerogue.git
synced 2025-06-30 21:42:20 +02:00
Splitting up methods in select-modifier-phase.ts
This commit is contained in:
parent
9769cfbc9c
commit
82e24bf4bc
@ -66,25 +66,7 @@ export class SelectModifierPhase extends BattlePhase {
|
||||
if (!this.isCopy) {
|
||||
regenerateModifierPoolThresholds(party, this.getPoolType(), this.rerollCount);
|
||||
}
|
||||
const modifierCount = new NumberHolder(3);
|
||||
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;
|
||||
}
|
||||
}
|
||||
const modifierCount = this.getModifierCount();
|
||||
|
||||
this.typeOptions = this.getModifierTypeOptions(modifierCount.value);
|
||||
|
||||
@ -98,24 +80,76 @@ export class SelectModifierPhase extends BattlePhase {
|
||||
globalScene.ui.setMode(UiMode.MESSAGE);
|
||||
super.end();
|
||||
},
|
||||
() =>
|
||||
globalScene.ui.setMode(
|
||||
UiMode.MODIFIER_SELECT,
|
||||
this.isPlayer(),
|
||||
this.typeOptions,
|
||||
modifierSelectCallback,
|
||||
this.getRerollCost(globalScene.lockModifierTiers),
|
||||
),
|
||||
() => this.resetModifierSelect(modifierSelectCallback),
|
||||
);
|
||||
});
|
||||
return false;
|
||||
}
|
||||
let modifierType: ModifierType;
|
||||
let cost: number;
|
||||
const rerollCost = this.getRerollCost(globalScene.lockModifierTiers);
|
||||
let cost = 0;
|
||||
switch (rowCursor) {
|
||||
// Execute option from the bottom row
|
||||
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) {
|
||||
// Reroll rewards
|
||||
case 0:
|
||||
if (rerollCost < 0 || globalScene.money < rerollCost) {
|
||||
globalScene.ui.playError();
|
||||
@ -137,6 +171,7 @@ export class SelectModifierPhase extends BattlePhase {
|
||||
}
|
||||
globalScene.playSound("se/buy");
|
||||
break;
|
||||
// Transfer modifiers among party pokemon
|
||||
case 1:
|
||||
globalScene.ui.setModeWithoutClear(
|
||||
UiMode.PARTY,
|
||||
@ -152,9 +187,7 @@ export class SelectModifierPhase extends BattlePhase {
|
||||
) {
|
||||
const itemModifiers = globalScene.findModifiers(
|
||||
m =>
|
||||
m instanceof PokemonHeldItemModifier &&
|
||||
m.isTransferable &&
|
||||
m.pokemonId === party[fromSlotIndex].id,
|
||||
m instanceof PokemonHeldItemModifier && m.isTransferable && m.pokemonId === party[fromSlotIndex].id,
|
||||
) as PokemonHeldItemModifier[];
|
||||
const itemModifier = itemModifiers[itemIndex];
|
||||
globalScene.tryTransferHeldItemModifier(
|
||||
@ -167,29 +200,19 @@ export class SelectModifierPhase extends BattlePhase {
|
||||
false,
|
||||
);
|
||||
} else {
|
||||
globalScene.ui.setMode(
|
||||
UiMode.MODIFIER_SELECT,
|
||||
this.isPlayer(),
|
||||
this.typeOptions,
|
||||
modifierSelectCallback,
|
||||
this.getRerollCost(globalScene.lockModifierTiers),
|
||||
);
|
||||
this.resetModifierSelect(modifierSelectCallback);
|
||||
}
|
||||
},
|
||||
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, () => {
|
||||
globalScene.ui.setMode(
|
||||
UiMode.MODIFIER_SELECT,
|
||||
this.isPlayer(),
|
||||
this.typeOptions,
|
||||
modifierSelectCallback,
|
||||
this.getRerollCost(globalScene.lockModifierTiers),
|
||||
);
|
||||
this.resetModifierSelect(modifierSelectCallback);
|
||||
});
|
||||
break;
|
||||
// Toggle reroll lock
|
||||
case 3:
|
||||
if (rerollCost < 0) {
|
||||
// Reroll lock button is also disabled when reroll is disabled
|
||||
@ -204,43 +227,9 @@ export class SelectModifierPhase extends BattlePhase {
|
||||
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) {
|
||||
// TODO: is the bang on cost correct?
|
||||
globalScene.ui.playError();
|
||||
return false;
|
||||
}
|
||||
|
||||
const applyModifier = (modifier: Modifier, playSound = false) => {
|
||||
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.
|
||||
// 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);
|
||||
super.end();
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
if (modifierType! instanceof PokemonModifierType) {
|
||||
//TODO: is the bang correct?
|
||||
if (modifierType instanceof FusePokemonModifierType) {
|
||||
private openFusionMenu(modifierType, cost, modifierSelectCallback) {
|
||||
const party = globalScene.getPlayerParty();
|
||||
globalScene.ui.setModeWithoutClear(
|
||||
UiMode.PARTY,
|
||||
PartyUiMode.SPLICE,
|
||||
@ -284,21 +272,18 @@ export class SelectModifierPhase extends BattlePhase {
|
||||
) {
|
||||
globalScene.ui.setMode(UiMode.MODIFIER_SELECT, this.isPlayer()).then(() => {
|
||||
const modifier = modifierType.newModifier(party[fromSlotIndex], party[spliceSlotIndex])!; //TODO: is the bang correct?
|
||||
applyModifier(modifier, true);
|
||||
this.applyModifier(modifier, cost, true);
|
||||
});
|
||||
} else {
|
||||
globalScene.ui.setMode(
|
||||
UiMode.MODIFIER_SELECT,
|
||||
this.isPlayer(),
|
||||
this.typeOptions,
|
||||
modifierSelectCallback,
|
||||
this.getRerollCost(globalScene.lockModifierTiers),
|
||||
);
|
||||
this.resetModifierSelect(modifierSelectCallback);
|
||||
}
|
||||
},
|
||||
modifierType.selectFilter,
|
||||
);
|
||||
} else {
|
||||
}
|
||||
|
||||
private openModifierMenu(modifierType, cost, modifierSelectCallback) {
|
||||
const party = globalScene.getPlayerParty();
|
||||
const pokemonModifierType = modifierType as PokemonModifierType;
|
||||
const isMoveModifier = modifierType instanceof PokemonMoveModifierType;
|
||||
const isTmModifier = modifierType instanceof TmModifierType;
|
||||
@ -325,16 +310,10 @@ export class SelectModifierPhase extends BattlePhase {
|
||||
? modifierType.newModifier(party[slotIndex])
|
||||
: modifierType.newModifier(party[slotIndex], option as number)
|
||||
: 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 {
|
||||
globalScene.ui.setMode(
|
||||
UiMode.MODIFIER_SELECT,
|
||||
this.isPlayer(),
|
||||
this.typeOptions,
|
||||
modifierSelectCallback,
|
||||
this.getRerollCost(globalScene.lockModifierTiers),
|
||||
);
|
||||
this.resetModifierSelect(modifierSelectCallback);
|
||||
}
|
||||
},
|
||||
pokemonModifierType.selectFilter,
|
||||
@ -345,12 +324,33 @@ export class SelectModifierPhase extends BattlePhase {
|
||||
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(
|
||||
UiMode.MODIFIER_SELECT,
|
||||
this.isPlayer(),
|
||||
|
Loading…
Reference in New Issue
Block a user