Skip to content

jalyna/oakdex-battle

Repository files navigation

fixer

Gem Version Build Status Maintainability Test Coverage

Based on oakdex-pokedex.

Getting Started

1 vs. 1

require 'oakdex/battle'

pok1 = Oakdex::Pokemon.create('Pikachu', level: 10)
pok2 = Oakdex::Pokemon.create('Bulbasaur', {
  exp: 120,
  gender: 'female',
  ability: 'Soundproof',
  nature: 'Bashful',
  item: 'Earth Plate',
  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]
  ]
})

trainer1 = Oakdex::Battle::Trainer.new('Ash', [pok1], ['Potion', 'Elixir', 'Ether'], enable_grow: true, using_exp_share: true) # trainer's pokemon receive exp and ev
trainer2 = Oakdex::Battle::Trainer.new('Misty', [pok2], ['Potion', 'Potion', 'Revive', 'Soda Pop'])

battle = Oakdex::Battle.new(trainer1, trainer2)
battle.continue # => true
battle.log.size # => 1
battle.log.last # => [['sends_to_battle', 'Ash', 'Pikachu'], ['sends_to_battle', 'Misty', 'Bulbasaur']]
battle.arena # => Snapshot of current state as Hash
battle.finished? # => false
valid_actions = battle.valid_actions_for(trainer1) # => [{"action"=>"move", "pokemon"=>"eb55b984-f0f0-48e5-9268-5bbf791a0793", "move"=>"Nuzzle", "target"=>["Misty", 0]}, {"action"=>"move", "pokemon"=>"eb55b984-f0f0-48e5-9268-5bbf791a0793", "move"=>"Hypnosis", "target"=>["Misty", 0]}, {"action"=>"recall", "pokemon"=>0, "target"=>"ceea31e4-adfc-4138-a148-424fa08c8f79"}, ...]

battle.add_action(trainer1, valid_actions.first) # => true

battle.add_action(trainer1, invalid_action) # => false

battle.valid_actions_for(trainer1) # => []
battle.continue # => false
battle.simulate_action(trainer2) # => true
battle.valid_actions_for(trainer2) # => []
battle.continue # => true

battle.log.size # => 2
battle.log.last # => [['uses_move', 'Ash', 'Pikachu', 'Thunder Shock'], ['received_damage', 'Misty', 'Bulbasaur', 'Thunder Shock'], ['uses_move', 'Misty', 'Bulbasaur', 'Leech Seed'], ['move_failed', 'Misty', 'Bulbasaur', 'Leech Seed']]

# ...

battle.finished? # => true
battle.winner # => trainer1

Other Battle types

pok3 = Oakdex::Pokemon.create('Altaria', level: 20)
pok4 = Oakdex::Pokemon.create('Elekid', level: 14)
trainer1 = Oakdex::Battle::Trainer.new('Ash', [pok1, pok3, pok9])
trainer2 = Oakdex::Battle::Trainer.new('Misty', [pok2, pok4, pok10])
trainer3 = Oakdex::Battle::Trainer.new('Brock', [pok5, pok6])
trainer4 = Oakdex::Battle::Trainer.new('Erika', [pok7, pok8])

# 2 vs. 2
battle = Oakdex::Battle.new([trainer1], [trainer2], pokemon_per_side: 2)
# 3 vs. 3
battle = Oakdex::Battle.new([trainer1], [trainer2], pokemon_per_side: 3)
# 2 vs. 2 (1 pokemon each trainer)
battle = Oakdex::Battle.new([trainer1, trainer3], [trainer2, trainer4])

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.

About

Pokémon Battle Engine Gen 7 Gem, based on oakdex-pokedex

Resources

License

Code of conduct

Stars

Watchers

Forks

Packages

No packages published

Languages