Module: Util::GiveTakeItem

Included in:
GamePlay::Party_Menu, GamePlay::PokemonStorage
Defined in:
scripts/01450 Systems/00102 Party/00101 GiveTakeItem.rb

Overview

Module adding the give / take item functionality to a scene

Instance Method Summary collapse

Instance Method Details

#givetake_give_egg_message(item)

Display the give item message to an egg

Parameters:



47
48
49
# File 'scripts/01450 Systems/00102 Party/00101 GiveTakeItem.rb', line 47

def givetake_give_egg_message(item)
  display_message(parse_text(22, 94, PFM::Text::ITEM2[0] => data_item(item).name))
end

#givetake_give_item(pokemon, item = -1)) {|pokemon| ... } ⇒ Boolean

Give an item to a Pokemon

Parameters:

  • pokemon (PFM::Pokemon)

    pokemon that will receive the item

  • item (Integer, Symbol) (defaults to: -1))

    item to give, -1 to open the bag

Yield Parameters:

  • pokemon (PFM::Pokemon)

    block we call with pokemon before and after the form calibration

Returns:

  • (Boolean)

    if the item was given



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'scripts/01450 Systems/00102 Party/00101 GiveTakeItem.rb', line 9

def givetake_give_item(pokemon, item = -1)
  return givetake_give_egg_message(item) && false if pokemon.egg?

  if item == -1
    GamePlay.open_bag_to_give_item_to_pokemon do |scene|
      item = scene.return_data
    end
    Graphics.wait(4) { update_graphics if respond_to?(:update_graphics) }
  end
  return false if item == -1

  item = data_item(item).id
  item1 = pokemon.item_holding
  givetake_give_item_message(item1, item, pokemon)
  givetake_give_item_update_state(item1, item, pokemon)
  yield(pokemon) if block_given?
  return true unless pokemon.form_calibrate # Form adjustment

  pokemon.hp = (pokemon.max_hp * pokemon.hp_rate).round
  yield(pokemon) if block_given?
  display_message(parse_text(22, 157, ::PFM::Text::PKNAME[0] => pokemon.given_name))
  return true
end

#givetake_give_item_message(item1, item2, pokemon)

Display the give item message

Parameters:



37
38
39
40
41
42
43
# File 'scripts/01450 Systems/00102 Party/00101 GiveTakeItem.rb', line 37

def givetake_give_item_message(item1, item2, pokemon)
  if item1 != 0 && item1 != item2
    display_message(parse_text(22, 91, PFM::Text::ITEM2[0] => pokemon.item_name, PFM::Text::ITEM2[1] => data_item(item2).name))
  elsif item1 != item2
    display_message(parse_text(22, 90, PFM::Text::ITEM2[0] => data_item(item2).name))
  end
end

#givetake_give_item_update_state(item1, item2, pokemon)

Update the bag and pokemon state when giving an item

Parameters:



55
56
57
58
59
# File 'scripts/01450 Systems/00102 Party/00101 GiveTakeItem.rb', line 55

def givetake_give_item_update_state(item1, item2, pokemon)
  pokemon.item_holding = item2
  $bag.remove_item(item2, 1)
  $bag.add_item(item1, 1) if item1 != 0
end

#givetake_take_item(pokemon) {|pokemon| ... }

Action of taking the item from the Pokemon

Parameters:

Yield Parameters:

  • pokemon (PFM::Pokemon)

    block we call with pokemon before and after the form calibration



64
65
66
67
68
69
70
71
72
73
74
75
# File 'scripts/01450 Systems/00102 Party/00101 GiveTakeItem.rb', line 64

def givetake_take_item(pokemon)
  item = pokemon.item_holding
  $bag.add_item(item, 1)
  pokemon.item_holding = 0
  yield(pokemon) if block_given?
  display_message(parse_text(23, 78, ::PFM::Text::PKNICK[0] => pokemon.given_name, ::PFM::Text::ITEM2[1] => data_item(item).name))
  return unless pokemon.form_calibrate # Form ajustment

  pokemon.hp = (pokemon.max_hp * pokemon.hp_rate).round
  yield(pokemon) if block_given?
  display_message(parse_text(22, 157, ::PFM::Text::PKNAME[0] => pokemon.given_name))
end