diff --git a/Data/Scripts/010_Data/001_GameData.rb b/Data/Scripts/010_Data/001_GameData.rb index 2341392fc..8495028cf 100644 --- a/Data/Scripts/010_Data/001_GameData.rb +++ b/Data/Scripts/010_Data/001_GameData.rb @@ -58,6 +58,10 @@ module GameData keys.each { |key| yield self::DATA[key] if !key.is_a?(Integer) } end + def count + return self::DATA.length / 2 + end + def load const_set(:DATA, load_data("Data/#{self::DATA_FILENAME}")) end @@ -125,6 +129,10 @@ module GameData keys.each { |key| yield self::DATA[key] } end + def count + return self::DATA.length + end + def load const_set(:DATA, load_data("Data/#{self::DATA_FILENAME}")) end @@ -182,6 +190,10 @@ module GameData keys.each { |key| yield self::DATA[key] } end + def count + return self::DATA.length + end + def load const_set(:DATA, load_data("Data/#{self::DATA_FILENAME}")) end diff --git a/Data/Scripts/010_Data/001_Hardcoded data/010_Status.rb b/Data/Scripts/010_Data/001_Hardcoded data/010_Status.rb index 0b852bd04..f596375f0 100644 --- a/Data/Scripts/010_Data/001_Hardcoded data/010_Status.rb +++ b/Data/Scripts/010_Data/001_Hardcoded data/010_Status.rb @@ -1,31 +1,29 @@ -# NOTE: The id_number is only used to determine the order of the status icons in -# the graphics containing them. Number 0 (:NONE) is ignored; they start -# with status 1. -# "Graphics/Pictures/statuses.png" also contains icons for being fainted +# NOTE: "Graphics/Pictures/statuses.png" also contains icons for being fainted # and for having Pokérus, in that order, at the bottom of the graphic. # "Graphics/Pictures/Battle/icon_statuses.png" also contains an icon for # bad poisoning (toxic), at the bottom of the graphic. -# Both graphics automatically handle varying numbers of defined statuses. +# Both graphics automatically handle varying numbers of defined statuses, +# as long as their extra icons remain at the bottom of them. module GameData class Status attr_reader :id - attr_reader :id_number attr_reader :real_name attr_reader :animation + attr_reader :icon_position # Where this status's icon is within statuses.png DATA = {} - extend ClassMethods + extend ClassMethodsSymbols include InstanceMethods def self.load; end def self.save; end def initialize(hash) - @id = hash[:id] - @id_number = hash[:id_number] - @real_name = hash[:name] || "Unnamed" - @animation = hash[:animation] + @id = hash[:id] + @real_name = hash[:name] || "Unnamed" + @animation = hash[:animation] + @icon_position = hash[:icon_position] || -1 # -1 means "no icon" end # @return [String] the translated name of this status condition @@ -38,42 +36,41 @@ end #=============================================================================== GameData::Status.register({ - :id => :NONE, - :id_number => 0, - :name => _INTL("None") + :id => :NONE, + :name => _INTL("None") }) GameData::Status.register({ - :id => :SLEEP, - :id_number => 1, - :name => _INTL("Sleep"), - :animation => "Sleep" + :id => :SLEEP, + :name => _INTL("Sleep"), + :animation => "Sleep", + :icon_position => 0 }) GameData::Status.register({ - :id => :POISON, - :id_number => 2, - :name => _INTL("Poison"), - :animation => "Poison" + :id => :POISON, + :name => _INTL("Poison"), + :animation => "Poison", + :icon_position => 1 }) GameData::Status.register({ - :id => :BURN, - :id_number => 3, - :name => _INTL("Burn"), - :animation => "Burn" + :id => :BURN, + :name => _INTL("Burn"), + :animation => "Burn", + :icon_position => 2 }) GameData::Status.register({ - :id => :PARALYSIS, - :id_number => 4, - :name => _INTL("Paralysis"), - :animation => "Paralysis" + :id => :PARALYSIS, + :name => _INTL("Paralysis"), + :animation => "Paralysis", + :icon_position => 3 }) GameData::Status.register({ - :id => :FROZEN, - :id_number => 5, - :name => _INTL("Frozen"), - :animation => "Frozen" + :id => :FROZEN, + :name => _INTL("Frozen"), + :animation => "Frozen", + :icon_position => 4 }) diff --git a/Data/Scripts/010_Data/002_PBS data/008_Species.rb b/Data/Scripts/010_Data/002_PBS data/008_Species.rb index 718ab7c8d..3b65e853a 100644 --- a/Data/Scripts/010_Data/002_PBS data/008_Species.rb +++ b/Data/Scripts/010_Data/002_PBS data/008_Species.rb @@ -53,10 +53,6 @@ module GameData extend ClassMethodsSymbols include InstanceMethods - def self.each_species - DATA.each_value { |species| yield species if species.form == 0 } - end - # @param species [Symbol, self, String, Integer] # @param form [Integer] # @return [self, nil] @@ -75,6 +71,16 @@ module GameData return (DATA.has_key?(species_form)) ? DATA[species_form] : nil end + def self.each_species + DATA.each_value { |species| yield species if species.form == 0 } + end + + def self.species_count + ret = 0 + self.species_count { |species| ret += 1 } + return ret + end + def self.schema(compiling_forms = false) ret = { "FormName" => [0, "q"], diff --git a/Data/Scripts/010_Data/002_PBS data/013_Trainer.rb b/Data/Scripts/010_Data/002_PBS data/013_Trainer.rb index aa13dd8ed..4276b876c 100644 --- a/Data/Scripts/010_Data/002_PBS data/013_Trainer.rb +++ b/Data/Scripts/010_Data/002_PBS data/013_Trainer.rb @@ -137,7 +137,7 @@ module GameData else # Make the nature random but consistent for the same species used by the same trainer type species_num = GameData::Species.keys.index(species) || 1 tr_type_num = GameData::TrainerType.keys.index(@trainer_type) || 1 - pkmn.nature = (species_num + tr_type_num) % (GameData::Nature::DATA.length / 2) + pkmn.nature = (species_num + tr_type_num) % GameData::Nature.count end GameData::Stat.each_main do |s| if pkmn_data[:iv] diff --git a/Data/Scripts/011_Battle/002_Move/006_Move_Effects_080-0FF.rb b/Data/Scripts/011_Battle/002_Move/006_Move_Effects_080-0FF.rb index d70f201da..347abdb4e 100644 --- a/Data/Scripts/011_Battle/002_Move/006_Move_Effects_080-0FF.rb +++ b/Data/Scripts/011_Battle/002_Move/006_Move_Effects_080-0FF.rb @@ -1665,7 +1665,7 @@ class PokeBattle_Move_0B6 < PokeBattle_Move def pbMoveFailed?(user,targets) @metronomeMove = nil - move_keys = GameData::Move::DATA.keys + move_keys = GameData::Move.keys # NOTE: You could be really unlucky and roll blacklisted moves 1000 times in # a row. This is too unlikely to care about, though. 1000.times do diff --git a/Data/Scripts/011_Battle/005_Battle scene/004_PokeBattle_SceneElements.rb b/Data/Scripts/011_Battle/005_Battle scene/004_PokeBattle_SceneElements.rb index 60ab999f7..f5c6b7843 100644 --- a/Data/Scripts/011_Battle/005_Battle scene/004_PokeBattle_SceneElements.rb +++ b/Data/Scripts/011_Battle/005_Battle scene/004_PokeBattle_SceneElements.rb @@ -247,12 +247,13 @@ class PokemonDataBox < SpriteWrapper end # Draw status icon if @battler.status != :NONE - s = GameData::Status.get(@battler.status).id_number - if s == :POISON && @battler.statusCount > 0 # Badly poisoned - s = GameData::Status::DATA.keys.length / 2 + if @battler.status == :POISON && @battler.statusCount > 0 # Badly poisoned + s = GameData::Status.count + else + s = GameData::Status.get(@battler.status).icon_position end imagePos.push(["Graphics/Pictures/Battle/icon_statuses",@spriteBaseX+24,36, - 0,(s-1)*STATUS_ICON_HEIGHT,-1,STATUS_ICON_HEIGHT]) + 0,(s-1)*STATUS_ICON_HEIGHT,-1,STATUS_ICON_HEIGHT]) if s >= 0 end pbDrawImagePositions(self.bitmap,imagePos) refreshHP diff --git a/Data/Scripts/014_Pokemon/001_Pokemon.rb b/Data/Scripts/014_Pokemon/001_Pokemon.rb index 34f49826c..6296a2220 100644 --- a/Data/Scripts/014_Pokemon/001_Pokemon.rb +++ b/Data/Scripts/014_Pokemon/001_Pokemon.rb @@ -456,7 +456,7 @@ class Pokemon # @return [GameData::Nature, nil] a Nature object corresponding to this Pokémon's nature def nature - @nature = GameData::Nature.get(@personalID % (GameData::Nature::DATA.keys.length / 2)).id if !@nature + @nature = GameData::Nature.get(@personalID % GameData::Nature.count).id if !@nature return GameData::Nature.try_get(@nature) end diff --git a/Data/Scripts/015_Trainers and player/002_Trainer_LoadAndNew.rb b/Data/Scripts/015_Trainers and player/002_Trainer_LoadAndNew.rb index 8a4e703e5..0cf9e6079 100644 --- a/Data/Scripts/015_Trainers and player/002_Trainer_LoadAndNew.rb +++ b/Data/Scripts/015_Trainers and player/002_Trainer_LoadAndNew.rb @@ -36,7 +36,7 @@ def pbNewTrainer(tr_type, tr_name, tr_version, save_changes = true) trainer = [tr_type, tr_name, [], party, tr_version] if save_changes trainer_hash = { - :id_number => GameData::Trainer::DATA.keys.length / 2, + :id_number => GameData::Trainer.count, :trainer_type => tr_type, :name => tr_name, :version => tr_version, diff --git a/Data/Scripts/016_UI/001_Non-interactive UI/001_UI_SplashesAndTitleScreen.rb b/Data/Scripts/016_UI/001_Non-interactive UI/001_UI_SplashesAndTitleScreen.rb index 7ec6833c5..033fe3a02 100644 --- a/Data/Scripts/016_UI/001_Non-interactive UI/001_UI_SplashesAndTitleScreen.rb +++ b/Data/Scripts/016_UI/001_Non-interactive UI/001_UI_SplashesAndTitleScreen.rb @@ -68,8 +68,8 @@ class IntroEventScene < EventScene onUpdate.clear onCTrigger.clear # Play random cry - species_keys = GameData::Species::DATA.keys - species_data = GameData::Species.get(species_keys[rand(species_keys.length)]) + species_keys = GameData::Species.keys + species_data = GameData::Species.get(species_keys.sample) Pokemon.play_cry(species_data.species, species_data.form) @pic.moveXY(0, 20, 0, 0) # Adds 20 ticks (1 second) pause pictureWait diff --git a/Data/Scripts/016_UI/005_UI_Party.rb b/Data/Scripts/016_UI/005_UI_Party.rb index ea2772491..9b6ebd758 100644 --- a/Data/Scripts/016_UI/005_UI_Party.rb +++ b/Data/Scripts/016_UI/005_UI_Party.rb @@ -374,15 +374,14 @@ class PokemonPartyPanel < SpriteWrapper @overlaysprite.bitmap.blt(128,52,@hpbar.bitmap,hprect) end # Draw status - status = 0 + status = -1 if @pokemon.fainted? - status = GameData::Status::DATA.keys.length / 2 + status = GameData::Status.count elsif @pokemon.status != :NONE - status = GameData::Status.get(@pokemon.status).id_number + status = GameData::Status.get(@pokemon.status).icon_position elsif @pokemon.pokerusStage == 1 - status = GameData::Status::DATA.keys.length / 2 + 1 + status = GameData::Status.count + 1 end - status -= 1 if status >= 0 statusrect = Rect.new(0,16*status,44,16) @overlaysprite.bitmap.blt(78,68,@statuses.bitmap,statusrect) @@ -751,7 +750,7 @@ class PokemonParty_Scene currentsel -= 1 while currentsel > 0 && currentsel < Settings::MAX_PARTY_SIZE && !@party[currentsel] currentsel -= 1 - end + end else begin currentsel -= 2 diff --git a/Data/Scripts/016_UI/006_UI_Summary.rb b/Data/Scripts/016_UI/006_UI_Summary.rb index bc75a38f2..96add6dfb 100644 --- a/Data/Scripts/016_UI/006_UI_Summary.rb +++ b/Data/Scripts/016_UI/006_UI_Summary.rb @@ -308,15 +308,14 @@ class PokemonSummary_Scene ballimage = sprintf("Graphics/Pictures/Summary/icon_ball_%s", @pokemon.poke_ball) imagepos.push([ballimage,14,60]) # Show status/fainted/Pokérus infected icon - status = 0 + status = -1 if @pokemon.fainted? - status = GameData::Status::DATA.keys.length / 2 + status = GameData::Status.count elsif @pokemon.status != :NONE - status = GameData::Status.get(@pokemon.status).id_number + status = GameData::Status.get(@pokemon.status).icon_position elsif @pokemon.pokerusStage == 1 - status = GameData::Status::DATA.keys.length / 2 + 1 + status = GameData::Status.count + 1 end - status -= 1 if status >= 0 imagepos.push(["Graphics/Pictures/statuses",124,100,0,16*status,44,16]) end diff --git a/Data/Scripts/017_Minigames/002_Minigame_TripleTriad.rb b/Data/Scripts/017_Minigames/002_Minigame_TripleTriad.rb index f4b91c8fe..3229c03b6 100644 --- a/Data/Scripts/017_Minigames/002_Minigame_TripleTriad.rb +++ b/Data/Scripts/017_Minigames/002_Minigame_TripleTriad.rb @@ -720,12 +720,12 @@ class TriadScreen @board = [] @playerName = $Trainer ? $Trainer.name : "Trainer" @opponentName = opponentName - type_keys = GameData::Type::DATA.keys + type_keys = GameData::Type.keys for i in 0...@width*@height square = TriadSquare.new if @elements loop do - trial_type = type_keys[rand(type_keys.length)] + trial_type = type_keys[type_keys.sample] type_data = GameData::Type.get(trial_type) next if type_data.pseudo_type square.type = type_data.id @@ -766,10 +766,10 @@ class TriadScreen opponentCards.push(species_data.id) end else - species_keys = GameData::Species::DATA.keys + species_keys = GameData::Species.keys candidates = [] while candidates.length < 200 - card = species_keys[rand(species_keys.length)] + card = species_keys[species_keys.sample] card_data = GameData::Species.get(card) card = card_data.id # Make sure it's a symbol triad = TriadCard.new(card) diff --git a/Data/Scripts/018_Alternate battle modes/003_Battle Frontier generator/002_ChallengeGenerator_Pokemon.rb b/Data/Scripts/018_Alternate battle modes/003_Battle Frontier generator/002_ChallengeGenerator_Pokemon.rb index 1302569f9..05fc99282 100644 --- a/Data/Scripts/018_Alternate battle modes/003_Battle Frontier generator/002_ChallengeGenerator_Pokemon.rb +++ b/Data/Scripts/018_Alternate battle modes/003_Battle Frontier generator/002_ChallengeGenerator_Pokemon.rb @@ -38,9 +38,9 @@ end #=============================================================================== # Used to replace Sketch with any other move. def pbRandomMove - keys = GameData::Move::DATA.keys + keys = GameData::Move.keys loop do - move_id = keys[rand(keys.length)] + move_id = keys[keys.sample] move = GameData::Move.get(move_id) next if move.id == :SKETCH || move.id == :STRUGGLE return move.id @@ -151,10 +151,10 @@ def pbRandomPokemonFromRule(rules, trainer) iteration += 1 species = nil level = rules.ruleset.suggestedLevel - keys = GameData::Species::DATA.keys + keys = GameData::Species.keys loop do loop do - species = keys[rand(keys.length)] + species = keys[keys.sample] break if GameData::Species.get(species).form == 0 end r = rand(20) @@ -174,9 +174,9 @@ def pbRandomPokemonFromRule(rules, trainer) ev = [] GameData::Stat.each_main { |s| ev.push(s.id) if rand(100) < 50 } nature = nil - keys = GameData::Nature::DATA.keys + keys = GameData::Nature.keys loop do - nature = keys[rand(keys.length)] + nature = keys[keys.sample] nature_data = GameData::Nature.get(nature) if [:LAX, :GENTLE].include?(nature_data.id) || nature_data.stat_changes.length == 0 next if rand(20) < 19 diff --git a/Data/Scripts/018_Alternate battle modes/003_Battle Frontier generator/003_ChallengeGenerator_Trainers.rb b/Data/Scripts/018_Alternate battle modes/003_Battle Frontier generator/003_ChallengeGenerator_Trainers.rb index bea2210b5..b26f45dff 100644 --- a/Data/Scripts/018_Alternate battle modes/003_Battle Frontier generator/003_ChallengeGenerator_Trainers.rb +++ b/Data/Scripts/018_Alternate battle modes/003_Battle Frontier generator/003_ChallengeGenerator_Trainers.rb @@ -25,9 +25,9 @@ def pbTrainerInfo(pokemonlist, trfile, rules) if GameData::TrainerType.exists?(:YOUNGSTER) && rand(30) == 0 trainerid = :YOUNGSTER else - tr_typekeys = GameData::TrainerType::DATA.keys + tr_typekeys = GameData::TrainerType.keys loop do - tr_type = tr_typekeys[rand(tr_typekeys.length)] + tr_type = tr_typekeys[tr_typekeys.sample] tr_type_data = GameData::TrainerType.get(tr_type) next if tr_type_data.base_money >= 100 trainerid = tr_type_data.id diff --git a/Data/Scripts/020_Debug/001_Editor screens/001_EditorScreens.rb b/Data/Scripts/020_Debug/001_Editor screens/001_EditorScreens.rb index 6648220cb..16318a2b6 100644 --- a/Data/Scripts/020_Debug/001_Editor screens/001_EditorScreens.rb +++ b/Data/Scripts/020_Debug/001_Editor screens/001_EditorScreens.rb @@ -595,7 +595,7 @@ def pbTrainerBattleEditor t = pbNewTrainer(tr_type, tr_name, tr_version, false) if t trainer_hash = { - :id_number => GameData::Trainer::DATA.keys.length / 2, + :id_number => GameData::Trainer.count, :trainer_type => tr_type, :name => tr_name, :version => tr_version,