Reroll prediction

Gets a list of every result from all the rerolls you can afford

Shows extra items if you have Golden Poke Balls

Doesn't use lock capsule

Ingame display is todo
This commit is contained in:
RedstonewolfX 2024-08-10 23:33:19 -04:00
parent 73f5d51dd2
commit c138d1b4e1
2 changed files with 152 additions and 21 deletions

View File

@ -6726,12 +6726,42 @@ export class AttemptRunPhase extends PokemonPhase {
export class SelectModifierPhase extends BattlePhase {
private rerollCount: integer;
private modifierTiers: ModifierTier[];
private modifierPredictions: ModifierTypeOption[][] = []
private predictionCost: integer;
constructor(scene: BattleScene, rerollCount: integer = 0, modifierTiers?: ModifierTier[]) {
constructor(scene: BattleScene, rerollCount: integer = 0, modifierTiers?: ModifierTier[], predictionCost?: integer, modifierPredictions?: ModifierTypeOption[][]) {
super(scene);
this.rerollCount = rerollCount;
this.modifierTiers = modifierTiers;
this.modifierPredictions = []
if (modifierPredictions != undefined) {
this.modifierPredictions = modifierPredictions;
}
this.predictionCost = 0
}
generateSelection(rerollOverride: integer, modifierOverride?: integer) {
//const STATE = Phaser.Math.RND.state() // Store RNG state
//console.log("====================")
//console.log(" Reroll Prediction: " + rerollOverride)
const party = this.scene.getParty();
regenerateModifierPoolThresholds(party, this.getPoolType(), rerollOverride);
const modifierCount = new Utils.IntegerHolder(3);
if (this.isPlayer()) {
this.scene.applyModifiers(ExtraModifierModifier, true, modifierCount);
}
if (modifierOverride) {
//modifierCount.value = modifierOverride
}
const typeOptions: ModifierTypeOption[] = this.getModifierTypeOptions(modifierCount.value);
typeOptions.forEach((option, idx) => {
//console.log(option.type.name)
})
//console.log("====================")
this.modifierPredictions.push(typeOptions)
this.predictionCost += this.getRerollCost(typeOptions, false, rerollOverride)
//Phaser.Math.RND.state(STATE) // Restore RNG state like nothing happened
}
start() {
@ -6739,6 +6769,12 @@ export class SelectModifierPhase extends BattlePhase {
if (!this.rerollCount) {
this.updateSeed();
console.log("\n\nPerforming reroll prediction\n\n")
this.predictionCost = 0
for (var idx = 0; idx < 10 && this.predictionCost < this.scene.money; idx++) {
this.generateSelection(idx)
}
this.updateSeed();
} else {
this.scene.reroll = false;
}
@ -6759,7 +6795,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(typeOptions, this.scene.lockModifierTiers)));
}, () => this.scene.ui.setMode(Mode.MODIFIER_SELECT, this.isPlayer(), typeOptions, modifierSelectCallback, this.getRerollCost(typeOptions, this.scene.lockModifierTiers), this.modifierPredictions));
});
return false;
}
@ -6769,17 +6805,48 @@ export class SelectModifierPhase extends BattlePhase {
case 0:
switch (cursor) {
case 0:
const rerollCost = this.getRerollCost(typeOptions, this.scene.lockModifierTiers);
if (this.scene.money < rerollCost) {
const rerollCost1 = this.getRerollCost(typeOptions, this.scene.lockModifierTiers);
if (this.scene.money < rerollCost1) {
this.scene.ui.playError();
return false;
} else {
this.scene.reroll = true;
LoggerTools.logActions(this.scene, this.scene.currentBattle.waveIndex, "Reroll" + (this.scene.lockModifierTiers ? " (Locked)" : ""))
this.scene.unshiftPhase(new SelectModifierPhase(this.scene, this.rerollCount + 1, typeOptions.map(o => o.type.tier)));
this.scene.unshiftPhase(new SelectModifierPhase(this.scene, this.rerollCount + 1, typeOptions.map(o => o.type.tier), this.predictionCost, this.modifierPredictions));
this.scene.ui.clearText();
this.scene.ui.setMode(Mode.MESSAGE).then(() => super.end());
this.scene.money -= rerollCost;
this.scene.money -= rerollCost1;
this.scene.updateMoneyText();
this.scene.animateMoneyChanged(false);
this.scene.playSound("buy");
}
break;
case 0.1:
const rerollCost2 = this.getRerollCost(this.modifierPredictions[this.rerollCount], false);
if (this.scene.money < rerollCost2) {
this.scene.ui.playError();
return false;
} else {
this.scene.reroll = true;
LoggerTools.logActions(this.scene, this.scene.currentBattle.waveIndex, "+1 Reroll")
this.scene.unshiftPhase(new SelectModifierPhase(this.scene, this.rerollCount + 1, typeOptions.map(o => o.type.tier), this.predictionCost, this.modifierPredictions));
this.scene.ui.clearText();
this.scene.ui.setMode(Mode.MESSAGE).then(() => super.end());
this.scene.money -= rerollCost2;
this.scene.updateMoneyText();
this.scene.animateMoneyChanged(false);
this.scene.playSound("buy");
}
break;
case 0.2:
const rerollCost3 = this.getRerollCost(this.modifierPredictions[this.rerollCount + 1], false);
{
this.scene.reroll = true;
LoggerTools.logActions(this.scene, this.scene.currentBattle.waveIndex, "-1 Reroll")
this.scene.unshiftPhase(new SelectModifierPhase(this.scene, this.rerollCount - 1, typeOptions.map(o => o.type.tier), this.predictionCost, this.modifierPredictions));
this.scene.ui.clearText();
this.scene.ui.setMode(Mode.MESSAGE).then(() => super.end());
this.scene.money += rerollCost3;
this.scene.updateMoneyText();
this.scene.animateMoneyChanged(false);
this.scene.playSound("buy");
@ -6918,6 +6985,14 @@ export class SelectModifierPhase extends BattlePhase {
return !cost;
};
if (this.rerollCount == 0) {
this.modifierPredictions.forEach((mp, r) => {
console.log("Rerolls: " + r)
mp.forEach((m, i) => {
console.log(" " + m.type.name)
})
})
}
this.scene.ui.setMode(Mode.MODIFIER_SELECT, this.isPlayer(), typeOptions, modifierSelectCallback, this.getRerollCost(typeOptions, this.scene.lockModifierTiers));
}
@ -6929,7 +7004,7 @@ export class SelectModifierPhase extends BattlePhase {
return true;
}
getRerollCost(typeOptions: ModifierTypeOption[], lockRarities: boolean): integer {
getRerollCost(typeOptions: ModifierTypeOption[], lockRarities: boolean, rerollOverride?: integer): integer {
let baseValue = 0;
if (lockRarities) {
const tierValues = [50, 125, 300, 750, 2000];
@ -6939,7 +7014,7 @@ export class SelectModifierPhase extends BattlePhase {
} else {
baseValue = 250;
}
return Math.min(Math.ceil(this.scene.currentBattle.waveIndex / 10) * baseValue * Math.pow(2, this.rerollCount), Number.MAX_SAFE_INTEGER);
return Math.min(Math.ceil(this.scene.currentBattle.waveIndex / 10) * baseValue * Math.pow(2, (rerollOverride != undefined ? rerollOverride : this.rerollCount)), Number.MAX_SAFE_INTEGER);
}
getPoolType(): ModifierPoolType {

View File

@ -11,6 +11,7 @@ import MoveInfoOverlay from "./move-info-overlay";
import { allMoves } from "../data/move";
import * as Utils from "./../utils";
import i18next from "i18next";
import { GameModes } from "#app/game-mode.js";
export const SHOP_OPTIONS_ROW_LIMIT = 6;
@ -31,9 +32,18 @@ export default class ModifierSelectUiHandler extends AwaitableUiHandler {
private transferButtonWidth: integer;
private checkButtonWidth: integer;
public args: any[] = [];
public refreshIndex: integer = 0;
public optionP: ModifierTypeOption[][];
public options: ModifierOption[];
public shopOptionsRows: ModifierOption[][];
private rerollUpContainer: Phaser.GameObjects.Container;
private rerollDownContainer: Phaser.GameObjects.Container;
private rerollUpLabel: Phaser.GameObjects.Text;
private rerollDownLabel: Phaser.GameObjects.Text;
private cursorObj: Phaser.GameObjects.Image;
constructor(scene: BattleScene) {
@ -92,6 +102,32 @@ export default class ModifierSelectUiHandler extends AwaitableUiHandler {
this.rerollCostText.setPositionRelative(rerollButtonText, rerollButtonText.displayWidth + 5, 1);
this.rerollButtonContainer.add(this.rerollCostText);
this.rerollUpContainer = this.scene.add.container(100, -78);
this.rerollUpContainer.setName("reroll-brn");
this.rerollUpContainer.setVisible(false);
ui.add(this.rerollUpContainer);
this.rerollUpLabel = addTextObject(this.scene, -4, -2, "+1 Reroll", TextStyle.PARTY);
this.rerollUpLabel.setName("text-reroll-btn");
this.rerollUpLabel.setOrigin(0, 0);
this.rerollUpContainer.add(this.rerollUpLabel);
this.rerollDownContainer = this.scene.add.container(100, -64);
this.rerollDownContainer.setName("reroll-brn");
this.rerollDownContainer.setVisible(false);
ui.add(this.rerollDownContainer);
this.rerollDownLabel = addTextObject(this.scene, -4, -2, "-1 Reroll", TextStyle.PARTY);
this.rerollDownLabel.setName("text-reroll-btn");
this.rerollDownLabel.setOrigin(0, 0);
this.rerollDownContainer.add(this.rerollDownLabel);
this.lockRarityButtonContainer = this.scene.add.container(16, -64);
this.lockRarityButtonContainer.setVisible(false);
ui.add(this.lockRarityButtonContainer);
@ -117,6 +153,7 @@ export default class ModifierSelectUiHandler extends AwaitableUiHandler {
}
show(args: any[]): boolean {
this.args = args
if (this.active) {
if (args.length >= 3) {
this.awaitingActionInput = true;
@ -151,6 +188,11 @@ export default class ModifierSelectUiHandler extends AwaitableUiHandler {
this.lockRarityButtonContainer.setVisible(false);
this.lockRarityButtonContainer.setAlpha(0);
this.rerollUpContainer.setVisible(false)
this.rerollUpContainer.setAlpha(0)
this.rerollDownContainer.setVisible(false)
this.rerollDownContainer.setAlpha(0)
this.rerollButtonContainer.setPositionRelative(this.lockRarityButtonContainer, 0, canLockRarities ? -12 : 0);
this.rerollCost = args[3] as integer;
@ -158,6 +200,8 @@ export default class ModifierSelectUiHandler extends AwaitableUiHandler {
this.updateRerollCostText();
const typeOptions = args[1] as ModifierTypeOption[];
//const typeOptionP = args[4] as ModifierTypeOption[][];
//this.optionP = typeOptionP;
const shopTypeOptions = !this.scene.gameMode.hasNoShop
? getPlayerShopModifierTypeOptionsForWave(this.scene.currentBattle.waveIndex, this.scene.getWaveMoneyAmount(1))
: [];
@ -235,9 +279,15 @@ export default class ModifierSelectUiHandler extends AwaitableUiHandler {
this.rerollButtonContainer.setAlpha(0);
this.checkButtonContainer.setAlpha(0);
this.lockRarityButtonContainer.setAlpha(0);
this.rerollUpContainer.setAlpha(0)
this.rerollDownContainer.setAlpha(0)
this.rerollButtonContainer.setVisible(true);
this.checkButtonContainer.setVisible(true);
this.lockRarityButtonContainer.setVisible(canLockRarities);
this.rerollUpContainer.setVisible(false)
this.rerollDownContainer.setVisible(false)
// , this.rerollUpContainer, this.rerollDownContainer
this.scene.tweens.add({
targets: [ this.rerollButtonContainer, this.lockRarityButtonContainer, this.checkButtonContainer ],
@ -258,6 +308,12 @@ export default class ModifierSelectUiHandler extends AwaitableUiHandler {
return true;
}
refresh() {
this.clear()
this.args[1] = this.optionP[this.refreshIndex]
this.show(this.args)
}
processInput(button: Button): boolean {
const ui = this.getUi();