class Oakdex::Pokemon::GrowthEvents::LearnMove

When pokemon could learn move

Public Instance Methods

execute(action = nil) click to toggle source
# File lib/oakdex/pokemon/growth_events/learn_move.rb, line 20
def execute(action = nil)
  if move_slot_left?
    @pokemon.learn_new_move(@options[:move_id])
    if available_evolution
      @pokemon.add_growth_event(GrowthEvents::Evolution,
                                evolution: available_evolution,
                                after: self)
    end
  else
    if action == not_learn_action
      @pokemon.add_growth_event(GrowthEvents::DidNotLearnMove,
                                move_id: @options[:move_id], after: self)
    else
      move_id = unlearn_moves[action]
      @pokemon.learn_new_move(@options[:move_id], move_id)
      @pokemon.add_growth_event(GrowthEvents::ForgotAndLearnedMove,
                                move_id: @options[:move_id],
                                forgot_move_id: move_id,
                                after: self)
    end
  end
  remove_event
end
message() click to toggle source
# File lib/oakdex/pokemon/growth_events/learn_move.rb, line 7
def message
  if move_slot_left?
    "#{@pokemon.name} learned #{@options[:move_id]}."
  else
    "#{@pokemon.name} wants to learn #{@options[:move_id]} but has already 4 moves."
  end
end
possible_actions() click to toggle source
# File lib/oakdex/pokemon/growth_events/learn_move.rb, line 15
def possible_actions
  return [] if move_slot_left?
  [not_learn_action] + unlearn_moves.keys
end

Private Instance Methods

available_evolution() click to toggle source
# File lib/oakdex/pokemon/growth_events/learn_move.rb, line 46
def available_evolution
  @available_evolution ||= Oakdex::Pokemon::EvolutionMatcher
    .new(@pokemon, 'move_learned', move_id: @options[:move_id]).evolution
end
move_slot_left?() click to toggle source
# File lib/oakdex/pokemon/growth_events/learn_move.rb, line 61
def move_slot_left?
  @pokemon.moves.size < 4
end
not_learn_action() click to toggle source
# File lib/oakdex/pokemon/growth_events/learn_move.rb, line 51
def not_learn_action
  "Do not learn #{@options[:move_id]}"
end
unlearn_moves() click to toggle source
# File lib/oakdex/pokemon/growth_events/learn_move.rb, line 55
def unlearn_moves
  @pokemon.moves.map do |move|
    ["Forget #{move.name}", move.name]
  end.to_h
end