Class: PFM::Storage
- Defined in:
- scripts/01450 Systems/00200 Storage/00001 PFM_Storage/00001 Main.rb,
scripts/01450 Systems/00200 Storage/00001 PFM_Storage/00002 Box.rb,
scripts/01450 Systems/00200 Storage/00001 PFM_Storage/00003 BattleBox.rb
Overview
Player PC storage
The main object is stored in $storage and PFM.game_state.storage
Defined Under Namespace
Constant Summary collapse
- MAX_BOXES =
Maximum amount of box
15
- MAX_BATTLE_BOX =
Maximum amount of battle box
16
- BOX_SIZE =
Size of a box
30
- NB_THEMES =
Number of box theme (background : Graphics/PC/f_id, title : Graphics/PC/title_id
32
- HEAL_AND_CURE_POKEMON =
Tell if the Pokemon gets healed & cured when stored
true
Instance Attribute Summary collapse
-
#battle_boxes ⇒ Array<BattleBox>
Get the battle boxes.
-
#current_battle_box ⇒ Integer
The id of the current battle box.
-
#current_box ⇒ Integer
The id of the current box.
-
#game_state ⇒ PFM::GameState
Get the game state responsive of the whole game state.
-
#lets_go_follower ⇒ PFM::Pokemon
The Let's Go Follower.
-
#other_party ⇒ Array<PFM::Pokemon>
The party of the other actor (friend).
Class Method Summary collapse
-
.box_size ⇒ Integer
Get the box size.
Instance Method Summary collapse
-
#add_box(name)
Add a new box.
-
#any_pokemon? {|pokemon| ... } ⇒ Boolean
Yield a block on each Pokemon of storage and check if any answers to the block.
-
#any_pokemon_alive? ⇒ Boolean
(also: #any_pokemon_alive)
Check if there's a Pokemon alive in the box (egg or not).
-
#auto_convert
Auto convert the data to the new format.
-
#box_count ⇒ Integer
(also: #max_box)
Return the amount of box in the storage.
-
#box_name_init(index)
Get the name of a box (initialize).
-
#count_pokemon(include_dead = true) ⇒ Integer
Count the number of Pokemon available in the box.
-
#current_box_object ⇒ PFM::Storage::Box
Get the current box object.
-
#delete_box(index)
Delete a box.
-
#each_pokemon {|pokemon| ... }
Yield a block on each Pokemon of storage.
-
#get_box_content(index) ⇒ Array<PFM::Pokemon, nil>
(also: #get_box)
Retrieve a box content.
-
#get_box_name(index) ⇒ String
Return a box name.
-
#get_box_theme(index) ⇒ Integer
Get a box theme.
-
#info(index) ⇒ PFM::Pokemon?
Return the Pokemon at an index in the current box.
-
#initialize(game_state) ⇒ Storage
constructor
Create a new storage.
-
#remove_pokemon_at(index) ⇒ PFM::Pokemon?
(also: #remove)
Remove a Pokemon in the current box and return what whas removed at the index.
-
#set_box_name(index, name)
Change the name of a box.
-
#set_box_theme(index, theme)
Change the theme of a box.
-
#slot_contain_pokemon?(index) ⇒ Boolean
Is the slot “index” containing a Pokemon ?.
-
#store(pokemon) ⇒ Boolean
Store a pokemon to the PC.
-
#store_pokemon_at(pokemon, index)
Store a Pokemon at a specific index in the current box.
Constructor Details
#initialize(game_state) ⇒ Storage
Create a new storage
37 38 39 40 41 42 43 44 45 46 |
# File 'scripts/01450 Systems/00200 Storage/00001 PFM_Storage/00001 Main.rb', line 37 def initialize(game_state) self.game_state = game_state # @type [Array<Box>] @boxes = Array.new(MAX_BOXES) { |index| Box.new(BOX_SIZE, send(*box_name_init(index)), index + 1) } @battle_boxes = Array.new(MAX_BATTLE_BOX) { |index| BattleBox.new("##{index + 1}") } @current_box = 0 @current_battle_box = 0 update_event_variables @other_party = [] end |
Instance Attribute Details
#battle_boxes ⇒ Array<BattleBox>
Get the battle boxes
34 35 36 |
# File 'scripts/01450 Systems/00200 Storage/00001 PFM_Storage/00001 Main.rb', line 34 def battle_boxes @battle_boxes end |
#current_battle_box ⇒ Integer
The id of the current battle box
25 26 27 |
# File 'scripts/01450 Systems/00200 Storage/00001 PFM_Storage/00001 Main.rb', line 25 def current_battle_box @current_battle_box end |
#current_box ⇒ Integer
The id of the current box
22 23 24 |
# File 'scripts/01450 Systems/00200 Storage/00001 PFM_Storage/00001 Main.rb', line 22 def current_box @current_box end |
#game_state ⇒ PFM::GameState
Get the game state responsive of the whole game state
31 32 33 |
# File 'scripts/01450 Systems/00200 Storage/00001 PFM_Storage/00001 Main.rb', line 31 def game_state @game_state end |
#lets_go_follower ⇒ PFM::Pokemon
The Let's Go Follower
28 29 30 |
# File 'scripts/01450 Systems/00200 Storage/00001 PFM_Storage/00001 Main.rb', line 28 def lets_go_follower @lets_go_follower end |
#other_party ⇒ Array<PFM::Pokemon>
The party of the other actor (friend)
19 20 21 |
# File 'scripts/01450 Systems/00200 Storage/00001 PFM_Storage/00001 Main.rb', line 19 def other_party @other_party end |
Class Method Details
Instance Method Details
#add_box(name)
Add a new box
210 211 212 |
# File 'scripts/01450 Systems/00200 Storage/00001 PFM_Storage/00001 Main.rb', line 210 def add_box(name) @boxes.push(Box.new(BOX_SIZE, name, 1)) end |
#any_pokemon? {|pokemon| ... } ⇒ Boolean
Yield a block on each Pokemon of storage and check if any answers to the block
194 195 196 197 198 199 200 |
# File 'scripts/01450 Systems/00200 Storage/00001 PFM_Storage/00001 Main.rb', line 194 def any_pokemon? @boxes.any? do |box| box.content.any? do |pokemon| yield(pokemon) if pokemon end end end |
#any_pokemon_alive? ⇒ Boolean Also known as: any_pokemon_alive
Check if there's a Pokemon alive in the box (egg or not)
163 164 165 166 167 168 169 |
# File 'scripts/01450 Systems/00200 Storage/00001 PFM_Storage/00001 Main.rb', line 163 def any_pokemon_alive? return @boxes.any? do |box| next box.content.any? { |pokemon| pokemon && !pokemon.dead? } end || @battle_boxes.any? do |box| next box.content.any? { |pokemon| pokemon && !pokemon.dead? } end end |
#auto_convert
Auto convert the data to the new format
49 50 51 52 53 54 55 56 57 |
# File 'scripts/01450 Systems/00200 Storage/00001 PFM_Storage/00001 Main.rb', line 49 def auto_convert if @names @boxes.map!.with_index { |box, index| Box.new(0, @names[index], @themes[index], box) } remove_instance_variable(:@names) remove_instance_variable(:@themes) end @battle_boxes ||= Array.new(MAX_BATTLE_BOX) { |index| BattleBox.new("##{index + 1}") } @current_battle_box ||= 0 end |
#box_count ⇒ Integer Also known as: max_box
Return the amount of box in the storage
156 157 158 |
# File 'scripts/01450 Systems/00200 Storage/00001 PFM_Storage/00001 Main.rb', line 156 def box_count return @boxes.size end |
#box_name_init(index)
Get the name of a box (initialize)
100 101 102 |
# File 'scripts/01450 Systems/00200 Storage/00001 PFM_Storage/00001 Main.rb', line 100 def box_name_init(index) return [:text_get, 16, index] end |
#count_pokemon(include_dead = true) ⇒ Integer
Count the number of Pokemon available in the box
175 176 177 178 179 |
# File 'scripts/01450 Systems/00200 Storage/00001 PFM_Storage/00001 Main.rb', line 175 def count_pokemon(include_dead = true) return @boxes.sum do |box| box.content.count { |pokemon| pokemon && (include_dead || !pokemon.dead?) } end end |
#current_box_object ⇒ PFM::Storage::Box
Any modification will be ignored
Get the current box object
72 73 74 |
# File 'scripts/01450 Systems/00200 Storage/00001 PFM_Storage/00001 Main.rb', line 72 def current_box_object return @boxes[current_box % @boxes.size].clone end |
#delete_box(index)
Delete a box
204 205 206 |
# File 'scripts/01450 Systems/00200 Storage/00001 PFM_Storage/00001 Main.rb', line 204 def delete_box(index) @boxes.delete_at(index) end |
#each_pokemon {|pokemon| ... }
Yield a block on each Pokemon of storage
183 184 185 186 187 188 189 |
# File 'scripts/01450 Systems/00200 Storage/00001 PFM_Storage/00001 Main.rb', line 183 def each_pokemon @boxes.each do |box| box.content.each do |pokemon| yield(pokemon) if pokemon end end end |
#get_box_content(index) ⇒ Array<PFM::Pokemon, nil> Also known as: get_box
Retrieve a box content
79 80 81 |
# File 'scripts/01450 Systems/00200 Storage/00001 PFM_Storage/00001 Main.rb', line 79 def get_box_content(index) return @boxes[index % @boxes.size].content end |
#get_box_name(index) ⇒ String
Return a box name
87 88 89 |
# File 'scripts/01450 Systems/00200 Storage/00001 PFM_Storage/00001 Main.rb', line 87 def get_box_name(index) return @boxes[index % @boxes.size].name end |
#get_box_theme(index) ⇒ Integer
Get a box theme
107 108 109 |
# File 'scripts/01450 Systems/00200 Storage/00001 PFM_Storage/00001 Main.rb', line 107 def get_box_theme(index) return @boxes[index % @boxes.size].theme end |
#info(index) ⇒ PFM::Pokemon?
Return the Pokemon at an index in the current box
138 139 140 |
# File 'scripts/01450 Systems/00200 Storage/00001 PFM_Storage/00001 Main.rb', line 138 def info(index) return @boxes[@current_box].content[index] end |
#remove_pokemon_at(index) ⇒ PFM::Pokemon? Also known as: remove
Remove a Pokemon in the current box and return what whas removed at the index
121 122 123 124 125 |
# File 'scripts/01450 Systems/00200 Storage/00001 PFM_Storage/00001 Main.rb', line 121 def remove_pokemon_at(index) pokemon = @boxes[@current_box].content[index] @boxes[@current_box].content[index] = nil return pokemon end |
#set_box_name(index, name)
Change the name of a box
94 95 96 |
# File 'scripts/01450 Systems/00200 Storage/00001 PFM_Storage/00001 Main.rb', line 94 def set_box_name(index, name) @boxes[index % @boxes.size].name = name.to_s end |
#set_box_theme(index, theme)
Change the theme of a box
114 115 116 |
# File 'scripts/01450 Systems/00200 Storage/00001 PFM_Storage/00001 Main.rb', line 114 def set_box_theme(index, theme) @boxes[index % @boxes.size].theme = theme.to_i end |
#slot_contain_pokemon?(index) ⇒ Boolean
Is the slot “index” containing a Pokemon ?
131 132 133 |
# File 'scripts/01450 Systems/00200 Storage/00001 PFM_Storage/00001 Main.rb', line 131 def slot_contain_pokemon?(index) return @boxes[@current_box].content[index].class == ::PFM::Pokemon end |
#store(pokemon) ⇒ Boolean
Store a pokemon to the PC
62 63 64 65 66 67 |
# File 'scripts/01450 Systems/00200 Storage/00001 PFM_Storage/00001 Main.rb', line 62 def store(pokemon) return true if store_in_current_box(pokemon) return false unless switch_to_box_with_space return store_in_current_box(pokemon) end |
#store_pokemon_at(pokemon, index)
The pokemon is healed when stored
Store a Pokemon at a specific index in the current box
146 147 148 149 150 151 152 |
# File 'scripts/01450 Systems/00200 Storage/00001 PFM_Storage/00001 Main.rb', line 146 def store_pokemon_at(pokemon, index) @boxes[@current_box].content[index] = pokemon return unless HEAL_AND_CURE_POKEMON pokemon.cure pokemon.hp = pokemon.max_hp end |