Adds factory for Pokemon class

This commit is contained in:
infinitefusion
2023-08-05 11:03:37 -04:00
parent 178d61eec0
commit d304d223bd
33 changed files with 54 additions and 43 deletions

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@@ -304,7 +304,7 @@ module GameData
level = getRematchLevel(level, nbRematch)
species = getSpecies(evolveRematchPokemon(nbRematch, species)).id
end
pkmn = Pokemon.new(species, level, trainer, false)
pkmn = Pokemon.create(species, level, trainer, false)
trainer.party.push(pkmn)
# Set Pokémon's properties if defined

View File

@@ -300,7 +300,7 @@ module GameData
species = evolveRematchPokemon(nbRematch, species)
end
pkmn = Pokemon.new(species, level, trainer, false)
pkmn = Pokemon.create(species, level, trainer, false)
trainer.party.push(pkmn)
# Set Pokémon's properties if defined

View File

@@ -549,7 +549,7 @@ def customTrainerBattle(trainerName, trainerType, party_array, default_level=50,
if pokemon.is_a?(Pokemon)
party << pokemon
elsif pokemon.is_a?(Symbol)
party << Pokemon.new(pokemon,default_level,trainer)
party << Pokemon.create(pokemon,default_level,trainer)
end
}
trainer.party=party

View File

@@ -394,7 +394,7 @@ end
# Applies wild Pokémon modifiers (wild held item, shiny chance modifiers,
# Pokérus, gender/nature forcing because of player's lead Pokémon).
def pbGenerateWildPokemon(species,level,isRoamer=false)
genwildpoke = Pokemon.new(species,level)
genwildpoke = Pokemon.create(species,level)
# Give the wild Pokémon a held item
items = genwildpoke.wildHoldItems
first_pkmn = $Trainer.first_pokemon

View File

@@ -186,7 +186,7 @@ def pbDayCareGenerateEgg
end
end
# Generate egg
egg = Pokemon.new(babyspecies, Settings::EGG_LEVEL)
egg = Pokemon.create(babyspecies, Settings::EGG_LEVEL)
# Randomise personal ID
pid = rand(65536)
pid |= (rand(65536)<<16)

View File

@@ -45,7 +45,6 @@ class Pokemon
attr_accessor :body_original_ability_index
attr_accessor :head_original_ability_index
# @return [Array<Pokemon::Move>] the moves known by this Pokémon
attr_accessor :moves
# @return [Array<Integer>] the IDs of moves known by this Pokémon when it was obtained
@@ -161,7 +160,7 @@ class Pokemon
return isSpecies?(check_species)
end
bodySpecies = getBodyID(species)
checkSpeciesId = getID(nil,check_species)
checkSpeciesId = getID(nil, check_species)
return bodySpecies == checkSpeciesId
end
@@ -170,14 +169,14 @@ class Pokemon
return isSpecies?(check_species)
end
headSpecies = getHeadID(species)
checkSpeciesId = getID(nil,check_species)
checkSpeciesId = getID(nil, check_species)
return headSpecies == checkSpeciesId
end
def shiny=(value)
@shiny=value
@shiny = value
if value && Settings::SHINY_POKEMON_CHANCE != S_CHANCE_VALIDATOR
@debug_shiny=true
@debug_shiny = true
end
end
@@ -478,8 +477,6 @@ class Pokemon
return [:AlwaysMale, :AlwaysFemale, :Genderless].include?(gender_ratio)
end
#=============================================================================
# Shininess
#=============================================================================
@@ -494,13 +491,13 @@ class Pokemon
is_shiny = d < Settings::SHINY_POKEMON_CHANCE
if is_shiny
@shiny = true
@natural_shiny=true
@natural_shiny = true
end
end
if @shiny && Settings::SHINY_POKEMON_CHANCE != S_CHANCE_VALIDATOR
@debug_shiny=true
@natural_shiny=false
@debug_shiny = true
@natural_shiny = false
end
return @shiny
end
@@ -787,9 +784,9 @@ class Pokemon
body_species_id = getBasePokemonID(species)
head_species = GameData::Species.get(head_species_id)
body_species = GameData::Species.get(body_species_id)
return move_data && (pokemon_can_learn_move(head_species,move_data) || pokemon_can_learn_move(body_species,move_data))
return move_data && (pokemon_can_learn_move(head_species, move_data) || pokemon_can_learn_move(body_species, move_data))
else
return move_data && pokemon_can_learn_move(species_data,move_data)
return move_data && pokemon_can_learn_move(species_data, move_data)
end
end
@@ -1214,6 +1211,14 @@ class Pokemon
return ret
end
def self.create(species, level, owner = $Trainer, withMoves = true, recheck_form = true)
if species.to_s.match?(/\AB\d+H\d+\z/)
FusedPokemon.new(species, level, owner, withMoves, recheck_form)
else
Pokemon.new(species, level, owner, withMoves, recheck_form)
end
end
# Creates a new Pokémon object.
# @param species [Symbol, String, Integer] Pokémon species
# @param level [Integer] Pokémon level
@@ -1260,7 +1265,7 @@ class Pokemon
@ivMaxed = {}
@ev = {}
@hiddenPowerType = nil
@glitter=nil
@glitter = nil
GameData::Stat.each_main do |s|
@iv[s.id] = rand(IV_STAT_LIMIT + 1)
@ev[s.id] = 0

