RpgTools 0.4.2 → 0.4.3
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 +4 -4
- data/lib/rpg_tools/coin.rb +18 -6
- data/lib/rpg_tools/dice.rb +30 -27
- data/lib/rpg_tools/dice_bag.rb +23 -15
- data/lib/rpg_tools/playing_card_deck.rb +13 -8
- data/rpg_tools.gemspec +3 -3
- data/spec/dice_spec.rb +6 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e037b7e017f13328353e5ace03a8e1b632277562
|
4
|
+
data.tar.gz: ef936dccbdcc627153014df1e9fcda723a1ee063
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: be88a1803c9d1b098a6c7741f868329f3730a7dcc52470fc5af37bb595285816285c9bc63a4527f442cec3de3319f99c7015da0da1c40b45333c0c050b3e870a
|
7
|
+
data.tar.gz: 9f494f144a2187090ff63371463fcc4910ebe8ee031606e9fc7f1ce670630139c0c3d08281021805aa86eaa7a9b4bafc331d2c087037395a50a6a0a00f4943a0
|
data/lib/rpg_tools/coin.rb
CHANGED
@@ -3,18 +3,30 @@ module RpgTools
|
|
3
3
|
attr_accessor :value, :flips, :heads, :tails
|
4
4
|
|
5
5
|
def initialize
|
6
|
-
@value = nil
|
7
|
-
@flips = 0
|
8
|
-
@heads = 0
|
9
|
-
@tails = 0
|
6
|
+
@value, @flips, @heads, @tails = nil, 0, 0, 0
|
10
7
|
end
|
11
8
|
|
12
9
|
def flip
|
13
10
|
@flips += 1
|
14
11
|
@value = rand(2) == 1 ? 'Heads' : 'Tails'
|
15
|
-
|
16
|
-
@tails += 1 if @value == 'Tails'
|
12
|
+
save_result
|
17
13
|
@value
|
18
14
|
end
|
15
|
+
alias_method :flip!, :flip
|
16
|
+
|
17
|
+
private
|
18
|
+
|
19
|
+
def save_result
|
20
|
+
@heads += 1 if heads?
|
21
|
+
@tails += 1 if tails?
|
22
|
+
end
|
23
|
+
|
24
|
+
def heads?
|
25
|
+
@value == 'Heads'
|
26
|
+
end
|
27
|
+
|
28
|
+
def tails?
|
29
|
+
@value == 'Tails'
|
30
|
+
end
|
19
31
|
end
|
20
32
|
end
|
data/lib/rpg_tools/dice.rb
CHANGED
@@ -3,39 +3,38 @@ module RpgTools
|
|
3
3
|
attr_accessor :base, :sides, :value, :type, :rolls, :bonus, :malus
|
4
4
|
|
5
5
|
def initialize(base)
|
6
|
-
@base = base
|
7
|
-
|
6
|
+
@base = base.upcase
|
7
|
+
@type = fudge_dice? ? 'Fudge' : 'Standard'
|
8
8
|
@value = nil
|
9
|
-
@
|
10
|
-
@sides = @type == 'Fudge' ? 3 : base.gsub(/^./, '').to_i
|
11
|
-
sides_check
|
9
|
+
@sides = fudge_dice? ? 3 : base.gsub(/^./, '').to_i
|
12
10
|
@rolls = 0
|
13
|
-
|
11
|
+
|
12
|
+
dice_validity_check
|
13
|
+
set_modifiers_and_clean_base unless fudge_dice?
|
14
14
|
end
|
15
15
|
|
16
16
|
def roll
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
return roll_with_malus if @bonus.nil?
|
17
|
+
@rolls += 1
|
18
|
+
|
19
|
+
fudge_dice? ? fudge_roll : standard_roll
|
21
20
|
end
|
21
|
+
alias_method :roll!, :roll
|
22
22
|
|
23
23
|
private
|
24
24
|
|
25
|
+
def dice_validity_check
|
26
|
+
sides_check
|
27
|
+
base_check
|
28
|
+
end
|
29
|
+
|
25
30
|
def modifier_check
|
26
|
-
|
31
|
+
if (@base =~ /^[D]\d+[+-]?\d*/).nil?
|
27
32
|
raise ArgumentError.new("You can only use + or - as modifiers.")
|
28
33
|
end
|
29
34
|
end
|
30
35
|
|
31
|
-
def set_modifiers
|
32
|
-
modifier_check
|
33
|
-
@bonus = (@base =~ /[Dd]\d+\+(\d+)/).nil? ? nil : @base.gsub(/[Dd]\d+\+/, '').to_i
|
34
|
-
@malus = (@base =~ /[Dd]\d+\-(\d+)/).nil? ? nil : @base.gsub(/[Dd]\d+\-/, '').to_i
|
35
|
-
end
|
36
|
-
|
37
36
|
def base_check
|
38
|
-
unless
|
37
|
+
unless standard_dice? || fudge_dice?
|
39
38
|
raise ArgumentError.new("You can only create strandard and fudge dices.")
|
40
39
|
end
|
41
40
|
end
|
@@ -46,24 +45,28 @@ module RpgTools
|
|
46
45
|
end
|
47
46
|
end
|
48
47
|
|
48
|
+
def set_modifiers_and_clean_base
|
49
|
+
modifier_check
|
50
|
+
|
51
|
+
@bonus = @base.gsub(/[D]\d+\+/, '').to_i
|
52
|
+
@malus = @base.gsub(/[D]\d+\-/, '').to_i
|
53
|
+
@base.gsub!(/[+-]\d+/ , '')
|
54
|
+
end
|
55
|
+
|
49
56
|
def fudge_roll
|
50
|
-
@rolls += 1
|
51
57
|
@value = (rand(1..3) - 2)
|
52
58
|
end
|
53
59
|
|
54
60
|
def standard_roll
|
55
|
-
@
|
56
|
-
@value = rand(1..@sides)
|
61
|
+
@value = rand(1..@sides) + @bonus - @malus
|
57
62
|
end
|
58
63
|
|
59
|
-
def
|
60
|
-
@
|
61
|
-
@value = rand(1..@sides) + @bonus
|
64
|
+
def fudge_dice?
|
65
|
+
@base == 'DF'
|
62
66
|
end
|
63
67
|
|
64
|
-
def
|
65
|
-
@
|
66
|
-
@value = rand(1..@sides) - @malus
|
68
|
+
def standard_dice?
|
69
|
+
@base.gsub(/^D\d*[+-]?[\d]+$/, '').empty?
|
67
70
|
end
|
68
71
|
end
|
69
72
|
end
|
data/lib/rpg_tools/dice_bag.rb
CHANGED
@@ -3,26 +3,18 @@ module RpgTools
|
|
3
3
|
attr_accessor :base, :dices, :rolls, :set, :total
|
4
4
|
|
5
5
|
def initialize(base)
|
6
|
-
@base = base
|
7
|
-
@dices = set_bag_content(@base.gsub(/[
|
6
|
+
@base = base.upcase
|
7
|
+
@dices = set_bag_content(@base.gsub(/[D].+/, '').to_i)
|
8
8
|
@rolls = 0
|
9
|
-
@set =
|
9
|
+
@set = []
|
10
10
|
@total = 0
|
11
11
|
end
|
12
12
|
|
13
13
|
def roll
|
14
|
-
@
|
15
|
-
|
16
|
-
end
|
17
|
-
|
18
|
-
@set = [].tap do |response|
|
19
|
-
@dices.each do |dice|
|
20
|
-
response << dice.value
|
21
|
-
end
|
22
|
-
end
|
23
|
-
@total = @set.inject{ |sum, x| sum + x }
|
24
|
-
@set
|
14
|
+
@set = roll_dices_set
|
15
|
+
calculate_total_and_show_set
|
25
16
|
end
|
17
|
+
alias_method :roll!, :roll
|
26
18
|
|
27
19
|
private
|
28
20
|
|
@@ -34,11 +26,27 @@ module RpgTools
|
|
34
26
|
|
35
27
|
def set_bag_content(dice_number)
|
36
28
|
empty_bag_check(dice_number)
|
29
|
+
|
37
30
|
[].tap do |bag|
|
38
|
-
dice_number.times do
|
31
|
+
dice_number.times do
|
39
32
|
bag << Dice.new(@base.gsub(/^\d+/, ''))
|
40
33
|
end
|
41
34
|
end
|
42
35
|
end
|
36
|
+
|
37
|
+
def roll_dices_set
|
38
|
+
@dices.each do |dice|
|
39
|
+
dice.roll
|
40
|
+
end
|
41
|
+
|
42
|
+
@dices.each_with_object([]) do |dice, response|
|
43
|
+
response << dice.value
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
def calculate_total_and_show_set
|
48
|
+
@total = @set.inject{ |sum, x| sum + x }
|
49
|
+
@set
|
50
|
+
end
|
43
51
|
end
|
44
52
|
end
|
@@ -11,18 +11,24 @@ module RpgTools
|
|
11
11
|
|
12
12
|
def card
|
13
13
|
@card_picks += 1
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
14
|
+
|
15
|
+
@value =
|
16
|
+
if @type == 52
|
17
|
+
joker_picked? ? 'Joker' : standard_card
|
18
|
+
else
|
19
|
+
standard_card
|
20
|
+
end
|
19
21
|
end
|
20
22
|
|
21
23
|
def hand
|
22
24
|
[].tap do |hand|
|
23
25
|
until hand.count == 5
|
24
26
|
card = standard_card
|
25
|
-
|
27
|
+
|
28
|
+
unless hand.include?(card) || hand.count('Joker') == 2
|
29
|
+
hand << card
|
30
|
+
@card_picks += 1
|
31
|
+
end
|
26
32
|
end
|
27
33
|
end
|
28
34
|
end
|
@@ -35,7 +41,7 @@ module RpgTools
|
|
35
41
|
end
|
36
42
|
end
|
37
43
|
|
38
|
-
def
|
44
|
+
def joker_picked?
|
39
45
|
[0, 1].include?((0..54).to_a.sample(1).first)
|
40
46
|
end
|
41
47
|
|
@@ -52,7 +58,6 @@ module RpgTools
|
|
52
58
|
end
|
53
59
|
|
54
60
|
def standard_card
|
55
|
-
@card_picks += 1
|
56
61
|
@value = [number, color].join(' of ')
|
57
62
|
end
|
58
63
|
end
|
data/rpg_tools.gemspec
CHANGED
@@ -1,10 +1,10 @@
|
|
1
1
|
Gem::Specification.new do |s|
|
2
2
|
s.name = %q{RpgTools}
|
3
|
-
s.version = '0.4.
|
3
|
+
s.version = '0.4.3'
|
4
4
|
s.author = 'Yohan Piron'
|
5
5
|
s.email = 'yinfei84@gmail.com'
|
6
|
-
s.date =
|
7
|
-
s.summary =
|
6
|
+
s.date = '2015-08-03'
|
7
|
+
s.summary = 'RpgTools is a toolbox for tabletop games and RPGs'
|
8
8
|
s.description = 'RpgTools gives you tools for your RPGs : dices, coins, cards...'
|
9
9
|
s.homepage = 'https://github.com/Yinfei/rpg_tools.git'
|
10
10
|
s.license = 'MIT'
|
data/spec/dice_spec.rb
CHANGED
@@ -35,4 +35,10 @@ describe RpgTools::Dice do
|
|
35
35
|
it "doesn't create a dice with an odd symbol" do
|
36
36
|
expect { described_class.new('d6%2') }.to raise_error(ArgumentError)
|
37
37
|
end
|
38
|
+
|
39
|
+
it "doesn't create very odd dices" do
|
40
|
+
expect { described_class.new('dDOGE') }.to raise_error(ArgumentError)
|
41
|
+
expect { described_class.new('dfoo') }.to raise_error(ArgumentError)
|
42
|
+
expect { described_class.new('foobarbaz') }.to raise_error(ArgumentError)
|
43
|
+
end
|
38
44
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: RpgTools
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.4.
|
4
|
+
version: 0.4.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Yohan Piron
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-03
|
11
|
+
date: 2015-08-03 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rake
|