From e1e9706cd9be69544e2c9915c80d2663676c89ff Mon Sep 17 00:00:00 2001 From: Maruno17 Date: Tue, 2 Feb 2021 23:09:57 +0000 Subject: [PATCH] Fixed bug with trainer data, tidied evolution-checking code --- .../011_Data/001_Game data/012_Trainer.rb | 2 +- .../013_Overworld/006_PField_Battles.rb | 2 +- Data/Scripts/015_Items/001_PItem_Items.rb | 4 +- .../015_Items/002_PItem_ItemEffects.rb | 4 +- .../005_Pokemon_Evolution.rb | 67 ++++++++++--------- 5 files changed, 42 insertions(+), 37 deletions(-) diff --git a/Data/Scripts/011_Data/001_Game data/012_Trainer.rb b/Data/Scripts/011_Data/001_Game data/012_Trainer.rb index d3f0e2786..8f6c1715b 100644 --- a/Data/Scripts/011_Data/001_Game data/012_Trainer.rb +++ b/Data/Scripts/011_Data/001_Game data/012_Trainer.rb @@ -62,7 +62,7 @@ module GameData # @param tr_name [String] # @param tr_version [Integer, nil] # @return [self, nil] - def try_get(tr_type, tr_name, tr_version = 0) + def self.try_get(tr_type, tr_name, tr_version = 0) validate tr_type => [Symbol, String] validate tr_name => [String] key = [tr_type.to_sym, tr_name, tr_version] diff --git a/Data/Scripts/013_Overworld/006_PField_Battles.rb b/Data/Scripts/013_Overworld/006_PField_Battles.rb index efb7f88e5..6df23466b 100644 --- a/Data/Scripts/013_Overworld/006_PField_Battles.rb +++ b/Data/Scripts/013_Overworld/006_PField_Battles.rb @@ -605,7 +605,7 @@ def pbEvolutionCheck(currentLevels) pkmn = $Trainer.party[i] next if !pkmn || (pkmn.hp==0 && !Settings::CHECK_EVOLUTION_FOR_FAINTED_POKEMON) next if currentLevels[i] && pkmn.level==currentLevels[i] - newSpecies = EvolutionCheck.check(pkmn) + newSpecies = EvolutionCheck.check_level_up_methods(pkmn) next if !newSpecies evo = PokemonEvolutionScene.new evo.pbStartScreen(pkmn,newSpecies) diff --git a/Data/Scripts/015_Items/001_PItem_Items.rb b/Data/Scripts/015_Items/001_PItem_Items.rb index a6b21ba86..7aa10b837 100644 --- a/Data/Scripts/015_Items/001_PItem_Items.rb +++ b/Data/Scripts/015_Items/001_PItem_Items.rb @@ -177,7 +177,7 @@ def pbChangeLevel(pkmn,newlevel,scene) pbLearnMove(pkmn,i[1],true) { scene.pbUpdate } end # Check for evolution - newspecies = EvolutionCheck.check(pkmn) + newspecies = EvolutionCheck.check_level_up_methods(pkmn) if newspecies pbFadeOutInWithMusic { evo = PokemonEvolutionScene.new @@ -490,7 +490,7 @@ def pbUseItem(bag,item,bagscene=nil) if itm.is_evolution_stone? annot = [] for pkmn in $Trainer.party - elig = EvolutionCheck.check(pkmn, item) + elig = EvolutionCheck.check_item_methods(pkmn, item) annot.push((elig) ? _INTL("ABLE") : _INTL("NOT ABLE")) end end diff --git a/Data/Scripts/015_Items/002_PItem_ItemEffects.rb b/Data/Scripts/015_Items/002_PItem_ItemEffects.rb index cf513c10f..0e4c69b90 100644 --- a/Data/Scripts/015_Items/002_PItem_ItemEffects.rb +++ b/Data/Scripts/015_Items/002_PItem_ItemEffects.rb @@ -348,7 +348,7 @@ ItemHandlers::UseOnPokemon.addIf(proc { |item| GameData::Item.get(item).is_evolu scene.pbDisplay(_INTL("It won't have any effect.")) next false end - newspecies = EvolutionCheck.check(pkmn,item) + newspecies = EvolutionCheck.check_item_methods(pkmn, item) if newspecies pbFadeOutInWithMusic { evo = PokemonEvolutionScene.new @@ -356,7 +356,7 @@ ItemHandlers::UseOnPokemon.addIf(proc { |item| GameData::Item.get(item).is_evolu evo.pbEvolution(false) evo.pbEndScreen if scene.is_a?(PokemonPartyScreen) - scene.pbRefreshAnnotations(proc { |p| !EvolutionCheck.check(p, item).nil? }) + scene.pbRefreshAnnotations(proc { |p| !EvolutionCheck.check_item_methods(p, item).nil? }) scene.pbRefresh end } diff --git a/Data/Scripts/016_Pokemon/001_Pokemon-related/005_Pokemon_Evolution.rb b/Data/Scripts/016_Pokemon/001_Pokemon-related/005_Pokemon_Evolution.rb index 570b0e171..6a924d0d5 100644 --- a/Data/Scripts/016_Pokemon/001_Pokemon-related/005_Pokemon_Evolution.rb +++ b/Data/Scripts/016_Pokemon/001_Pokemon-related/005_Pokemon_Evolution.rb @@ -257,46 +257,32 @@ end # Evolution checks #=============================================================================== module EvolutionCheck - # The core method that performs evolution checks. Needs a block given to it, - # which will provide either a GameData::Species ID (the species to evolve - # into) or nil (keep checking). - # @param pkmn [Pokemon] the Pokémon trying to evolve - def self.check_ex(pkmn) - return nil if !pkmn.species || pokemon.egg? || pokemon.shadowPokemon? - return nil if pkmn.hasItem?(:EVERSTONE) - return nil if pkmn.hasAbility?(:BATTLEBOND) - ret = nil - pkmn.species_data.evolutions.each do |evo| # [new_species, method, parameter, boolean] - next if evo[3] # Prevolution - ret = yield pkmn, evo[1], evo[2], evo[0] # pkmn, method, parameter, new_species - break if ret - end - return ret - end + module_function - # Checks whether a Pokemon can evolve because of levelling up. If the item - # parameter is not nil, instead checks whether a Pokémon can evolve because of - # using the item on it. + # Checks whether a Pokemon can evolve because of levelling up. # @param pkmn [Pokemon] the Pokémon trying to evolve - # @param item [Symbol, GameData::Item, nil] the item being used - def self.check(pkmn, item = nil) - if item - return self.check_ex(pkmn) { |pkmn, method, parameter, new_species| - success = PBEvolution.call("itemCheck", method, pkmn, parameter, item) - return (success) ? new_species : nil - } - end - return self.check_ex(pkmn) { |pkmn, method, parameter, new_species| + def check_level_up_methods(pkmn) + return check_ex(pkmn) { |pkmn, method, parameter, new_species| success = PBEvolution.call("levelUpCheck", method, pkmn, parameter) next (success) ? new_species : nil } end + # Checks whether a Pokemon can evolve because of using an item on it. + # @param pkmn [Pokemon] the Pokémon trying to evolve + # @param item [Symbol, GameData::Item, nil] the item being used + def check_item_methods(pkmn, item) + return check_ex(pkmn) { |pkmn, method, parameter, new_species| + success = PBEvolution.call("itemCheck", method, pkmn, parameter, item) + return (success) ? new_species : nil + } + end + # Checks whether a Pokemon can evolve because of being traded. # @param pkmn [Pokemon] the Pokémon trying to evolve # @param other_pkmn [Pokemon] the other Pokémon involved in the trade - def self.check_trade_methods(pkmn, other_pkmn) - return self.check_ex(pkmn) { |pkmn, method, parameter, new_species| + def check_trade_methods(pkmn, other_pkmn) + return check_ex(pkmn) { |pkmn, method, parameter, new_species| success = PBEvolution.call("tradeCheck", method, pkmn, parameter, other_pkmn) next (success) ? new_species : nil } @@ -306,12 +292,31 @@ module EvolutionCheck # required it to have a held item) or duplicate the Pokémon (Shedinja only). # @param pkmn [Pokemon] the Pokémon trying to evolve # @param evolved_species [Pokemon] the species that the Pokémon evolved into - def self.check_after_evolution(pkmn, evolved_species) + def check_after_evolution(pkmn, evolved_species) pkmn.species_data.evolutions.each do |evo| # [new_species, method, parameter, boolean] next if evo[3] # Prevolution break if PBEvolution.call("afterEvolution", evo[1], pkmn, evo[0], evo[2], evolved_species) end end + + private + + # The core method that performs evolution checks. Needs a block given to it, + # which will provide either a GameData::Species ID (the species to evolve + # into) or nil (keep checking). + # @param pkmn [Pokemon] the Pokémon trying to evolve + def self.check_ex(pkmn) + return nil if !pkmn.species || pkmn.egg? || pkmn.shadowPokemon? + return nil if pkmn.hasItem?(:EVERSTONE) + return nil if pkmn.hasAbility?(:BATTLEBOND) + ret = nil + pkmn.species_data.evolutions.each do |evo| # [new_species, method, parameter, boolean] + next if evo[3] # Prevolution + ret = yield pkmn, evo[1], evo[2], evo[0] # pkmn, method, parameter, new_species + break if ret + end + return ret + end end #===============================================================================