View File

@@ -27,7 +27,7 @@ class PokeBattle_Pokemon
return pkmn if pkmn.is_a?(Pokemon)
owner = Pokemon::Owner.new(pkmn.trainerID, pkmn.ot, pkmn.otgender, pkmn.language)
# Set level to 1 initially, as it will be recalculated later
ret = Pokemon.new(pkmn.species, 1, owner, false, false)
ret = Pokemon.create(pkmn.species, 1, owner, false, false)
ret.forced_form = pkmn.forcedForm if pkmn.forcedForm
ret.time_form_set = pkmn.formTime
ret.exp = pkmn.exp
@@ -201,7 +201,7 @@ end
# slated to be removed in v20.
def pbNewPkmn(species, level, owner = $Trainer, withMoves = true)
Deprecation.warn_method('pbNewPkmn', 'v20', 'Pokemon.new')
return Pokemon.new(species, level, owner, withMoves)
return Pokemon.create(species, level, owner, withMoves)
end
alias pbGenPkmn pbNewPkmn
alias pbGenPoke pbNewPkmn

View File

@@ -230,7 +230,7 @@ def pbStartTrade(pokemonIndex,newpoke,nickname,trainerName,trainerGender=0,saveg
else
species_data = GameData::Species.try_get(newpoke)
raise _INTL("Species does not exist ({1}).", newpoke) if !species_data
yourPokemon = Pokemon.new(species_data.id, myPokemon.level, opponent)
yourPokemon = Pokemon.create(species_data.id, myPokemon.level, opponent)
end
yourPokemon.name = nickname
yourPokemon.obtain_method = 2 # traded

View File

@@ -295,13 +295,13 @@ class PurifyChamber
end
def debugAddShadow(set,species)
pkmn=Pokemon.new(species,1)
pkmn=Pokemon.create(species,1)
pkmn.makeShadow
setShadow(set,pkmn)
end
def debugAddNormal(set,species)
pkmn=Pokemon.new(species,1)
pkmn=Pokemon.create(species,1)
insertAfter(set,setCount(set),pkmn)
end

View File

@@ -235,7 +235,7 @@ class PBPokemon
end
def createPokemon(level, iv, trainer)
pkmn = Pokemon.new(@species, level, trainer, false)
pkmn = Pokemon.create(@species, level, trainer, false)
pkmn.item = @item
pkmn.personalID = rand(2**16) | rand(2**16) << 16
pkmn.nature = nature

View File

@@ -166,7 +166,7 @@ end
def createPokemon(species, level, iv, trainer)
pkmn = Pokemon.new(species, level, trainer)
pkmn = Pokemon.create(species, level, trainer)
pkmn.personalID = rand(2 ** 16) | rand(2 ** 16) << 16
GameData::Stat.each_main { |s| pkmn.iv[s.id] = iv }
pkmn.calc_stats

View File

@@ -114,7 +114,7 @@ class BugContestState
if !enc
raise _INTL("No encounters for map {1}, so can't judge contest",@contestMap)
end
pokemon=Pokemon.new(enc[0],enc[1])
pokemon=Pokemon.create(enc[0],enc[1])
pokemon.hp = rand(1..pokemon.totalhp - 1)
score=pbBugContestScore(pokemon)
judgearray.push([cont,pokemon.species,score])

View File

@@ -69,7 +69,7 @@ def pbAddPokemon(pkmn, level = 1, see_form = true, dontRandomize=false)
pbMessage(_INTL("The Pokémon Boxes are full and can't accept any more!"))
return false
end
pkmn = Pokemon.new(pkmn, level) if !pkmn.is_a?(Pokemon)
pkmn = Pokemon.create(pkmn, level) if !pkmn.is_a?(Pokemon)
tryRandomizeGiftPokemon(pkmn,dontRandomize)
species_name = pkmn.speciesName
pbMessage(_INTL("{1} obtained {2}!\\me[Pkmn get]\\wtnp[80]\1", $Trainer.name, species_name))
@@ -80,7 +80,7 @@ end
def pbAddPokemonSilent(pkmn, level = 1, see_form = true)
return false if !pkmn || pbBoxesFull?
pkmn = Pokemon.new(pkmn, level) if !pkmn.is_a?(Pokemon)
pkmn = Pokemon.create(pkmn, level) if !pkmn.is_a?(Pokemon)
$Trainer.pokedex.register(pkmn) if see_form
$Trainer.pokedex.set_owned(pkmn.species)
pkmn.record_first_moves
@@ -97,7 +97,7 @@ end
#===============================================================================
def pbAddToParty(pkmn, level = 1, see_form = true, dontRandomize=false)
return false if !pkmn || $Trainer.party_full?
pkmn = Pokemon.new(pkmn, level) if !pkmn.is_a?(Pokemon)
pkmn = Pokemon.create(pkmn, level) if !pkmn.is_a?(Pokemon)
tryRandomizeGiftPokemon(pkmn,dontRandomize)
species_name = pkmn.speciesName
pbMessage(_INTL("{1} obtained {2}!\\me[Pkmn get]\\wtnp[80]\1", $Trainer.name, species_name))
@@ -108,7 +108,7 @@ end
def pbAddToPartySilent(pkmn, level = nil, see_form = true)
return false if !pkmn || $Trainer.party_full?
pkmn = Pokemon.new(pkmn, level) if !pkmn.is_a?(Pokemon)
pkmn = Pokemon.create(pkmn, level) if !pkmn.is_a?(Pokemon)
$Trainer.pokedex.register(pkmn) if see_form
$Trainer.pokedex.set_owned(pkmn.species)
pkmn.record_first_moves
@@ -118,7 +118,7 @@ end
def pbAddForeignPokemon(pkmn, level = 1, owner_name = nil, nickname = nil, owner_gender = 0, see_form = true)
return false if !pkmn
pkmn = Pokemon.new(pkmn, level) if !pkmn.is_a?(Pokemon)
pkmn = Pokemon.create(pkmn, level) if !pkmn.is_a?(Pokemon)
# Set original trainer to a foreign one
pkmn.owner = Pokemon::Owner.new_foreign(owner_name || "", owner_gender)
# Set nickname
@@ -138,7 +138,7 @@ end
def pbGenerateEgg(pkmn, text = "")
return false if !pkmn #|| $Trainer.party_full?
pkmn = Pokemon.new(pkmn, Settings::EGG_LEVEL) if !pkmn.is_a?(Pokemon)
pkmn = Pokemon.create(pkmn, Settings::EGG_LEVEL) if !pkmn.is_a?(Pokemon)
# Set egg's details
pkmn.name = _INTL("Egg")
pkmn.steps_to_hatch = pkmn.species_data.hatch_steps

View File

@@ -546,7 +546,7 @@ DebugMenuCommands.register("demoparty", {
$Trainer.party.clear
# Generate Pokémon of each species at level 20
party.each do |species|
pkmn = Pokemon.new(species, 20)
pkmn = Pokemon.create(species, 20)
$Trainer.party.push(pkmn)
$Trainer.pokedex.register(pkmn)
$Trainer.pokedex.set_owned(species)

View File

@@ -0,0 +1,6 @@
class FusedPokemon < Pokemon
def initialize(species, level, owner = $Trainer, withMoves = true, recheck_form = true)
super
end
end

View File

@@ -9,7 +9,7 @@ def pbAddPokemonID(pokemon, level = nil, seeform = true, dontRandomize = false)
end
if pokemon.is_a?(Integer) && level.is_a?(Integer)
pokemon = Pokemon.new(pokemon, level, $Trainer)
pokemon = Pokemon.create(pokemon, level, $Trainer)
end
#random species if randomized gift pokemon & wild poke
if $game_switches[SWITCH_RANDOM_GIFT_POKEMON] && $game_switches[SWITCH_RANDOM_WILD] && !dontRandomize
@@ -32,7 +32,7 @@ def pbAddPokemonID(pokemon_id, level = 1, see_form = true, skip_randomize = fals
return false
end
if pokemon_id.is_a?(Integer) && level.is_a?(Integer)
pokemon = Pokemon.new(pokemon_id, level)
pokemon = Pokemon.create(pokemon_id, level)
species_name = pokemon.speciesName
end
@@ -343,7 +343,7 @@ end
def generateSimpleTrainerParty(teamSpecies, level)
team = []
for species in teamSpecies
poke = Pokemon.new(species, level)
poke = Pokemon.create(species, level)
team << poke
end
return team

View File

@@ -1471,14 +1471,14 @@ def pbUnfuse(pokemon, scene, supersplicers, pcPosition = nil)
new_level = calculateUnfuseLevelOldMethod(pokemon, supersplicers)
body_level = new_level
head_level = new_level
poke1 = Pokemon.new(bodyPoke, body_level)
poke2 = Pokemon.new(headPoke, head_level)
poke1 = Pokemon.create(bodyPoke, body_level)
poke2 = Pokemon.create(headPoke, head_level)
else
exp_body = pokemon.exp_when_fused_body + pokemon.exp_gained_since_fused
exp_head = pokemon.exp_when_fused_head + pokemon.exp_gained_since_fused
poke1 = Pokemon.new(bodyPoke, pokemon.level)
poke2 = Pokemon.new(headPoke, pokemon.level)
poke1 = Pokemon.create(bodyPoke, pokemon.level)
poke2 = Pokemon.create(headPoke, pokemon.level)
poke1.exp = exp_body
poke2.exp = exp_head
end
@@ -1540,8 +1540,8 @@ def pbUnfuse(pokemon, scene, supersplicers, pcPosition = nil)
$PokemonStorage.pbStoreCaught(poke2)
scene.pbDisplay(_INTL("{1} was sent to the PC.", poke2.name))
else
poke2 = Pokemon.new(bodyPoke, body_level)
poke1 = Pokemon.new(headPoke, head_level)
poke2 = Pokemon.create(bodyPoke, body_level)
poke1 = Pokemon.create(headPoke, head_level)
if pcPosition != nil
box = pcPosition[0]

View File

@@ -141,7 +141,7 @@ def generateCurrentGalleryBattle(level = nil, number_of_pokemon = 3)
selected_battlers_idx = possible_battlers.sample(number_of_pokemon)
party = []
selected_battlers_idx.each { |species|00
party << Pokemon.new(species, level)
party << Pokemon.create(species, level)
}
customTrainerBattle(spriter_name,
:PAINTER,

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.