Class: Sabrina::Plugins::Stats
- Inherits:
-
Sabrina::Plugin
- Object
- Sabrina::Plugin
- Sabrina::Plugins::Stats
- Defined in:
- lib/sabrina/plugins/stats.rb
Overview
Finish this class.
This Sabrina::Plugin aids in manipulating the basic stats of any Monster.
Constant Summary collapse
- ENHANCES =
Monster
- PLUGIN_NAME =
'Stats'
- SHORT_NAME =
'stats'
- FEATURES =
Set.new [:reread, :write]
- STRUCTURE =
Describes the order in which various stats appear in the byte data. All of these will also be converted into attributes on runtime and can be modified directly.
[ :hp, :attack, :defense, :speed, :sp_atk, :sp_def, :type_1, :type_2, :catch_rate, :exp_yield, :ev_yield, :item_1, :item_2, :gender, :egg_cycles, :friendship, :level_curve, :egg_group_1, :egg_group_2, :ability_1, :ability_2, :safari_rate, :color_flip ]
- LEVEL_CURVES =
Code names for level up types.
[ 'Medium-Fast', 'Erratic', 'Fluctuating', 'Medium-Slow', 'Fast', 'Slow' ]
- EGG_GROUPS =
Code names for egg groups.
[ 'None', 'Monster', 'Water 1', 'Bug', 'Flying', 'Field', 'Fairy', 'Grass', 'Human-Like', 'Water 3', 'Mineral', 'Amorphous', 'Water 2', 'Ditto', 'Dragon', 'Undiscovered' ]
- NAMES =
Where to pull descriptive names from if applicable, these can be arrays or ROM tables.
{ type_1: :type_table, type_2: :type_table, item_1: :item_table, item_2: :item_table, level_curve: LEVEL_CURVES, egg_group_1: EGG_GROUPS, egg_group_2: EGG_GROUPS, ability_1: :ability_table, ability_2: :ability_table }
Instance Method Summary collapse
-
#initialize(monster) ⇒ Stats
constructor
Generates a new Stats object.
-
#reread ⇒ self
Reloads the data from a ROM, dropping any changes.
-
#stream ⇒ Bytestream
Returns a Bytestream object representing the stats, ready to be written to the ROM.
-
#to_h ⇒ Hash
Returns a hash representation of the stats.
-
#to_hex ⇒ String
Returns a pretty hexadecimal representation of the stats byte data.
-
#to_json ⇒ String
Returns a pretty JSON representation of the stats.
-
#to_s ⇒ String
Returns a blurb containing the base stats total.
-
#total ⇒ Integer
Returns the base stats total.
-
#write ⇒ Object
Write data to the ROM.
Methods inherited from Sabrina::Plugin
#feature?, feature_all, feature_this, features, inherited, plugin_name, short_name, target, to_s
Constructor Details
#initialize(monster) ⇒ Stats
Generates a new Stats object.
67 68 69 70 71 72 73 74 75 76 77 78 79 80 |
# File 'lib/sabrina/plugins/stats.rb', line 67 def initialize(monster) @monster = monster @rom = monster.rom @index = monster.index @stream = Bytestream.from_table( @rom, :stats_table, @monster.index, @rom.stats_length ) parse_stats end |
Instance Method Details
#reread ⇒ self
Reloads the data from a ROM, dropping any changes.
92 93 94 95 |
# File 'lib/sabrina/plugins/stats.rb', line 92 def reread parse_stats self end |
#stream ⇒ Bytestream
Returns a Bytestream object representing the stats, ready to be written to the ROM.
106 107 108 109 110 111 112 113 |
# File 'lib/sabrina/plugins/stats.rb', line 106 def stream Bytestream.from_bytes( unparse_stats, rom: @rom, table: :stats_table, index: @index ) end |
#to_h ⇒ Hash
Returns a hash representation of the stats.
118 119 120 121 122 123 124 125 126 |
# File 'lib/sabrina/plugins/stats.rb', line 118 def to_h h = {} STRUCTURE.each do |entry| h[entry] = instance_variable_get('@' << entry.to_s) end { @index => { stats: h } } end |
#to_hex ⇒ String
Returns a pretty hexadecimal representation of the stats byte data.
131 132 133 |
# File 'lib/sabrina/plugins/stats.rb', line 131 def to_hex stream.to_hex(true) end |
#to_json ⇒ String
Returns a pretty JSON representation of the stats.
138 139 140 |
# File 'lib/sabrina/plugins/stats.rb', line 138 def to_json JSON.pretty_generate(to_h) end |
#to_s ⇒ String
Returns a blurb containing the base stats total.
145 146 147 |
# File 'lib/sabrina/plugins/stats.rb', line 145 def to_s "<Stats (#{total})>" end |
#total ⇒ Integer
Returns the base stats total.
85 86 87 |
# File 'lib/sabrina/plugins/stats.rb', line 85 def total @hp + @attack + @defense + @speed + @sp_atk + @sp_def end |
#write ⇒ Object
Write data to the ROM.
98 99 100 |
# File 'lib/sabrina/plugins/stats.rb', line 98 def write stream.write_to_rom end |