From 218307d993c252d7dba4fb71f96985830147f34c Mon Sep 17 00:00:00 2001 From: Maruno17 Date: Tue, 31 Aug 2021 16:54:03 +0100 Subject: [PATCH] Added Gen 8's shiny chance increase with number battled, fixed other shiny chance-boosting effects not working --- Data/Scripts/001_Settings.rb | 17 +++--- .../002_Save data/005_Game_SaveConversions.rb | 11 ++++ .../001_Battler/003_Battler_ChangeSelf.rb | 1 + .../003_Battle/001_PokeBattle_BattleCommon.rb | 3 +- .../003_Battle/002_PokeBattle_Battle.rb | 24 +++++++- .../002_PokeBattle_SafariZone.rb | 20 ++++++- .../003_Overworld_WildEncounters.rb | 22 +++++++- .../012_Overworld/007_Overworld_DayCare.rb | 1 + Data/Scripts/014_Pokemon/001_Pokemon.rb | 2 +- .../005_Player_Pokedex.rb | 47 ++++++++++++++++ Data/Scripts/016_UI/004_UI_Pokedex_Entry.rb | 55 ++++++++++++------- Data/Scripts/Gen 8 notes.txt | 9 ++- 12 files changed, 172 insertions(+), 40 deletions(-) diff --git a/Data/Scripts/001_Settings.rb b/Data/Scripts/001_Settings.rb index 6eafee312..ba43c0016 100644 --- a/Data/Scripts/001_Settings.rb +++ b/Data/Scripts/001_Settings.rb @@ -28,17 +28,20 @@ module Settings #============================================================================= # The maximum level Pokémon can reach. - MAXIMUM_LEVEL = 100 + MAXIMUM_LEVEL = 100 # The level of newly hatched Pokémon. - EGG_LEVEL = 1 + EGG_LEVEL = 1 # The odds of a newly generated Pokémon being shiny (out of 65536). - SHINY_POKEMON_CHANCE = (MECHANICS_GENERATION >= 6) ? 16 : 8 + SHINY_POKEMON_CHANCE = (MECHANICS_GENERATION >= 6) ? 16 : 8 # Whether super shininess is enabled (uses a different shiny animation). - SUPER_SHINY = (MECHANICS_GENERATION >= 8) + SUPER_SHINY = (MECHANICS_GENERATION >= 8) + # Whether shiny wild Pokémon are more likely to appear if the player has + # previously defeated/caught lots of other Pokémon of the same species. + HIGHER_SHINY_CHANCES_WITH_NUMBER_BATTLED = (MECHANICS_GENERATION >= 8) # The odds of a wild Pokémon/bred egg having Pokérus (out of 65536). - POKERUS_CHANCE = 3 - # Whether a bred baby Pokémon can inherit any TM/HM moves from its father. It - # can never inherit TM/HM moves from its mother. + POKERUS_CHANCE = 3 + # Whether a bred baby Pokémon can inherit any TM/TR/HM moves from its father. + # It can never inherit TM/TR/HM moves from its mother. BREEDING_CAN_INHERIT_MACHINE_MOVES = (MECHANICS_GENERATION <= 5) # Whether a bred baby Pokémon can inherit egg moves from its mother. It can # always inherit egg moves from its father. diff --git a/Data/Scripts/002_Save data/005_Game_SaveConversions.rb b/Data/Scripts/002_Save data/005_Game_SaveConversions.rb index b82418feb..9eab23d98 100644 --- a/Data/Scripts/002_Save data/005_Game_SaveConversions.rb +++ b/Data/Scripts/002_Save data/005_Game_SaveConversions.rb @@ -88,3 +88,14 @@ SaveData.register_conversion(:v19_2_fix_berry_plants) do end end end + +SaveData.register_conversion(:v20_add_battled_counts) do + essentials_version 20 + display_title 'Adding Pokédex battle counts' + to_value :player do |player| + player.pokedex.instance_eval do + @caught_counts = {} if @caught_counts.nil? + @defeated_counts = {} if @defeated_counts.nil? + end + end +end diff --git a/Data/Scripts/011_Battle/001_Battler/003_Battler_ChangeSelf.rb b/Data/Scripts/011_Battle/001_Battler/003_Battler_ChangeSelf.rb index 8ccb0921e..06226570e 100644 --- a/Data/Scripts/011_Battle/001_Battler/003_Battler_ChangeSelf.rb +++ b/Data/Scripts/011_Battle/001_Battler/003_Battler_ChangeSelf.rb @@ -55,6 +55,7 @@ class PokeBattle_Battler @battle.pbDisplayBrief(_INTL("{1} fainted!",pbThis)) if showMessage PBDebug.log("[Pokémon fainted] #{pbThis} (#{@index})") if !showMessage @battle.scene.pbFaintBattler(self) + @battle.pbSetDefeated(self) if opposes? pbInitEffects(false) # Reset status self.status = :NONE diff --git a/Data/Scripts/011_Battle/003_Battle/001_PokeBattle_BattleCommon.rb b/Data/Scripts/011_Battle/003_Battle/001_PokeBattle_BattleCommon.rb index a9e0922a6..26ea787c3 100644 --- a/Data/Scripts/011_Battle/003_Battle/001_PokeBattle_BattleCommon.rb +++ b/Data/Scripts/011_Battle/003_Battle/001_PokeBattle_BattleCommon.rb @@ -42,7 +42,8 @@ module PokeBattle_BattleCommon # Register all caught Pokémon in the Pokédex, and store them. def pbRecordAndStoreCaughtPokemon @caughtPokemon.each do |pkmn| - pbPlayer.pokedex.register(pkmn) # In case the form changed upon leaving battle + pbSetCaught(pkmn) + pbSetSeen(pkmn) # In case the form changed upon leaving battle # Record the Pokémon's species as owned in the Pokédex if !pbPlayer.owned?(pkmn.species) pbPlayer.pokedex.set_owned(pkmn.species) diff --git a/Data/Scripts/011_Battle/003_Battle/002_PokeBattle_Battle.rb b/Data/Scripts/011_Battle/003_Battle/002_PokeBattle_Battle.rb index 3fb221ec5..29cc86954 100644 --- a/Data/Scripts/011_Battle/003_Battle/002_PokeBattle_Battle.rb +++ b/Data/Scripts/011_Battle/003_Battle/002_PokeBattle_Battle.rb @@ -628,7 +628,29 @@ class PokeBattle_Battle def pbSetSeen(battler) return if !battler || !@internalBattle - pbPlayer.pokedex.register(battler.displaySpecies,battler.displayGender,battler.displayForm) + if battler.is_a?(PokeBattle_Battler) + pbPlayer.pokedex.register(battler.displaySpecies,battler.displayGender,battler.displayForm) + else + pbPlayer.pokedex.register(battler) + end + end + + def pbSetCaught(battler) + return if !battler || !@internalBattle + if battler.is_a?(PokeBattle_Battler) + pbPlayer.pokedex.register_caught(battler.displaySpecies) + else + pbPlayer.pokedex.register_caught(battler.species) + end + end + + def pbSetDefeated(battler) + return if !battler || !@internalBattle + if battler.is_a?(PokeBattle_Battler) + pbPlayer.pokedex.register_defeated(battler.displaySpecies) + else + pbPlayer.pokedex.register_defeated(battler.species) + end end def nextPickupUse diff --git a/Data/Scripts/011_Battle/006_Other battle types/002_PokeBattle_SafariZone.rb b/Data/Scripts/011_Battle/006_Other battle types/002_PokeBattle_SafariZone.rb index 9cbb99927..4e452ed27 100644 --- a/Data/Scripts/011_Battle/006_Other battle types/002_PokeBattle_SafariZone.rb +++ b/Data/Scripts/011_Battle/006_Other battle types/002_PokeBattle_SafariZone.rb @@ -355,6 +355,24 @@ class PokeBattle_SafariZone def pbGetOwnerFromBattlerIndex(idxBattler); return pbPlayer; end + def pbSetSeen(battler) + return if !battler || !@internalBattle + if battler.is_a?(PokeBattle_Battler) + pbPlayer.pokedex.register(battler.displaySpecies,battler.displayGender,battler.displayForm) + else + pbPlayer.pokedex.register(battler) + end + end + + def pbSetCaught(battler) + return if !battler || !@internalBattle + if battler.is_a?(PokeBattle_Battler) + pbPlayer.pokedex.register_caught(battler.displaySpecies) + else + pbPlayer.pokedex.register_caught(battler.species) + end + end + #============================================================================= # Get party info (counts all teams on the same side) #============================================================================= @@ -417,7 +435,7 @@ class PokeBattle_SafariZone def pbStartBattle begin pkmn = @party2[0] - self.pbPlayer.pokedex.register(pkmn) + pbSetSeen(pkmn) @scene.pbStartBattle(self) pbDisplayPaused(_INTL("Wild {1} appeared!",pkmn.name)) @scene.pbSafariStart diff --git a/Data/Scripts/012_Overworld/002_Battle triggering/003_Overworld_WildEncounters.rb b/Data/Scripts/012_Overworld/002_Battle triggering/003_Overworld_WildEncounters.rb index 29bbdd7b8..df9200052 100644 --- a/Data/Scripts/012_Overworld/002_Battle triggering/003_Overworld_WildEncounters.rb +++ b/Data/Scripts/012_Overworld/002_Battle triggering/003_Overworld_WildEncounters.rb @@ -411,10 +411,26 @@ def pbGenerateWildPokemon(species,level,isRoamer=false) elsif itemrnd<(chances[0]+chances[1]+chances[2]) genwildpoke.item = items[2] end - # Shiny Charm makes shiny Pokémon more likely to generate - if GameData::Item.exists?(:SHINYCHARM) && $PokemonBag.pbHasItem?(:SHINYCHARM) - 2.times do # 3 times as likely + # Improve chances of shiny Pokémon with Shiny Charm and battling more of the + # same species + shiny_retries = 0 + shiny_retries += 2 if GameData::Item.exists?(:SHINYCHARM) && $PokemonBag.pbHasItem?(:SHINYCHARM) + if Settings::HIGHER_SHINY_CHANCES_WITH_NUMBER_BATTLED + values = [0, 0] + case $Trainer.pokedex.battled_count(species) + when 0...50 then values = [0, 0] + when 50...100 then values = [1, 15] + when 100...200 then values = [2, 20] + when 200...300 then values = [3, 25] + when 300...500 then values = [4, 30] + else values = [5, 30] + end + shiny_retries += values[0] if values[1] > 0 && rand(1000) < values[1] + end + if shiny_retries > 0 + shiny_retries.times do break if genwildpoke.shiny? + genwildpoke.shiny = nil # Make it recalculate shininess genwildpoke.personalID = rand(2**16) | rand(2**16) << 16 end end diff --git a/Data/Scripts/012_Overworld/007_Overworld_DayCare.rb b/Data/Scripts/012_Overworld/007_Overworld_DayCare.rb index 82f5c8936..ebec3ac3f 100644 --- a/Data/Scripts/012_Overworld/007_Overworld_DayCare.rb +++ b/Data/Scripts/012_Overworld/007_Overworld_DayCare.rb @@ -324,6 +324,7 @@ def pbDayCareGenerateEgg if shinyretries>0 shinyretries.times do break if egg.shiny? + egg.shiny = nil # Make it recalculate shininess egg.personalID = rand(2**16) | rand(2**16) << 16 end end diff --git a/Data/Scripts/014_Pokemon/001_Pokemon.rb b/Data/Scripts/014_Pokemon/001_Pokemon.rb index b8e79229e..a3391c18b 100644 --- a/Data/Scripts/014_Pokemon/001_Pokemon.rb +++ b/Data/Scripts/014_Pokemon/001_Pokemon.rb @@ -338,7 +338,7 @@ class Pokemon else @gender = 2 end else - female_chance = GameData::GenderRatio.get(gender_ratio).female_chance + female_chance = GameData::GenderRatio.get(species_data.gender_ratio).female_chance @gender = ((@personalID & 0xFF) < female_chance) ? 1 : 0 end end diff --git a/Data/Scripts/015_Trainers and player/005_Player_Pokedex.rb b/Data/Scripts/015_Trainers and player/005_Player_Pokedex.rb index cd063efaa..c17a47488 100644 --- a/Data/Scripts/015_Trainers and player/005_Player_Pokedex.rb +++ b/Data/Scripts/015_Trainers and player/005_Player_Pokedex.rb @@ -27,6 +27,8 @@ class Player < Trainer @seen_forms = {} @last_seen_forms = {} @owned_shadow = {} + @caught_counts = {} + @defeated_counts = {} self.refresh_accessible_dexes end @@ -199,6 +201,51 @@ class Player < Trainer #=========================================================================== + # @param species [Symbol, GameData::Species] species to check + # @return [Integer] the number of Pokémon of the given species that have + # been caught by the player + def caught_count(species) + species_id = GameData::Species.try_get(species)&.species + return 0 if species_id.nil? + return @caught_counts[species] || 0 + end + + # @param species [Symbol, GameData::Species] species to check + # @return [Integer] the number of Pokémon of the given species that have + # been defeated by the player + def defeated_count(species) + species_id = GameData::Species.try_get(species)&.species + return 0 if species_id.nil? + return @defeated_counts[species] || 0 + end + + # @param species [Symbol, GameData::Species] species to check + # @return [Integer] the number of Pokémon of the given species that have + # been defeated or caught by the player + def battled_count(species) + species_id = GameData::Species.try_get(species)&.species + return 0 if species_id.nil? + return (@defeated_counts[species] || 0) + (@caught_counts[species] || 0) + end + + # @param species [Symbol, GameData::Species] species to count as caught + def register_caught(species) + species_id = GameData::Species.try_get(species)&.species + return if species_id.nil? + @caught_counts[species] = 0 if @caught_counts[species].nil? + @caught_counts[species] += 1 + end + + # @param species [Symbol, GameData::Species] species to count as defeated + def register_defeated(species) + species_id = GameData::Species.try_get(species)&.species + return if species_id.nil? + @defeated_counts[species] = 0 if @defeated_counts[species].nil? + @defeated_counts[species] += 1 + end + + #=========================================================================== + # Unlocks the given Dex, -1 being the National Dex. # @param dex [Integer] Dex ID (-1 is the National Dex) def unlock(dex) diff --git a/Data/Scripts/016_UI/004_UI_Pokedex_Entry.rb b/Data/Scripts/016_UI/004_UI_Pokedex_Entry.rb index 9236ef2e0..73cbf497d 100644 --- a/Data/Scripts/016_UI/004_UI_Pokedex_Entry.rb +++ b/Data/Scripts/016_UI/004_UI_Pokedex_Entry.rb @@ -9,6 +9,7 @@ class PokemonPokedexInfo_Scene @index = index @region = region @page = 1 + @show_battled_count = false @typebitmap = AnimatedBitmap.new(_INTL("Graphics/Pictures/Pokedex/icon_types")) @sprites = {} @sprites["background"] = IconSprite.new(0,0,@viewport) @@ -219,24 +220,31 @@ class PokemonPokedexInfo_Scene end textpos = [ [_INTL("{1}{2} {3}", indexText, " ", species_data.name), - 246, 36, 0, Color.new(248, 248, 248), Color.new(0, 0, 0)], - [_INTL("Height"), 314, 152, 0, base, shadow], - [_INTL("Weight"), 314, 184, 0, base, shadow] + 246, 36, 0, Color.new(248, 248, 248), Color.new(0, 0, 0)] ] + if @show_battled_count + textpos.push([_INTL("Number Battled"), 314, 152, 0, base, shadow]) + textpos.push([$Trainer.pokedex.battled_count(@species).to_s, 452, 184, 1, base, shadow]) + else + textpos.push([_INTL("Height"), 314, 152, 0, base, shadow]) + textpos.push([_INTL("Weight"), 314, 184, 0, base, shadow]) + end if $Trainer.owned?(@species) # Write the category textpos.push([_INTL("{1} Pokémon", species_data.category), 246, 68, 0, base, shadow]) # Write the height and weight - height = species_data.height - weight = species_data.weight - if System.user_language[3..4] == "US" # If the user is in the United States - inches = (height / 0.254).round - pounds = (weight / 0.45359).round - textpos.push([_ISPRINTF("{1:d}'{2:02d}\"", inches / 12, inches % 12), 460, 152, 1, base, shadow]) - textpos.push([_ISPRINTF("{1:4.1f} lbs.", pounds / 10.0), 494, 184, 1, base, shadow]) - else - textpos.push([_ISPRINTF("{1:.1f} m", height / 10.0), 470, 152, 1, base, shadow]) - textpos.push([_ISPRINTF("{1:.1f} kg", weight / 10.0), 482, 184, 1, base, shadow]) + if !@show_battled_count + height = species_data.height + weight = species_data.weight + if System.user_language[3..4] == "US" # If the user is in the United States + inches = (height / 0.254).round + pounds = (weight / 0.45359).round + textpos.push([_ISPRINTF("{1:d}'{2:02d}\"", inches / 12, inches % 12), 460, 152, 1, base, shadow]) + textpos.push([_ISPRINTF("{1:4.1f} lbs.", pounds / 10.0), 494, 184, 1, base, shadow]) + else + textpos.push([_ISPRINTF("{1:.1f} m", height / 10.0), 470, 152, 1, base, shadow]) + textpos.push([_ISPRINTF("{1:.1f} kg", weight / 10.0), 482, 184, 1, base, shadow]) + end end # Draw the Pokédex entry text drawTextEx(overlay, 40, 244, Graphics.width - (40 * 2), 4, # overlay, x, y, width, num lines @@ -263,12 +271,14 @@ class PokemonPokedexInfo_Scene # Write the category textpos.push([_INTL("????? Pokémon"), 246, 68, 0, base, shadow]) # Write the height and weight - if System.user_language[3..4] == "US" # If the user is in the United States - textpos.push([_INTL("???'??\""), 460, 152, 1, base, shadow]) - textpos.push([_INTL("????.? lbs."), 494, 184, 1, base, shadow]) - else - textpos.push([_INTL("????.? m"), 470, 152, 1, base, shadow]) - textpos.push([_INTL("????.? kg"), 482, 184, 1, base, shadow]) + if !@show_battled_count + if System.user_language[3..4] == "US" # If the user is in the United States + textpos.push([_INTL("???'??\""), 460, 152, 1, base, shadow]) + textpos.push([_INTL("????.? lbs."), 494, 184, 1, base, shadow]) + else + textpos.push([_INTL("????.? m"), 470, 152, 1, base, shadow]) + textpos.push([_INTL("????.? kg"), 482, 184, 1, base, shadow]) + end end end # Draw all text @@ -458,9 +468,12 @@ class PokemonPokedexInfo_Scene pbPlayCloseMenuSE break elsif Input.trigger?(Input::USE) - if @page==2 # Area + if @page == 1 # Info + @show_battled_count = !@show_battled_count + dorefresh = true + elsif @page == 2 # Area # dorefresh = true - elsif @page==3 # Forms + elsif @page == 3 # Forms if @available.length>1 pbPlayDecisionSE pbChooseForm diff --git a/Data/Scripts/Gen 8 notes.txt b/Data/Scripts/Gen 8 notes.txt index e6519610c..90cabaff8 100644 --- a/Data/Scripts/Gen 8 notes.txt +++ b/Data/Scripts/Gen 8 notes.txt @@ -4,11 +4,6 @@ # To do #=============================================================================== -The game records, for each species, how many have been caught or defeated -(counts both wild and trainer battles), and the shiny chance increases for that -species because of this. This value is also shown in the Pokédex entry screen. -(Will be implemented by me in the next PR) - Some moves have changed properties/effects: - Parting Shot is able to make the user switch out if its effect is redirected by Mirror Armor. Throat Spray is triggered and applies before the switch. @@ -173,4 +168,8 @@ In Gen 7+, Shaymin/Hoopa revert their form when withdrawn from storage rather than when deposited. It still also reverts under other conditions. Shaymin reverts its form when deposited in the Day Care (all Gens). +The game records, for each species, how many have been caught or defeated +(counts both wild and trainer battles), and the shiny chance increases for that +species because of this. This value is also shown in the Pokédex entry screen. + =end