From de77db70d7dd68fe15f59cc208c865add1a8b5ac Mon Sep 17 00:00:00 2001 From: Flashfyre Date: Thu, 4 Apr 2024 00:38:02 -0400 Subject: [PATCH] Rerolls lock rarity tiers and price accordingly --- src/modifier/modifier-type.ts | 34 ++++++++++++++++++++++++---------- src/phases.ts | 32 +++++++++++++++++++------------- 2 files changed, 43 insertions(+), 23 deletions(-) diff --git a/src/modifier/modifier-type.ts b/src/modifier/modifier-type.ts index c33fd3e4d..47453747c 100644 --- a/src/modifier/modifier-type.ts +++ b/src/modifier/modifier-type.ts @@ -695,7 +695,7 @@ export class EnemyInstantReviveChanceModifierType extends ModifierType { } export type ModifierTypeFunc = () => ModifierType; -type WeightedModifierTypeWeightFunc = (party: Pokemon[]) => integer; +type WeightedModifierTypeWeightFunc = (party: Pokemon[], rerollCount?: integer) => integer; class WeightedModifierType { public modifierType: ModifierType; @@ -1019,7 +1019,7 @@ const modifierPool: ModifierPool = { new WeightedModifierType(modifierTypes.EXP_SHARE, 12), new WeightedModifierType(modifierTypes.EXP_BALANCE, 4), new WeightedModifierType(modifierTypes.TERA_ORB, (party: Pokemon[]) => Math.min(Math.max(Math.floor(party[0].scene.currentBattle.waveIndex / 50) * 2, 1), 4), 4), - new WeightedModifierType(modifierTypes.VOUCHER, (party: Pokemon[]) => !party[0].scene.gameMode.isDaily ? 3 : 0, 3), + new WeightedModifierType(modifierTypes.VOUCHER, (party: Pokemon[], rerollCount: integer) => !party[0].scene.gameMode.isDaily ? Math.max(3 - rerollCount, 0) : 0, 3), ].map(m => { m.setTier(ModifierTier.ULTRA); return m; }), [ModifierTier.ROGUE]: [ new WeightedModifierType(modifierTypes.ROGUE_BALL, 24), @@ -1040,10 +1040,10 @@ const modifierPool: ModifierPool = { ].map(m => { m.setTier(ModifierTier.ROGUE); return m; }), [ModifierTier.MASTER]: [ new WeightedModifierType(modifierTypes.MASTER_BALL, 32), - new WeightedModifierType(modifierTypes.SHINY_CHARM, 18), + new WeightedModifierType(modifierTypes.SHINY_CHARM, 14), new WeightedModifierType(modifierTypes.HEALING_CHARM, 18), - new WeightedModifierType(modifierTypes.MULTI_LENS, 24), - new WeightedModifierType(modifierTypes.VOUCHER_PLUS, (party: Pokemon[]) => !party[0].scene.gameMode.isDaily ? 8 : 0, 8), + new WeightedModifierType(modifierTypes.MULTI_LENS, 18), + new WeightedModifierType(modifierTypes.VOUCHER_PLUS, (party: Pokemon[], rerollCount: integer) => !party[0].scene.gameMode.isDaily ? Math.max(9 - rerollCount * 3, 0) : 0, 9), new WeightedModifierType(modifierTypes.DNA_SPLICERS, (party: Pokemon[]) => !party[0].scene.gameMode.isSplicedOnly && party.filter(p => !p.fusionSpecies).length > 1 ? 24 : 0, 24), new WeightedModifierType(modifierTypes.MINI_BLACK_HOLE, (party: Pokemon[]) => party[0].scene.gameData.unlocks[Unlockables.MINI_BLACK_HOLE] ? 1 : 0, 1), ].map(m => { m.setTier(ModifierTier.MASTER); return m; }) @@ -1175,7 +1175,7 @@ let enemyBuffIgnoredPoolIndexes = {}; const tierWeights = [ 769 / 1024, 192 / 1024, 48 / 1024, 12 / 1024, 1 / 1024 ]; -export function regenerateModifierPoolThresholds(party: Pokemon[], poolType: ModifierPoolType) { +export function regenerateModifierPoolThresholds(party: Pokemon[], poolType: ModifierPoolType, rerollCount: integer = 0) { let pool: ModifierPool; switch (poolType) { case ModifierPoolType.PLAYER: @@ -1213,7 +1213,7 @@ export function regenerateModifierPoolThresholds(party: Pokemon[], poolType: Mod || itemModifierType instanceof FormChangeItemModifierType || existingModifiers.find(m => m.stackCount < m.getMaxStackCount(party[0].scene, true)) ? weightedModifierType.weight instanceof Function - ? (weightedModifierType.weight as Function)(party) + ? (weightedModifierType.weight as Function)(party, rerollCount) : weightedModifierType.weight as integer : 0; if (weightedModifierType.maxWeight) { @@ -1267,11 +1267,11 @@ export function getModifierTypeFuncById(id: string): ModifierTypeFunc { return modifierTypes[id]; } -export function getPlayerModifierTypeOptions(count: integer, party: PlayerPokemon[]): ModifierTypeOption[] { +export function getPlayerModifierTypeOptions(count: integer, party: PlayerPokemon[], modifierTiers?: ModifierTier[]): ModifierTypeOption[] { const options: ModifierTypeOption[] = []; const retryCount = Math.min(count * 5, 50); - new Array(count).fill(0).map(() => { - let candidate = getNewModifierTypeOption(party, ModifierPoolType.PLAYER); + new Array(count).fill(0).map((_, i) => { + let candidate = getNewModifierTypeOption(party, ModifierPoolType.PLAYER, modifierTiers?.length > i ? modifierTiers[i] : undefined); let r = 0; while (options.length && ++r < retryCount && options.filter(o => o.type.name === candidate.type.name || o.type.group === candidate.type.group).length) candidate = getNewModifierTypeOption(party, ModifierPoolType.PLAYER, candidate.type.tier, candidate.upgradeCount); @@ -1393,6 +1393,7 @@ function getNewModifierTypeOption(party: Pokemon[], poolType: ModifierPoolType, } while (upgraded); } tier = tierValue > 255 ? ModifierTier.COMMON : tierValue > 60 ? ModifierTier.GREAT : tierValue > 12 ? ModifierTier.ULTRA : tierValue ? ModifierTier.ROGUE : ModifierTier.MASTER; + // Does this actually do anything? if (!upgradeCount) upgradeCount = Math.min(upgradeCount, ModifierTier.MASTER - tier); tier += upgradeCount; @@ -1401,6 +1402,19 @@ function getNewModifierTypeOption(party: Pokemon[], poolType: ModifierPoolType, if (upgradeCount) upgradeCount--; } + } else if (upgradeCount === undefined && player) { + upgradeCount = 0; + if (tier < ModifierTier.MASTER) { + const partyShinyCount = 6;//party.filter(p => p.isShiny() && !p.isFainted()).length; + const upgradeOdds = Math.floor(32 / ((partyShinyCount + 2) / 2)); + while (modifierPool.hasOwnProperty(tier + upgradeCount + 1) && modifierPool[tier + upgradeCount + 1].length) { + if (!Utils.randSeedInt(upgradeOdds)) + upgradeCount++; + else + break; + } + tier += upgradeCount; + } } else if (retryCount === 10 && tier) { retryCount = 0; tier--; diff --git a/src/phases.ts b/src/phases.ts index 58593eaab..f1e529888 100644 --- a/src/phases.ts +++ b/src/phases.ts @@ -3878,11 +3878,13 @@ export class AttemptRunPhase extends PokemonPhase { export class SelectModifierPhase extends BattlePhase { private rerollCount: integer; + private modifierTiers: ModifierTier[]; - constructor(scene: BattleScene, rerollCount: integer = 0) { + constructor(scene: BattleScene, rerollCount: integer = 0, modifierTiers?: ModifierTier[]) { super(scene); this.rerollCount = rerollCount; + this.modifierTiers = modifierTiers; } start() { @@ -3892,7 +3894,7 @@ export class SelectModifierPhase extends BattlePhase { this.updateSeed(); const party = this.scene.getParty(); - regenerateModifierPoolThresholds(party, this.getPoolType()); + regenerateModifierPoolThresholds(party, this.getPoolType(), this.rerollCount); const modifierCount = new Utils.IntegerHolder(3); if (this.isPlayer()) this.scene.applyModifiers(ExtraModifierModifier, true, modifierCount); @@ -3905,7 +3907,7 @@ export class SelectModifierPhase extends BattlePhase { this.scene.ui.revertMode(); this.scene.ui.setMode(Mode.MESSAGE); super.end(); - }, () => this.scene.ui.setMode(Mode.MODIFIER_SELECT, this.isPlayer(), typeOptions, modifierSelectCallback, this.getRerollCost())); + }, () => this.scene.ui.setMode(Mode.MODIFIER_SELECT, this.isPlayer(), typeOptions, modifierSelectCallback, this.getRerollCost(typeOptions))); }); return false; } @@ -3914,12 +3916,12 @@ export class SelectModifierPhase extends BattlePhase { switch (rowCursor) { case 0: if (!cursor) { - const rerollCost = this.getRerollCost(); + const rerollCost = this.getRerollCost(typeOptions); if (this.scene.money < rerollCost) { this.scene.ui.playError(); return false; } else { - this.scene.unshiftPhase(new SelectModifierPhase(this.scene, this.rerollCount + 1)); + this.scene.unshiftPhase(new SelectModifierPhase(this.scene, this.rerollCount + 1, typeOptions.map(o => o.type.tier))); this.scene.ui.clearText(); this.scene.ui.setMode(Mode.MESSAGE).then(() => super.end()); this.scene.money -= rerollCost; @@ -3929,14 +3931,14 @@ export class SelectModifierPhase extends BattlePhase { } else { this.scene.ui.setModeWithoutClear(Mode.PARTY, PartyUiMode.MODIFIER_TRANSFER, -1, (fromSlotIndex: integer, itemIndex: integer, toSlotIndex: integer) => { if (toSlotIndex !== undefined && fromSlotIndex < 6 && toSlotIndex < 6 && fromSlotIndex !== toSlotIndex && itemIndex > -1) { - this.scene.ui.setMode(Mode.MODIFIER_SELECT, this.isPlayer(), typeOptions, modifierSelectCallback, this.getRerollCost()).then(() => { + this.scene.ui.setMode(Mode.MODIFIER_SELECT, this.isPlayer(), typeOptions, modifierSelectCallback, this.getRerollCost(typeOptions)).then(() => { const itemModifiers = this.scene.findModifiers(m => m instanceof PokemonHeldItemModifier && (m as PokemonHeldItemModifier).getTransferrable(true) && (m as PokemonHeldItemModifier).pokemonId === party[fromSlotIndex].id) as PokemonHeldItemModifier[]; const itemModifier = itemModifiers[itemIndex]; this.scene.tryTransferHeldItemModifier(itemModifier, party[toSlotIndex], true, true); }); } else - this.scene.ui.setMode(Mode.MODIFIER_SELECT, this.isPlayer(), typeOptions, modifierSelectCallback, this.getRerollCost()); + this.scene.ui.setMode(Mode.MODIFIER_SELECT, this.isPlayer(), typeOptions, modifierSelectCallback, this.getRerollCost(typeOptions)); }, PartyUiHandler.FilterItemMaxStacks); } return true; @@ -3979,7 +3981,7 @@ export class SelectModifierPhase extends BattlePhase { applyModifier(modifier, true); }); } else - this.scene.ui.setMode(Mode.MODIFIER_SELECT, this.isPlayer(), typeOptions, modifierSelectCallback, this.getRerollCost()); + this.scene.ui.setMode(Mode.MODIFIER_SELECT, this.isPlayer(), typeOptions, modifierSelectCallback, this.getRerollCost(typeOptions)); }, modifierType.selectFilter); } else { const pokemonModifierType = modifierType as PokemonModifierType; @@ -4004,7 +4006,7 @@ export class SelectModifierPhase extends BattlePhase { applyModifier(modifier, true); }); } else - this.scene.ui.setMode(Mode.MODIFIER_SELECT, this.isPlayer(), typeOptions, modifierSelectCallback, this.getRerollCost()); + this.scene.ui.setMode(Mode.MODIFIER_SELECT, this.isPlayer(), typeOptions, modifierSelectCallback, this.getRerollCost(typeOptions)); }, pokemonModifierType.selectFilter, modifierType instanceof PokemonMoveModifierType ? (modifierType as PokemonMoveModifierType).moveSelectFilter : undefined, tmMoveId); } } else @@ -4012,7 +4014,7 @@ export class SelectModifierPhase extends BattlePhase { return !cost; }; - this.scene.ui.setMode(Mode.MODIFIER_SELECT, this.isPlayer(), typeOptions, modifierSelectCallback, this.getRerollCost()); + this.scene.ui.setMode(Mode.MODIFIER_SELECT, this.isPlayer(), typeOptions, modifierSelectCallback, this.getRerollCost(typeOptions)); } updateSeed(): void { @@ -4023,8 +4025,12 @@ export class SelectModifierPhase extends BattlePhase { return true; } - getRerollCost(): integer { - return Math.ceil(this.scene.currentBattle.waveIndex / 10) * 250 * Math.pow(2, this.rerollCount); + getRerollCost(typeOptions: ModifierTypeOption[]): integer { + let baseValue = 0; + const tierValues = [ 50, 125, 300, 750, 2000 ]; + for (let opt of typeOptions) + baseValue += tierValues[opt.type.tier]; + return Math.ceil(this.scene.currentBattle.waveIndex / 10) * baseValue * Math.pow(2, this.rerollCount); } getPoolType(): ModifierPoolType { @@ -4032,7 +4038,7 @@ export class SelectModifierPhase extends BattlePhase { } getModifierTypeOptions(modifierCount: integer): ModifierTypeOption[] { - return getPlayerModifierTypeOptions(modifierCount, this.scene.getParty()); + return getPlayerModifierTypeOptions(modifierCount, this.scene.getParty(), this.modifierTiers); } addModifier(modifier: Modifier): Promise {