oakdex-breeding 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: e3da66c8b3d644f56eb549b9461e115dc5d17f50
4
+ data.tar.gz: 74c45da483be507d4c37c9e95076ac0389654b93
5
+ SHA512:
6
+ metadata.gz: fbbbd126a939f26d70dc676d6344fda6b2e6eec3e1edea2d19fc92445db8b092fe0d70f08a4172f6d355034ed5a4fcc47ab66e255592e854c1115e94d6e5ae82
7
+ data.tar.gz: 1550a7617f3658fbae90e11e46946e81b181513bf967bd7db88aec1eb4986abee08ac41fadfb7c28e394ad959b2a77da8759f5fcada1b91631261257ac513f4b
@@ -0,0 +1,34 @@
1
+ # <img src="https://v20.imgup.net/oakdex_logfbad.png" alt="fixer" width=282>
2
+
3
+ [![Gem Version](https://badge.fury.io/rb/oakdex-breeding.svg)](https://badge.fury.io/rb/oakdex-breeding) [![Build Status](https://travis-ci.org/jalyna/oakdex-breeding.svg?branch=master)](https://travis-ci.org/jalyna/oakdex-breeding) [![Maintainability](https://api.codeclimate.com/v1/badges/c3b27152c3b239b50c08/maintainability)](https://codeclimate.com/github/jalyna/oakdex-breeding/maintainability) [![Test Coverage](https://api.codeclimate.com/v1/badges/c3b27152c3b239b50c08/test_coverage)](https://codeclimate.com/github/jalyna/oakdex-breeding/test_coverage)
4
+
5
+ Based on [oakdex-pokemon](https://github.com/jalyna/oakdex-pokemon).
6
+
7
+ ## Getting Started
8
+
9
+
10
+ ```ruby
11
+ require 'oakdex/breeding'
12
+
13
+ pok1 = Oakdex::Pokemon.create('Ditto', level: 20)
14
+ pok2 = Oakdex::Pokemon.create('Pikachu', level: 20, gender: 'female')
15
+
16
+ Oakdex::Breeding.compatible?(pok1, pok2) # => true
17
+ Oakdex::Breeding.chance_in_percentage(pok1, pok2) # => 20
18
+ Oakdex::Breeding.breed(pok1, pok2) #=> Oakdex::Pokemon Pichu
19
+ ```
20
+
21
+
22
+ ## Contributing
23
+
24
+ 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.
25
+
26
+ Please respect the [Code of Conduct](//github.com/jalyna/oakdex-pokemon/blob/master/CODE_OF_CONDUCT.md).
27
+
28
+ ## License
29
+
30
+ MIT License. See the included MIT-LICENSE file.
31
+
32
+ ## Credits
33
+
34
+ Logo Icon by [Roundicons Freebies](http://www.flaticon.com/authors/roundicons-freebies).
@@ -0,0 +1,3 @@
1
+ # Main Namespace Oakdex
2
+ module Oakdex
3
+ end
@@ -0,0 +1,110 @@
1
+ require 'oakdex/pokemon'
2
+ require 'oakdex/pokedex'
3
+
4
+ module Oakdex
5
+ # Pokemon Breeding
6
+ class Breeding
7
+ class << self
8
+ def compatible?(pokemon1, pokemon2)
9
+ new(pokemon1, pokemon2).compatible?
10
+ end
11
+
12
+ def chance_in_percentage(pokemon1, pokemon2)
13
+ new(pokemon1, pokemon2).chance_in_percentage
14
+ end
15
+
16
+ def breed(pokemon1, pokemon2)
17
+ new(pokemon1, pokemon2).child
18
+ end
19
+ end
20
+
21
+ def initialize(pokemon1, pokemon2)
22
+ @female = pokemon1.gender == 'female' ? pokemon1 : pokemon2
23
+ @male = ([pokemon1, pokemon2] - [@female]).first
24
+ end
25
+
26
+ def compatible?
27
+ (opposite_gender? && same_egg_group? && !any_undiscovered?) ||
28
+ (exactly_one_is_ditto? && non_ditto_is_discovered?)
29
+ end
30
+
31
+ def chance_in_percentage
32
+ return 0 unless compatible?
33
+ return 50 if same_species?
34
+ 20
35
+ end
36
+
37
+ def child
38
+ return unless compatible?
39
+ Oakdex::Pokemon.create(child_species.name,
40
+ level: 1,
41
+ additional_moves: enabled_egg_moves
42
+ )
43
+ end
44
+
45
+ private
46
+
47
+ def child_species
48
+ @child_species ||=
49
+ lowest_in_evolutionary_chain(non_ditto_or_female.species)
50
+ end
51
+
52
+ def enabled_egg_moves
53
+ egg_moves & parent_moves
54
+ end
55
+
56
+ def parent_moves
57
+ @female.moves.map(&:name) + @male.moves.map(&:name)
58
+ end
59
+
60
+ def egg_moves
61
+ child_species.learnset
62
+ .map { |l| l['egg_move'] ? l['move'] : nil }
63
+ .compact
64
+ end
65
+
66
+ def lowest_in_evolutionary_chain(species)
67
+ # TODO: take incenses into account
68
+ lowest_species = species
69
+ while lowest_species.evolution_from
70
+ lowest_species = Oakdex::Pokedex::Pokemon
71
+ .find!(lowest_species.evolution_from)
72
+ end
73
+ lowest_species
74
+ end
75
+
76
+ def exactly_one_is_ditto?
77
+ (@female.name == 'Ditto') ^ (@male.name == 'Ditto')
78
+ end
79
+
80
+ def non_ditto_is_discovered?
81
+ !non_ditto.species.egg_groups.include?('Undiscovered')
82
+ end
83
+
84
+ def non_ditto
85
+ return unless exactly_one_is_ditto?
86
+ @female.name == 'Ditto' ? @male : @female
87
+ end
88
+
89
+ def non_ditto_or_female
90
+ non_ditto || @female
91
+ end
92
+
93
+ def opposite_gender?
94
+ @female.gender == 'female' && @male.gender == 'male'
95
+ end
96
+
97
+ def same_egg_group?
98
+ !(@female.species.egg_groups & @male.species.egg_groups).empty?
99
+ end
100
+
101
+ def any_undiscovered?
102
+ (@female.species.egg_groups + @male.species.egg_groups)
103
+ .include?('Undiscovered')
104
+ end
105
+
106
+ def same_species?
107
+ @female.name == @male.name
108
+ end
109
+ end
110
+ end
@@ -0,0 +1,5 @@
1
+ module Oakdex
2
+ class Breeding
3
+ VERSION = '0.0.1'
4
+ end
5
+ end
metadata ADDED
@@ -0,0 +1,61 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: oakdex-breeding
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Jalyna Schroeder
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2019-01-20 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: oakdex-pokemon
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: 0.0.3
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: 0.0.3
27
+ description: Pokémon Breeding Matcher and Egg Generator, based on oakdex-pokedex
28
+ email: jalyna.schroeder@gmail.com
29
+ executables: []
30
+ extensions: []
31
+ extra_rdoc_files: []
32
+ files:
33
+ - README.md
34
+ - lib/oakdex.rb
35
+ - lib/oakdex/breeding.rb
36
+ - lib/oakdex/breeding/version.rb
37
+ homepage: http://github.com/jalyna/oakdex-breeding
38
+ licenses:
39
+ - MIT
40
+ metadata: {}
41
+ post_install_message:
42
+ rdoc_options: []
43
+ require_paths:
44
+ - lib
45
+ required_ruby_version: !ruby/object:Gem::Requirement
46
+ requirements:
47
+ - - ">="
48
+ - !ruby/object:Gem::Version
49
+ version: '0'
50
+ required_rubygems_version: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ requirements: []
56
+ rubyforge_project:
57
+ rubygems_version: 2.5.2
58
+ signing_key:
59
+ specification_version: 4
60
+ summary: Pokémon Breeding Matcher and Egg Generator
61
+ test_files: []