Fixed bug with trainer data, tidied evolution-checking code

This commit is contained in:
Maruno17
2021-02-02 23:09:57 +00:00
parent 44e3c934ad
commit e1e9706cd9
5 changed files with 42 additions and 37 deletions

View File

@@ -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]

View File

@@ -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)

View File

@@ -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

View File

@@ -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
}

View File

@@ -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
#===============================================================================