diff --git a/custom/debugcheatstools.user.js b/custom/debugcheatstools.user.js index d7a5aef..f2eaca3 100644 --- a/custom/debugcheatstools.user.js +++ b/custom/debugcheatstools.user.js @@ -1,11 +1,11 @@ // ==UserScript== // @name [Pokeclicker] Debug Cheats Tools // @namespace Pokeclicker Scripts -// @author kevingrillet +// @author kevingrillet (Credit: iamc24, ajthompson) // @description Edit your save for debug (currency, gems, pokeballs, pokemons, ...) // @copyright https://github.com/Ephenia // @license GPL-3.0 License -// @version 1.0.3 +// @version 1.1.0 // @homepageURL https://github.com/Ephenia/Pokeclicker-Scripts/ // @supportURL https://github.com/Ephenia/Pokeclicker-Scripts/issues @@ -34,22 +34,43 @@ function getPokeballImgSrc(id, pkm){ } // eslint-disable-next-line no-unused-vars -function gainPk(id){ +function gainPk(){ + let id = parseFloat(this.parentElement.children[0].innerHTML); let lpkm = App.game.party.getPokemon(id); if (!lpkm) App.game.party.gainPokemonById(id) else if (!(lpkm?.shiny === true)) App.game.party.gainPokemonById(id, true); document.querySelectorAll(`:scope #pkdx_${id.toString().replace('.','_')} img`)[1].src = getPokeballImgSrc(id, lpkm); + filterPkdx(); } // eslint-disable-next-line no-unused-vars -function gainPkrs(id){ +function gainPkrs(){ + let id = parseFloat(this.parentElement.children[0].innerHTML); let lpkm = App.game.party.getPokemon(id); if (!lpkm) return; lpkm.effortPoints = ((lpkm.pokerus < 2) ? 1 : 50) * 1000; // strange lpkm.pokerus = (lpkm.pokerus < 2) ? 2 : 3; document.querySelectorAll(`:scope #pkdx_${id.toString().replace('.','_')} img`)[2].src = getPokerusImgSrc(id, lpkm); + filterPkdx(); +} + +function gainCurrency() { + let currency = parseInt(this.getAttribute("currency")); + let changeAmount = parseInt(document.getElementById("inputAddCurrency").value || 0); + if (changeAmount > 0) { + App.game.wallet.addAmount(new Amount(changeAmount,currency),true); + } else if (changeAmount < 0) { + changeAmount = Math.abs(changeAmount); + if (changeAmount > App.game.wallet.currencies[currency]()) { + changeAmount = App.game.wallet.currencies[currency](); + if (changeAmount == 0) { + return; + } + } + App.game.wallet.loseAmount(new Amount(changeAmount,currency)); + } } function filterPkdx(){ @@ -59,7 +80,7 @@ function filterPkdx(){ let display = true; if (document.getElementById('pkdxNameFilter').value !== ""){ - display = tdb.innerHTML.includes(document.getElementById('pkdxNameFilter').value); + display = tdb.innerHTML.match(/.*<\/td>/g)[3].toLowerCase().includes(document.getElementById('pkdxNameFilter').value.toLowerCase()); } if (display === true) { @@ -67,7 +88,7 @@ function filterPkdx(){ case 'all': break; default: - display = tdb.innerHTML.toLowerCase().includes(document.getElementById('pkdxRegionFilter').value); + display = tdb.innerHTML.match(/.*<\/td>/g)[1].toLowerCase().includes(document.getElementById('pkdxRegionFilter').value); break; } } @@ -138,11 +159,11 @@ function loadPkdx(){ pkdxBody.innerHTML = ''; let toAdd = ""; for (const pokemon of pokemonList) { - if (pokemon.nativeRegion <= playerRegion) { + if ((pokemon.nativeRegion <= playerRegion && pokemon.nativeRegion > -1) || (pokemon.nativeRegion == -1 && playerRegion >= GameConstants.Region.alola) || pokemon.id == 0) { let lpkm = App.game.party.getPokemon(pokemon.id); - let region = GameConstants.Region[pokemon.nativeRegion].charAt(0).toUpperCase() + GameConstants.Region[pokemon.nativeRegion].slice(1) + let region = GameConstants.Region[pokemon.nativeRegion].charAt(0).toUpperCase() + GameConstants.Region[pokemon.nativeRegion].slice(1); let hint = ""; - let getPokemonLocation = PokemonHelper.getPokemonLocations(pokemon.name, playerRegion); + let getPokemonLocation = PokemonLocations.getPokemonLocations(pokemon.name, playerRegion); let roadLocations = getPokemonLocation[0] if (roadLocations) { for (let i = 0; i <= playerRegion; i++) { @@ -163,8 +184,8 @@ function loadPkdx(){ ${region} ${pokemon.name} - - + + YES') : '194, 46, 40);">NO'} `; @@ -172,6 +193,7 @@ function loadPkdx(){ } pkdxBody.innerHTML = toAdd; filterPkdx(); + pkdxLoadEventHandlers(); } function loadQuestLines() { @@ -197,11 +219,11 @@ function loadQuestLines() { } toAdd += ` - - ${ql.name} - ${state} - - `; + + ${ql.name} + ${state} + + `; } // App.game.quests.questLines().filter(e => e.state() < 2).forEach(e => console.log(e.name, e.state())) @@ -210,14 +232,97 @@ function loadQuestLines() { filterQuestLine(); } -function initSaveEditor() { - window.gainPk = gainPk; - window.gainPkrs = gainPkrs; - window.loadPkdx = loadPkdx; - window.filterPkdx = filterPkdx; - window.loadQuestLines = loadQuestLines; - window.filterQuestLine = filterQuestLine; +function loadEventHandlers() { + // currency + for (let i = 0; i < Object.keys(GameConstants.Currency).filter(isNaN).length; i++) { + document.getElementById("currency_" + i).addEventListener("click", gainCurrency); + } + + // gems + for (let i = 0; i < Gems.nTypes; i++) { + document.getElementById("gems_" + i).addEventListener("click", function () { + App.game.gems.gainGems(parseInt(document.getElementById('inputAddGems').value || 0), i); + }); + } + + // pokeballs + for (let i = 0; i < Object.keys(GameConstants.Pokeball).filter(isNaN).length - 1; i++) { + document.getElementById("pokeballs_" + i).addEventListener("click", function () { + App.game.pokeballs.gainPokeballs(i, parseInt(document.getElementById('inputAddPokeballs').value || 0), true); + }); + } + // berries + for (let i = 0; i < Object.keys(BerryType).filter(isNaN).length - 1; i++) { + document.getElementById("berries_" + i).addEventListener("click", function () { + App.game.farming.gainBerry(i, parseInt(document.getElementById('inputAddBerries').value || 0), true); + }); + } + + // evolution items + for (let i = 0; i < Object.keys(GameConstants.StoneType).filter(isNaN).length - 1; i++) { + document.getElementById("evolutionitems_" + i).addEventListener("click", function () { + player.gainItem(this.getAttribute("item"), parseInt(document.getElementById('inputAddEvolutionItems').value || 0), true); + }); + } + + // vitamins + for (let i = 0; i < Object.keys(GameConstants.VitaminType).filter(isNaN).length; i++) { + document.getElementById("vitamins_" + i).addEventListener("click", function () { + player.gainItem(this.getAttribute("vitamin"), parseInt(document.getElementById('inputAddVitamins').value || 0), true); + }); + } + + // held items + HeldItem.getSortedHeldItems().attack.items.forEach((itm, idx) => { + document.getElementById("attackhelditems_" + idx).addEventListener("click", function () { + HeldItem.getSortedHeldItems().attack.items[idx].gain(parseInt(document.getElementById('inputAddHeldItems').value || 0)); + }); + }); + HeldItem.getSortedHeldItems().typeRestricted.items.forEach((itm, idx) => { + document.getElementById("typehelditems_" + idx).addEventListener("click", function () { + HeldItem.getSortedHeldItems().typeRestricted.items[idx].gain(parseInt(document.getElementById('inputAddHeldItems').value || 0)); + }); + }); + HeldItem.getSortedHeldItems().ev.items.forEach((itm, idx) => { + document.getElementById("evhelditems_" + idx).addEventListener("click", function () { + HeldItem.getSortedHeldItems().ev.items[idx].gain(parseInt(document.getElementById('inputAddHeldItems').value || 0)); + }); + }); + HeldItem.getSortedHeldItems().exp.items.forEach((itm, idx) => { + document.getElementById("exphelditems_" + idx).addEventListener("click", function () { + HeldItem.getSortedHeldItems().exp.items[idx].gain(parseInt(document.getElementById('inputAddHeldItems').value || 0)); + }); + }); + HeldItem.getSortedHeldItems().other.items.forEach((itm, idx) => { + document.getElementById("otherhelditems_" + idx).addEventListener("click", function () { + HeldItem.getSortedHeldItems().other.items[idx].gain(parseInt(document.getElementById('inputAddHeldItems').value || 0)); + }); + }); + + // pokedex + document.getElementById("pokedex").children[1].addEventListener("click", loadPkdx); + document.getElementById("pkdxNameFilter").addEventListener("input", filterPkdx); + document.getElementById("pkdxRegionFilter").addEventListener("change", filterPkdx); + document.getElementById("pkdxShinyFilter").addEventListener("change", filterPkdx); + document.getElementById("pkdxPKRSFilter").addEventListener("change", filterPkdx); + + // questline + document.getElementById("questlines").children[1].addEventListener("click", loadQuestLines); + document.getElementById("questLineFilter").addEventListener("change", filterQuestLine); +} + +function pkdxLoadEventHandlers() { + for (const pokemon of pokemonList) { + let pkElement = document.getElementById("pkdx_" + pokemon.id.toString().replace('.','_')); + if (pkElement){ + pkElement.children[4].addEventListener("click", gainPk); + pkElement.children[5].addEventListener("click", gainPkrs); + } + } +} + +function initSaveEditor() { // Add menu item let eventLi = document.createElement('li'); eventLi.innerHTML = `Debug Cheats` @@ -247,15 +352,15 @@ function initSaveEditor() { - + - +
-

