fixes Pokedex

This commit is contained in:
infinitefusion
2022-04-16 22:13:46 -04:00
parent 1c569684c0
commit c041fad340
12 changed files with 163 additions and 170 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.

View File

@@ -238,7 +238,7 @@ module Settings
# Dex list, no matter which region the player is currently in. # Dex list, no matter which region the player is currently in.
def self.pokedex_names def self.pokedex_names
return [ return [
[_INTL("Kanto Pokédex"), 0] # [_INTL("Kanto Pokédex"), 0]
] ]
end end

View File

@@ -26,10 +26,12 @@ class Player < Trainer
@owned = {} #deprecated @owned = {} #deprecated
@seen_standard = initStandardDexArray() @seen_standard = initStandardDexArray()
@owned_standard = initStandardDexArray()
@seen_fusion = initFusionDexArray() @seen_fusion = initFusionDexArray()
@seen_triple = {}
@owned_standard = initStandardDexArray()
@owned_fusion = initFusionDexArray() @owned_fusion = initFusionDexArray()
@owned_triple = {}
@seen_forms = {} @seen_forms = {}
@last_seen_forms = {} @last_seen_forms = {}
@@ -39,62 +41,63 @@ class Player < Trainer
def initStandardDexArray() def initStandardDexArray()
dex_array = [] dex_array = []
for poke in 0..NB_POKEMON (0..NB_POKEMON).each { |poke|
if poke == 0 if poke == 0
dex_array << nil dex_array << nil
end end
dex_array << false dex_array << false
end }
return dex_array return dex_array
end end
def initFusionDexArray() def initFusionDexArray()
head_array = [] head_array = []
for head in 0..NB_POKEMON (0..NB_POKEMON).each { |head|
body_array = [] body_array = []
if head == 0 if head == 0
head_array << nil head_array << nil
end end
for body in 0..NB_POKEMON (0..NB_POKEMON).each { |body|
if body == 0 if body == 0
body_array << nil body_array << nil
end end
body_array << false body_array << false
end }
head_array << body_array head_array << body_array
end }
return head_array return head_array
end end
def isFusion(species) def isTripleFusion(num)
num = getDexNumberForSpecies(species) return num >= Settings::ZAPMOLCUNO_NB
return num > Settings::NB_POKEMON && num < Settings::ZAPMOLCUNO_NB
end end
#=========================================================================== def isFusion(num)
return num > Settings::NB_POKEMON && !isTripleFusion(num)
end
# Sets the given species as seen in the Pokédex.
# @param species [Symbol, GameData::Species] species to set as seen
# @param should_refresh_dexes [Boolean] whether Dex accessibility should be recalculated
def set_seen_fusion(species) def set_seen_fusion(species)
bodyId = getBodyID(species) bodyId = getBodyID(species)
headId = getHeadID(species, bodyId) headId = getHeadID(species, bodyId)
@seen_fusion[headId][bodyId] = true @seen_fusion[headId][bodyId] = true
end end
# def set_seen_normalDex(species)
# species_id = GameData::Species.try_get(species)&.species
# return if species_id.nil?
# @seen[species_id] = true
# end
def set_seen_normalDex(species) def set_seen_normalDex(species)
dex_num = getDexNumberForSpecies(species) dex_num = getDexNumberForSpecies(species)
@seen_standard[dex_num] = true @seen_standard[dex_num] = true
end end
def set_seen_triple(species)
species_id = GameData::Species.try_get(species)&.species
return if species_id.nil?
@seen_triple[species_id] = true
end
def set_seen(species, should_refresh_dexes = true) def set_seen(species, should_refresh_dexes = true)
if isFusion(species) dexNum = getDexNumberForSpecies(species)
if isTripleFusion(dexNum)
set_seen_triple(species)
elsif isFusion(dexNum)
set_seen_fusion(species) set_seen_fusion(species)
else else
set_seen_normalDex(species) set_seen_normalDex(species)
@@ -120,18 +123,23 @@ class Player < Trainer
return @seen_standard[getDexNumberForSpecies(species)] return @seen_standard[getDexNumberForSpecies(species)]
end end
def seen_triple?(species)
species_id = GameData::Species.try_get(species)&.species
return false if species_id.nil?
return @seen_triple[species_id]
end
def seen?(species) def seen?(species)
if isFusion(species) num = getDexNumberForSpecies(species)
if isTripleFusion(num)
return seen_triple?(species)
elsif isFusion(num)
return seen_fusion?(species) return seen_fusion?(species)
else else
return seen_normalDex?(species) return seen_normalDex?(species)
end end
end end
# @param species [Symbol, GameData::Species] species to check
# @param gender [Integer] gender to check
# @param form [Integer] form to check
# @return [Boolean] whether the species of the given gender and form is seen
def seen_form?(species, gender, form) def seen_form?(species, gender, form)
return false return false
# species_id = GameData::Species.try_get(species)&.species # species_id = GameData::Species.try_get(species)&.species
@@ -145,10 +153,10 @@ class Player < Trainer
# in that region. # in that region.
# @param dex [Integer] region ID # @param dex [Integer] region ID
def seen_count(dex = -1) def seen_count(dex = -1)
if @seen_standard == nil || @owned_standard == nil if dex_sync_needed?()
resync_pokedex() resync_pokedex()
end end
count_dex(@seen_standard,@seen_fusion) return count_dex(@seen_standard, @seen_fusion) + @owned_triple.size
end end
# Returns whether there are any seen Pokémon. # Returns whether there are any seen Pokémon.
@@ -160,35 +168,12 @@ class Player < Trainer
return seen_count >= 1 return seen_count >= 1
end end
# def seen_any?(dex = -1)
# validate dex => Integer
# if dex == -1
# GameData::Species.each { |s| return true if s.form == 0 && @seen[s.species] }
# else
# pbAllRegionalSpecies(dex).each { |s| return true if s && @seen[s] }
# end
# return false
# end
# Returns the amount of seen forms for the given species. # Returns the amount of seen forms for the given species.
# @param species [Symbol, GameData::Species] Pokémon species # @param species [Symbol, GameData::Species] Pokémon species
# @return [Integer] amount of seen forms # @return [Integer] amount of seen forms
def seen_forms_count(species) def seen_forms_count(species)
return 0 return 0
end end
# def seen_forms_count(species)
# species_id = GameData::Species.try_get(species)&.species
# return 0 if species_id.nil?
# ret = 0
# @seen_forms[species_id] ||= [[], []]
# array = @seen_forms[species_id]
# for i in 0...[array[0].length, array[1].length].max
# ret += 1 if array[0][i] || array[1][i]
# end
# return ret
# end
# @param species [Symbol, GameData::Species] Pokémon species # @param species [Symbol, GameData::Species] Pokémon species
def last_form_seen(species) def last_form_seen(species)
@@ -214,18 +199,21 @@ class Player < Trainer
@owned_fusion[headId][bodyId] = true @owned_fusion[headId][bodyId] = true
end end
def set_owned_triple(species)
species_id = GameData::Species.try_get(species)&.species
return if species_id.nil?
@owned_triple[species_id] = true
end
# def set_owned_normalDex(species)
# species_id = GameData::Species.try_get(species)&.species
# return if species_id.nil?
# @owned[species_id] = true
# end
def set_owned_normalDex(species) def set_owned_normalDex(species)
@owned_standard[getDexNumberForSpecies(species)] = true @owned_standard[getDexNumberForSpecies(species)] = true
end end
def set_owned(species, should_refresh_dexes = true) def set_owned(species, should_refresh_dexes = true)
if isFusion(species) dexNum = getDexNumberForSpecies(species)
if isTripleFusion(dexNum)
set_owned_triple(species)
elsif isFusion(dexNum)
set_owned_fusion(species) set_owned_fusion(species)
else else
set_owned_normalDex(species) set_owned_normalDex(species)
@@ -237,10 +225,6 @@ class Player < Trainer
# @param species [Symbol, GameData::Species] species to set as owned # @param species [Symbol, GameData::Species] species to set as owned
def set_shadow_pokemon_owned(species) def set_shadow_pokemon_owned(species)
return return
# species_id = GameData::Species.try_get(species)&.species
# return if species_id.nil?
# @owned_shadow[species_id] = true
# self.refresh_accessible_dexes
end end
# @param species [Symbol, GameData::Species] species to check # @param species [Symbol, GameData::Species] species to check
@@ -251,29 +235,31 @@ class Player < Trainer
return @owned_fusion[headId][bodyId] == true return @owned_fusion[headId][bodyId] == true
end end
def owned_triple?(species)
species_id = GameData::Species.try_get(species)&.species
return false if species_id.nil?
return @owned_triple[species_id]
end
def owned?(species) def owned?(species)
if isFusion(species) num = getDexNumberForSpecies(species)
if isTripleFusion(num)
return owned_triple?(species)
elsif isFusion(num)
return owned_fusion?(species) return owned_fusion?(species)
else else
return owned_normalDex?(species) return owned_normalDex?(species)
end end
end end
# def owned_normalDex?(species)
# species_id = GameData::Species.try_get(species)&.species
# return false if species_id.nil?
# return @owned[species_id] == true
# end
def owned_normalDex?(species) def owned_normalDex?(species)
return @owned_standard[getDexNumberForSpecies(species)] return @owned_standard[getDexNumberForSpecies(species)]
end end
# @param species [Symbol, GameData::Species] species to check # @param species [Symbol, GameData::Species] species to check
# @return [Boolean] whether a Shadow Pokémon of the species is owned # @return [Boolean] whether a Shadow Pokémon of the species is owned
def owned_shadow_pokemon?(species) def owned_shadow_pokemon?(species)
return return
# species_id = GameData::Species.try_get(species)&.species
# return false if species_id.nil?
# return @owned_shadow[species_id] == true
end end
# Returns the amount of owned Pokémon. # Returns the amount of owned Pokémon.
@@ -281,45 +267,82 @@ class Player < Trainer
# in that region. # in that region.
# @param region [Integer] region ID # @param region [Integer] region ID
def owned_count(dex = -1) def owned_count(dex = -1)
if @owned_standard == nil || @owned_fusion == nil if dex_sync_needed?()
resync_pokedex() resync_pokedex()
end end
count_dex(@owned_standard,@owned_fusion) return count_dex(@owned_standard, @owned_fusion) + @owned_triple.size
#
# validate dex => Integer
# return self.count_species(@owned, dex)
end end
def count_dex(standardList,fusedList) def count_dex(standardList, fusedList)
owned_standard = count_true(standardList) owned_standard = count_true(standardList)
owned_fused = 0 owned_fused = 0
for head_poke_list in fusedList fusedList.each { |head_poke_list|
if head_poke_list != nil if head_poke_list != nil
owned_fused += count_true(head_poke_list) owned_fused += count_true(head_poke_list)
end end
end }
return owned_standard + owned_fused return owned_standard + owned_fused
end end
def count_true(list) def count_true(list)
count=0 count = 0
for owned in list list.each { |owned|
if owned if owned
count+=1 count += 1
end end
end }
return count return count
end end
def dex_sync_needed?()
return @owned_standard == nil || @owned_fusion == nil || @owned_triple == nil
end
#todo: #todo:
# loop on @owned and @seen and add the pokemon in @owned_standard/fusion @seen_standard/fusion # loop on @owned and @seen and add the pokemon in @owned_standard/fusion @seen_standard/fusion
# then clear @owned and @seen # then clear @owned and @seen
def resync_pokedex() def resync_pokedex()
self.clear Kernel.pbMessage(_INTL("Syncing Pokédex... This might take some time."))
init_new_pokedex_if_needed()
@seen.each { |pokemon|
set_seen(pokemon[0])
}
@owned.each { |pokemon|
set_owned(pokemon[0])
}
self.refresh_accessible_dexes
@seen = {} #deprecated
@owned = {} #deprecated
#self.clear
end end
def resync_boxes_to_pokedex
$PokemonStorage.boxes.each { |box|
box.pokemon.each { |pokemon|
if pokemon != nil
if !pokemon.egg?
set_owned(pokemon.species)
set_seen(pokemon.species)
end
end
}
}
end
def init_new_pokedex_if_needed()
@seen_standard = initStandardDexArray() if @seen_standard == nil
@seen_fusion = initFusionDexArray() if @seen_fusion == nil
@seen_triple = {} if @seen_triple == nil
@owned_standard = initStandardDexArray() if @owned_standard == nil
@owned_fusion = initFusionDexArray() if @owned_fusion == nil
@owned_triple = {} if @owned_triple == nil
end
#=========================================================================== #===========================================================================
# @param pkmn [Pokemon, Symbol, GameData::Species] Pokemon to register as seen # @param pkmn [Pokemon, Symbol, GameData::Species] Pokemon to register as seen
@@ -327,16 +350,6 @@ class Player < Trainer
# @param form [Integer] form to register # @param form [Integer] form to register
def register(species, gender = 0, form = 0, should_refresh_dexes = true) def register(species, gender = 0, form = 0, should_refresh_dexes = true)
set_seen(species, should_refresh_dexes) set_seen(species, should_refresh_dexes)
# return
# if species.is_a?(Pokemon)
# species_data = species.species_data
# #gender = species.gender
# else
# species_data = GameData::Species.get(species)
# end
# species = species_data.species
# @seen[species] = true
# self.refresh_accessible_dexes if should_refresh_dexes
end end
# @param pkmn [Pokemon] Pokemon to register as most recently seen # @param pkmn [Pokemon] Pokemon to register as most recently seen
@@ -372,9 +385,10 @@ class Player < Trainer
# @param dex [Integer] Dex ID (-1 is the National Dex) # @param dex [Integer] Dex ID (-1 is the National Dex)
# @return [Boolean] whether the given Dex is unlocked # @return [Boolean] whether the given Dex is unlocked
def unlocked?(dex) def unlocked?(dex)
validate dex => Integer return dex == -1
dex = @unlocked_dexes.length - 1 if dex == -1 # validate dex => Integer
return @unlocked_dexes[dex] == true # dex = @unlocked_dexes.length - 1 if dex == -1
# return @unlocked_dexes[dex] == true
end end
# @return [Integer] the number of defined Dexes (including the National Dex) # @return [Integer] the number of defined Dexes (including the National Dex)
@@ -390,25 +404,8 @@ class Player < Trainer
# if a species in the current region has been seen - doesn't look at other # if a species in the current region has been seen - doesn't look at other
# regions. # regions.
def refresh_accessible_dexes def refresh_accessible_dexes
@accessible_dexes = [] if self.unlocked?(0) && self.seen_any?
if Settings::USE_CURRENT_REGION_DEX @accessible_dexes.push(-1)
region = pbGetCurrentRegion
region = -1 if region >= dexes_count - 1
@accessible_dexes[0] = region if self.seen_any?(region)
return
end
if dexes_count == 1 # Only National Dex is defined
if self.unlocked?(0) && self.seen_any?
@accessible_dexes.push(-1)
end
else
# Regional Dexes + National Dex
for i in 0...dexes_count
dex_list_to_check = (i == dexes_count - 1) ? -1 : i
if self.unlocked?(i) && self.seen_any?(dex_list_to_check)
@accessible_dexes.push(dex_list_to_check)
end
end
end end
end end
@@ -421,13 +418,6 @@ class Player < Trainer
# @return [Integer] # @return [Integer]
def count_species(hash, region = -1) def count_species(hash, region = -1)
return hash.size() return hash.size()
# ret = 0
# if region == -1
# GameData::Species.each { |s| ret += 1 if s.form == 0 && hash[s.species] }
# else
# pbAllRegionalSpecies(region).each { |s| ret += 1 if s && hash[s] }
# end
# return ret
end end
end end
end end

