pktool 0.2.0 → 0.2.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/lib/attack.rb +66 -0
- data/lib/{builder.rb → cli/builder.rb} +8 -7
- data/lib/{cli.rb → cli/cli.rb} +25 -10
- data/lib/{command → cli/command}/party.rb +2 -2
- data/lib/models/acquisition.rb +13 -0
- data/lib/{database.rb → models/database.rb} +0 -0
- data/lib/models/move.rb +13 -0
- data/lib/{nature.rb → models/nature.rb} +0 -1
- data/lib/{pokemon.rb → models/pokemon.rb} +31 -4
- data/lib/party.rb +5 -6
- data/lib/version.rb +1 -1
- data/pktool.rb +1 -1
- data/spec/attack_spec.rb +75 -0
- data/spec/{pokemon_spec.rb → models/pokemon_spec.rb} +11 -1
- metadata +14 -12
- data/lib/move.rb +0 -52
- data/spec/move_spec.rb +0 -29
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: dcfda98a106cfc380a525ded26be5be7441177fb
|
4
|
+
data.tar.gz: 9dfd17382348141419dd7567ebe362b799c2d248
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7229411c11e02d4e89c3d3e8bf000a37fe16bb433de62d6c8c88cfdb43077f16de1c7e565d2962b833810a63e4f0e9f51c51d29b07bbb5a51ac86701516a8d7b
|
7
|
+
data.tar.gz: 0624e5a6193b1a7b19a1b9375f9c1dff24ecc80a86cc2e1177aa221e9f304559b76d0471bbcb6e6f7962316ac2a4cdf229388472767e37d5fd23ff5f3f3ee1d2
|
data/Gemfile.lock
CHANGED
data/lib/attack.rb
ADDED
@@ -0,0 +1,66 @@
|
|
1
|
+
require_relative "models/move"
|
2
|
+
|
3
|
+
module Pktool
|
4
|
+
|
5
|
+
class Attack
|
6
|
+
def initialize(move, attacker, defender)
|
7
|
+
move = Move.where(name: move).first
|
8
|
+
raise Error, "存在ない技です。" unless move
|
9
|
+
@move = move
|
10
|
+
@attacker = attacker
|
11
|
+
@defender = defender
|
12
|
+
@effects = []
|
13
|
+
@level = 50.0
|
14
|
+
@effect_rate = 1.0
|
15
|
+
@type_match = [attacker.type1, attacker.type2].include?(move.attack_type)
|
16
|
+
@type_rate = 1.0
|
17
|
+
@vital_rate = 1.5
|
18
|
+
end
|
19
|
+
|
20
|
+
def add_effect(effect)
|
21
|
+
end
|
22
|
+
|
23
|
+
def type_effect
|
24
|
+
type_effect = open("data/type.json") do |io|
|
25
|
+
JSON.load(io)
|
26
|
+
end
|
27
|
+
@type_rate *= type_effect[@defender.type1][@move.attack_type]
|
28
|
+
@type_rate *= type_effect[@defender.type2][@move.attack_type] unless @defender.type2.empty?
|
29
|
+
end
|
30
|
+
|
31
|
+
def type_match
|
32
|
+
@type_match ? 1.5 : 1.0
|
33
|
+
end
|
34
|
+
|
35
|
+
def select_move_type
|
36
|
+
case @move.move_type
|
37
|
+
when "物理"
|
38
|
+
@attack_stat = :A
|
39
|
+
@defence_stat = :B
|
40
|
+
when "特殊"
|
41
|
+
@attack_stat = :C
|
42
|
+
@defence_stat = :D
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
def fetch_base_damage
|
47
|
+
((@move.power * @attacker.effected_statistics(@attack_stat) * (@level * 2.0 / 5.0 + 2.0 )) / @defender.effected_statistics(@defence_stat) / 50.0 * @effect_rate * type_match + 2.0) * @type_rate
|
48
|
+
end
|
49
|
+
|
50
|
+
def damage
|
51
|
+
type_effect
|
52
|
+
select_move_type
|
53
|
+
base = fetch_base_damage
|
54
|
+
min = base * 0.85
|
55
|
+
max = base * 1.0
|
56
|
+
{min: min.floor, max: max.floor}
|
57
|
+
end
|
58
|
+
|
59
|
+
def defeat
|
60
|
+
hp = @defender.statistics(:H)
|
61
|
+
return {num: (hp.to_f / damage[:min]).ceil, rate: (damage[:min] / hp.to_f)}
|
62
|
+
end
|
63
|
+
|
64
|
+
end
|
65
|
+
|
66
|
+
end
|
@@ -1,8 +1,9 @@
|
|
1
|
-
require_relative 'pokemon'
|
2
|
-
require_relative "nature"
|
3
|
-
require_relative '
|
4
|
-
require_relative '
|
5
|
-
require_relative '
|
1
|
+
require_relative '../models/pokemon'
|
2
|
+
require_relative "../models/nature"
|
3
|
+
require_relative '../models/move'
|
4
|
+
require_relative '../attack'
|
5
|
+
require_relative '../party'
|
6
|
+
require_relative '../log'
|
6
7
|
|
7
8
|
module Pktool
|
8
9
|
|
@@ -49,10 +50,10 @@ module Pktool
|
|
49
50
|
return Pokemon.fetch(name, feature)
|
50
51
|
end
|
51
52
|
|
52
|
-
def self.
|
53
|
+
def self.attack(attacker, defender)
|
53
54
|
moves = Move.pluck(:name)
|
54
55
|
move = fetch("わざ", moves)
|
55
|
-
|
56
|
+
Attack.new(move, attacker, defender)
|
56
57
|
end
|
57
58
|
|
58
59
|
def self.fetch(name, completion = [])
|
data/lib/{cli.rb → cli/cli.rb}
RENAMED
@@ -2,12 +2,12 @@ require 'thor'
|
|
2
2
|
require 'thor/group'
|
3
3
|
require 'romaji'
|
4
4
|
require 'romaji/core_ext/string'
|
5
|
-
require_relative "log"
|
6
|
-
require_relative "version"
|
7
|
-
require_relative "pokemon"
|
8
|
-
require_relative "move"
|
9
5
|
require_relative "builder"
|
10
|
-
require_relative "
|
6
|
+
require_relative "../log"
|
7
|
+
require_relative "../version"
|
8
|
+
require_relative "../exceptions"
|
9
|
+
require_relative "../models/pokemon"
|
10
|
+
require_relative "../models/move"
|
11
11
|
|
12
12
|
Dir.glob(File.expand_path(File.join(File.dirname(__FILE__), "command", "*.rb"))) do |path|
|
13
13
|
require path
|
@@ -26,8 +26,13 @@ module Pktool
|
|
26
26
|
puts "<underline>種族値</underline>".termcolor
|
27
27
|
puts pokemon.base_stat.map{|k,v| "<bold>#{k}</bold>:<red>#{v}</red> ".termcolor}.join
|
28
28
|
puts "<underline>相性</underline>".termcolor
|
29
|
-
puts pokemon.types.select{|k,v| v
|
30
|
-
puts pokemon.types.select{|k,v| v
|
29
|
+
puts "4.0: " + pokemon.types.select{|k,v| v == 4.00 }.map{|k,v| "<red>#{k}</red>".termcolor}.join
|
30
|
+
puts "2.0: " + pokemon.types.select{|k,v| v == 2.00 }.map{|k,v| "<red>#{k}</red>".termcolor}.join
|
31
|
+
puts "1.0: " + pokemon.types.select{|k,v| v == 1.00 }.map{|k,v| "#{k}".termcolor}.join
|
32
|
+
puts "1/2: " + pokemon.types.select{|k,v| v == 0.50 }.map{|k,v| "<blue>#{k}</blue>".termcolor}.join
|
33
|
+
puts "1/4: " + pokemon.types.select{|k,v| v == 0.25 }.map{|k,v| "<blue>#{k}</blue>".termcolor}.join
|
34
|
+
puts ""
|
35
|
+
power(pokemon)
|
31
36
|
end
|
32
37
|
|
33
38
|
desc "status", "ポケモンのステータスを見る"
|
@@ -42,6 +47,16 @@ module Pktool
|
|
42
47
|
puts pokemon.types.select{|k,v| v < 1 }.map{|k,v| "<bold>#{k}</bold>:<blue>#{v}</blue> ".termcolor}.join
|
43
48
|
end
|
44
49
|
|
50
|
+
desc "power", "ポケモンのタイプ別の威力を見る"
|
51
|
+
def power(pokemon = Builder.default_pokemon)
|
52
|
+
pokemon.type_ranked_moves.each do |kind, moves|
|
53
|
+
puts "<underline>#{kind}</underline>".termcolor
|
54
|
+
moves.each do |move|
|
55
|
+
puts "<bold>#{move.attack_type}</bold> 威力:#{'%3d' % move.power} 命中:#{'%3d' % move.accuracy} #{move.name}".termcolor
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
45
60
|
desc "damage", "ダメージ計算する"
|
46
61
|
def damage
|
47
62
|
puts "<underline>攻撃側の指定</underline>".termcolor
|
@@ -51,7 +66,7 @@ module Pktool
|
|
51
66
|
defender = Builder.new_pokemon
|
52
67
|
|
53
68
|
puts "<underline>技の指定</underline>".termcolor
|
54
|
-
|
69
|
+
attack = Builder.attack(attacker, defender)
|
55
70
|
|
56
71
|
puts ""
|
57
72
|
puts "<underline>攻撃側</underline>".termcolor
|
@@ -59,8 +74,8 @@ module Pktool
|
|
59
74
|
puts "<underline>防御側</underline>".termcolor
|
60
75
|
puts defender.name + " " + defender.stats.map{|k,v| "<bold>#{k}</bold>:<blue>#{v}</blue> ".termcolor}.join
|
61
76
|
puts
|
62
|
-
puts
|
63
|
-
defeat =
|
77
|
+
puts attack.damage.map{|k,v| "<bold>#{k}</bold>:<blue>#{v}</blue> ".termcolor}.join
|
78
|
+
defeat = attack.defeat
|
64
79
|
puts "<bold>確定数</bold>:<red>#{defeat[:num]}回</red> (#{'%.2f' % (defeat[:rate] * 100)}%) ".termcolor
|
65
80
|
|
66
81
|
end
|
File without changes
|
data/lib/models/move.rb
ADDED
@@ -1,12 +1,15 @@
|
|
1
1
|
require 'json'
|
2
2
|
require_relative "database"
|
3
|
-
require_relative "exceptions"
|
4
3
|
require_relative "nature"
|
4
|
+
require_relative "acquisition"
|
5
|
+
require_relative "move"
|
5
6
|
|
6
7
|
|
7
8
|
module Pktool
|
8
9
|
|
9
10
|
class Pokemon < ActiveRecord::Base
|
11
|
+
has_many :acquisitions
|
12
|
+
has_many :moves, through: :acquisitions
|
10
13
|
|
11
14
|
attr_accessor :nature, :effort_value, :individual_value, :ability, :item
|
12
15
|
attr_accessor :description
|
@@ -38,6 +41,7 @@ module Pktool
|
|
38
41
|
@ability = feature[:ability] || 1
|
39
42
|
@item = feature[:item] || ""
|
40
43
|
@level = feature[:level] || 50
|
44
|
+
@rank = feature[:rank] || 1
|
41
45
|
|
42
46
|
if effort_value.instance_of?(Symbol) && @@ways.include?(effort_value)
|
43
47
|
case effort_value
|
@@ -77,13 +81,36 @@ module Pktool
|
|
77
81
|
[:H, :A, :B, :C, :D, :S].map { |name| [name, statistics(name)]}.to_h
|
78
82
|
end
|
79
83
|
|
84
|
+
def effected_statistics(name)
|
85
|
+
effected = statistics(name)
|
86
|
+
effected *= rank_effect
|
87
|
+
effected *= 1.5 if name == :A && @item == "こだわりハチマキ"
|
88
|
+
effected *= 1.5 if name == :C && @item == "こだわりメガネ"
|
89
|
+
|
90
|
+
effected
|
91
|
+
end
|
92
|
+
|
93
|
+
def rank_effect
|
94
|
+
if @rank == 1
|
95
|
+
1.0
|
96
|
+
else
|
97
|
+
@rank > 0 ? (@rank.abs + 2.0) / 2.0 : 2.0 / (@rank.abs + 2.0)
|
98
|
+
end
|
99
|
+
end
|
100
|
+
|
80
101
|
def types
|
81
102
|
type_effect = open("data/type.json") do |io|
|
82
103
|
JSON.load(io)
|
83
104
|
end
|
84
|
-
Hash[type_effect.keys.map
|
85
|
-
|
86
|
-
|
105
|
+
Hash[type_effect.keys.map { |t| [t, type_effect[type1][t] * (type2.present? ? type_effect[type2][t]: 1.0)] }]
|
106
|
+
end
|
107
|
+
|
108
|
+
def type_ranked_moves
|
109
|
+
list = moves.group("move_type, attack_type").having("max(power)").order("power desc")
|
110
|
+
{
|
111
|
+
"物理": list.where(move_type: "物理"),
|
112
|
+
"特殊": list.where(move_type: "特殊"),
|
113
|
+
}
|
87
114
|
end
|
88
115
|
|
89
116
|
def to_h
|
data/lib/party.rb
CHANGED
@@ -1,23 +1,22 @@
|
|
1
1
|
require 'json'
|
2
|
-
require_relative "pokemon"
|
2
|
+
require_relative "models/pokemon"
|
3
3
|
|
4
4
|
module Pktool
|
5
5
|
|
6
6
|
class Party
|
7
7
|
attr_accessor :list
|
8
8
|
|
9
|
-
@@
|
9
|
+
@@json_path = "data/user/party.json"
|
10
10
|
|
11
|
-
def initialize
|
12
|
-
|
13
|
-
json = open(@file_path) do |io|
|
11
|
+
def initialize
|
12
|
+
json = open(@@json_path) do |io|
|
14
13
|
JSON.load(io, nil, { symbolize_names: true})
|
15
14
|
end
|
16
15
|
@list = json.map {|j| Pokemon.fetch(j[:name], j)}
|
17
16
|
end
|
18
17
|
|
19
18
|
def save
|
20
|
-
open(
|
19
|
+
open(@@json_path, 'w') do |io|
|
21
20
|
JSON.dump(@list.map{|p| p.to_h}, io)
|
22
21
|
end
|
23
22
|
end
|
data/lib/version.rb
CHANGED
data/pktool.rb
CHANGED
data/spec/attack_spec.rb
ADDED
@@ -0,0 +1,75 @@
|
|
1
|
+
require_relative '../lib/attack'
|
2
|
+
require_relative '../lib/models/pokemon'
|
3
|
+
|
4
|
+
include Pktool
|
5
|
+
|
6
|
+
describe "Move" do
|
7
|
+
|
8
|
+
it "should calculate the damage without any aditional condition in case #1" do
|
9
|
+
attacker = Pokemon.fetch("ガブリアス", {nature: :いじっぱり, effort_value: :hAS})
|
10
|
+
defender = Pokemon.fetch("カビゴン", {nature: :ずぶとい, effort_value: :HB})
|
11
|
+
a = Attack.new("げきりん", attacker, defender)
|
12
|
+
|
13
|
+
expect(a.damage).to eq({min: 106, max: 125})
|
14
|
+
end
|
15
|
+
|
16
|
+
it "should calculate the damage without any aditional condition in case #2" do
|
17
|
+
attacker = Pokemon.fetch("ガブリアス", {nature: :いじっぱり, effort_value: :hAS})
|
18
|
+
defender = Pokemon.fetch("クレセリア", {nature: :ずぶとい, effort_value: :HB})
|
19
|
+
a = Attack.new("げきりん", attacker, defender)
|
20
|
+
|
21
|
+
expect(a.damage).to eq({min: 72, max: 85})
|
22
|
+
end
|
23
|
+
|
24
|
+
it "should calculate the damage with type effect" do
|
25
|
+
attacker = Pokemon.fetch("ボーマンダ", {nature: :いじっぱり, effort_value: :hAS})
|
26
|
+
defender = Pokemon.fetch("ナットレイ", {nature: :ずぶとい, effort_value: :HB})
|
27
|
+
a = Attack.new("だいもんじ", attacker, defender)
|
28
|
+
|
29
|
+
expect(a.damage).to eq({min: 148, max: 174})
|
30
|
+
# pokemon-trainer: expect(m.damage(attacker, defender)).to eq({min: 144, max: 172})
|
31
|
+
end
|
32
|
+
|
33
|
+
it "should calculate the damage without any aditional condition in case #1" do
|
34
|
+
attacker = Pokemon.fetch("ガブリアス", {nature: :いじっぱり, effort_value: :hAS})
|
35
|
+
defender = Pokemon.fetch("カビゴン", {nature: :ずぶとい, effort_value: :HB})
|
36
|
+
a = Attack.new("げきりん", attacker, defender)
|
37
|
+
|
38
|
+
expect(a.damage).to eq({min: 106, max: 125})
|
39
|
+
end
|
40
|
+
|
41
|
+
it "should calculate the damage with attack rank 2" do
|
42
|
+
attacker = Pokemon.fetch("ガブリアス", {nature: :いじっぱり, effort_value: :hAS, rank: 2})
|
43
|
+
defender = Pokemon.fetch("クレセリア", {nature: :ずぶとい, effort_value: :HB})
|
44
|
+
a = Attack.new("げきりん", attacker, defender)
|
45
|
+
|
46
|
+
expect(a.damage).to eq({min: 144, max: 169})
|
47
|
+
end
|
48
|
+
|
49
|
+
it "should calculate the damage with defence rank 2" do
|
50
|
+
attacker = Pokemon.fetch("ガブリアス", {nature: :いじっぱり, effort_value: :hAS})
|
51
|
+
defender = Pokemon.fetch("クレセリア", {nature: :ずぶとい, effort_value: :HB, rank: 2})
|
52
|
+
a = Attack.new("げきりん", attacker, defender)
|
53
|
+
|
54
|
+
expect(a.damage).to eq({min: 37, max: 43})
|
55
|
+
# pokemon-trainer: expect(a.damage).to eq({min: 36, max: 43})
|
56
|
+
end
|
57
|
+
|
58
|
+
it "should calculate the damage with こだわりハチマキ" do
|
59
|
+
attacker = Pokemon.fetch("ガブリアス", {nature: :いじっぱり, effort_value: :hAS, item: "こだわりハチマキ"})
|
60
|
+
defender = Pokemon.fetch("クレセリア", {nature: :ずぶとい, effort_value: :HB})
|
61
|
+
a = Attack.new("げきりん", attacker, defender)
|
62
|
+
|
63
|
+
expect(a.damage).to eq({min: 108, max: 127})
|
64
|
+
# pokemon-trainer: expect(a.damage).to eq({min: 36, max: 43})
|
65
|
+
end
|
66
|
+
|
67
|
+
it "should calculate the damage with こだわりハチマキ" do
|
68
|
+
attacker = Pokemon.fetch("ラティオス", {nature: :ひかえめ, effort_value: :hCS, item: "こだわりメガネ"})
|
69
|
+
defender = Pokemon.fetch("クレセリア", {nature: :ずぶとい, effort_value: :HB})
|
70
|
+
a = Attack.new("りゅうせいぐん", attacker, defender)
|
71
|
+
|
72
|
+
expect(a.damage).to eq({min: 147, max: 173})
|
73
|
+
# pokemon-trainer: expect(a.damage).to eq({min: 147, max: 174})
|
74
|
+
end
|
75
|
+
end
|
@@ -1,4 +1,4 @@
|
|
1
|
-
require_relative '
|
1
|
+
require_relative '../../lib/models/pokemon.rb'
|
2
2
|
|
3
3
|
include Pktool
|
4
4
|
|
@@ -39,5 +39,15 @@ describe "Pokemon" do
|
|
39
39
|
p = Pokemon.fetch("ガブリアス", {nature: :いじっぱり, effort_value: :hAS})
|
40
40
|
expect(p.types["氷"]).to eq(4)
|
41
41
|
end
|
42
|
+
|
43
|
+
it "should has moves list" do
|
44
|
+
p = Pokemon.fetch("ガブリアス", {nature: :いじっぱり, effort_value: :hAS})
|
45
|
+
expect(p.moves.pluck(:name)).to include("げきりん")
|
46
|
+
end
|
47
|
+
|
48
|
+
it "should has moves list" do
|
49
|
+
p = Pokemon.fetch("ガブリアス", {nature: :いじっぱり, effort_value: :hAS})
|
50
|
+
expect(p.type_ranked_moves[:物理].find_by_attack_type("地").name).to include("じしん")
|
51
|
+
end
|
42
52
|
end
|
43
53
|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: pktool
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- uzimith
|
@@ -129,22 +129,24 @@ files:
|
|
129
129
|
- data/pokemonData.sqlite
|
130
130
|
- data/type.json
|
131
131
|
- data/user/party.json
|
132
|
-
- lib/
|
133
|
-
- lib/cli.rb
|
134
|
-
- lib/
|
135
|
-
- lib/
|
132
|
+
- lib/attack.rb
|
133
|
+
- lib/cli/builder.rb
|
134
|
+
- lib/cli/cli.rb
|
135
|
+
- lib/cli/command/party.rb
|
136
136
|
- lib/exceptions.rb
|
137
137
|
- lib/log.rb
|
138
|
-
- lib/
|
139
|
-
- lib/
|
138
|
+
- lib/models/acquisition.rb
|
139
|
+
- lib/models/database.rb
|
140
|
+
- lib/models/move.rb
|
141
|
+
- lib/models/nature.rb
|
142
|
+
- lib/models/pokemon.rb
|
140
143
|
- lib/party.rb
|
141
144
|
- lib/pktool.rb
|
142
|
-
- lib/pokemon.rb
|
143
145
|
- lib/version.rb
|
144
146
|
- pktool.gemspec
|
145
147
|
- pktool.rb
|
146
|
-
- spec/
|
147
|
-
- spec/pokemon_spec.rb
|
148
|
+
- spec/attack_spec.rb
|
149
|
+
- spec/models/pokemon_spec.rb
|
148
150
|
- spec/spec_helper.rb
|
149
151
|
- tool/create_pokemon_db/.gitignore
|
150
152
|
- tool/create_pokemon_db/Gemfile
|
@@ -175,6 +177,6 @@ signing_key:
|
|
175
177
|
specification_version: 4
|
176
178
|
summary: ''
|
177
179
|
test_files:
|
178
|
-
- spec/
|
179
|
-
- spec/pokemon_spec.rb
|
180
|
+
- spec/attack_spec.rb
|
181
|
+
- spec/models/pokemon_spec.rb
|
180
182
|
- spec/spec_helper.rb
|
data/lib/move.rb
DELETED
@@ -1,52 +0,0 @@
|
|
1
|
-
require_relative "database"
|
2
|
-
|
3
|
-
module Pktool
|
4
|
-
class Move < ActiveRecord::Base
|
5
|
-
attr_accessor :attacker, :defender
|
6
|
-
|
7
|
-
def self.fetch(name, attacker, defender)
|
8
|
-
move = self.where(name: name).first
|
9
|
-
raise Error, "存在ない技です。" unless move
|
10
|
-
move.attacker = attacker
|
11
|
-
move.defender = defender
|
12
|
-
return move
|
13
|
-
end
|
14
|
-
|
15
|
-
def damage
|
16
|
-
level = 50.0
|
17
|
-
effect = 1.0
|
18
|
-
effect *= 1.5 if [@attacker.type1, @attacker.type2].include?(self.attack_type)
|
19
|
-
|
20
|
-
# type effect
|
21
|
-
type_effect = open("data/type.json") do |io|
|
22
|
-
JSON.load(io)
|
23
|
-
end
|
24
|
-
type = 1.0
|
25
|
-
type *= type_effect[@defender.type1][self.attack_type]
|
26
|
-
type *= type_effect[@defender.type2][self.attack_type] unless @defender.type2.empty?
|
27
|
-
|
28
|
-
vital = 1.0
|
29
|
-
case move_type
|
30
|
-
when "物理"
|
31
|
-
attack_stat = :A
|
32
|
-
defence_stat = :B
|
33
|
-
when "特殊"
|
34
|
-
attack_stat = :C
|
35
|
-
defence_stat = :D
|
36
|
-
end
|
37
|
-
# todo: this equation may be mistake.
|
38
|
-
base = ((power * @attacker.statistics(attack_stat) * (level * 2.0 / 5.0 + 2.0 )) / @defender.statistics(defence_stat) / 50.0 * effect + 2.0) * type
|
39
|
-
min = base * vital * 0.85
|
40
|
-
max = base * vital * 1.0
|
41
|
-
{min: min.floor, max: max.floor}
|
42
|
-
end
|
43
|
-
|
44
|
-
def defeat
|
45
|
-
hp = @defender.statistics(:H)
|
46
|
-
damage = self.damage
|
47
|
-
return {num: (hp.to_f / damage[:min]).ceil, rate: (damage[:min] / hp.to_f)}
|
48
|
-
end
|
49
|
-
|
50
|
-
end
|
51
|
-
|
52
|
-
end
|
data/spec/move_spec.rb
DELETED
@@ -1,29 +0,0 @@
|
|
1
|
-
require_relative '../lib/move.rb'
|
2
|
-
require_relative '../lib/pokemon.rb'
|
3
|
-
|
4
|
-
include Pktool
|
5
|
-
|
6
|
-
describe "Move" do
|
7
|
-
|
8
|
-
it "should calculate the damage without any aditional condition in case #1" do
|
9
|
-
attacker = Pokemon.fetch("ガブリアス", {nature: :いじっぱり, effort_value: :hAS})
|
10
|
-
defender = Pokemon.fetch("カビゴン", {nature: :ずぶとい, effort_value: :HB})
|
11
|
-
m = Move.fetch("げきりん", attacker, defender)
|
12
|
-
expect(m.damage).to eq({min: 106, max: 125})
|
13
|
-
end
|
14
|
-
|
15
|
-
it "should calculate the damage without any aditional condition in case #2" do
|
16
|
-
attacker = Pokemon.fetch("ガブリアス", {nature: :いじっぱり, effort_value: :hAS})
|
17
|
-
defender = Pokemon.fetch("クレセリア", {nature: :ずぶとい, effort_value: :HB})
|
18
|
-
m = Move.fetch("げきりん", attacker, defender)
|
19
|
-
expect(m.damage).to eq({min: 72, max: 85})
|
20
|
-
end
|
21
|
-
|
22
|
-
it "should calculate the damage with type effect" do
|
23
|
-
attacker = Pokemon.fetch("ボーマンダ", {nature: :いじっぱり, effort_value: :hAS})
|
24
|
-
defender = Pokemon.fetch("ナットレイ", {nature: :ずぶとい, effort_value: :HB})
|
25
|
-
m = Move.fetch("だいもんじ", attacker, defender)
|
26
|
-
# expect(m.damage(attacker, defender)).to eq({min: 144, max: 172})
|
27
|
-
expect(m.damage).to eq({min: 148, max: 174})
|
28
|
-
end
|
29
|
-
end
|