pktool 0.1.2 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 8c02b9db1edc76daca381dcb086a293d0a075ba8
4
- data.tar.gz: a3b199a5d0c08acbd76dc3d68fa6c614c95148cd
3
+ metadata.gz: 089a7e263e1c981304b149fc8e411068521ffa36
4
+ data.tar.gz: c7e85e680df581d54d0f1b00ad568c68699f591b
5
5
  SHA512:
6
- metadata.gz: a58d6138ed42df3f3b467bb177e5b5e7de1881dabbfa37eaa90c7bcb94196b659e866a1d7ce169370e09ee4e47c223a10890afce49e6ef41ed7dc7bc302144e9
7
- data.tar.gz: 3c121cd0d5ed6466722b21976cb52a881ffb8de8a0afd98f6794ff62ea14e087a4a83125ca26c4b2443d0b01b33866a899b7222702ae7e589194ca748e099850
6
+ metadata.gz: a6fc3901e7780a2061757a352885fc49325b0979a142aea23c5c7eb03494522f25c7c932e80b58ed23f0b14d0f79a85da056e55fe8cf309df1c90f04b61d4b2c
7
+ data.tar.gz: 41a4d2f9701e00b2e782913d7304f4419b99a212c77ed8ed16ef2536a177bb61d0a1ea58151c9a03df3540311c1c577dc0f35e901530670ea471c996e05f39d7
data/Gemfile CHANGED
@@ -8,3 +8,5 @@ gem "guard"
8
8
  gem "guard-rspec"
9
9
  gem "pry"
10
10
  gem 'pry-byebug'
11
+ gem 'activerecord'
12
+ gem 'sqlite3'
data/Gemfile.lock CHANGED
@@ -1,11 +1,11 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- pktool (0.1.2)
4
+ pktool (0.2.0)
5
+ activerecord (~> 4.2.1)
5
6
  bundler (~> 1.3)
6
7
  rake (~> 10.4.1)
7
8
  romaji (~> 0.2.1)
8
- sequel (~> 4.17.0)
9
9
  sqlite3 (~> 1.3.10)
10
10
  termcolorlight (~> 1.1.1)
11
11
  thor (~> 0.19.1)
@@ -13,71 +13,100 @@ PATH
13
13
  GEM
14
14
  remote: https://rubygems.org/
15
15
  specs:
16
- byebug (3.5.1)
17
- columnize (~> 0.8)
18
- debugger-linecache (~> 1.2)
19
- slop (~> 3.6)
16
+ activemodel (4.2.1)
17
+ activesupport (= 4.2.1)
18
+ builder (~> 3.1)
19
+ activerecord (4.2.1)
20
+ activemodel (= 4.2.1)
21
+ activesupport (= 4.2.1)
22
+ arel (~> 6.0)
23
+ activesupport (4.2.1)
24
+ i18n (~> 0.7)
25
+ json (~> 1.7, >= 1.7.7)
26
+ minitest (~> 5.1)
27
+ thread_safe (~> 0.3, >= 0.3.4)
28
+ tzinfo (~> 1.1)
29
+ arel (6.0.0)
30
+ builder (3.2.2)
31
+ byebug (4.0.5)
32
+ columnize (= 0.9.0)
20
33
  celluloid (0.16.0)
21
34
  timers (~> 4.0.0)
22
35
  coderay (1.1.0)
23
- columnize (0.8.9)
24
- debugger-linecache (1.2.0)
36
+ columnize (0.9.0)
25
37
  diff-lcs (1.2.5)
26
- ffi (1.9.6)
38
+ ffi (1.9.8)
27
39
  formatador (0.2.5)
28
- guard (2.10.1)
40
+ guard (2.12.5)
29
41
  formatador (>= 0.2.4)
30
42
  listen (~> 2.7)
31
43
  lumberjack (~> 1.0)
44
+ nenv (~> 0.1)
45
+ notiffany (~> 0.0)
32
46
  pry (>= 0.9.12)
47
+ shellany (~> 0.0)
33
48
  thor (>= 0.18.1)
34
- guard-rspec (4.3.1)
49
+ guard-compat (1.2.1)
50
+ guard-rspec (4.5.0)
35
51
  guard (~> 2.1)
36
- rspec (>= 2.14, < 4.0)
52
+ guard-compat (~> 1.1)
53
+ rspec (>= 2.99.0, < 4.0)
37
54
  hitimes (1.2.2)
38
- listen (2.8.3)
39
- celluloid (>= 0.15.2)
55
+ i18n (0.7.0)
56
+ json (1.8.2)
57
+ listen (2.10.0)
58
+ celluloid (~> 0.16.0)
40
59
  rb-fsevent (>= 0.9.3)
41
60
  rb-inotify (>= 0.9)
42
61
  lumberjack (1.0.9)
43
62
  method_source (0.8.2)
63
+ minitest (5.6.1)
64
+ nenv (0.2.0)
65
+ notiffany (0.0.6)
66
+ nenv (~> 0.1)
67
+ shellany (~> 0.0)
44
68
  pry (0.10.1)
45
69
  coderay (~> 1.1.0)
46
70
  method_source (~> 0.8.1)
47
71
  slop (~> 3.4)
48
- pry-byebug (2.0.0)
49
- byebug (~> 3.4)
72
+ pry-byebug (3.1.0)
73
+ byebug (~> 4.0)
50
74
  pry (~> 0.10)
51
- rake (10.4.1)
75
+ rake (10.4.2)
52
76
  rb-fsevent (0.9.4)
53
77
  rb-inotify (0.9.5)
54
78
  ffi (>= 0.5.0)
55
- romaji (0.2.1)
79
+ romaji (0.2.2)
56
80
  rake (>= 0.8.0)