View File

@@ -156,7 +156,7 @@ class PokemonPauseMenu
@scene.pbRefresh @scene.pbRefresh
} }
else else
if $Trainer.pokedex.accessible_dexes.length == 1 #if $Trainer.pokedex.accessible_dexes.length == 1
$PokemonGlobal.pokedexDex = $Trainer.pokedex.accessible_dexes[0] $PokemonGlobal.pokedexDex = $Trainer.pokedex.accessible_dexes[0]
pbFadeOutIn { pbFadeOutIn {
scene = PokemonPokedex_Scene.new scene = PokemonPokedex_Scene.new
@@ -164,14 +164,14 @@ class PokemonPauseMenu
screen.pbStartScreen screen.pbStartScreen
@scene.pbRefresh @scene.pbRefresh
} }
else # else
pbFadeOutIn { # pbFadeOutIn {
scene = PokemonPokedexMenu_Scene.new # scene = PokemonPokedexMenu_Scene.new
screen = PokemonPokedexMenuScreen.new(scene) # screen = PokemonPokedexMenuScreen.new(scene)
screen.pbStartScreen # screen.pbStartScreen
@scene.pbRefresh # @scene.pbRefresh
} # }
end # end
end end
elsif cmdPokemon>=0 && command==cmdPokemon elsif cmdPokemon>=0 && command==cmdPokemon
pbPlayDecisionSE pbPlayDecisionSE

