mirror of
https://github.com/infinitefusion/infinitefusion-e18.git
synced 2025-12-09 06:04:59 +00:00
Fixed bug with trainer data, tidied evolution-checking code
This commit is contained in:
@@ -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
|
||||
|
||||
#===============================================================================
|
||||
|
||||
Reference in New Issue
Block a user