Click on button to add money (input * achievement bonus)

+

Click on button to add money (input)

@@ -270,7 +375,7 @@ function initSaveEditor() {

On click add berries (input)

-
+

On click add evolution items (input)

@@ -279,26 +384,26 @@ function initSaveEditor() {
-

On click add held items items (input)

+

On click add held items (input)

You can break your game, please backup!
Do not complete pokedex from another region if you are not in the region you will not be able to go to the next region!

- +
- +
-
- @@ -308,7 +413,7 @@ function initSaveEditor() {
- @@ -333,11 +438,11 @@ function initSaveEditor() {
- +
- @@ -371,7 +476,7 @@ function initSaveEditor() { const itm = GameConstants.Currency[i]; const itmPretty = itm.charAt(0).toUpperCase() + itm.replace(/[A-Z]/g, ' $&').trim().slice(1); modalBody.querySelector('#currency').innerHTML += ` -
+
${itmPretty}
@@ -382,7 +487,7 @@ function initSaveEditor() { for (let i = 0; i < Gems.nTypes; i++) { const itm = PokemonType[i]; modalBody.querySelector('#gems').innerHTML += ` -
+
${itm}
@@ -393,7 +498,7 @@ function initSaveEditor() { for (let i = 0; i < Object.keys(GameConstants.Pokeball).filter(isNaN).length - 1; i++) { const itm = GameConstants.Pokeball[i]; modalBody.querySelector('#pokeballs').innerHTML += ` -
+
${itm}
@@ -404,19 +509,21 @@ function initSaveEditor() { for (let i = 0; i < Object.keys(BerryType).filter(isNaN).length - 1; i++) { const itm = BerryType[i]; modalBody.querySelector('#berries').innerHTML += ` -
+
${itm}
`; } - // evolutionitems + // evolution items for (let i = 0; i < Object.keys(GameConstants.StoneType).filter(isNaN).length - 1; i++) { const itm = GameConstants.StoneType[i]; - const itmPretty = itm.replaceAll('_', ' '); - modalBody.querySelector('#evolutionitems').innerHTML += ` -
+ const itmPretty = itm.replaceAll('_', ' ').replace(/\b\w/g, function(char) { + return char.toUpperCase(); + }); + modalBody.querySelector('#evolutionItems').innerHTML += ` +
${itmPretty}
@@ -427,18 +534,54 @@ function initSaveEditor() { for (let i = 0; i < Object.keys(GameConstants.VitaminType).filter(isNaN).length; i++) { const itm = GameConstants.VitaminType[i]; modalBody.querySelector('#vitamins').innerHTML += ` -
+
${itm}
`; } - // heldItems - HeldItem.getSortedHeldItems().forEach((itm, idx) => { + // held items + HeldItem.getSortedHeldItems().attack.items.forEach((itm, idx) => { const itmPretty = itm.name.replaceAll('_', ' '); modalBody.querySelector('#heldItems').innerHTML += ` -
+
+ +
${itmPretty}
+
+ `; + }); + HeldItem.getSortedHeldItems().typeRestricted.items.forEach((itm, idx) => { + const itmPretty = itm.name.replaceAll('_', ' '); + modalBody.querySelector('#heldItems').innerHTML += ` +
+ +
${itmPretty}
+
+ `; + }); + HeldItem.getSortedHeldItems().ev.items.forEach((itm, idx) => { + const itmPretty = itm.name.replaceAll('_', ' '); + modalBody.querySelector('#heldItems').innerHTML += ` +
+ +
${itmPretty}
+
+ `; + }); + HeldItem.getSortedHeldItems().exp.items.forEach((itm, idx) => { + const itmPretty = itm.name.replaceAll('_', ' '); + modalBody.querySelector('#heldItems').innerHTML += ` +
+ +
${itmPretty}
+
+ `; + }); + HeldItem.getSortedHeldItems().other.items.forEach((itm, idx) => { + const itmPretty = itm.name.replaceAll('_', ' '); + modalBody.querySelector('#heldItems').innerHTML += ` +
${itmPretty}
@@ -451,6 +594,10 @@ function initSaveEditor() { const reg = GameConstants.Region[i] pkdxRegFilt.innerHTML += ``; } + pkdxRegFilt.innerHTML += ''; + + + loadEventHandlers(); } /* WIP, sevii helper