Class: Oakdex::Pokemon::UseItemService

Inherits:
Object
  • Object
show all
Defined in:
lib/oakdex/pokemon/use_item_service.rb

Overview

Represents Item usage

Instance Method Summary collapse

Constructor Details

#initialize(pokemon, item_id, options = {}) ⇒ UseItemService

Returns a new instance of UseItemService.



5
6
7
8
9
# File 'lib/oakdex/pokemon/use_item_service.rb', line 5

def initialize(pokemon, item_id, options = {})
  @pokemon = pokemon
  @item = Oakdex::Pokedex::Item.find!(item_id)
  @options = options
end

Instance Method Details

#usable?Boolean

Returns:

  • (Boolean)


11
12
13
# File 'lib/oakdex/pokemon/use_item_service.rb', line 11

def usable?
  !evolution.nil? || effect_usable?
end

#useObject



15
16
17
18
19
20
21
22
23
# File 'lib/oakdex/pokemon/use_item_service.rb', line 15

def use
  return unless usable?
  unless evolution.nil?
    @pokemon.add_growth_event(GrowthEvents::Evolution,
                              evolution: evolution)
  end
  execute_effects
  true
end