Class: Battle::Actions::Item

Inherits:
Base show all
Defined in:
scripts/01600 Alpha 25 Battle Engine/03000 Actions/00004 Item.rb

Overview

Class describing the usage of an Item

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Base

#valid?

Constructor Details

#initialize(scene, item_wrapper, bag, user) ⇒ Item

Create a new item action

Parameters:



17
18
19
20
21
22
# File 'scripts/01600 Alpha 25 Battle Engine/03000 Actions/00004 Item.rb', line 17

def initialize(scene, item_wrapper, bag, user)
  super(scene)
  @item_wrapper = item_wrapper
  @bag = bag
  @user = user
end

Instance Attribute Details

#item_wrapperPFM::ItemDescriptor::Wrapper (readonly)

Get the item wrapper executing the action



10
11
12
# File 'scripts/01600 Alpha 25 Battle Engine/03000 Actions/00004 Item.rb', line 10

def item_wrapper
  @item_wrapper
end

#userPFM::PokemonBattler (readonly)

Get the Pokemon responsive of the item usage

Returns:



7
8
9
# File 'scripts/01600 Alpha 25 Battle Engine/03000 Actions/00004 Item.rb', line 7

def user
  @user
end

Instance Method Details

#<=>(other) ⇒ Integer

Compare this action with another

Parameters:

  • other (Base)

    other action

Returns:



27
28
29
30
31
32
33
# File 'scripts/01600 Alpha 25 Battle Engine/03000 Actions/00004 Item.rb', line 27

def <=>(other)
  return 1 if other.is_a?(HighPriorityItem)
  return 1 if other.is_a?(Attack) && Attack.from(other).pursuit_enabled
  return Item.from(other).user.spd <=> @user.spd if other.is_a?(Item)

  return -1
end

#execute

Execute the action



36
37
38
39
40
41
42
43
44
# File 'scripts/01600 Alpha 25 Battle Engine/03000 Actions/00004 Item.rb', line 36

def execute
  names = @scene.battle_info.names
  trname = names.dig(@user.bank, @user.party_id) || names.dig(@user.bank, 0) || names.dig(0, 0)
  message = parse_text(18, 34, PFM::Text::ITEM2[1] => @item_wrapper.item.name, PFM::Text::TRNAME[0] => trname)
  @scene.display_message_and_wait(message)
  @bag.remove_item(@item_wrapper.item.id, 1) if @item_wrapper.item.is_limited
  @bag.last_battle_item_db_symbol = @item_wrapper.item.db_symbol
  @item_wrapper.execute_battle_action
end