Class: PFM::Storage

Inherits:
Object show all
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

Author:

  • Nuri Yuri

Defined Under Namespace

Classes: BattleBox, Box

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

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(game_state) ⇒ Storage

Create a new storage

Parameters:

  • game_state (PFM::GameState)

    variable responsive of containing the whole game state for easier access



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_boxesArray<BattleBox>

Get the battle boxes

Returns:



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_boxInteger

The id of the current battle box

Returns:



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_boxInteger

The id of the current box

Returns:



22
23
24
# File 'scripts/01450 Systems/00200 Storage/00001 PFM_Storage/00001 Main.rb', line 22

def current_box
  @current_box
end

#game_statePFM::GameState

Get the game state responsive of the whole game state

Returns:



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_followerPFM::Pokemon

The Let's Go Follower

Returns:



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_partyArray<PFM::Pokemon>

The party of the other actor (friend)

Returns:



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

.box_sizeInteger

Get the box size

Returns:



253
254
255
# File 'scripts/01450 Systems/00200 Storage/00001 PFM_Storage/00001 Main.rb', line 253

def box_size
  BOX_SIZE
end

Instance Method Details

#add_box(name)

Add a new box

Parameters:

  • name (String)

    name of the 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

Yield Parameters:

Returns:

  • (Boolean)


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)

Returns:

  • (Boolean)


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_countInteger Also known as: max_box

Return the amount of box in the storage

Returns:



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)

Parameters:

  • index (Integer)

    the index of the box



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

Parameters:

  • include_dead (Boolean) (defaults to: true)

    if the counter include the “dead” Pokemon

Returns:



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_objectPFM::Storage::Box

Note:

Any modification will be ignored

Get the current box object

Returns:



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

Parameters:

  • index (Integer)

    index of the box to delete



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

Yield Parameters:



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

Parameters:

  • index (Integer)

    the index of the box

Returns:



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

Parameters:

  • index (Integer)

    the index of the box

Returns:



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

Parameters:

  • index (Integer)

    the index of the box

Returns:

  • (Integer)

    the id of the 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

Parameters:

  • index (Integer)

    index of the Pokemon in the current box

Returns:



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

Parameters:

  • index (Integer)

    index of the Pokemon in the current box

Returns:



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

Parameters:

  • index (Integer)

    the index of the box

  • name (String)

    the new name



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

Parameters:

  • index (Integer)

    the index of the box

  • theme (Integer)

    the id of the box theme



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 ?

Parameters:

  • index (Integer)

    index of the entity in the current box

Returns:

  • (Boolean)


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

Parameters:

Returns:

  • (Boolean)

    if the Pokemon has been stored



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)

Note:

The pokemon is healed when stored

Store a Pokemon at a specific index in the current box

Parameters:

  • pokemon (PFM::Pokemon)

    the Pokemon to store

  • index (Integer)

    index of the Pokemon 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