Class: Pktool::Builder

Inherits:
Object
  • Object
show all
Defined in:
lib/cli/builder.rb

Class Method Summary collapse

Class Method Details

.attack(attacker, defender) ⇒ Object



53
54
55
56
57
# File 'lib/cli/builder.rb', line 53

def self.attack(attacker, defender)
  moves = Move.pluck(:name)
  move = fetch("わざ", moves)
  Attack.new(move, attacker, defender)
end

.default_pokemonObject



43
44
45
46
47
48
49
50
51
# File 'lib/cli/builder.rb', line 43

def self.default_pokemon
  pokemons = Pokemon.pluck(:name)
  name = fetch("なまえ", pokemons)
  feature = {}
  feature[:nature] = Nature.first.name
  feature[:effort_value] = { H: 0, A: 0, B: 0, C: 0, D: 0, S: 0 }
  feature[:individual_value] = { H: 31, A: 31, B: 31, C: 31, D: 31, S: 31 }
  return Pokemon.fetch(name, feature)
end

.fetch(name, completion = []) ⇒ Object



59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
# File 'lib/cli/builder.rb', line 59

def self.fetch(name, completion = [])
  Readline.completion_append_character = ""
  Readline.completion_proc = proc {|s|
    completion.grep(/^#{Romaji.romaji2kana(s)}|#{Romaji.romaji2kana(s, :kana_type => :hiragana)}/)
  }
  begin
    fetch = ::Readline.readline(name + '>', true)
    raise Error, "対象が見つかりません" unless completion.empty? or completion.include?(fetch)
    if block_given?
      return yield(fetch)
    else
      return fetch
    end
  rescue Error => e
    Log::error e.message
    retry
  end

end

.new_pokemonObject



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/cli/builder.rb', line 24

def self.new_pokemon
  pokemons = Pokemon.pluck(:name)
  natures = Nature.pluck(:name)
  name = fetch("なまえ", pokemons)
  feature = {} 
  feature[:nature] = fetch("せいかく", natures) do |input| input.to_sym end
  feature[:effort_value] = fetch("努力値(default: 0)") do |input|
    if(Pokemon.ways.include?(input.to_sym))
      input.to_sym
    else
      { H: 0, A: 0, B: 0, C: 0, D: 0, S: 0 }
    end
  end
  feature[:individual_value] = fetch("個体値(default: 6V)") do |input|
    { H: 31, A: 31, B: 31, C: 31, D: 31, S: 31 }
  end
  return Pokemon.fetch(name, feature)
end

.party_pokemonObject



12
13
14
15
16
17
18
19
20
21
22
# File 'lib/cli/builder.rb', line 12

def self.party_pokemon
  party = Party.new
  command = fetch("command")
  if(command == "new")
    return self.new_pokemon
  end
  if(command =~ /^\d+$/)
    return party[command.to_i]
  end
  warn "Not found."
end