Added def count to all GameData variants, and one that returns the number of species for Species, removed all uses of ID numbers for GameData::Status, made more use of GameData::X.keys

This commit is contained in:
Maruno17
2021-06-17 22:21:24 +01:00
parent 5358037986
commit eaa915878a
15 changed files with 86 additions and 72 deletions

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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