This commit is contained in:
RedstonewolfX 2024-08-17 16:16:52 -04:00
commit 8608a5bfdc
6 changed files with 107 additions and 58 deletions

View File

@ -1,6 +1,6 @@
import Phaser from "phaser";
import UI from "./ui/ui";
import { NextEncounterPhase, NewBiomeEncounterPhase, SelectBiomePhase, MessagePhase, TurnInitPhase, ReturnPhase, LevelCapPhase, ShowTrainerPhase, LoginPhase, MovePhase, TitlePhase, SwitchPhase, SummonPhase, ToggleDoublePositionPhase, runShinyCheck } from "./phases";
import { NextEncounterPhase, NewBiomeEncounterPhase, SelectBiomePhase, MessagePhase, TurnInitPhase, ReturnPhase, LevelCapPhase, ShowTrainerPhase, LoginPhase, MovePhase, TitlePhase, SwitchPhase, SummonPhase, ToggleDoublePositionPhase, runShinyCheck, findBest } from "./phases";
import Pokemon, { PlayerPokemon, EnemyPokemon } from "./field/pokemon";
import PokemonSpecies, { PokemonSpeciesFilter, allSpecies, getPokemonSpecies } from "./data/pokemon-species";
import { Constructor } from "#app/utils";
@ -1145,6 +1145,23 @@ export default class BattleScene extends SceneBase {
if (this.waveShinyFlag) {
this.arenaFlyout.display2()
}
LoggerTools.logLuck(this)
}
updateCatchRate() {
var txt = ["Turn: " + this.currentBattle.turn]
if (!this.getEnemyField()[0].hasTrainer()) {
this.getEnemyField().forEach((pk, i) => {
if (pk.isActive() && pk.hp > 0)
txt = txt.concat(findBest(this, pk))
})
}
if (txt.length > 2) {
txt = ["Turn: " + this.currentBattle.turn]
}
this.arenaFlyout.updateFieldText()
this.setScoreText(txt.join(" / "))
}
newBattle(waveIndex?: integer, battleType?: BattleType, trainerData?: TrainerData, double?: boolean): Battle {

View File

@ -357,7 +357,7 @@ export default class Battle {
return null;
}
multiInt(scene: BattleScene, out: integer[], count: integer, range: integer, min: integer = 0) {
multiInt(scene: BattleScene, out: integer[], count: integer, range: integer, min: integer = 0, reason: string = "Unlabeled randSeedInt", offset: integer = 0) {
if (range <= 1) {
return min;
}
@ -370,9 +370,14 @@ export default class Battle {
Phaser.Math.RND.sow([ Utils.shiftCharCodes(this.battleSeed, this.turn << 6) ]);
console.log("Battle Seed:", this.battleSeed);
}
for (var i = 0; i < offset; i++) {
// Perform useless rolls to offset RNG counter
Utils.randSeedInt(5)
}
for (var i = 0; i < count; i++) {
out.push(Utils.randSeedInt(range, min))
}
console.log("[SIMULATED] " + reason + " (x" + count + (offset ? " + offset " + offset : "") + ")", out)
Phaser.Math.RND.state(state);
//scene.setScoreText("RNG: " + tempRngCounter + " (Last sim: " + this.rngCounter + ")")
scene.rngCounter = tempRngCounter;

View File

@ -45,7 +45,7 @@ SECTIONS
/** The number of enemy actions to log. */
export const EnemyEventLogCount = 3
/** The current DRPD version. */
export const DRPD_Version = "1.1.0"
export const DRPD_Version = "1.1.0a"
/** (Unused / reference only) All the log versions that this mod can keep updated.
* @see updateLog
*/
@ -53,6 +53,7 @@ export const acceptedVersions = [
"1.0.0",
"1.0.0a",
"1.1.0",
"1.1.0a",
]
// Value holders
@ -455,7 +456,10 @@ export interface DRPD {
*/
waves: Wave[],
/** The Pokemon that the player started with. Daily runs will have 3. @see PokeData */
starters?: PokeData[]
starters?: PokeData[],
/** The maximum luck value you can have. If your luck value is higher than this, some floors may break. */
maxluck?: integer;
minSafeLuckFloor?: integer[];
}
/**
* Imports a string as a DRPD.
@ -476,12 +480,14 @@ export function newDocument(name: string = "Untitled Run", authorName: string |
version: DRPD_Version,
seed: "",
title: name,
label: "",
label: "unnamedRoute",
uuid: "",
authors: (Array.isArray(authorName) ? authorName : [authorName]),
date: new Date().getUTCFullYear() + "-" + (new Date().getUTCMonth() + 1 < 10 ? "0" : "") + (new Date().getUTCMonth() + 1) + "-" + (new Date().getUTCDate() < 10 ? "0" : "") + new Date().getUTCDate(),
waves: new Array(50),
starters: new Array(3),
//maxluck: 14,
//minSafeLuckFloor: [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]
}
var RState = Phaser.Math.RND.state()
ret.uuid = Phaser.Math.RND.uuid()
@ -587,6 +593,11 @@ function updateLog(drpd: DRPD): DRPD {
Phaser.Math.RND.state(RState)
drpd.label = "route"
} // 1.0.0a → 1.1.0
if (drpd.version == "1.1.0") {
drpd.version = "1.1.0a"
drpd.maxluck = 14
drpd.minSafeLuckFloor = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]
} // 1.1.0 → 1.1.0a
return drpd;
}
// #endregion
@ -1681,6 +1692,25 @@ export function logPlayerTeam(scene: BattleScene) {
console.log("--> ", drpd)
localStorage.setItem(getLogID(scene), JSON.stringify(drpd))
}
/**
* Checks the minimum luck that will break this floor's shop, and updates the appropriate values.
* @param scene The BattleScene.
*/
export function logLuck(scene: BattleScene) {
//return;
var drpd = getDRPD(scene)
if (scene.waveShinyMinToBreak > 0) {
console.log(`Logging luck stats`)
drpd.maxluck = Math.min(drpd.maxluck!, scene.waveShinyMinToBreak - 1)
for (var i = scene.waveShinyMinToBreak; i <= 14; i++) {
drpd.minSafeLuckFloor![i] = Math.max(drpd.minSafeLuckFloor![i], scene.currentBattle.waveIndex)
}
console.log("--> ", drpd)
localStorage.setItem(getLogID(scene), JSON.stringify(drpd))
} else {
console.log(`Skipped logging luck stats: Luck has no effect on this floor`)
}
}
/**
* Logs a wild Pokémon to a wave's data.
* @param scene The BattleScene. Used to retrieve the log ID.

View File

@ -129,7 +129,7 @@ function catchCalcRaw(pokemon: EnemyPokemon) {
* @param override Show the best Poké Ball to use, even if you don't have any.
* @returns The name and % rate of the best Poké Ball.
*/
function findBest(scene: BattleScene, pokemon: EnemyPokemon, override?: boolean) {
export function findBest(scene: BattleScene, pokemon: EnemyPokemon, override?: boolean) {
var rates = catchCalc(pokemon)
var rates_raw = catchCalcRaw(pokemon)
var rolls = []
@ -144,7 +144,7 @@ function findBest(scene: BattleScene, pokemon: EnemyPokemon, override?: boolean)
}
})
})
scene.currentBattle.multiInt(scene, rolls, offset + 3, 65536)
scene.currentBattle.multiInt(scene, rolls, offset + 3, 65536, undefined, "Catch prediction")
//console.log(rolls)
//console.log(rolls.slice(offset, offset + 3))
if (scene.pokeballCounts[0] == 0 && !override) rates[0] = 0
@ -2922,12 +2922,15 @@ export class TurnInitPhase extends FieldPhase {
if (false) {
this.scene.getField().forEach((pokemon, i) => {
if (pokemon != undefined && pokemon != null)
console.log("Handle " + pokemon.name)
if (pokemon?.isActive()) {
if (pokemon.isPlayer()) {
this.scene.currentBattle.addParticipant(pokemon as PlayerPokemon);
} else {
pokemon.flyout.setText()
console.log("Marked " + pokemon.name + " as used")
pokemon.usedInBattle = true;
pokemon.flyout.setText()
pokemon.getBattleInfo().iconsActive = true
}
pokemon.resetTurnData();
@ -2990,20 +2993,7 @@ export class TurnInitPhase extends FieldPhase {
this.scene.pushPhase(new TurnStartPhase(this.scene));
var txt = ["Turn: " + this.scene.currentBattle.turn]
if (!this.scene.getEnemyField()[0].hasTrainer()) {
this.scene.getEnemyField().forEach((pk, i) => {
if (pk.isActive() && pk.hp > 0)
txt = txt.concat(findBest(this.scene, pk))
})
}
if (txt.length > 2) {
txt = ["Turn: " + this.scene.currentBattle.turn]
}
this.scene.arenaFlyout.updateFieldText()
this.scene.setScoreText(txt.join(" / "))
this.scene.updateCatchRate()
this.end();
}
@ -3355,20 +3345,7 @@ export class EnemyCommandPhase extends FieldPhase {
enemyPokemon.flyout.setText()
var txt = ["Turn: " + this.scene.currentBattle.turn]
if (!this.scene.getEnemyField()[0].hasTrainer()) {
this.scene.getEnemyField().forEach((pk, i) => {
if (pk.isActive() && pk.hp > 0)
txt = txt.concat(findBest(this.scene, pk))
})
}
if (txt.length > 2) {
txt = ["Turn: " + this.scene.currentBattle.turn]
}
this.scene.arenaFlyout.updateFieldText()
this.scene.setScoreText(txt.join(" / "))
this.scene.updateCatchRate()
return this.end();
}
@ -3410,24 +3387,20 @@ export class EnemyCommandPhase extends FieldPhase {
LoggerTools.enemyPlan[this.fieldIndex*2 + 1] = "→ " + nextMove.targets.map((m) => targetLabels[m + 1])
this.scene.arenaFlyout.updateFieldText()
var txt = ["Turn: " + this.scene.currentBattle.turn]
if (!this.scene.getEnemyField()[0].hasTrainer()) {
this.scene.getEnemyField().forEach((pk, i) => {
if (pk.isActive() && pk.hp > 0)
txt = txt.concat(findBest(this.scene, pk))
})
}
if (txt.length > 2) {
txt = ["Turn: " + this.scene.currentBattle.turn]
}
this.scene.arenaFlyout.updateFieldText()
this.scene.setScoreText(txt.join(" / "))
this.scene.updateCatchRate()
this.end();
}
}
export function enemyTurnCalc(scene: BattleScene) {
scene.getField().forEach(pokemon => {
if (pokemon.isActive()) {
if (!pokemon.isPlayer()) {
var pk = pokemon as EnemyPokemon;
}
}
})
}
//#endregion

View File

@ -16,6 +16,7 @@ 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";
import { Species } from "#app/enums/species.js";
/** Enum used to differentiate {@linkcode Arena} effects */
enum ArenaEffectType {
@ -316,12 +317,29 @@ export class ArenaFlyout extends Phaser.GameObjects.Container {
var formtext = ""
if (poke[i].species.forms?.[poke[i].formIndex]?.formName) {
formtext = " (" + poke[i].species.forms?.[poke[i].formIndex]?.formName + ")"
if (formtext == " (Normal)") {
if (formtext == " (Normal)" || formtext == " (Hero of Many Battles)") {
formtext = ""
}
if (poke[i].species.speciesId == Species.MINIOR) {
formtext = " (" + poke[i].species.forms?.[poke[i].formIndex]?.formName.split(" ")[0] + ")"
}
if (poke[i].species.speciesId == Species.SQUAWKABILLY) {
formtext = " (" + poke[i].species.forms?.[poke[i].formIndex]?.formName.substring(0, poke[i].species.forms?.[poke[i].formIndex]?.formName.length - " Plumage".length) + ")"
}
if (poke[i].species.speciesId == Species.ORICORIO) {
formtext = " (" + poke[i].species.forms?.[poke[i].formIndex]?.formName.substring(0, poke[i].species.forms?.[poke[i].formIndex]?.formName.length - " Style".length) + ")"
}
}
this.flyoutTextPlayer.text += poke[i].name + formtext + " " + (poke[i].gender == Gender.MALE ? "♂" : (poke[i].gender == Gender.FEMALE ? "♀" : "-")) + " " + poke[i].level + "\n"
this.flyoutTextEnemy.text += poke[i].getAbility().name + " / " + (poke[i].isBoss() ? poke[i].getPassiveAbility().name + " / " : "") + getNatureName(poke[i].nature) + (getNatureIncrease(poke[i].nature) != "" ? " (+" + getNatureIncrease(poke[i].nature) + " -" + getNatureDecrease(poke[i].nature) + ")" : "") + "\n\n\n"
const beforeText1 = this.flyoutTextPlayer.text
const beforeText2 = this.flyoutTextEnemy.text
this.flyoutTextPlayer.text = poke[i].name + formtext + " " + (poke[i].gender == Gender.MALE ? "♂" : (poke[i].gender == Gender.FEMALE ? "♀" : "-")) + " " + poke[i].level
this.flyoutTextEnemy.text = poke[i].getAbility().name + (poke[i].isBoss() ? ", " + poke[i].getPassiveAbility().name : "") + " / " + getNatureName(poke[i].nature) + (getNatureIncrease(poke[i].nature) != "" ? " (+" + getNatureIncrease(poke[i].nature) + " -" + getNatureDecrease(poke[i].nature) + ")" : "")
if (this.flyoutTextEnemy.width + this.flyoutTextPlayer.width > this.flyoutWidth * 6 - 120) {
this.flyoutTextEnemy.text = poke[i].getAbility().name + (poke[i].isBoss() ? ", " + poke[i].getPassiveAbility().name : "") + " / " + getNatureName(poke[i].nature)
}
//console.log(this.flyoutTextEnemy.width + this.flyoutTextPlayer.width, this.flyoutWidth * 6 - 120)
this.flyoutTextPlayer.text = beforeText1 + this.flyoutTextPlayer.text + "\n"
this.flyoutTextEnemy.text = beforeText2 + this.flyoutTextEnemy.text + "\n\n\n"
}
this.flyoutTextPlayer.text += "HP: " + poke[i].ivs[0]
this.flyoutTextPlayer.text += ", Atk: " + poke[i].ivs[1]

View File

@ -580,6 +580,7 @@ export default class BattleInfo extends Phaser.GameObjects.Container {
} else {
P = party
}
console.log("Updating ball icons for party (Pokemon: " + P.length + ")", P)
var staticparty = (this.scene as BattleScene).getEnemyParty()
var states = new Array(6)
for (var i = 0; i < 6; i++) {
@ -591,8 +592,12 @@ export default class BattleInfo extends Phaser.GameObjects.Container {
states[i] = "ball"
if (!P[i].hp) {
states[i] = "faint"
console.log(P[i].name + " - fainted")
} else if (P[i].status) {
states[i] = (this.scene as BattleScene).showTeamSprites ? "ball" : "status"
console.log(P[i].name + " - ball (status condition)")
} else {
console.log(P[i].name + " - ball")
}
if (P[i].isOnField()) {
//console.log(P[i].name + " is in battle; set it as seen")
@ -600,9 +605,10 @@ export default class BattleInfo extends Phaser.GameObjects.Container {
}
if (P[i].usedInBattle) total_visible++;
//console.log(P[i].name, P[i].getIconAtlasKey(true))
} else {
console.log("[undefined]: empty")
}
}
console.log("Updating ball icons for party (" + P.length + ")")
if (staticparty.length > 0) {
for (var i = 0; i < staticparty.length; i++) {
//console.log(i, staticparty[i].name)
@ -1022,10 +1028,10 @@ export default class BattleInfo extends Phaser.GameObjects.Container {
targets: this.teamIconOver,
duration: Utils.fixedInt(125),
ease: "Sine.easeInOut",
alphaTopLeft: visible ? 0.4 : 0,
alphaTopRight: visible ? 0.4 : 0,
alphaBottomLeft: visible ? 0.7 : 0,
alphaBottomRight: visible ? 0.7 : 0,
alphaTopLeft: !this.teamIconsShow ? 0 : (visible ? 0.4 : 0),
alphaTopRight: !this.teamIconsShow ? 0 : (visible ? 0.4 : 0),
alphaBottomLeft: !this.teamIconsShow ? 0 : (visible ? 0.7 : 0),
alphaBottomRight: !this.teamIconsShow ? 0 : (visible ? 0.7 : 0),
});
this.scene.tweens.add({
targets: [ this.championRibbon, this.ownedIcon ],