57
- rspec (3.1.0)
58
- rspec-core (~> 3.1.0)
59
- rspec-expectations (~> 3.1.0)
60
- rspec-mocks (~> 3.1.0)
61
- rspec-core (3.1.7)
62
- rspec-support (~> 3.1.0)
63
- rspec-expectations (3.1.2)
81
+ rspec (3.2.0)
82
+ rspec-core (~> 3.2.0)
83
+ rspec-expectations (~> 3.2.0)
84
+ rspec-mocks (~> 3.2.0)
85
+ rspec-core (3.2.3)
86
+ rspec-support (~> 3.2.0)
87
+ rspec-expectations (3.2.1)
64
88
  diff-lcs (>= 1.2.0, < 2.0)
65
- rspec-support (~> 3.1.0)
66
- rspec-mocks (3.1.3)
67
- rspec-support (~> 3.1.0)
68
- rspec-support (3.1.2)
69
- sequel (4.17.0)
89
+ rspec-support (~> 3.2.0)
90
+ rspec-mocks (3.2.1)
91
+ diff-lcs (>= 1.2.0, < 2.0)
92
+ rspec-support (~> 3.2.0)
93
+ rspec-support (3.2.2)
94
+ shellany (0.0.1)
70
95
  slop (3.6.0)
71
96
  sqlite3 (1.3.10)
72
97
  termcolorlight (1.1.1)
73
98
  thor (0.19.1)
99
+ thread_safe (0.3.5)
74
100
  timers (4.0.1)
75
101
  hitimes
102
+ tzinfo (1.2.2)
103
+ thread_safe (~> 0.1)
76
104
 
77
105
  PLATFORMS
78
106
  ruby
79
107
 
80
108
  DEPENDENCIES
109
+ activerecord
81
110
  guard
82
111
  guard-rspec
83
112
  pktool!
@@ -85,3 +114,4 @@ DEPENDENCIES
85
114
  pry-byebug
86
115
  rspec
87
116
  rspec-core
117
+ sqlite3
data/Guardfile CHANGED
@@ -17,7 +17,7 @@
17
17
  # * 'just' rspec: 'rspec'
18
18
  guard :rspec, cmd: 'bundle exec rspec -c' do
19
19
  watch(%r{^spec/.+_spec\.rb$})
20
- watch(%r{^lib/(.+)\.rb$}) { |m| "spec/lib/#{m[1]}_spec.rb" }
20
+ watch(%r{^lib/(.+)\.rb$}) { |m| "spec/#{m[1]}_spec.rb" }
21
21
  watch('spec/spec_helper.rb') { "spec" }
22
22
 
23
23
  # Rails example
data/README.md CHANGED
@@ -4,12 +4,16 @@
4
4
  Pktoolはポケモンのレート対戦の技選択時間1分の間になるべく様々な情報を得ることを目標としたツールです。
5
5
  オフラインで動作するため、高速での検索を可能とします。
6
6
 
7
- 1. ダメージ計算(開発中)
7
+ 1. ダメージ計算
8
8
  2. ポケモンの能力値確認
9
9
  3. パーティメモ(開発中)
10
10
  4. 素早さ確認(開発中)
11
11
 
