pktool 0.1.2 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile +2 -0
- data/Gemfile.lock +60 -30
- data/Guardfile +1 -1
- data/README.md +6 -2
- data/data/pokemon.sqlite3 +0 -0
- data/data/type.json +18 -18
- data/lib/builder.rb +28 -4
- data/lib/cli.rb +19 -6
- data/lib/database.rb +5 -2
- data/lib/move.rb +8 -7
- data/lib/nature.rb +13 -0
- data/lib/party.rb +5 -4
- data/lib/pokemon.rb +14 -12
- data/lib/version.rb +1 -1
- data/pktool.gemspec +1 -1
- data/spec/pokemon_spec.rb +6 -1
- data/tool/create_pokemon_db/.gitignore +2 -0
- data/tool/create_pokemon_db/Gemfile +6 -0
- data/tool/create_pokemon_db/Gemfile.lock +36 -0
- data/tool/create_pokemon_db/create_pokemon_db.rb +144 -0
- metadata +12 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 089a7e263e1c981304b149fc8e411068521ffa36
|
4
|
+
data.tar.gz: c7e85e680df581d54d0f1b00ad568c68699f591b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a6fc3901e7780a2061757a352885fc49325b0979a142aea23c5c7eb03494522f25c7c932e80b58ed23f0b14d0f79a85da056e55fe8cf309df1c90f04b61d4b2c
|
7
|
+
data.tar.gz: 41a4d2f9701e00b2e782913d7304f4419b99a212c77ed8ed16ef2536a177bb61d0a1ea58151c9a03df3540311c1c577dc0f35e901530670ea471c996e05f39d7
|
data/Gemfile
CHANGED
data/Gemfile.lock
CHANGED
@@ -1,11 +1,11 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
pktool (0.
|
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
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
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.
|
24
|
-
debugger-linecache (1.2.0)
|
36
|
+
columnize (0.9.0)
|
25
37
|
diff-lcs (1.2.5)
|
26
|
-
ffi (1.9.
|
38
|
+
ffi (1.9.8)
|
27
39
|
formatador (0.2.5)
|
28
|
-
guard (2.
|
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-
|
49
|
+
guard-compat (1.2.1)
|
50
|
+
guard-rspec (4.5.0)
|
35
51
|
guard (~> 2.1)
|
36
|
-
|
52
|
+
guard-compat (~> 1.1)
|
53
|
+
rspec (>= 2.99.0, < 4.0)
|
37
54
|
hitimes (1.2.2)
|
38
|
-
|
39
|
-
|
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 (
|
49
|
-
byebug (~>
|
72
|
+
pry-byebug (3.1.0)
|
73
|
+
byebug (~> 4.0)
|
50
74
|
pry (~> 0.10)
|
51
|
-
rake (10.4.
|
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.
|
79
|
+
romaji (0.2.2)
|
56
80
|
rake (>= 0.8.0)
|
57
|
-
rspec (3.
|
58
|
-
rspec-core (~> 3.
|
59
|
-
rspec-expectations (~> 3.
|
60
|
-
rspec-mocks (~> 3.
|
61
|
-
rspec-core (3.
|
62
|
-
rspec-support (~> 3.
|
63
|
-
rspec-expectations (3.1
|
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.
|
66
|
-
rspec-mocks (3.1
|
67
|
-
|
68
|
-
|
69
|
-
|
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
|
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
|
-
|
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
|
-
"
|
3
|
-
"
|
4
|
-
"
|
5
|
-
"
|
6
|
-
"
|
7
|
-
"
|
8
|
-
"
|
9
|
-
"
|
10
|
-
"
|
11
|
-
"
|
12
|
-
"
|
13
|
-
"
|
14
|
-
"
|
15
|
-
"
|
16
|
-
"
|
17
|
-
"
|
18
|
-
"
|
19
|
-
"
|
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.
|
10
|
-
|
11
|
-
|
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.
|
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.
|
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
|
-
|
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.
|
48
|
+
attacker = Builder.new_pokemon
|
36
49
|
|
37
50
|
puts "<underline>防御側の指定</underline>".termcolor
|
38
|
-
defender = Builder.
|
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
data/lib/move.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
require_relative "database"
|
2
2
|
|
3
3
|
module Pktool
|
4
|
-
class 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.
|
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.
|
25
|
-
type *= type_effect[@defender.type2][self.
|
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
data/lib/party.rb
CHANGED
@@ -6,17 +6,18 @@ module Pktool
|
|
6
6
|
class Party
|
7
7
|
attr_accessor :list
|
8
8
|
|
9
|
-
@@
|
9
|
+
@@party_path = "data/user/"
|
10
10
|
|
11
|
-
def initialize
|
12
|
-
|
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(
|
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
|
-
|
7
|
+
module Pktool
|
8
8
|
|
9
|
-
|
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.
|
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
|
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
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 "
|
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 =
|
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,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.
|
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:
|
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:
|
42
|
+
name: activerecord
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
45
|
- - "~>"
|
46
46
|
- !ruby/object:Gem::Version
|
47
|
-
version: 4.
|
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.
|
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.
|
173
|
+
rubygems_version: 2.4.5
|
168
174
|
signing_key:
|
169
175
|
specification_version: 4
|
170
176
|
summary: ''
|