From 4320517234263b9048bc805b160d82d8c699bc30 Mon Sep 17 00:00:00 2001 From: RedstonewolfX <108761527+RedstonewolfX@users.noreply.github.com> Date: Sat, 20 Jul 2024 16:30:06 -0400 Subject: [PATCH] Reapply "Reload Detection is here" This reverts commit ecdc035ab57dde4f635fd510b5003e3c0dab808b. --- src/logger.ts | 127 ++++++++++++++++++++++++++++++++++++++++---------- src/phases.ts | 40 +++++++++++++--- 2 files changed, 135 insertions(+), 32 deletions(-) diff --git a/src/logger.ts b/src/logger.ts index 80a78a20c2d..80ab9da7152 100644 --- a/src/logger.ts +++ b/src/logger.ts @@ -47,8 +47,13 @@ export const rarities = [] export const rarityslot = [0, ""] /** Stores a list of the user's battle actions in a turn. * - * Its contents are printed to the current wave's actions list, separated by pipes `|`, when the turn begins playing out. */ + * Its contents are printed to the current wave's `actions` list, separated by pipes `|`, when the turn begins playing out. */ export const Actions = [] +/** Stores a list of the opponent's battle actions in a turn. + * + * Its contents are printed to the current wave's `initialActions` list, separated by pipes `|`, when the turn begins playing out. +*/ +export const EnemyActions = [] // Booleans export const isPreSwitch: Utils.BooleanHolder = new Utils.BooleanHolder(false); @@ -212,7 +217,7 @@ export function getDRPD(scene: BattleScene): DRPD { } export function save(scene: BattleScene, drpd: DRPD) { - console.log(drpd) + console.log("--> ", drpd) localStorage.setItem(getLogID(scene), JSON.stringify(drpd)) } @@ -561,6 +566,7 @@ export interface Wave { */ trainer?: TrainerData, /** The Pokémon that you have to battle against. + * * Not included if this is a trainer battle. * @see PokeData * @see Wave.type @@ -568,11 +574,20 @@ export interface Wave { pokemon?: PokeData[], /** * Contains the first 3 turns or so of the enemy's actions. + * * Used to check for refreshes. */ initialActions: string[], + /** + * The current writing index in the `initialActions` array. + * + * Used to track changes between this wave's actions and the previous one + * @see Wave.initialActions + */ + turnIndex: integer, /** * Contains the names of the first set of modifier rewards. + * * Used to check for refreshes. */ modifiers: string[] @@ -593,6 +608,7 @@ export function exportWave(scene: BattleScene): Wave { clearActionsFlag: false, biome: getBiomeName(scene.arena.biomeType), initialActions: [], + turnIndex: 0, modifiers: [] } if (ret.double == undefined) ret.double = false; @@ -710,7 +726,7 @@ function printWave(inData: string, indent: string, wave: Wave): string { export function getWave(drpd: DRPD, floor: integer, scene: BattleScene): Wave { var wv: Wave; var insertPos: integer; - console.log(drpd.waves) + //console.log(drpd.waves) for (var i = 0; i < drpd.waves.length; i++) { if (drpd.waves[i] != undefined && drpd.waves[i] != null) { if (drpd.waves[i].id == floor) { @@ -736,6 +752,7 @@ export function getWave(drpd: DRPD, floor: integer, scene: BattleScene): Wave { clearActionsFlag: false, biome: getBiomeName(scene.arena.biomeType), initialActions: [], + turnIndex: 0, modifiers: [], //pokemon: [] } @@ -771,6 +788,7 @@ export function getWave(drpd: DRPD, floor: integer, scene: BattleScene): Wave { biome: getBiomeName(scene.arena.biomeType), clearActionsFlag: false, initialActions: [], + turnIndex: 0, modifiers: [], //pokemon: [] }) @@ -809,6 +827,7 @@ export function getWave(drpd: DRPD, floor: integer, scene: BattleScene): Wave { biome: getBiomeName(scene.arena.biomeType), clearActionsFlag: false, initialActions: [], + turnIndex: 0, modifiers: [], //pokemon: [] } @@ -839,6 +858,7 @@ export function getWave(drpd: DRPD, floor: integer, scene: BattleScene): Wave { clearActionsFlag: false, biome: getBiomeName(scene.arena.biomeType), initialActions: [], + turnIndex: 0, modifiers: [], //pokemon: [] } @@ -1503,10 +1523,34 @@ export function logActions(scene: BattleScene, floor: integer, action: string) { console.log("Triggered clearActionsFlag") wv.clearActionsFlag = false wv.actions = [] + wv.turnIndex = 0 } wv.actions.push(action) - console.log("--> ", drpd) - localStorage.setItem(getLogID(scene), JSON.stringify(drpd)) + save(scene, drpd) +} +/** + * Logs an opposing Pokemon's attack. If there is existing data, and it is different from the new data, a reload is flagged. + * @param scene The BattleScene. Used to get the log ID. + * @param floor The wave index to write to. Defaults to the current wave. + * @param action The action to write. + */ +export function logEnemyAction(scene: BattleScene, floor: integer = undefined, action: string) { + if (floor == undefined) + floor = scene.currentBattle.waveIndex; + var drpd = getDRPD(scene) + var wv = getWave(drpd, floor, scene) + if (wv.turnIndex >= EnemyEventLogCount) { + // Don't log any actions if we already logged the maximum amount + return; + } + console.log(`Log enemy action: "${action}" (Turn ${wv.turnIndex})`, drpd) + if (wv.initialActions[wv.turnIndex] != undefined && wv.initialActions[wv.turnIndex] != action) { + console.log(`New action (${action}) is different from old action (${wv.initialActions[wv.turnIndex]})! Flagging a reload`) + wv.reload = true + } + wv.initialActions[wv.turnIndex] = action + wv.turnIndex++ + save(scene, drpd) } /** * Logs the actions that the player took, adding text to the most recent action. @@ -1524,13 +1568,13 @@ export function appendAction(scene: BattleScene, floor: integer, action: string) console.log("Triggered clearActionsFlag") wv.clearActionsFlag = false wv.actions = [] + wv.turnIndex = 0 } console.log(`Appending to an action: "${wv.actions[wv.actions.length - 1]}" + "${action}"`) if (wv.double == undefined) wv.double = false wv.actions[wv.actions.length - 1] = wv.actions[wv.actions.length - 1] + action - console.log("--> ", drpd) - localStorage.setItem(getLogID(scene), JSON.stringify(drpd)) + save(scene, drpd) } /** * Logs the actions that the player took. @@ -1553,6 +1597,7 @@ export function getActionCount(scene: BattleScene, floor: integer) { console.log("Triggered clearActionsFlag") wv.clearActionsFlag = false wv.actions = [] + wv.turnIndex = 0 } return (wv.actions.length) } @@ -1569,8 +1614,30 @@ export function logCapture(scene: BattleScene, floor: integer, target: EnemyPoke var wv: Wave = getWave(drpd, floor, scene) var pkslot = target.partyslot wv.pokemon[pkslot].captured = true; - console.log("--> ", drpd) - localStorage.setItem(getLogID(scene), JSON.stringify(drpd)) + save(scene, drpd) +} +/** + * Logs the player's modifiers/loot. If there is existing data, and it is different from the new data, a reload is flagged. + * @param scene The BattleScene. Used to get the log ID. + * @param floor The wave index to write to. Defaults to the current wave. + * @param logModifiers The action to write. + */ +export function logModifiers(scene: BattleScene, floor: integer = undefined, modifiers: string[]) { + if (floor == undefined) + floor = scene.currentBattle.waveIndex; + var drpd = getDRPD(scene) + var wv = getWave(drpd, floor, scene) + console.log("Log modifiers list", drpd) + if (wv.modifiers.length > 0 && wv.modifiers.join(", ") != modifiers.join(", ")) { + console.log("The modifiers list changed!") + for (var i = 0; i < wv.modifiers.length; i++) { + console.log(wv.modifiers[i], modifiers[i]) + console.log("Flagging a reload") + } + wv.reload = true + } + wv.modifiers = modifiers + save(scene, drpd) } /** * Logs the player's current party. @@ -1585,8 +1652,7 @@ export function logPlayerTeam(scene: BattleScene) { for (var i = 0; i < P.length; i++) { drpd.starters[i] = exportPokemon(P[i]) } - console.log("--> ", drpd) - localStorage.setItem(getLogID(scene), JSON.stringify(drpd)) + save(scene, drpd) } /** * Logs a wild Pokémon to a wave's data. @@ -1666,8 +1732,7 @@ export function logPokemon(scene: BattleScene, floor: integer = undefined, slot: //wv.actions = [] wv.clearActionsFlag = false; wv.shop = "" - console.log("--> ", drpd) - localStorage.setItem(getLogID(scene), JSON.stringify(drpd)) + save(scene, drpd) } /** * Logs what the player took from the rewards pool and, if applicable, who they used it on. @@ -1681,8 +1746,7 @@ export function logShop(scene: BattleScene, floor: integer, action: string) { console.log(`Logging shop result: "${action}"`) var wv: Wave = getWave(drpd, floor, scene) wv.shop = action - console.log("--> ", drpd) - localStorage.setItem(getLogID(scene), JSON.stringify(drpd)) + save(scene, drpd) } /** * Logs the current floor's Trainer. @@ -1699,18 +1763,33 @@ export function logTrainer(scene: BattleScene, floor: integer = undefined) { var t: TrainerData = exportTrainer(scene.currentBattle.trainer) wv.trainer = t wv.type = "trainer" - console.log("--> ", drpd) - localStorage.setItem(getLogID(scene), JSON.stringify(drpd)) + save(scene, drpd) } +/** + * Logs the player's modifiers/loot. If there is existing data, and it is different from the new data, a reload is flagged. + * @param scene The BattleScene. Used to get the log ID. + * @param floor The wave index to write to. Defaults to the current wave. + */ +export function deleteReloadDetectionData(scene: BattleScene, floor: integer = undefined) { + if (floor == undefined) + floor = scene.currentBattle.waveIndex; + var drpd = getDRPD(scene) + var wv = getWave(drpd, floor, scene) + console.log("Clear action & modifier storage", drpd) + wv.modifiers = [] + wv.initialActions = [] + wv.turnIndex = 0 + save(scene, drpd) +} /** * Flags a wave as a reset. * @param scene The BattleScene. Used to get the log ID. - * @param floor The wave index to write to. + * @param floor The wave index to write to. Defaults to the current wave. */ export function flagReset(scene: BattleScene, floor: integer = undefined) { if (floor == undefined) @@ -1721,8 +1800,7 @@ export function flagReset(scene: BattleScene, floor: integer = undefined) { console.log("Flag Reset", drpd) var wv = getWave(drpd, floor, scene) wv.reload = true; - console.log("--> ", drpd) - localStorage.setItem(getLogID(scene), JSON.stringify(drpd)) + save(scene, drpd) } /** * Flags a wave as a reset, unless this is your first time playing the wave. @@ -1750,8 +1828,7 @@ export function flagResetIfExists(scene: BattleScene, floor: integer = undefined console.log("Flag reset as wave was already played before", drpd) var wv = getWave(drpd, floor, scene) wv.reload = true; - console.log("--> ", drpd) - localStorage.setItem(getLogID(scene), JSON.stringify(drpd)) + save(scene, drpd) } @@ -1773,9 +1850,9 @@ export function resetWaveActions(scene: BattleScene, floor: integer = undefined, if (softflag) { wv.clearActionsFlag = true; } else { - wv.actions = [] + wv.actions = []; + wv.turnIndex = 0; } - console.log("--> ", drpd) - localStorage.setItem(getLogID(scene), JSON.stringify(drpd)) + save(scene, drpd) } //#endregion \ No newline at end of file diff --git a/src/phases.ts b/src/phases.ts index 3c60d3288bc..b3a89e64a5e 100644 --- a/src/phases.ts +++ b/src/phases.ts @@ -1700,6 +1700,30 @@ export class EncounterPhase extends BattlePhase { } } } + // Get this run's log (or generate it, if there isn't one) + var d = LoggerTools.getDRPD(this.scene) + if (d != undefined) { + // Get the current wave (or generate one, if there isn't any data) + var w = LoggerTools.getWave(d, this.scene.currentBattle.waveIndex, this.scene) + if (w != undefined) { + if (w.initialActions == undefined) w.initialActions = [] + if (w.modifiers == undefined) w.modifiers = [] + if (w.turnIndex == undefined) w.turnIndex = 0 + // If any data has been written for this wave + if (w.initialActions.length > 0 || w.modifiers.length > 0 || w.turnIndex > 0) { + this.scene.ui.showText("This wave has existing data.\nClear it?", undefined, () => { + this.scene.ui.setMode(Mode.CONFIRM, () => { + //this.scene.ui.revertMode() + this.scene.ui.clearText() + LoggerTools.deleteReloadDetectionData(this.scene) + }, () => { + //this.scene.ui.revertMode() + this.scene.ui.clearText() + }) + }, 500) + } + } + } handleTutorial(this.scene, Tutorial.Access_Menu).then(() => super.end()); } @@ -3312,6 +3336,7 @@ export class TurnStartPhase extends FieldPhase { this.scene.pushPhase(new MovePhase(this.scene, pokemon, turnCommand.targets || turnCommand.move.targets, move, false, queuedMove.ignorePP)); var targets = turnCommand.targets || turnCommand.move.targets var mv = new PokemonMove(queuedMove.move) + LoggerTools.EnemyActions[pokemon.getBattlerIndex() - 2] = move.getName() } break; case Command.BALL: @@ -3360,8 +3385,8 @@ export class TurnStartPhase extends FieldPhase { if (LoggerTools.Actions.length > 1 && (LoggerTools.Actions[0] == "" || LoggerTools.Actions[0] == undefined || LoggerTools.Actions[0] == null)) LoggerTools.Actions.shift() // If the left slot isn't doing anything, delete its entry - LoggerTools.logActions(this.scene, this.scene.currentBattle.waveIndex, LoggerTools.Actions.join(" | ")) + LoggerTools.logEnemyAction(this.scene, this.scene.currentBattle.waveIndex, LoggerTools.EnemyActions.join(" | ")) this.end(); } @@ -6403,12 +6428,6 @@ export class SelectModifierPhase extends BattlePhase { start() { super.start(); - if (!this.rerollCount) { - this.updateSeed(); - } else { - this.scene.reroll = false; - } - const party = this.scene.getParty(); regenerateModifierPoolThresholds(party, this.getPoolType(), this.rerollCount); const modifierCount = new Utils.IntegerHolder(3); @@ -6582,6 +6601,13 @@ export class SelectModifierPhase extends BattlePhase { applyModifier(modifierType.newModifier()); } + if (!this.rerollCount) { + this.updateSeed(); + LoggerTools.logModifiers(this.scene, undefined, typeOptions.map(v => v.type.name)) + } else { + this.scene.reroll = false; + } + return !cost; }; this.scene.ui.setMode(Mode.MODIFIER_SELECT, this.isPlayer(), typeOptions, modifierSelectCallback, this.getRerollCost(typeOptions, this.scene.lockModifierTiers));