12
- データはとりあえず暇ツール(http://blog.livedoor.jp/hima_shi/)のデータベースからです。
12
+ ## インストール
13
+
14
+ ```
15
+ gem install pktool
16
+ ```
13
17
 
14
18
  ## 使い方
15
19
 
Binary file
data/data/type.json CHANGED
@@ -1,21 +1,21 @@
1
1
  {
2
- "ノーマル" : {"ノーマル" : 1, "ほのお" : 1, "みず" : 1, "でんき" : 1, "くさ" : 1, "こおり" : 1, "かくとう" : 2, "どく" : 1, "じめん" : 1, "ひこう" : 1, "エスパー" : 1, "むし" : 1, "いわ" : 1, "ゴースト" : 0, "ドラゴン" : 1, "あく" : 1, "はがね" : 1, "フェアリー" : 1},
3
- "ほのお" : {"ノーマル" : 1, "ほのお" : 0.5, "みず" : 2, "でんき" : 1, "くさ" : 0.5, "こおり" : 0.5, "かくとう" : 1, "どく" : 1, "じめん" : 2, "ひこう" : 1, "エスパー" : 1, "むし" : 0.5, "いわ" : 2, "ゴースト" : 1, "ドラゴン" : 1, "あく" : 1, "はがね" : 0.5, "フェアリー" : 0.5},
4
- "みず" : {"ノーマル" : 1, "ほのお" : 0.5, "みず" : 0.5, "でんき" : 2, "くさ" : 2, "こおり" : 0.5, "かくとう" : 1, "どく" : 1, "じめん" : 1, "ひこう" : 1, "エスパー" : 1, "むし" : 1, "いわ" : 1, "ゴースト" : 1, "ドラゴン" : 1, "あく" : 1, "はがね" : 0.5, "フェアリー" : 1},
5
- "でんき" : {"ノーマル" : 1, "ほのお" : 1, "みず" : 1, "でんき" : 0.5, "くさ" : 1, "こおり" : 1, "かくとう" : 1, "どく" : 1, "じめん" : 2, "ひこう" : 0.5, "エスパー" : 1, "むし" : 1, "いわ" : 1, "ゴースト" : 1, "ドラゴン" : 1, "あく" : 1, "はがね" : 0.5, "フェアリー" : 1},
6
- "くさ" : {"ノーマル" : 1, "ほのお" : 2, "みず" : 0.5, "でんき" : 0.5, "くさ" : 0.5, "こおり" : 2, "かくとう" : 1, "どく" : 2, "じめん" : 0.5, "ひこう" : 2, "エスパー" : 1, "むし" : 2, "いわ" : 1, "ゴースト" : 1, "ドラゴン" : 1, "あく" : 1, "はがね" : 1, "フェアリー" : 1},
7
- "こおり" : {"ノーマル" : 1, "ほのお" : 2, "みず" : 1, "でんき" : 1, "くさ" : 1, "こおり" : 0.5, "かくとう" : 2, "どく" : 1, "じめん" : 1, "ひこう" : 1, "エスパー" : 1, "むし" : 1, "いわ" : 2, "ゴースト" : 1, "ドラゴン" : 1, "あく" : 1, "はがね" : 2, "フェアリー" : 1},
8
- "かくとう" : {"ノーマル" : 1, "ほのお" : 1, "みず" : 1, "でんき" : 1, "くさ" : 1, "こおり" : 1, "かくとう" : 1, "どく" : 1, "じめん" : 1, "ひこう" : 2, "エスパー" : 2, "むし" : 0.5, "いわ" : 0.5, "ゴースト" : 1, "ドラゴン" : 1, "あく" : 0.5, "はがね" : 1, "フェアリー" : 2},
9
- "どく" : {"ノーマル" : 1, "ほのお" : 1, "みず" : 1, "でんき" : 1, "くさ" : 0.5, "こおり" : 1, "かくとう" : 0.5, "どく" : 0.5, "じめん" : 2, "ひこう" : 1, "エスパー" : 2, "むし" : 0.5, "いわ" : 1, "ゴースト" : 1, "ドラゴン" : 1, "あく" : 1, "はがね" : 1, "フェアリー" : 0.5},
10
- "じめん" : {"ノーマル" : 1, "ほのお" : 1, "みず" : 2, "でんき" : 0, "くさ" : 2, "こおり" : 2, "かくとう" : 1, "どく" : 0.5, "じめん" : 1, "ひこう" : 1, "エスパー" : 1, "むし" : 1, "いわ" : 0.5, "ゴースト" : 1, "ドラゴン" : 1, "あく" : 1, "はがね" : 1, "フェアリー" : 1},
11
- "ひこう" : {"ノーマル" : 1, "ほのお" : 1, "みず" : 1, "でんき" : 2, "くさ" : 0.5, "こおり" : 2, "かくとう" : 0.5, "どく" : 1, "じめん" : 0, "ひこう" : 1, "エスパー" : 1, "むし" : 0.5, "いわ" : 2, "ゴースト" : 1, "ドラゴン" : 1, "あく" : 1, "はがね" : 1, "フェアリー" : 1},
12
- "エスパー" : {"ノーマル" : 1, "ほのお" : 1, "みず" : 1, "でんき" : 1, "くさ" : 1, "こおり" : 1, "かくとう" : 0.5, "どく" : 1, "じめん" : 1, "ひこう" : 1, "エスパー" : 0.5, "むし" : 2, "いわ" : 1, "ゴースト" : 2, "ドラゴン" : 1, "あく" : 2, "はがね" : 1, "フェアリー" : 1},
13
- "むし" : {"ノーマル" : 1, "ほのお" : 2, "みず" : 1, "でんき" : 1, "くさ" : 0.5, "こおり" : 1, "かくとう" : 0.5, "どく" : 1, "じめん" : 0.5, "ひこう" : 2, "エスパー" : 1, "むし" : 1, "いわ" : 2, "ゴースト" : 1, "ドラゴン" : 1, "あく" : 1, "はがね" : 1, "フェアリー" : 1},
14
- "いわ" : {"ノーマル" : 0.5, "ほのお" : 0.5, "みず" : 2, "でんき" : 1, "くさ" : 2, "こおり" : 1, "かくとう" : 2, "どく" : 0.5, "じめん" : 2, "ひこう" : 0.5, "エスパー" : 1, "むし" : 1, "いわ" : 1, "ゴースト" : 1, "ドラゴン" : 1, "あく" : 1, "はがね" : 2, "フェアリー" : 1},
15
- "ゴースト" : {"ノーマル" : 0, "ほのお" : 1, "みず" : 1, "でんき" : 1, "くさ" : 1, "こおり" : 1, "かくとう" : 0, "どく" : 0.5, "じめん" : 1, "ひこう" : 1, "エスパー" : 1, "むし" : 0.5, "いわ" : 1, "ゴースト" : 2, "ドラゴン" : 1, "あく" : 2, "はがね" : 1, "フェアリー" : 1},
16
- "ドラゴン" : {"ノーマル" : 1, "ほのお" : 0.5, "みず" : 0.5, "でんき" : 0.5, "くさ" : 0.5, "こおり" : 2, "かくとう" : 1, "どく" : 1, "じめん" : 1, "ひこう" : 1, "エスパー" : 1, "むし" : 1, "いわ" : 1, "ゴースト" : 1, "ドラゴン" : 2, "あく" : 1, "はがね" : 1, "フェアリー" : 2},
17
- "あく" : {"ノーマル" : 1, "ほのお" : 1, "みず" : 1, "でんき" : 1, "くさ" : 1, "こおり" : 1, "かくとう" : 2, "どく" : 1, "じめん" : 1, "ひこう" : 1, "エスパー" : 0, "むし" : 2, "いわ" : 1, "ゴースト" : 0.5, "ドラゴン" : 1, "あく" : 0.5, "はがね" : 1, "フェアリー" : 2},
18
- "はがね" : {"ノーマル" : 0.5, "ほのお" : 2, "みず" : 1, "でんき" : 1, "くさ" : 0.5, "こおり" : 0.5, "かくとう" : 2, "どく" : 0, "じめん" : 2, "ひこう" : 0.5, "エスパー" : 0.5, "むし" : 0.5, "いわ" : 0.5, "ゴースト" : 1, "ドラゴン" : 0.5, "あく" : 1, "はがね" : 0.5, "フェアリー" : 0.5},
19
- "フェアリー" : {"ノーマル" : 1, "ほのお" : 1, "みず" : 1, "でんき" : 1, "くさ" : 1, "こおり" : 1, "かくとう" : 0.5, "どく" : 2, "じめん" : 1, "ひこう" : 1, "エスパー" : 1, "むし" : 0.5, "いわ" : 1, "ゴースト" : 1, "ドラゴン" : 0, "あく" : 0.5, "はがね" : 2, "フェアリー" : 1 }
2
+ "" : {"" : 1, "" : 1, "" : 1, "" : 1, "" : 1, "" : 1, "" : 2, "" : 1, "" : 1, "" : 1, "" : 1, "" : 1, "" : 1, "" : 0, "" : 1, "" : 1, "" : 1, "" : 1},
3
+ "" : {"" : 1, "" : 0.5, "" : 2, "" : 1, "" : 0.5, "" : 0.5, "" : 1, "" : 1, "" : 2, "" : 1, "" : 1, "" : 0.5, "" : 2, "" : 1, "" : 1, "" : 1, "" : 0.5, "" : 0.5},
4
+ "" : {"" : 1, "" : 0.5, "" : 0.5, "" : 2, "" : 2, "" : 0.5, "" : 1, "" : 1, "" : 1, "" : 1, "" : 1, "" : 1, "" : 1, "" : 1, "" : 1, "" : 1, "" : 0.5, "" : 1},
5
+ "" : {"" : 1, "" : 1, "" : 1, "" : 0.5, "" : 1, "" : 1, "" : 1, "" : 1, "" : 2, "" : 0.5, "" : 1, "" : 1, "" : 1, "" : 1, "" : 1, "" : 1, "" : 0.5, "" : 1},
6
+ "" : {"" : 1, "" : 2, "" : 0.5, "" : 0.5, "" : 0.5, "" : 2, "" : 1, "" : 2, "" : 0.5, "" : 2, "" : 1, "" : 2, "" : 1, "" : 1, "" : 1, "" : 1, "" : 1, "" : 1},
7
+ "" : {"" : 1, "" : 2, "" : 1, "" : 1, "" : 1, "" : 0.5, "" : 2, "" : 1, "" : 1, "" : 1, "" : 1, "" : 1, "" : 2, "" : 1, "" : 1, "" : 1, "" : 2, "" : 1},
8
+ "" : {"" : 1, "" : 1, "" : 1, "" : 1, "" : 1, "" : 1, "" : 1, "" : 1, "" : 1, "" : 2, "" : 2, "" : 0.5, "" : 0.5, "" : 1, "" : 1, "" : 0.5, "" : 1, "" : 2},
9
+ "" : {"" : 1, "" : 1, "" : 1, "" : 1, "" : 0.5, "" : 1, "" : 0.5, "" : 0.5, "" : 2, "" : 1, "" : 2, "" : 0.5, "" : 1, "" : 1, "" : 1, "" : 1, "" : 1, "" : 0.5},
10
+ "" : {"" : 1, "" : 1, "" : 2, "" : 0, "" : 2, "" : 2, "" : 1, "" : 0.5, "" : 1, "" : 1, "" : 1, "" : 1, "" : 0.5, "" : 1, "" : 1, "" : 1, "" : 1, "" : 1},
11
+ "" : {"" : 1, "" : 1, "" : 1, "" : 2, "" : 0.5, "" : 2, "" : 0.5, "" : 1, "" : 0, "" : 1, "" : 1, "" : 0.5, "" : 2, "" : 1, "" : 1, "" : 1, "" : 1, "" : 1},
12
+ "" : {"" : 1, "" : 1, "" : 1, "" : 1, "" : 1, "" : 1, "" : 0.5, "" : 1, "" : 1, "" : 1, "" : 0.5, "" : 2, "" : 1, "" : 2, "" : 1, "" : 2, "" : 1, "" : 1},
13
+ "" : {"" : 1, "" : 2, "" : 1, "" : 1, "" : 0.5, "" : 1, "" : 0.5, "" : 1, "" : 0.5, "" : 2, "" : 1, "" : 1, "" : 2, "" : 1, "" : 1, "" : 1, "" : 1, "" : 1},
14
+ "" : {"" : 0.5, "" : 0.5, "" : 2, "" : 1, "" : 2, "" : 1, "" : 2, "" : 0.5, "" : 2, "" : 0.5, "" : 1, "" : 1, "" : 1, "" : 1, "" : 1, "" : 1, "" : 2, "" : 1},
15
+ "" : {"" : 0, "" : 1, "" : 1, "" : 1, "" : 1, "" : 1, "" : 0, "" : 0.5, "" : 1, "" : 1, "" : 1, "" : 0.5, "" : 1, "" : 2, "" : 1, "" : 2, "" : 1, "" : 1},
16
+ "" : {"" : 1, "" : 0.5, "" : 0.5, "" : 0.5, "" : 0.5, "" : 2, "" : 1, "" : 1, "" : 1, "" : 1, "" : 1, "" : 1, "" : 1, "" : 1, "" : 2, "" : 1, "" : 1, "" : 2},
17
+ "" : {"" : 1, "" : 1, "" : 1, "" : 1, "" : 1, "" : 1, "" : 2, "" : 1, "" : 1, "" : 1, "" : 0, "" : 2, "" : 1, "" : 0.5, "" : 1, "" : 0.5, "" : 1, "" : 2},
18
+ "" : {"" : 0.5, "" : 2, "" : 1, "" : 1, "" : 0.5, "" : 0.5, "" : 2, "" : 0, "" : 2, "" : 0.5, "" : 0.5, "" : 0.5, "" : 0.5, "" : 1, "" : 0.5, "" : 1, "" : 0.5, "" : 0.5},
19
+ "" : {"" : 1, "" : 1, "" : 1, "" : 1, "" : 1, "" : 1, "" : 0.5, "" : 2, "" : 1, "" : 1, "" : 1, "" : 0.5, "" : 1, "" : 1, "" : 0, "" : 0.5, "" : 2, "" : 1 }
20
20
  }
21
21
 
data/lib/builder.rb CHANGED
@@ -1,4 +1,6 @@
1
1
  require_relative 'pokemon'
2
+ require_relative "nature"
3
+ require_relative 'party'
2
4
  require_relative 'move'
3
5
  require_relative 'log'
4
6
 
@@ -6,9 +8,21 @@ module Pktool
6
8
 
7
9
  class Builder
8
10
 
9
- def self.pokemon
10
- pokemons = Pokemon.select_map(:name)
11
- natures = Pokemon::Nature.select_map(:name)
11
+ def self.party_pokemon
12
+ party = Party.new
13
+ command = fetch("command")
14
+ if(command == "new")
15
+ return self.new_pokemon
16
+ end
17
+ if(command =~ /^\d+$/)
18
+ return party[command.to_i]
19
+ end
20
+ warn "Not found."
21
+ end
22
+
23
+ def self.new_pokemon
24
+ pokemons = Pokemon.pluck(:name)
25
+ natures = Nature.pluck(:name)
12
26
  name = fetch("なまえ", pokemons)
13
27
  feature = {}
14
28
  feature[:nature] = fetch("せいかく", natures) do |input| input.to_sym end
@@ -25,8 +39,18 @@ module Pktool
25
39
  return Pokemon.fetch(name, feature)
26
40
  end
27
41
 
42
+ def self.default_pokemon
43
+ pokemons = Pokemon.pluck(:name)
44
+ name = fetch("なまえ", pokemons)
45
+ feature = {}
46
+ feature[:nature] = Nature.first.name
47
+ feature[:effort_value] = { H: 0, A: 0, B: 0, C: 0, D: 0, S: 0 }
48
+ feature[:individual_value] = { H: 31, A: 31, B: 31, C: 31, D: 31, S: 31 }
49
+ return Pokemon.fetch(name, feature)
50
+ end
51
+
28
52
  def self.move(attacker, defender)
29
- moves = Move.select_map(:name)
53
+ moves = Move.pluck(:name)
30
54
  move = fetch("わざ", moves)
31
55
  move = Move.fetch(move, attacker, defender)
32
56
  end
data/lib/cli.rb CHANGED
@@ -16,26 +16,39 @@ end
16
16
  module Pktool
17
17
 
18
18
  class Cli < Thor
19
- register(Pktool::Command::Party, "party", "party [COMMAND]", "自分のパーティを編成する")
19
+ # register(Pktool::Command::Party, "party", "party [COMMAND]", "自分のパーティを編成する")
20
20
 
21
21
  desc "info", "ポケモンの情報を見る"
22
22
  def info
23
- pokemon = Builder.pokemon
23
+ pokemon = Builder.default_pokemon
24
+ puts "<underline>図鑑番号</underline>".termcolor
25
+ puts pokemon.pokemon_id
26
+ puts "<underline>種族値</underline>".termcolor
27
+ puts pokemon.base_stat.map{|k,v| "<bold>#{k}</bold>:<red>#{v}</red> ".termcolor}.join
28
+ puts "<underline>相性</underline>".termcolor
29
+ puts pokemon.types.select{|k,v| v > 1 }.map{|k,v| "<bold>#{k}</bold>:<red>#{v}</red> ".termcolor}.join
30
+ puts pokemon.types.select{|k,v| v < 1 }.map{|k,v| "<bold>#{k}</bold>:<blue>#{v}</blue> ".termcolor}.join
31
+ end
32
+
33
+ desc "status", "ポケモンのステータスを見る"
34
+ def status
35
+ pokemon = Builder.new_pokemon
24
36
  puts "<underline>種族値</underline>".termcolor
25
37
  puts pokemon.base_stat.map{|k,v| "<bold>#{k}</bold>:<red>#{v}</red> ".termcolor}.join
26
38
  puts "<underline>能力値</underline>".termcolor
27
39
  puts pokemon.stats.map{|k,v| "<bold>#{k}</bold>:<blue>#{v}</blue> ".termcolor}.join
28
-
29
- #TODO: 相性
40
+ puts "<underline>相性</underline>".termcolor
41
+ puts pokemon.types.select{|k,v| v > 1 }.map{|k,v| "<bold>#{k}</bold>:<red>#{v}</red> ".termcolor}.join
42
+ puts pokemon.types.select{|k,v| v < 1 }.map{|k,v| "<bold>#{k}</bold>:<blue>#{v}</blue> ".termcolor}.join
30
43
  end
31
44
 
32
45
  desc "damage", "ダメージ計算する"
33
46
  def damage
34
47
  puts "<underline>攻撃側の指定</underline>".termcolor
35
- attacker = Builder.pokemon
48
+ attacker = Builder.new_pokemon
36
49
 
37
50
  puts "<underline>防御側の指定</underline>".termcolor
38
- defender = Builder.pokemon
51
+ defender = Builder.new_pokemon
39
52
 
40
53
  puts "<underline>技の指定</underline>".termcolor
41
54
  move = Builder.move(attacker, defender)
data/lib/database.rb CHANGED
@@ -1,5 +1,8 @@
1
- require 'sequel'
1
+ require 'active_record'
2
2
 
3
3
  module Pktool
4
- DB = Sequel.connect('sqlite://data/pokemonData.sqlite')
4
+ ActiveRecord::Base.establish_connection(
5
+ :adapter => 'sqlite3',
6
+ :database => 'data/pokemon.sqlite3'
7
+ )
5
8
  end
data/lib/move.rb CHANGED
@@ -1,7 +1,7 @@
1
1
  require_relative "database"
2
2
 
3
3
  module Pktool
4
- class Move < Sequel::Model(:move)
4
+ class Move < ActiveRecord::Base
5
5
  attr_accessor :attacker, :defender
6
6
 
7
7
  def self.fetch(name, attacker, defender)
@@ -15,25 +15,26 @@ module Pktool
15
15
  def damage
16
16
  level = 50.0
17
17
  effect = 1.0
18
- effect *= 1.5 if [@attacker.type1, @attacker.type2].include?(self.type)
18
+ effect *= 1.5 if [@attacker.type1, @attacker.type2].include?(self.attack_type)
19
19
 
20
+ # type effect
20
21
  type_effect = open("data/type.json") do |io|
21
22
  JSON.load(io)
22
23
  end
23
24
  type = 1.0
24
- type *= type_effect[@defender.type1][self.type]
25
- type *= type_effect[@defender.type2][self.type] if @defender.type2
25
+ type *= type_effect[@defender.type1][self.attack_type]
26
+ type *= type_effect[@defender.type2][self.attack_type] unless @defender.type2.empty?
26
27
 
27
28
  vital = 1.0
28
29
  case move_type
29
- when "ぶつり"
30
+ when "物理"
30
31
  attack_stat = :A
31
32
  defence_stat = :B
32
- when "とくしゅ"
33
+ when "特殊"
33
34
  attack_stat = :C
34
35
  defence_stat = :D
35
36
  end
36
- # this equation may be mistake.
37
+ # todo: this equation may be mistake.
37
38
  base = ((power * @attacker.statistics(attack_stat) * (level * 2.0 / 5.0 + 2.0 )) / @defender.statistics(defence_stat) / 50.0 * effect + 2.0) * type
38
39
  min = base * vital * 0.85
39
40
  max = base * vital * 1.0
data/lib/nature.rb ADDED
@@ -0,0 +1,13 @@
1
+ require_relative "database"
2
+ require_relative "exceptions"
3
+
4
+ module Pktool
5
+ class Nature < ActiveRecord::Base
6
+ def to_s
7
+ self.name.to_s
8
+ end
9
+ def to_sym
10
+ self.name.to_sym
11
+ end
12
+ end
13
+ end
data/lib/party.rb CHANGED
@@ -6,17 +6,18 @@ module Pktool
6
6
  class Party
7
7
  attr_accessor :list
8
8
 
9
- @@json_path = "data/user/party.json"
9
+ @@party_path = "data/user/"
10
10
 
11
- def initialize
12
- json = open(@@json_path) do |io|
11
+ def initialize(name = "party")
12
+ @file_path = @@party_path + "#{name}.json"
13
+ json = open(@file_path) do |io|
13
14
  JSON.load(io, nil, { symbolize_names: true})
14
15
  end
15
16
  @list = json.map {|j| Pokemon.fetch(j[:name], j)}
16
17
  end
17
18
 
18
19
  def save
19
- open(@@json_path, 'w') do |io|
20
+ open(@file_path, 'w') do |io|
20
21
  JSON.dump(@list.map{|p| p.to_h}, io)
21
22
  end
22
23
  end
data/lib/pokemon.rb CHANGED
@@ -1,19 +1,12 @@
1
1
  require 'json'
2
2
  require_relative "database"
3
3
  require_relative "exceptions"
4
+ require_relative "nature"
4
5
 
5
- module Pktool
6
6
 
7
- class Pokemon < Sequel::Model(:pokemon)
7
+ module Pktool
8
8
 
9
- class Nature < Sequel::Model(:nature)
10
- def to_s
11
- self.name.to_s
12
- end
13
- def to_sym
14
- self.name.to_sym
15
- end
16
- end
9
+ class Pokemon < ActiveRecord::Base
17
10
 
18
11
  attr_accessor :nature, :effort_value, :individual_value, :ability, :item
19
12
  attr_accessor :description
@@ -23,7 +16,7 @@ module Pktool
23
16
  @@ways = [:AS, :CS, :hAS, :hCS, :HB, :HD, :HAs, :HCs]
24
17
 
25
18
  def self.fetch(name, feature = {})
26
- pokemon = self.where(name: name).first
19
+ pokemon = self.find_by_name(name)
27
20
  raise Error, "存在ないポケモンです。" unless pokemon
28
21
  pokemon.set(feature)
29
22
  return pokemon
@@ -39,7 +32,7 @@ module Pktool
39
32
 
40
33
  def set(feature)
41
34
  @description = feature[:description] || ""
42
- @nature = Nature[feature[:nature].to_s] || Nature["がんばりや"]
35
+ @nature = Nature.find_by_name(feature[:nature]) || Nature.find_by_name("がんばりや")
43
36
  @effort_value = feature[:effort_value] || { H: 0, A: 0, B: 0, C: 0, D: 0, S: 0 }
44
37
  @individual_value = feature[:individual_value] || { H: 31, A: 31, B: 31, C: 31, D: 31, S: 31 }
45
38
  @ability = feature[:ability] || 1
@@ -84,6 +77,15 @@ module Pktool
84
77
  [:H, :A, :B, :C, :D, :S].map { |name| [name, statistics(name)]}.to_h
85
78
  end
86
79
 
80
+ def types
81
+ type_effect = open("data/type.json") do |io|
82
+ JSON.load(io)
83
+ end
84
+ Hash[type_effect.keys.map do |t|
85
+ [t, type_effect[type1][t] * type_effect[type2][t]]
86
+ end]
87
+ end
88
+
87
89
  def to_h
88
90
  {
89
91
  name: name,
data/lib/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Pktool
2
- VERSION = "0.1.2"
2
+ VERSION = "0.2.0"
3
3
  end
data/pktool.gemspec CHANGED
@@ -20,7 +20,7 @@ Gem::Specification.new do |spec|
20
20
 
21
21
  spec.add_runtime_dependency "bundler", "~> 1.3"
22
22
  spec.add_runtime_dependency "rake", "~> 10.4.1"
23
- spec.add_runtime_dependency "sequel", "~> 4.17.0"
23
+ spec.add_runtime_dependency "activerecord", "~> 4.2.1"
24
24
  spec.add_runtime_dependency "sqlite3", "~> 1.3.10"
25
25
  spec.add_runtime_dependency "termcolorlight", "~> 1.1.1"
26
26
  spec.add_runtime_dependency "thor", "~> 0.19.1"
data/spec/pokemon_spec.rb CHANGED
@@ -4,7 +4,7 @@ include Pktool
4
4
 
5
5
  describe "Nature" do
6
6
  it "should fecth nature effect" do
7
- n = Pokemon::Nature[:まじめ.to_s]
7
+ n = Nature.find_by_name(:まじめ)
8
8
  expect(n.A).to eq 1.0
9
9
  end
10
10
  end
@@ -34,5 +34,10 @@ describe "Pokemon" do
34
34
  }
35
35
  )
36
36
  end
37
+
38
+ it "should has type effect" do
39
+ p = Pokemon.fetch("ガブリアス", {nature: :いじっぱり, effort_value: :hAS})
40
+ expect(p.types["氷"]).to eq(4)
41
+ end
37
42
  end
38
43
 
@@ -0,0 +1,2 @@
1
+ pokemon.sqlite3
2
+ .bundle
@@ -0,0 +1,6 @@
1
+ source "https://rubygems.org"
2
+
3
+ gem 'sqlite3'
4
+ gem 'activerecord'
5
+ gem 'nokogiri'
6
+
@@ -0,0 +1,36 @@
1
+ GEM
2
+ remote: https://rubygems.org/
3
+ specs:
4
+ activemodel (4.2.1)
5
+ activesupport (= 4.2.1)
6
+ builder (~> 3.1)
7
+ activerecord (4.2.1)
8
+ activemodel (= 4.2.1)
9
+ activesupport (= 4.2.1)
10
+ arel (~> 6.0)
11
+ activesupport (4.2.1)
12
+ i18n (~> 0.7)
13
+ json (~> 1.7, >= 1.7.7)
14
+ minitest (~> 5.1)
15
+ thread_safe (~> 0.3, >= 0.3.4)
16
+ tzinfo (~> 1.1)
17
+ arel (6.0.0)
18
+ builder (3.2.2)
19
+ i18n (0.7.0)
20
+ json (1.8.2)
21
+ mini_portile (0.6.2)
22
+ minitest (5.6.0)
23
+ nokogiri (1.6.6.2)
24
+ mini_portile (~> 0.6.0)
25
+ sqlite3 (1.3.10)
26
+ thread_safe (0.3.5)
27
+ tzinfo (1.2.2)
28
+ thread_safe (~> 0.1)
29
+
30
+ PLATFORMS
31
+ ruby
32
+
33
+ DEPENDENCIES
34
+ activerecord
35
+ nokogiri
36
+ sqlite3
@@ -0,0 +1,144 @@
1
+ require 'active_record'
2
+ require 'nokogiri'
3
+ require 'open-uri'
4
+
5
+ ActiveRecord::Base.establish_connection(
6
+ :adapter => 'sqlite3',
7
+ :database => 'pokemon.sqlite3'
8
+ )
9
+
10
+ if ActiveRecord::Base.connection.table_exists? :pokemons
11
+ ActiveRecord::Migration.drop_table :pokemons
12
+ end
13
+ if ActiveRecord::Base.connection.table_exists? :moves
14
+ ActiveRecord::Migration.drop_table :moves
15
+ end
16
+ if ActiveRecord::Base.connection.table_exists? :natures
17
+ ActiveRecord::Migration.drop_table :natures
18
+ end
19
+ if ActiveRecord::Base.connection.table_exists? :acquisitions
20
+ ActiveRecord::Migration.drop_table :acquisitions
21
+ end
22
+
23
+ ActiveRecord::Migration.create_table :pokemons do |t|
24
+ t.string :pokemon_id
25
+ t.string :name
26
+ t.integer :H
27
+ t.integer :A
28
+ t.integer :B
29
+ t.integer :C
30
+ t.integer :D
31
+ t.integer :S
32
+ t.string :type1
33
+ t.string :type2
34
+ t.string :ability1
35
+ t.string :ability2
36
+ t.string :hidden_ability
37
+ t.float :weight
38
+ t.float :height
39
+ t.boolean :last_evolution
40
+ end
41
+
42
+ ActiveRecord::Migration.create_table :moves do |t|
43
+ t.string :name
44
+ t.string :attack_type
45
+ t.integer :power
46
+ t.integer :accuracy
47
+ t.integer :pp
48
+ t.integer :priority
49
+ t.string :move_type
50
+ end
51
+
52
+ ActiveRecord::Migration.create_table :natures do |t|
53
+ t.string :name
54
+ t.float :A
55
+ t.float :B
56
+ t.float :C
57
+ t.float :D
58
+ t.float :S
59
+ end
60
+
61
+ ActiveRecord::Migration.create_table :acquisitions do |t|
62
+ t.string :pokemon_id
63
+ t.integer :move_id
64
+ end
65
+
66
+ class Pokemon < ActiveRecord::Base
67
+ end
68
+ class Move < ActiveRecord::Base
69
+ end
70
+ class Nature < ActiveRecord::Base
71
+ end
72
+ class Acquisition < ActiveRecord::Base
73
+ end
74
+
75
+ pokemon_url = 'http://pokedb.com/pokemon/'
76
+ move_url = 'http://pokedb.com/move/'
77
+
78
+ Nokogiri::HTML.parse(open(move_url), nil).css("#moveTbl tr")[1..-1].each do |tr|
79
+ puts tr.children[0].text
80
+ Move.create(
81
+ name: tr.children[0].text,
82
+ attack_type: tr.children[1].text,
83
+ power: tr.children[2].text,
84
+ accuracy: tr.children[3].text,
85
+ pp: tr.children[4].text,
86
+ priority: tr.children[5].text == "-" ? 0 : tr.children[5].text,
87
+ move_type: tr.children[6].text
88
+ )
89
+ end
90
+
91
+ Nokogiri::HTML.parse(open(pokemon_url), nil).css("#pokemonTbl tr")[1..-1].each do |tr|
92
+ puts tr.children[0].text
93
+ href = tr.css("a").first.attribute('href').value
94
+ detail = Nokogiri::HTML.parse(open(URI.join(pokemon_url, href)), nil)
95
+ infomation = detail.xpath("id('biLeft')/section[1]//table//tr")
96
+ abilities = detail.xpath("id('biLeft')/section[3]//table//tr")
97
+ pokemon = Pokemon.create(
98
+ pokemon_id: tr.children[0].text,
99
+ name: tr.children[1].text,
100
+ type1: tr.children[2].text,
101
+ type2: tr.children[3].text,
102
+ H: tr.children[4].text,
103
+ A: tr.children[5].text,
104
+ B: tr.children[6].text,
105
+ C: tr.children[7].text,
106
+ D: tr.children[8].text,
107
+ S: tr.children[9].text,
108
+ ability1: abilities[0].children[1].text,
109
+ ability2: abilities[1].children[1].text,
110
+ hidden_ability: abilities[2].children[1].text,
111
+ height: infomation[3].children[1].text,
112
+ weight: infomation[4].children[1].text.match(/(.*)kg/)[1]
113
+ )
114
+ detail.css("#moveTbl tr")[1..-1].each do |move_tr|
115
+ Acquisition.create(
116
+ pokemon_id: pokemon.id,
117
+ move_id: Move.where(name:move_tr.children[0].text).first.id
118
+ )
119
+ end
120
+ end
121
+
122
+ nature_url = 'http://yakkun.com/data/seikaku.htm'
123
+
124
+ def convert_nature_effect(label)
125
+ case label
126
+ when "○"
127
+ return 1.1
128
+ when "×"
129
+ return 0.9
130
+ else
131
+ return 1.0
132
+ end
133
+ end
134
+
135
+ Nokogiri::HTML.parse(open(nature_url), nil).css("table[summary='性格リスト'] tr")[2..-1].each do |tr|
136
+ Nature.create(
137
+ name: tr.children[0].text,
138
+ A: convert_nature_effect(tr.children[1].text),
139
+ B: convert_nature_effect(tr.children[2].text),
140
+ C: convert_nature_effect(tr.children[3].text),
141
+ D: convert_nature_effect(tr.children[4].text),
142
+ S: convert_nature_effect(tr.children[5].text),
143
+ )
144
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pktool
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - uzimith
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-12-09 00:00:00.000000000 Z
11
+ date: 2015-05-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -39,19 +39,19 @@ dependencies:
39
39
  - !ruby/object:Gem::Version
