Based on oakdex-pokedex.
Used as a representation for Pokémon across other Projects like oakdex-battle and oakdex-breeding.
Getting Started
require 'oakdex/pokemon'
pikachu = Oakdex::Pokemon.create('Pikachu', level: 12)
bulbasaur = Oakdex::Pokemon.create('Bulbasaur', { # many options available
exp: 120,
gender: 'female',
ability_id: 'Soundproof',
nature_id: 'Bashful',
hp: 2,
iv: {
hp: 8,
atk: 12,
def: 31,
sp_atk: 12,
sp_def: 5,
speed: 14
},
ev: {
hp: 8,
atk: 12,
def: 99,
sp_atk: 4,
sp_def: 12,
speed: 14
},
moves: [
['Swords Dance', 12, 30],
['Cut', 40, 44]
],
original_trainer: 'Cool trainer name',
item_id: 'Lucky Egg',
wild: true,
primary_status_condition: 'sleep'
})
pikachu.for_game
# {:name=>"Pikachu",
# :primary_status_condition=>nil,
# :type_ids=>["Electric"],
# :gender=>"female",
# :friendship=>70,
# :moves=>
# [{:move_id=>"Thunder Shock", :pp=>30, :max_pp=>40, :type_id=>"Electric"}],
# :current_hp=>12,
# :fainted=>false,
# :wild=>nil,
# :original_trainer=>nil,
# :item_id=>nil,
# :traded=>false,
# :exp=>100,
# :level=>4,
# :exp_next_level=>125,
# :nature_id=>"Bashful",
# :ability_id=>"Static",
# :hp=>17,
# :atk=>9,
# :def=>7,
# :sp_atk=>9,
# :sp_def=>8,
# :speed=>12}
pikachu.gender # => female
pikachu.name # => Pikachu
pikachu.level # => 12
pikachu.moves.map { |p| "#{p.name} #{p.pp}" } # => ["Quick Attack 30", "Tail Whip 30", "Growl 40", "Thunder Shock 30"]
pikachu.hp # => 34
pikachu.atk # => 18
pikachu.current_hp # => 34
pikachu.traded? # => false
pikachu.change_hp_by(38)
pikachu.current_hp # => 0
pikachu.change_pp_by('Thunder Shock', -1)
pikachu.moves.map { |p| "#{p.name} #{p.pp}" } # => ["Quick Attack 30", "Tail Whip 30", "Growl 40", "Thunder Shock 29"]
pikachu.exp # => 1728
pikachu.increment_level
pikachu.level # => 12
pikachu.exp # => 1728
# Pikachu learns Electro Ball in Level 13
while pikachu.growth_event? do
e = pikachu.growth_event
if e.read_only?
puts e.message
e.execute
else
puts e.message
puts e.possible_actions # => ['Forget Quick Attack', ..., 'Do not learn Electro Ball']
e.execute(e.possible_actions.sample)
end
end
pikachu.level # => 13
pikachu.exp # => 2197
# Calculate exp and ev from won battles
fainted_opponent = bulbasaur
pikachu.grow_from_battle(fainted_opponent, using_exp_share: false, flat: false)
# Evolution by level
charmander = Oakdex::Pokemon.create('Charmander', level: 15)
charmander.increment_level
# Charmander envolves to Charmeleon
while charmander.growth_event? do
e = charmander.growth_event
if e.read_only?
puts e.message
e.execute
else
puts e.message
puts e.possible_actions # => ['Continue', 'Skip']
e.execute(e.possible_actions.first)
end
end
charmander.level # => 16
charmander.name # => Charmeleon
# Evolution by trade
feebas = Oakdex::Pokemon.create('Feebas', level: 12, item_id: 'Prism Scale')
trainer = OpenStruct.new(name: 'My Awesome Trainer')
feebas.trade_to(trainer)
# Feebas envolves to Milotic
while feebas.growth_event? do
e = feebas.growth_event
if e.read_only?
puts e.message
e.execute
else
puts e.message
puts e.possible_actions # => ['Continue', 'Skip']
e.execute(e.possible_actions.first)
end
end
feebas.name # => Milotic
feebas.trainer # => trainer
# Evolution by item
exeggcute = Oakdex::Pokemon.create('Exeggcute', level: 12)
exeggcute.usable_item?('Leaf Stone') # => true
exeggcute.use_item('Leaf Stone')
# Exeggcute envolves to Exeggutor
while exeggcute.growth_event? do
e = exeggcute.growth_event
if e.read_only?
puts e.message
e.execute
else
puts e.message
puts e.possible_actions # => ['Continue', 'Skip']
e.execute(e.possible_actions.first)
end
end
exeggcute.name # => Exeggutor
# Item Usage
charmander = Oakdex::Pokemon.create('Charmander', level: 15, hp: 32)
charmander.usable_item?('Potion') # => true
charmander.use_item('Potion')
# Charmander gets HP
while charmander.growth_event? do
e = charmander.growth_event
if e.read_only?
puts e.message
e.execute # => gains ~8HP
end
end
charmander.hp # => 40
charmander.usable_item?('Potion') # => false
# Increase pp by PP Up
exeggcute = Oakdex::Pokemon.create('Exeggcute', level: 12)
exeggcute.usable_item?('PP Up') # => true
exeggcute.use_item('PP Up')
# Exeggcute can increase pp of a mvoe
while exeggcute.growth_event? do
e = exeggcute.growth_event
if e.read_only?
puts e.message
e.execute
else
puts e.message
puts e.possible_actions # => name of moves
e.execute(e.possible_actions.first)
end
end
exeggcute.moves.first.max_pp # => Changed
charmander = Oakdex::Pokemon.create('Charmander', level: 15, primary_status_condition: 'poison')
charmander.usable_item?('Antidote') # => true
charmander.use_item('Antidote')
# Charmander heals status condition
while charmander.growth_event? do
e = charmander.growth_event
if e.read_only?
puts e.message
e.execute # => heals poison
end
end
charmander.primary_status_condition # => nil
charmander.usable_item?('Antidote') # => false
Import and export Pokemon
squirtle = Oakdex::Pokemon.create('Squirtle', level: 12)
json = squirtle.to_json
# Might throw Oakdex::Pokemon::InvalidPokemon
identical_squirtle = Oakdex::Pokemon.from_json(json)
Contributing
I would be happy if you want to add your contribution to the project. In order to contribute, you just have to fork this repository.
Please respect the Code of Conduct.
License
MIT License. See the included MIT-LICENSE file.
Credits
Logo Icon by Roundicons Freebies.