[Beta] Updating the manage data->unlock all option to work with all abilities, natures, forms and passives (#2967)

* Updated code to allow user to unlock all pokemon from the manage data menu option

* Added code to Utils to allow it to check for a beta env, and hid the unlock all code behind that. This should stop it from being accessed in prod envs

* Updated another section to be locked behind beta check, and also updated the everything.prsv to have everything unlocked going forward

* Fixed some code reviews
This commit is contained in:
Opaque02 2024-07-13 10:09:27 +10:00 committed by GitHub
parent 9df3bdde70
commit 8e44ddfde2
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 86 additions and 12 deletions

File diff suppressed because one or more lines are too long

View File

@ -2,6 +2,7 @@ import BattleScene from "../battle-scene";
import { TextStyle, addTextObject } from "./text"; import { TextStyle, addTextObject } from "./text";
import { Mode } from "./ui"; import { Mode } from "./ui";
import UiHandler from "./ui-handler"; import UiHandler from "./ui-handler";
import { unlockAll } from "./menu-ui-handler";
import { addWindow } from "./ui-theme"; import { addWindow } from "./ui-theme";
import * as Utils from "../utils"; import * as Utils from "../utils";
import { argbFromRgba } from "@material/material-color-utilities"; import { argbFromRgba } from "@material/material-color-utilities";
@ -42,6 +43,9 @@ export default abstract class AbstractOptionSelectUiHandler extends UiHandler {
protected scrollCursor: integer = 0; protected scrollCursor: integer = 0;
private konamiIndex: integer = 0;
static readonly konamiCode: Button[] = [Button.UP, Button.UP, Button.DOWN, Button.DOWN, Button.LEFT, Button.RIGHT, Button.LEFT, Button.RIGHT, Button.CANCEL, Button.ACTION];
private cursorObj: Phaser.GameObjects.Image; private cursorObj: Phaser.GameObjects.Image;
constructor(scene: BattleScene, mode?: Mode) { constructor(scene: BattleScene, mode?: Mode) {
@ -159,6 +163,20 @@ export default abstract class AbstractOptionSelectUiHandler extends UiHandler {
let playSound = true; let playSound = true;
if (ui.getMode() === Mode.TITLE) {
if (button === AbstractOptionSelectUiHandler.konamiCode[this.konamiIndex] && (Utils.isLocal || Utils.isBeta)) {
if (this.konamiIndex !== AbstractOptionSelectUiHandler.konamiCode.length - 1) {
this.konamiIndex += 1;
} else {
unlockAll(this.scene);
this.konamiIndex = 0;
return false;
}
} else {
this.konamiIndex = 0;
}
}
if (button === Button.ACTION || button === Button.CANCEL) { if (button === Button.ACTION || button === Button.CANCEL) {
if (this.blockInput) { if (this.blockInput) {
ui.playError(); ui.playError();

View File

@ -11,6 +11,11 @@ import i18next from "i18next";
import {Button} from "#enums/buttons"; import {Button} from "#enums/buttons";
import { GameDataType } from "#enums/game-data-type"; import { GameDataType } from "#enums/game-data-type";
import BgmBar from "#app/ui/bgm-bar"; import BgmBar from "#app/ui/bgm-bar";
import { Species } from "#app/enums/species.js";
import { DexAttr, AbilityAttr } from "#app/system/game-data.js";
import { getPokemonSpecies, starterPassiveAbilities } from "../data/pokemon-species";
import { Nature } from "../data/nature";
import { Passive } from "../enums/passive";
enum MenuOptions { enum MenuOptions {
GAME_SETTINGS, GAME_SETTINGS,
@ -30,6 +35,47 @@ const discordUrl = "https://discord.gg/uWpTfdKG49";
const githubUrl = "https://github.com/pagefaultgames/pokerogue"; const githubUrl = "https://github.com/pagefaultgames/pokerogue";
const redditUrl = "https://www.reddit.com/r/pokerogue"; const redditUrl = "https://www.reddit.com/r/pokerogue";
export function unlockAll(scene: BattleScene) {
if (Utils.isLocal || Utils.isBeta) {
const totalSpecies = Object.keys(Species).filter(s => !isNaN(Number(s)));
for (const species of totalSpecies) {
//const pokemonSpecies = Number(species) > 2000 ? allSpecies.find(s => s.speciesId === Number(species)) : allSpecies[Number(species) - 1]; // thie converts the species to a pokemon from allSpecies by checking regional variants and returning the normal species index
const pokemonSpecies = getPokemonSpecies(Number(species));
let dexAttrLength = Object.values(DexAttr).length; // this will be the final amount of bits to set; we start by getting the length of the DexAttr so we know how many things every pokemon will get at minimum
if (pokemonSpecies.forms?.length > 0) { // this checks if the specific pokemon has forms
dexAttrLength += pokemonSpecies.forms?.length; // if it does have forms, add it to the dexAttrLength
}
const natureAttrLength = Object.values(Nature).length; // this gets a list of all the natures to set bits for
let abilityAttr: number; // since pokemon can have 1, 2 or 3 abilities
switch (pokemonSpecies.getAbilityCount()) {
case 1: // if it's one ability, return one ability
abilityAttr = AbilityAttr.ABILITY_1;
break;
case 2: // if it's one ability and the hidden ability, return ability 1 and the hidden ability
abilityAttr = AbilityAttr.ABILITY_1 + AbilityAttr.ABILITY_HIDDEN;
break;
case 3: // if it's 3 abilities, return all three
abilityAttr = AbilityAttr.ABILITY_1 + AbilityAttr.ABILITY_2 + AbilityAttr.ABILITY_HIDDEN;
break;
}
scene.gameData.dexData[species].seenAttr = BigInt(Math.pow(2, dexAttrLength) - 1); // we can set these values as 2^n - 1 if n is one more than the total number of total bits compared to what we need
scene.gameData.dexData[species].caughtAttr = BigInt(Math.pow(2, dexAttrLength) - 1);
scene.gameData.dexData[species].natureAttr = Math.pow(2, natureAttrLength) - 1;
scene.gameData.dexData[species].caughtCount = 1;
scene.gameData.dexData[species].seenCount = 1;
scene.gameData.dexData[species].ivs = [31, 31, 31, 31, 31, 31];
if (scene.gameData.starterData[species]) { // this checks to make sure the species has a starter
scene.gameData.starterData[species].abilityAttr = abilityAttr; // if so, it sets the abilityAttr for the starter
}
if (starterPassiveAbilities[species]) { // checks to see if the species has a passive - this is different to the starter code above as this needs to check babies instead of evolutions (i.e. check pichu instead of pikachu)
scene.gameData.starterData[species].passiveAttr = Passive.UNLOCKED + Passive.ENABLED; // if so, it sets the passiveAttr for the starter to be
}
}
//scene.gameData.saveAll(scene, true, true, false, true); // I could not for the life of me figure out how to make it save
scene.ui.revertMode();
}
}
export default class MenuUiHandler extends MessageUiHandler { export default class MenuUiHandler extends MessageUiHandler {
private menuContainer: Phaser.GameObjects.Container; private menuContainer: Phaser.GameObjects.Container;
private menuMessageBoxContainer: Phaser.GameObjects.Container; private menuMessageBoxContainer: Phaser.GameObjects.Container;
@ -188,22 +234,30 @@ export default class MenuUiHandler extends MessageUiHandler {
keepOpen: true keepOpen: true
}); });
} }
manageDataOptions.push( manageDataOptions.push({
{ label: i18next.t("menuUiHandler:exportData"),
label: i18next.t("menuUiHandler:exportData"), handler: () => {
handler: () => { this.scene.gameData.tryExportData(GameDataType.SYSTEM);
this.scene.gameData.tryExportData(GameDataType.SYSTEM); return true;
return true;
},
keepOpen: true
}, },
{ keepOpen: true
label: i18next.t("menuUiHandler:cancel"), });
if (Utils.isLocal || Utils.isBeta) {
manageDataOptions.push({
label: "Unlock All",
handler: () => { handler: () => {
this.scene.ui.revertMode(); unlockAll(this.scene);
return true; return true;
} }
});
}
manageDataOptions.push({
label: i18next.t("menuUiHandler:cancel"),
handler: () => {
this.scene.ui.revertMode();
return true;
} }
}
); );
this.manageDataConfig = { this.manageDataConfig = {

View File

@ -292,6 +292,8 @@ export const apiUrl = localServerUrl ?? "https://api.pokerogue.net";
// used to disable api calls when isLocal is true and a server is not found // used to disable api calls when isLocal is true and a server is not found
export let isLocalServerConnected = true; export let isLocalServerConnected = true;
export const isBeta = import.meta.env.DEV; // this checks to see if the env mode is development. Technically this gives the same value for beta AND for dev envs
export function setCookie(cName: string, cValue: string): void { export function setCookie(cName: string, cValue: string): void {
const expiration = new Date(); const expiration = new Date();
expiration.setTime(new Date().getTime() + 3600000 * 24 * 30 * 3/*7*/); expiration.setTime(new Date().getTime() + 3600000 * 24 * 30 * 3/*7*/);