40
40
  version: 10.4.1
41
41
  - !ruby/object:Gem::Dependency
42
- name: sequel
42
+ name: activerecord
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
45
  - - "~>"
46
46
  - !ruby/object:Gem::Version
47
- version: 4.17.0
47
+ version: 4.2.1
48
48
  type: :runtime
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
52
  - - "~>"
53
53
  - !ruby/object:Gem::Version
54
- version: 4.17.0
54
+ version: 4.2.1
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: sqlite3
57
57
  requirement: !ruby/object:Gem::Requirement
@@ -125,6 +125,7 @@ files:
125
125
  - Rakefile
126
126
  - bin/pktool
127
127
  - data/nature.json
128
+ - data/pokemon.sqlite3
128
129
  - data/pokemonData.sqlite
129
130
  - data/type.json
130
131
  - data/user/party.json
@@ -135,6 +136,7 @@ files:
135
136
  - lib/exceptions.rb
136
137
  - lib/log.rb
137
138
  - lib/move.rb
139
+ - lib/nature.rb
138
140
  - lib/party.rb
139
141
  - lib/pktool.rb
140
142
  - lib/pokemon.rb
@@ -144,6 +146,10 @@ files:
144
146
  - spec/move_spec.rb
145
147
  - spec/pokemon_spec.rb
146
148
  - spec/spec_helper.rb
149
+ - tool/create_pokemon_db/.gitignore
150
+ - tool/create_pokemon_db/Gemfile
151
+ - tool/create_pokemon_db/Gemfile.lock
152
+ - tool/create_pokemon_db/create_pokemon_db.rb
147
153
  homepage: ''
148
154
  licenses:
149
155
  - MIT
@@ -164,7 +170,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
164
170
  version: '0'
165
171
  requirements: []
166
172
  rubyforge_project:
167
- rubygems_version: 2.2.2
173
+ rubygems_version: 2.4.5
168
174
  signing_key:
169
175
  specification_version: 4
170
176
  summary: ''