pazzdra 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: edd5fc05d0712a9934273788e00563e4df439400
4
+ data.tar.gz: d7554ca92bd701fc38fdd222ff56dc9332de085d
5
+ SHA512:
6
+ metadata.gz: 4968043f83dde9c09e9957d56b6bdbbbc5c260ddde4369714e4cb2ba789c7f5e9c74454124ea43019bd0a843ea2a298ffe809222973fb7e96186039890de2934
7
+ data.tar.gz: e40a33f730024443a1f6ebca32a2904daf43423379f73033b869c13f3e31177a59009f6b011f6929f884bc81c5c7c546314d88c2ced86a51cdeb235b3a7e06ae
data/.gitignore ADDED
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in pazzdra.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 takashi.akagi
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,63 @@
1
+ # Pazzdra
2
+
3
+ TODO: Write a gem description
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'pazzdra'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install pazzdra
18
+
19
+ ## Usage
20
+
21
+ このgemはパズドラの攻撃力を計算する計算機です。
22
+
23
+ インストールすると pad_cal コマンドが使えるようになります。
24
+
25
+ $ pad_cal
26
+
27
+ このコマンドは引数として数値を複数取れますが、その場合は単に数値を掛け合わせたものを表示するだけの簡単な計算機です。
28
+
29
+ 引数を指定せずに実行すると対話形式で計算ができます。
30
+
31
+ > help!
32
+
33
+ で使えるコマンドが出ますので、試してみてください。
34
+
35
+ ## 使用例
36
+
37
+ $ pad_calc
38
+ pazzdra calc ver.0.0.1
39
+ > help!
40
+ [1] pry(Pazzdra)> base_1 r: 1200, sub: :g # 1人目の攻撃力 火属性 1200, 副属性は木で登録
41
+ => {:r=>1200, :sub=>:g}
42
+ [2] pry(Pazzdra)> base_2 g: 880, sub: :y # 2人目の攻撃力 火属性 880, 副属性は木で登録
43
+ => {:g=>880, :sub=>:y}
44
+ [3] pry(Pazzdra)> combo_red [3,3] # コンボ赤は 3個が2つ
45
+ => [3, 3]
46
+ [4] pry(Pazzdra)> combo_green [4] # コンボ緑は 4個が1つ
47
+ => [4]
48
+ [5] pry(Pazzdra)> combo_purple [3,3] # コンボ紫は 3個が2つ
49
+ => [3, 3]
50
+ [6] pry(Pazzdra)> show # 結果を表示しろ
51
+ {:base=>[{:r=>1200, :sub=>:g}, {:g=>880, :sub=>:y}], :leader=>1, :friend=>nil, :skill=>nil, :up_drops=>nil, :combo=>{:r=>[3, 3], :g=>[4], :p=>[3, 3]}}
52
+ [{:r=>4800, :sub=>{:g=>1500}}, {:g=>2200, :sub=>{:y=>0}}]
53
+ => [{:r=>4800, :sub=>{:g=>1500}}, {:g=>2200, :sub=>{:y=>0}}] # 計算結果
54
+ [7] pry(Pazzdra)>
55
+
56
+
57
+ ## Contributing
58
+
59
+ 1. Fork it ( http://github.com/<my-github-username>/pazzdra/fork )
60
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
61
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
62
+ 4. Push to the branch (`git push origin my-new-feature`)
63
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
data/bin/pad_calc ADDED
@@ -0,0 +1,98 @@
1
+ #!/usr/bin/env ruby
2
+ #
3
+ # (c)2014 akagi takashi
4
+ #
5
+
6
+ require 'pazzdra'
7
+ require "pry"
8
+
9
+ module Pazzdra
10
+ extend self
11
+
12
+ def run()
13
+ start
14
+ end
15
+
16
+ def start
17
+ init
18
+ print <<EOS
19
+ pazzdra calc ver.#{Pazzdra::VERSION}
20
+ > help!
21
+ EOS
22
+ pry
23
+ end
24
+
25
+ private
26
+ def init
27
+ @base = Pazzdra::Calc.new
28
+ end
29
+
30
+ Pazzdra::Calc.DEFAULT_BASE.keys.each do |key|
31
+ define_method key do |val=nil|
32
+ @base.merge({ key => val }) if val && val > 0
33
+ @base.data[key]
34
+ end
35
+ end
36
+
37
+ [:red, :green, :blue, :yellow, :purple].each do |key_color|
38
+ key = key_color.to_s[0].to_sym
39
+ combo_method_names = ["combo_#{key_color}".to_sym, "combo_#{key}".to_sym]
40
+ define_method combo_method_names[0] do |val=nil|
41
+ @base.data[:combo] = {} if !@base.data[:combo] || @base.data[:combo].is_a?(Numeric)
42
+ @base.data[:combo][key] = val if val
43
+ @base.data[:combo][key]
44
+ end
45
+ alias_method combo_method_names[1].to_sym, combo_method_names[0].to_sym
46
+ end
47
+
48
+ [*1..6].each do |key|
49
+ base_method_names = "base_#{key}".to_sym
50
+ define_method base_method_names do |val=nil|
51
+ @base.data[:base] = [] if !@base.data[:base] || @base.data[:base].is_a?(Numeric)
52
+ @base.data[:base][key-1] = val if val
53
+ @base.data[:base][key-1]
54
+ end
55
+ end
56
+
57
+ def show
58
+ @base.show
59
+ end
60
+
61
+ def help!
62
+ print <<EOS
63
+ # -----
64
+ > init # 入力されたデータを破棄して初期化します
65
+
66
+ # 設定
67
+ > base 99 # 単に数字の場合は1つの値のみ計算
68
+ > base_1 〜 base_6 color: 99, sub: :color
69
+ # 1〜6 の数字で、複数のキャラクターの能力値を指定可能
70
+ # color: は r: g: b: y: p: h: で各色を指定、副属性がある場合は sub: :color で色を指定
71
+ # exp: キャラ1 火属性で攻撃力1000、副属性木。キャラ2 光属性で攻撃力880、副属性闇の場合
72
+ # > base_1 r: 1000, sub: :g
73
+ # > base_2 y: 880, sub: :p
74
+ > leader 99 # リーダースキルによる倍率
75
+ > friend 99 # フレンドスキルによる倍率
76
+ > skill 99 # その他スキルによる倍率
77
+ > combo_red [ 99, ... ] # 火属性のコンボ設定 数字カンマ区切りで何個でも。数字は同時消しの数
78
+ # 3個を1つ、4個を1つ消したら [3,4] となる 略式: combo_r
79
+ > combo_green [ 99, ... ] # 木属性のコンボ設定 以下同文 略式: combo_g
80
+ > combo_blue [ 99, ... ] # 水属性のコンボ設定 以下同文 略式: combo_b
81
+ > combo_yellow [ 99, ... ] # 光属性のコンボ設定 以下同文 略式: combo_y
82
+ > combo_purple [ 99, ... ] # 闇属性のコンボ設定 以下同文 略式: combo_p
83
+ # 結果確認
84
+ > show # 計算結果を表示します
85
+
86
+ # 終了
87
+ > exit # 終了します
88
+ # -----
89
+ EOS
90
+ end
91
+ end
92
+
93
+ if ARGV.count >= 1
94
+ base_pw = ARGV[0].to_i
95
+ puts Pazzdra::Calc.cal(base_pw ,ARGV[1] ,ARGV[2] ,ARGV[3])
96
+ else
97
+ Pazzdra.run
98
+ end
@@ -0,0 +1,119 @@
1
+
2
+ module Pazzdra
3
+ class Calc
4
+ COMBO_UP_BASE = 0.25 # コンボ時の追加倍率(1コンボにつき)
5
+ LENGTH_UP_BASE = 0.25 # 同時消しの長さによる増加率(1個につき)
6
+ DROP_COLORS = [:r,:g,:b,:y,:p,:h] # 色指定のsymbol定義
7
+ attr_accessor :data
8
+ class << Calc
9
+ # 単に引数全てを掛け合わせるだけの簡単なお仕事
10
+ def cal(*ups)
11
+ ups.compact.inject(1){|base, i| base.to_f * i.to_f }.round
12
+ end
13
+ # 何も指定しない場合の値
14
+ def DEFAULT_BASE
15
+ { base: 0, leader: 1, friend: nil, skill: nil, up_drops: nil, combo: nil }
16
+ end
17
+ end
18
+
19
+ def initialize(data=nil)
20
+ self.data = data
21
+ end
22
+
23
+ def data=(data)
24
+ data ||= Calc.DEFAULT_BASE
25
+ @data = data
26
+ end
27
+
28
+ def merge(data={})
29
+ @data.merge!(data)
30
+ end
31
+
32
+ def show
33
+ p @data
34
+ p cal
35
+ end
36
+
37
+ # データを元に計算する
38
+ def cal(data={})
39
+ merge data
40
+ case @data[:base]
41
+ when Numeric
42
+ Calc.cal @data[:base], @data[:leader], @data[:friend], @data[:skill], combo_up_pct
43
+ when Array
44
+ dragons = []
45
+ @data[:base].each do |val|
46
+ dragon = {}
47
+ DROP_COLORS.each do |key|
48
+ next unless val[key]
49
+ dragon[key] = Calc.cal attack_power_with_length_pct(val[key], key),
50
+ @data[:leader], @data[:friend], @data[:skill], combo_up_pct
51
+ next unless val[:sub]
52
+ dragon[:sub] = {}
53
+ dragon[:sub][val[:sub]] = Calc.cal attack_power_with_length_pct((val[key].to_f / 2).to_i, val[:sub]),
54
+ @data[:leader], @data[:friend], @data[:skill], combo_up_pct
55
+ end
56
+ dragons.push(dragon)
57
+ end
58
+ dragons
59
+ end
60
+ end
61
+
62
+ private
63
+ # コンボ数による倍率
64
+ def combo_up_pct
65
+ return 1 unless @data[:combo]
66
+ 1 + ((combo_count - 1) * COMBO_UP_BASE)
67
+ end
68
+
69
+ # コンボ総数
70
+ def combo_count(color=nil)
71
+ case @data[:combo]
72
+ when Numeric
73
+ @data[:combo].to_i
74
+ when Hash
75
+ if color
76
+ return @data[:combo][color].count if @data[:combo][color]
77
+ return 0
78
+ end
79
+ total_count = 0
80
+ DROP_COLORS.each do |key|
81
+ total_count += @data[:combo][key].count if @data[:combo][key]
82
+ end
83
+ total_count
84
+ else
85
+ 1
86
+ end
87
+ end
88
+
89
+ # 繋げた長さを考慮したベース攻撃力
90
+ def attack_power_with_length_pct(base_power, color=nil)
91
+ base_power * length_up_pct(color)
92
+ end
93
+
94
+ # 繋げた長さによる加算倍率
95
+ def length_up_pct(color=nil)
96
+ combo_count(color) + (length_count(color) * LENGTH_UP_BASE)
97
+ end
98
+
99
+ # 繋げた長さ(余剰分)
100
+ def length_count(color=nil)
101
+ return 0 unless color
102
+ case @data[:combo]
103
+ when Numeric
104
+ 0
105
+ when Hash
106
+ return 0 unless @data[:combo][color]
107
+ length_count_sub(@data[:combo][color])
108
+ else
109
+ 0
110
+ end
111
+ end
112
+
113
+ # 配列内の 3 以上の余剰分の数を返す
114
+ def length_count_sub(count_data)
115
+ count_data.inject(0) do |val, i| val += i - 3 end
116
+ end
117
+
118
+ end
119
+ end
@@ -0,0 +1,3 @@
1
+ module Pazzdra
2
+ VERSION = "0.0.1"
3
+ end
data/lib/pazzdra.rb ADDED
@@ -0,0 +1,6 @@
1
+ require "pazzdra/version"
2
+ require "pazzdra/calc"
3
+
4
+ module Pazzdra
5
+
6
+ end
data/pazzdra.gemspec ADDED
@@ -0,0 +1,25 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'pazzdra/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "pazzdra"
8
+ spec.version = Pazzdra::VERSION
9
+ spec.authors = ["takashi.akagi"]
10
+ spec.email = ["nisyu@mac.com"]
11
+ spec.summary = %q{PAZZRU & DRAGONS calc.}
12
+ spec.description = %q{PAZZRU & DRAGONS calc.}
13
+ spec.homepage = "https://github.com/majosystems/pazzdra"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0")
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_development_dependency "bundler", "~> 1.5"
22
+ spec.add_development_dependency "rake"
23
+ spec.add_development_dependency "rspec"
24
+ spec.add_development_dependency "pry"
25
+ end
@@ -0,0 +1,72 @@
1
+
2
+ require 'spec_helper'
3
+ require 'pazzdra'
4
+
5
+ describe Pazzdra, "パズドラ各種計算アプリ" do
6
+ describe Pazzdra::Calc, "攻撃力計算機能" do
7
+ context 'クラスから使用する場合' do
8
+ it "基本の攻撃力のみ" do
9
+ expect(Pazzdra::Calc.cal(1010)).to eq(1010)
10
+ end
11
+
12
+ it "リーダー x フレンド x エンハンス" do
13
+ expect(Pazzdra::Calc.cal(1010,3.5)).to eq(3535)
14
+ expect(Pazzdra::Calc.cal(810,2.5,3.5)).to eq(7088)
15
+ expect(Pazzdra::Calc.cal(1234,2.5,2,1.5)).to eq(9255)
16
+ end
17
+
18
+ it "ドロップ追加" do
19
+ expect(Pazzdra::Calc.cal(1010,3.5,3.5)).to eq(12373)
20
+ end
21
+ end
22
+
23
+ context 'インスタンスで使用する場合' do
24
+ before do
25
+ @calc = Pazzdra::Calc.new
26
+ end
27
+
28
+ subject{ @calc.cal }
29
+ context '基本!' do
30
+ it "リーダーのみ" do
31
+ @calc.merge({ base: 1000, leader: 1.5 })
32
+ should eq 1500
33
+ end
34
+ it "リーダー x フレンド x エンハンス" do
35
+ @calc.merge({ base: 1000, leader: 1.5, friend: 2, skill: 3.5 })
36
+ should eq 10500
37
+ end
38
+ end
39
+ context 'コンボデータ有' do
40
+ it "ベースの色無し、コンボ数指定" do
41
+ @calc.merge({ base: 1000, leader: 2.5, combo: 3 })
42
+ should eq 3750
43
+ end
44
+ it "ベースの色無し、コンボ色指定" do
45
+ @calc.merge({ base: 1000, leader: 2.5, combo: {r: [3], g: [3,4,4], b: [3] } })
46
+ should eq 5000
47
+ end
48
+ it "ベースの色指定、コンボ色指定" do
49
+ @calc.merge({ base: [{r: 1000}], leader: 2.5, combo: {r: [3], g: [3,4,4], b: [3] } })
50
+ should eq [{r: 5000}]
51
+ end
52
+ it "ベースの色指定、コンボ色指定 複数" do
53
+ @calc.merge({ base: [{r: 1000, sub: :r},{b: 1200, sub: :r}], leader: 2.5, combo: {r: [3], g: [3,4,4], b: [3] } })
54
+ should eq [{r: 5000, sub: {r: 2500}},{b: 6000, sub: {r: 3000}}]
55
+ end
56
+ it "ベースの色指定、コンボ色指定 攻撃色が複数" do
57
+ @calc.merge({ base: [{r: 1000}], leader: 2.5, combo: {r: [3, 3], g: [3,4], b: [3] } })
58
+ should eq [{r: 10000}]
59
+ end
60
+ it "ベースの色指定、コンボ色指定 攻撃色が複数、長さ4越え" do
61
+ @calc.merge({ base: [{g: 1200, sub: :g}], leader: 2.5, combo: {r: [3, 3], g: [3,4], b: [3] } })
62
+ should eq [{g: 13500, sub: {g: 6750}}]
63
+ end
64
+ it "ベースの色指定、コンボ色指定 攻撃色が複数、長さ4越え 複数" do
65
+ @calc.merge({ base: [{g: 1200, sub: :g},{y: 1234, sub: :r}], leader: 2.5, friend: 2, skill: 1.5, combo: {r: [3, 3], g: [3,4], b: [3], y: [4, 6] } })
66
+ should eq [{g: 50625, sub: {g: 25313}},{y: 69413, sub: {r: 23138}}]
67
+ end
68
+ end
69
+ end
70
+ end
71
+ end
72
+
@@ -0,0 +1,7 @@
1
+ require 'rubygems'
2
+
3
+ #RSpec::Matchers.define :my_matcher do |expected|
4
+ # match do |actual|
5
+ # true
6
+ # end
7
+ #end
metadata ADDED
@@ -0,0 +1,116 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: pazzdra
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - takashi.akagi
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-04-19 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.5'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.5'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: pry
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ description: PAZZRU & DRAGONS calc.
70
+ email:
71
+ - nisyu@mac.com
72
+ executables:
73
+ - pad_calc
74
+ extensions: []
75
+ extra_rdoc_files: []
76
+ files:
77
+ - ".gitignore"
78
+ - Gemfile
79
+ - LICENSE.txt
80
+ - README.md
81
+ - Rakefile
82
+ - bin/pad_calc
83
+ - lib/pazzdra.rb
84
+ - lib/pazzdra/calc.rb
85
+ - lib/pazzdra/version.rb
86
+ - pazzdra.gemspec
87
+ - spec/pazzdra_spec.rb
88
+ - spec/spec_helper.rb
89
+ homepage: https://github.com/majosystems/pazzdra
90
+ licenses:
91
+ - MIT
92
+ metadata: {}
93
+ post_install_message:
94
+ rdoc_options: []
95
+ require_paths:
96
+ - lib
97
+ required_ruby_version: !ruby/object:Gem::Requirement
98
+ requirements:
99
+ - - ">="
100
+ - !ruby/object:Gem::Version
101
+ version: '0'
102
+ required_rubygems_version: !ruby/object:Gem::Requirement
103
+ requirements:
104
+ - - ">="
105
+ - !ruby/object:Gem::Version
106
+ version: '0'
107
+ requirements: []
108
+ rubyforge_project:
109
+ rubygems_version: 2.2.0
110
+ signing_key:
111
+ specification_version: 4
112
+ summary: PAZZRU & DRAGONS calc.
113
+ test_files:
114
+ - spec/pazzdra_spec.rb
115
+ - spec/spec_helper.rb
116
+ has_rdoc: