Added class GameData::Stat

This commit is contained in:
Maruno17
2021-03-04 22:59:48 +00:00
parent 934e38662a
commit ff0c2f00c8
46 changed files with 1301 additions and 1202 deletions

View File

@@ -1,68 +1,129 @@
begin
module PBStats
# NOTE: You can change the order that the compiler expects Pokémon base
# stats/EV yields (effort points) to be in, by simply renumbering the
# stats here. The "main" stats (i.e. not accuracy/evasion) must still
# use up numbers 0 to 5 inclusive, though. It's up to you to write the
# base stats/EV yields in pokemon.txt and pokemonforms.txt in the
# order expected.
HP = 0
ATTACK = 1
DEFENSE = 2
SPEED = 3
SPATK = 4
SPDEF = 5
ACCURACY = 6
EVASION = 7
# The id_number value determines which order the stats are iterated through by
# the "each" methods.
# The pbs_order value determines the order in which the stats are written in
# several PBS files, where base stats/IVs/EVs/EV yields are defined. Only stats
# which are yielded by the "each_main" method can have stat numbers defined in
# those places. The values of pbs_order defined below should start with 0 and
# increase without skipping any numbers.
module GameData
class Stat
attr_reader :id
attr_reader :id_number
attr_reader :real_name
attr_reader :real_name_brief
attr_reader :type
attr_reader :pbs_order
def self.getName(id)
id = getID(PBStats,id)
names = []
names[HP] = _INTL("HP")
names[ATTACK] = _INTL("Attack")
names[DEFENSE] = _INTL("Defense")
names[SPEED] = _INTL("Speed")
names[SPATK] = _INTL("Special Attack")
names[SPDEF] = _INTL("Special Defense")
names[ACCURACY] = _INTL("accuracy")
names[EVASION] = _INTL("evasiveness")
return names[id]
DATA = {}
extend ClassMethods
include InstanceMethods
def self.load; end
def self.save; end
# These stats are defined in PBS files, and should have the :pbs_order
# property.
def self.each_main
self.each { |s| yield s if [:main, :main_battle].include?(s.type) }
end
def self.getNameBrief(id)
id = getID(PBStats,id)
names = []
names[HP] = _INTL("HP")
names[ATTACK] = _INTL("Atk")
names[DEFENSE] = _INTL("Def")
names[SPEED] = _INTL("Spd")
names[SPATK] = _INTL("SpAtk")
names[SPDEF] = _INTL("SpDef")
names[ACCURACY] = _INTL("acc")
names[EVASION] = _INTL("eva")
return names[id]
def self.each_main_battle
self.each { |s| yield s if [:main_battle].include?(s.type) }
end
def self.eachStat
[HP,ATTACK,DEFENSE,SPATK,SPDEF,SPEED].each { |s| yield s }
# These stats have associated stat stages in battle.
def self.each_battle
self.each { |s| yield s if [:main_battle, :battle].include?(s.type) }
end
def self.eachMainBattleStat
[ATTACK,DEFENSE,SPATK,SPDEF,SPEED].each { |s| yield s }
def initialize(hash)
@id = hash[:id]
@id_number = hash[:id_number] || -1
@real_name = hash[:name] || "Unnamed"
@real_name_brief = hash[:name_brief] || "None"
@type = hash[:type] || :none
@pbs_order = hash[:pbs_order] || -1
end
def self.eachBattleStat
[ATTACK,DEFENSE,SPATK,SPDEF,SPEED,ACCURACY,EVASION].each { |s| yield s }
# @return [String] the translated name of this stat
def name
return _INTL(@real_name)
end
def self.validBattleStat?(stat)
self.eachBattleStat { |s| return true if s==stat }
return false
# @return [String] the translated brief name of this stat
def name_brief
return _INTL(@real_name_brief)
end
end
rescue Exception
if $!.is_a?(SystemExit) || "#{$!.class}"=="Reset"
raise $!
end
end
GameData::Stat.register({
:id => :HP,
:id_number => 0,
:name => _INTL("HP"),
:name_brief => _INTL("HP"),
:type => :main,
:pbs_order => 0
})
GameData::Stat.register({
:id => :ATTACK,
:id_number => 1,
:name => _INTL("Attack"),
:name_brief => _INTL("Atk"),
:type => :main_battle,
:pbs_order => 1
})
GameData::Stat.register({
:id => :DEFENSE,
:id_number => 2,
:name => _INTL("Defense"),
:name_brief => _INTL("Def"),
:type => :main_battle,
:pbs_order => 2
})
GameData::Stat.register({
:id => :SPECIAL_ATTACK,
:id_number => 3,
:name => _INTL("Special Attack"),
:name_brief => _INTL("SpAtk"),
:type => :main_battle,
:pbs_order => 4
})
GameData::Stat.register({
:id => :SPECIAL_DEFENSE,
:id_number => 4,
:name => _INTL("Special Defense"),
:name_brief => _INTL("SpDef"),
:type => :main_battle,
:pbs_order => 5
})
GameData::Stat.register({
:id => :SPEED,
:id_number => 5,
:name => _INTL("Speed"),
:name_brief => _INTL("Spd"),
:type => :main_battle,
:pbs_order => 3
})
GameData::Stat.register({
:id => :ACCURACY,
:id_number => 6,
:name => _INTL("accuracy"),
:name_brief => _INTL("Acc"),
:type => :battle
})
GameData::Stat.register({
:id => :EVASION,
:id_number => 7,
:name => _INTL("evasiveness"),
:name_brief => _INTL("Eva"),
:type => :battle
})