Remove enemy attack pre-calc

Due to the bugs it was causing, I've reverted the change I made where the enemy performs its attacks before you.

As a result, this breaks the following features that rely on this:
- Enemy attack prediction
- Catch prediction (I'm so sorry) (this has been reverted to showing % chance of success until I rework it)

In addition, if having a shiny breaks the shop, the minimum luck value that breaks the shop is shown on the charm.
This commit is contained in:
RedstonewolfX 2024-08-14 09:58:06 -04:00
parent ec7852a706
commit 310a497627
5 changed files with 54 additions and 16 deletions

View File

@ -131,6 +131,7 @@ export default class BattleScene extends SceneBase {
public disableDailyShinies: boolean = true; // Disables shiny luck in Daily Runs to prevent affecting RNG
public quickloadDisplayMode: string = "Dailies";
public waveShinyFlag: boolean = false;
public waveShinyMinToBreak: integer = 0;
public waveShinyChecked: boolean = false;
public tempWaveSeed: string;
public tempRngCounter: integer = 0;
@ -1288,7 +1289,9 @@ export default class BattleScene extends SceneBase {
doShinyCheck() {
this.waveShinyChecked = true;
this.waveShinyFlag = runShinyCheck(this, 1, this.currentBattle.waveIndex);
var r = runShinyCheck(this, 1, this.currentBattle.waveIndex)
this.waveShinyFlag = r[0] as boolean;
this.waveShinyMinToBreak = r[1] as integer;
if (this.waveShinyFlag) {
this.arenaFlyout.display2()
}

View File

@ -1958,8 +1958,8 @@ export class StealHeldItemChanceAttr extends MoveEffectAttr {
console.error("Reload discrepancy: Succeeds now, but fails after reload")
LoggerTools.flagReset(user.scene, user.scene.currentBattle.waveIndex)
}
*/
//*/
if (rand >= this.chance) {
return resolve(false);
}

View File

@ -186,9 +186,9 @@ function findBest(scene: BattleScene, pokemon: EnemyPokemon, override?: boolean)
}
})
if (func_output != "") {
return func_output
//return func_output
}
return "Can't catch"
//return "Can't catch"
var n = ""
switch (rates2[0]) {
case rates[0]:
@ -215,7 +215,7 @@ function findBest(scene: BattleScene, pokemon: EnemyPokemon, override?: boolean)
return "No balls"
}
}
return n + " (FAIL)"
//return n + " (FAIL)"
return n + Math.round(rates2[0] * 100) + "%";
}
export function parseSlotData(slotId: integer): SessionSaveData {
@ -2901,7 +2901,7 @@ export class TurnInitPhase extends FieldPhase {
LoggerTools.enemyPlan[2] = ""
LoggerTools.enemyPlan[3] = ""
if (false) {
if (true) {
this.scene.getField().forEach((pokemon, i) => {
if (pokemon?.isActive()) {
if (pokemon.isPlayer()) {
@ -3302,8 +3302,8 @@ export class EnemyCommandPhase extends FieldPhase {
console.log(enemyPokemon.name + " selects:", "Switch to " + this.scene.getEnemyParty()[index].name)
battle.enemySwitchCounter++;
LoggerTools.enemyPlan[this.fieldIndex*2] = "Switching out"
LoggerTools.enemyPlan[this.fieldIndex*2 + 1] = "→ " + this.scene.getEnemyParty()[index].name
//LoggerTools.enemyPlan[this.fieldIndex*2] = "Switching out"
//LoggerTools.enemyPlan[this.fieldIndex*2 + 1] = "→ " + this.scene.getEnemyParty()[index].name
enemyPokemon.flyout.setText()
@ -3357,8 +3357,8 @@ export class EnemyCommandPhase extends FieldPhase {
console.log(enemyPokemon.name + " selects:", mv.getName() + " → " + nextMove.targets.map((m) => targetLabels[m + 1]))
this.scene.currentBattle.enemySwitchCounter = Math.max(this.scene.currentBattle.enemySwitchCounter - 1, 0);
LoggerTools.enemyPlan[this.fieldIndex*2] = mv.getName()
LoggerTools.enemyPlan[this.fieldIndex*2 + 1] = "→ " + nextMove.targets.map((m) => targetLabels[m + 1])
//LoggerTools.enemyPlan[this.fieldIndex*2] = mv.getName()
//LoggerTools.enemyPlan[this.fieldIndex*2 + 1] = "→ " + nextMove.targets.map((m) => targetLabels[m + 1])
this.scene.arenaFlyout.updateFieldText()
var txt = ["Turn: " + this.scene.currentBattle.turn]
@ -3368,6 +3368,9 @@ export class EnemyCommandPhase extends FieldPhase {
txt = txt.concat(findBest(this.scene, pk))
})
}
if (txt.length > 2) {
txt = ["Turn: " + this.scene.currentBattle.turn]
}
this.scene.arenaFlyout.updateFieldText()
@ -6770,6 +6773,7 @@ const tierNames = [
* @returns
*/
export function shinyCheckStep(scene: BattleScene, predictionCost: Utils.IntegerHolder, rerollOverride: integer, modifierOverride?: integer) {
var minLuck = -1
var modifierPredictions = []
const party = scene.getParty();
regenerateModifierPoolThresholds(party, ModifierPoolType.PLAYER, rerollOverride);
@ -6788,13 +6792,15 @@ export function shinyCheckStep(scene: BattleScene, predictionCost: Utils.Integer
//lastTier = option.alternates[i]
//console.log("Conflict found! (" + i + " luck, " + rerollOverride + " rolls, item " + (idx + 1) + ")")
isOk = false // Shiny Luck affects this wave in some way
if (minLuck == -1 && i != 0)
minLuck = i
}
}
}
})
modifierPredictions.push(typeOptions)
predictionCost.value += (Math.min(Math.ceil(scene.currentBattle.waveIndex / 10) * 250 * Math.pow(2, rerollOverride), Number.MAX_SAFE_INTEGER))
return isOk;
return [isOk, minLuck];
}
/**
* Simulates modifier rolls for as many rerolls as you can afford, checking to see if shiny luck will alter your results.
@ -6802,6 +6808,7 @@ export function shinyCheckStep(scene: BattleScene, predictionCost: Utils.Integer
* @returns `true` if no changes were detected, `false` otherwise
*/
export function runShinyCheck(scene: BattleScene, mode: integer, wv?: integer) {
var minLuck: integer = -1
if (mode == 1) {
scene.emulateReset(wv)
} else {
@ -6809,8 +6816,18 @@ export function runShinyCheck(scene: BattleScene, mode: integer, wv?: integer) {
}
const predictionCost = new Utils.IntegerHolder(0)
var isOk = true;
for (var i = 0; isOk && predictionCost.value < scene.money && i < 20; i++) {
isOk = isOk && shinyCheckStep(scene, predictionCost, i)
for (var i = 0; predictionCost.value < scene.money && i < 8; i++) {
var r = shinyCheckStep(scene, predictionCost, i)
isOk = isOk && (r[0] as boolean)
if (isOk || (r[1] as integer) === -1) {
// Do nothing
} else if (minLuck == -1) {
minLuck = (r[1] as integer)
console.log("Luck " + r[1] + " breaks")
} else {
console.log("Updated from " + minLuck + " to " + Math.min(minLuck, (r[1] as integer)))
minLuck = Math.min(minLuck, (r[1] as integer))
}
}
if (mode == 1) {
scene.restoreSeed(wv)
@ -6820,7 +6837,10 @@ export function runShinyCheck(scene: BattleScene, mode: integer, wv?: integer) {
if (!isOk) {
console.log("Conflict found!")
}
return isOk
if (minLuck == 15) {
//minLuck = 0
}
return [isOk, minLuck]
}
export class SelectModifierPhase extends BattlePhase {
private rerollCount: integer;

View File

@ -15,6 +15,7 @@ import * as LoggerTools from "../logger"
import { BattleEndPhase } from "#app/phases.js";
import { Gender } from "#app/data/gender.js";
import { getBiomeName } from "#app/data/biomes.js";
import { getLuckString } from "#app/modifier/modifier-type.js";
/** Enum used to differentiate {@linkcode Arena} effects */
enum ArenaEffectType {
@ -95,6 +96,7 @@ export class ArenaFlyout extends Phaser.GameObjects.Container {
private flyoutTextField: Phaser.GameObjects.Text;
private shinyCharmIcon: Phaser.GameObjects.Sprite;
private shinyCharmLuckCount: Phaser.GameObjects.Text;
public shinyState: integer = 0;
/** Container for all field effects observed by this object */
@ -198,26 +200,38 @@ export class ArenaFlyout extends Phaser.GameObjects.Container {
this.shinyCharmIcon.setScale(0.4)
this.shinyCharmIcon.setInteractive(new Phaser.Geom.Rectangle(2, 2, 26, 27), Phaser.Geom.Rectangle.Contains);
this.flyoutContainer.add(this.shinyCharmIcon)
this.shinyCharmLuckCount = addTextObject(this.scene, this.flyoutWidth - 9, 5, "?", TextStyle.BATTLE_INFO);
this.shinyCharmLuckCount.setLineSpacing(-1);
this.shinyCharmLuckCount.setFontSize(40);
this.shinyCharmLuckCount.setAlign("center");
this.shinyCharmLuckCount.setOrigin(0, 0);
this.flyoutContainer.add(this.shinyCharmLuckCount)
}
doShinyCharmTooltip() {
if ((this.scene as BattleScene).currentBattle.waveIndex % 10 == 0) {
this.shinyCharmIcon.setVisible(false)
this.shinyCharmLuckCount.setVisible(false)
return;
}
this.shinyCharmIcon.setVisible(true)
this.shinyCharmLuckCount.setVisible(true)
if (true) { // this.shinyCharmIcon.visible
this.shinyCharmIcon.removeAllListeners()
if (!(this.scene as BattleScene).waveShinyChecked) {
this.shinyCharmIcon.setVisible(false)
this.shinyCharmLuckCount.setVisible(false)
return;
//this.shinyCharmIcon.on("pointerover", () => (this.scene as BattleScene).ui.showTooltip(null, `???`));
} else if ((this.scene as BattleScene).waveShinyFlag) {
this.shinyCharmIcon.clearTint()
this.shinyCharmIcon.on("pointerover", () => (this.scene as BattleScene).ui.showTooltip(null, `Shinies are OK`));
this.shinyCharmLuckCount.setVisible(false)
} else {
this.shinyCharmIcon.setTintFill(0x000000)
this.shinyCharmIcon.on("pointerover", () => (this.scene as BattleScene).ui.showTooltip(null, `Shinies change shop`));
this.shinyCharmIcon.on("pointerover", () => (this.scene as BattleScene).ui.showTooltip(null, `Shinies change shop with luck ${(this.scene as BattleScene).waveShinyMinToBreak} or higher`));
this.shinyCharmLuckCount.text = getLuckString((this.scene as BattleScene).waveShinyMinToBreak)
}
this.shinyCharmIcon.on("pointerout", () => (this.scene as BattleScene).ui.hideTooltip());
}

View File

@ -126,6 +126,7 @@ export default class BattleFlyout extends Phaser.GameObjects.Container {
/** Sets and formats the text property for all {@linkcode Phaser.GameObjects.Text} in the flyoutText array */
setText(highlight?: integer) {
highlight = undefined // Disable move highlighting - for now, it shows what the pokemon used last turn, which is confusing
var e = this.battleScene.getEnemyField()
console.log(this.moveInfo.map(v => v.move.name))
for (let i = 0; i < this.flyoutText.length; i++) {