View File

@@ -25,7 +25,7 @@ class Window_Pokedex < Window_DrawableCommand
end end
def species def species
if self.index > @commands.size if self.index > @commands.size-1
self.index = 0 self.index = 0
end end
current_position= self.index current_position= self.index

View File

@@ -124,7 +124,9 @@ class PokemonPokedexInfo_Scene
def pbUpdateDummyPokemon def pbUpdateDummyPokemon
@species = @dexlist[@index][0] @species = @dexlist[@index][0]
@gender, @form = $Trainer.pokedex.last_form_seen(@species) @gender, @form = $Trainer.pokedex.last_form_seen(@species)
species_data = GameData::Species.get_species_form(@species, @form)
# species_data = pbGetSpeciesData(@species)
species_data = GameData::Species.get_species_form(@species, @form)
@sprites["infosprite"].setSpeciesBitmap(@species,@gender,@form) @sprites["infosprite"].setSpeciesBitmap(@species,@gender,@form)
if @sprites["formfront"] if @sprites["formfront"]
@sprites["formfront"].setSpeciesBitmap(@species,@gender,@form) @sprites["formfront"].setSpeciesBitmap(@species,@gender,@form)
@@ -141,42 +143,43 @@ class PokemonPokedexInfo_Scene
def pbGetAvailableForms def pbGetAvailableForms
ret = [] ret = []
multiple_forms = false
# Find all genders/forms of @species that have been seen
GameData::Species.each do |sp|
next if sp.species != @species
next if sp.form != 0 && (!sp.real_form_name || sp.real_form_name.empty?)
next if sp.pokedex_form != sp.form
multiple_forms = true if sp.form > 0
case sp.gender_ratio
when :AlwaysMale, :AlwaysFemale, :Genderless
real_gender = (sp.gender_ratio == :AlwaysFemale) ? 1 : 0
next if !$Trainer.pokedex.seen_form?(@species, real_gender, sp.form) && !Settings::DEX_SHOWS_ALL_FORMS
real_gender = 2 if sp.gender_ratio == :Genderless
ret.push([sp.form_name, real_gender, sp.form])
else # Both male and female
for real_gender in 0...2
next if !$Trainer.pokedex.seen_form?(@species, real_gender, sp.form) && !Settings::DEX_SHOWS_ALL_FORMS
ret.push([sp.form_name, real_gender, sp.form])
break if sp.form_name && !sp.form_name.empty? # Only show 1 entry for each non-0 form
end
end
end
# Sort all entries
ret.sort! { |a, b| (a[2] == b[2]) ? a[1] <=> b[1] : a[2] <=> b[2] }
# Create form names for entries if they don't already exist
ret.each do |entry|
if !entry[0] || entry[0].empty? # Necessarily applies only to form 0
case entry[1]
when 0 then entry[0] = _INTL("Male")
when 1 then entry[0] = _INTL("Female")
else
entry[0] = (multiple_forms) ? _INTL("One Form") : _INTL("Genderless")
end
end
entry[1] = 0 if entry[1] == 2 # Genderless entries are treated as male
end
return ret return ret
# multiple_forms = false
# # Find all genders/forms of @species that have been seen
# GameData::Species.each do |sp|
# next if sp.species != @species
# next if sp.form != 0 && (!sp.real_form_name || sp.real_form_name.empty?)
# next if sp.pokedex_form != sp.form
# multiple_forms = true if sp.form > 0
# case sp.gender_ratio
# when :AlwaysMale, :AlwaysFemale, :Genderless
# real_gender = (sp.gender_ratio == :AlwaysFemale) ? 1 : 0
# next if !$Trainer.pokedex.seen_form?(@species, real_gender, sp.form) && !Settings::DEX_SHOWS_ALL_FORMS
# real_gender = 2 if sp.gender_ratio == :Genderless
# ret.push([sp.form_name, real_gender, sp.form])
# else # Both male and female
# for real_gender in 0...2
# next if !$Trainer.pokedex.seen_form?(@species, real_gender, sp.form) && !Settings::DEX_SHOWS_ALL_FORMS
# ret.push([sp.form_name, real_gender, sp.form])
# break if sp.form_name && !sp.form_name.empty? # Only show 1 entry for each non-0 form
# end
# end
# end
# # Sort all entries
# ret.sort! { |a, b| (a[2] == b[2]) ? a[1] <=> b[1] : a[2] <=> b[2] }
# # Create form names for entries if they don't already exist
# ret.each do |entry|
# if !entry[0] || entry[0].empty? # Necessarily applies only to form 0
# case entry[1]
# when 0 then entry[0] = _INTL("Male")
# when 1 then entry[0] = _INTL("Female")
# else
# entry[0] = (multiple_forms) ? _INTL("One Form") : _INTL("Genderless")
# end
# end
# entry[1] = 0 if entry[1] == 2 # Genderless entries are treated as male
# end
# return ret
end end
def drawPage(page) def drawPage(page)

Binary file not shown.