mythal 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 +5 -5
- data/README.md +25 -0
- data/config.yml +49 -0
- data/lib/mythal.rb +9 -2
- data/lib/mythal/config.rb +34 -0
- data/lib/mythal/npc.rb +9 -50
- data/lib/mythal/roll.rb +52 -17
- data/lib/mythal/version.rb +1 -1
- metadata +5 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: '0755594699c3e8ada4db324d5b88d181c0c6d9b3f1c1d04c3bdd64e14cbeffdc'
|
4
|
+
data.tar.gz: '09d0440f87024bfe12a8dcda037296b2e74f7b23c863b85a35419537850dfca0'
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 47ff05214de1e6a62e6720f14edea452d03c3d646b2031cd2201a19b7769b70223b06c3205b4c9332f69d686bb0c32db6c736eed56c27ce88578d868624f5ac3
|
7
|
+
data.tar.gz: b5857f68899ff251732dba197fc88b3d2e5e0e06ca8271aad6a51472d17ae4a1cfbe574084496a65e0a06ff660499e97309ef5f4cdb26600f5d5ed53a97748da
|
data/README.md
CHANGED
@@ -19,6 +19,31 @@ Or install it yourself as:
|
|
19
19
|
|
20
20
|
## Usage
|
21
21
|
|
22
|
+
Roll dice on command line!
|
23
|
+
|
24
|
+
```
|
25
|
+
$ mythal roll 1d20
|
26
|
+
rolling d20... 7
|
27
|
+
|
28
|
+
$ mythal roll 5d8 + 4
|
29
|
+
rolling d8... 7
|
30
|
+
rolling d8... 3
|
31
|
+
rolling d8... 3
|
32
|
+
rolling d8... 5
|
33
|
+
rolling d8... 3
|
34
|
+
25
|
35
|
+
```
|
36
|
+
|
37
|
+
Generate quick NPC ideas!
|
38
|
+
|
39
|
+
```
|
40
|
+
$ mythal npc
|
41
|
+
timid tiefling paladin
|
42
|
+
|
43
|
+
$ mythal npc
|
44
|
+
drunk elf wizard
|
45
|
+
```
|
46
|
+
|
22
47
|
## Development
|
23
48
|
|
24
49
|
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
data/config.yml
ADDED
@@ -0,0 +1,49 @@
|
|
1
|
+
traits:
|
2
|
+
- bombastic
|
3
|
+
- scrappy
|
4
|
+
- nimble
|
5
|
+
- argumentative
|
6
|
+
- grumpy
|
7
|
+
- drunk
|
8
|
+
- overly friendly
|
9
|
+
- touchy
|
10
|
+
- flirtatious
|
11
|
+
- ponderous
|
12
|
+
- inquisitive
|
13
|
+
- skeptical
|
14
|
+
- ruminating
|
15
|
+
- articulate
|
16
|
+
- ejaculatory (in terms of sound)
|
17
|
+
- timid
|
18
|
+
- bold
|
19
|
+
- dubious
|
20
|
+
- overly sympathetic
|
21
|
+
- boorish
|
22
|
+
- feckless
|
23
|
+
- nefarious
|
24
|
+
- honorable
|
25
|
+
- spasmodic
|
26
|
+
|
27
|
+
races:
|
28
|
+
- orc
|
29
|
+
- half-orc
|
30
|
+
- human
|
31
|
+
- elf
|
32
|
+
- half-elf
|
33
|
+
- halfling
|
34
|
+
- dragonborn
|
35
|
+
- tiefling
|
36
|
+
- dwarf
|
37
|
+
- gnome
|
38
|
+
|
39
|
+
dnd_classes:
|
40
|
+
- fighter
|
41
|
+
- rogue
|
42
|
+
- wizard
|
43
|
+
- sorceror
|
44
|
+
- druid
|
45
|
+
- cleric
|
46
|
+
- bard
|
47
|
+
- monk
|
48
|
+
- warlock
|
49
|
+
- paladin
|
data/lib/mythal.rb
CHANGED
@@ -2,6 +2,7 @@
|
|
2
2
|
require "thor"
|
3
3
|
require "procto"
|
4
4
|
require "mythal/version"
|
5
|
+
require "mythal/config"
|
5
6
|
require "mythal/roll"
|
6
7
|
require "mythal/npc"
|
7
8
|
|
@@ -11,13 +12,19 @@ module Mythal
|
|
11
12
|
desc "roll", "roll some number of dice, plus modifiers e.g. 1d20, or 3d8 + 4"
|
12
13
|
|
13
14
|
def roll(*args)
|
14
|
-
puts Mythal::Roll.call(*args)
|
15
|
+
puts Mythal::Roll.call(*args).message
|
15
16
|
end
|
16
17
|
|
17
18
|
desc "npc", "generate a random npc, e.g. 'a half-orc barbarian'"
|
18
19
|
|
19
20
|
def npc
|
20
|
-
puts Mythal::Npc.call
|
21
|
+
puts Mythal::Npc.call(config: config)
|
22
|
+
end
|
23
|
+
|
24
|
+
private
|
25
|
+
|
26
|
+
def config
|
27
|
+
@config ||= Mythal::Config.new
|
21
28
|
end
|
22
29
|
end
|
23
30
|
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
require "yaml"
|
2
|
+
require "pathname"
|
3
|
+
|
4
|
+
module Mythal
|
5
|
+
class Config
|
6
|
+
def initialize(user_overrides: {})
|
7
|
+
@user_overrides = user_overrides
|
8
|
+
end
|
9
|
+
|
10
|
+
def traits
|
11
|
+
config["traits"]
|
12
|
+
end
|
13
|
+
|
14
|
+
def races
|
15
|
+
config["races"]
|
16
|
+
end
|
17
|
+
|
18
|
+
def dnd_classes
|
19
|
+
config["dnd_classes"]
|
20
|
+
end
|
21
|
+
|
22
|
+
def config
|
23
|
+
@config ||= user_overrides.empty? ? YAML.load(File.read(config_file)) : user_overrides
|
24
|
+
end
|
25
|
+
|
26
|
+
private
|
27
|
+
|
28
|
+
attr_reader :user_overrides
|
29
|
+
|
30
|
+
def config_file
|
31
|
+
Pathname.new(File.expand_path("../../../config.yml", __FILE__))
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
data/lib/mythal/npc.rb
CHANGED
@@ -2,73 +2,32 @@ module Mythal
|
|
2
2
|
class Npc
|
3
3
|
include Procto.call
|
4
4
|
|
5
|
+
def initialize(config:)
|
6
|
+
@config = config
|
7
|
+
end
|
8
|
+
|
5
9
|
def call
|
6
10
|
character_description
|
7
11
|
end
|
8
12
|
|
9
13
|
private
|
10
14
|
|
15
|
+
attr_reader :config
|
16
|
+
|
11
17
|
def character_description
|
12
18
|
trait + " " + race + " " + dnd_class
|
13
19
|
end
|
14
20
|
|
15
21
|
def trait
|
16
|
-
|
17
|
-
"bombastic",
|
18
|
-
"scrappy",
|
19
|
-
"nimble",
|
20
|
-
"argumentative",
|
21
|
-
"grumpy",
|
22
|
-
"drunk",
|
23
|
-
"overly friendly",
|
24
|
-
"touchy",
|
25
|
-
"flirtatious",
|
26
|
-
"ponderous",
|
27
|
-
"inquisitive",
|
28
|
-
"skeptical",
|
29
|
-
"ruminating",
|
30
|
-
"articulate",
|
31
|
-
"ejaculatory (in terms of sound)",
|
32
|
-
"timid",
|
33
|
-
"bold",
|
34
|
-
"dubious",
|
35
|
-
"overly sympathetic",
|
36
|
-
"boorish",
|
37
|
-
"feckless",
|
38
|
-
"nefarious",
|
39
|
-
"honorable",
|
40
|
-
"spasmodic",
|
41
|
-
].sample
|
22
|
+
config.traits.sample
|
42
23
|
end
|
43
24
|
|
44
25
|
def race
|
45
|
-
|
46
|
-
"orc",
|
47
|
-
"half-orc",
|
48
|
-
"human",
|
49
|
-
"elf",
|
50
|
-
"half-elf",
|
51
|
-
"halfling",
|
52
|
-
"dragonborn",
|
53
|
-
"tiefling",
|
54
|
-
"dwarf",
|
55
|
-
"gnome",
|
56
|
-
].sample
|
26
|
+
config.races.sample
|
57
27
|
end
|
58
28
|
|
59
29
|
def dnd_class
|
60
|
-
|
61
|
-
"fighter",
|
62
|
-
"rogue",
|
63
|
-
"wizard",
|
64
|
-
"sorceror",
|
65
|
-
"druid",
|
66
|
-
"cleric",
|
67
|
-
"bard",
|
68
|
-
"monk",
|
69
|
-
"warlock",
|
70
|
-
"paladin",
|
71
|
-
].sample
|
30
|
+
config.dnd_classes.sample
|
72
31
|
end
|
73
32
|
end
|
74
33
|
end
|
data/lib/mythal/roll.rb
CHANGED
@@ -6,7 +6,7 @@ module Mythal
|
|
6
6
|
NUMBER_OF_DICE = 1..100
|
7
7
|
|
8
8
|
def initialize(*dice_string)
|
9
|
-
@dice_string = dice_string.join
|
9
|
+
@dice_string = dice_string.join.gsub(" ", '')
|
10
10
|
end
|
11
11
|
|
12
12
|
def call
|
@@ -15,35 +15,70 @@ module Mythal
|
|
15
15
|
|
16
16
|
private
|
17
17
|
|
18
|
-
attr_reader :dice_string, :number_of_dice, :denomination, :
|
18
|
+
attr_reader :dice_string, :number_of_dice, :denomination, :modifier
|
19
|
+
|
20
|
+
class DiceRollResult
|
21
|
+
attr_reader :rolls, :modifier, :message, :total, :success
|
22
|
+
|
23
|
+
def initialize(rolls: [], modifier: 0, message: "", total: 0, success: false)
|
24
|
+
@rolls = rolls
|
25
|
+
@modifier = modifier
|
26
|
+
@success = success
|
27
|
+
@message = message
|
28
|
+
@total = total
|
29
|
+
end
|
30
|
+
|
31
|
+
def success?
|
32
|
+
success
|
33
|
+
end
|
34
|
+
end
|
19
35
|
|
20
36
|
def result
|
21
|
-
return "can't roll #{dice_string}" unless match_data
|
37
|
+
return DiceRollResult.new(message: "can't roll #{dice_string}") unless match_data
|
22
38
|
|
23
|
-
|
24
|
-
|
25
|
-
|
39
|
+
parse_input_string
|
40
|
+
|
41
|
+
return DiceRollResult.new(message: "can't roll #{dice_string}") unless valid_denomination?
|
42
|
+
return DiceRollResult.new(message: "can only roll #{min_dice} - #{max_dice} dice") unless valid_number_of_dice?
|
26
43
|
|
27
|
-
|
28
|
-
|
44
|
+
rolls = Array.new(number_of_dice) { random_dice_roll }
|
45
|
+
total = rolls.inject(:+) + modifier
|
46
|
+
message = format_output_message(rolls, total)
|
29
47
|
|
30
|
-
|
48
|
+
DiceRollResult.new(
|
49
|
+
rolls: rolls,
|
50
|
+
total: total,
|
51
|
+
message: message,
|
52
|
+
success: true,
|
53
|
+
modifier: modifier,
|
54
|
+
)
|
31
55
|
end
|
32
56
|
|
33
|
-
def
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
57
|
+
def format_output_message(rolls, total)
|
58
|
+
subtotal = rolls.inject(:+)
|
59
|
+
sign = modifier > 0 ? "+" : "-"
|
60
|
+
messages = rolls.map { |roll| "rolling d#{denomination}... #{roll}" }
|
61
|
+
messages << "#{subtotal} #{sign} #{modifier.abs}" unless modifier.zero?
|
62
|
+
messages << total
|
63
|
+
messages.join("\n")
|
39
64
|
end
|
40
65
|
|
41
66
|
def match_data
|
42
|
-
@match_data ||=
|
67
|
+
@match_data ||= pattern.match(dice_string)
|
68
|
+
end
|
69
|
+
|
70
|
+
def parse_input_string
|
71
|
+
@number_of_dice = match_data[1].to_i
|
72
|
+
@denomination = match_data[2].to_i
|
73
|
+
@modifier = match_data[3] ? match_data[3].to_i : 0
|
74
|
+
end
|
75
|
+
|
76
|
+
def random_dice_roll
|
77
|
+
rand(1..denomination)
|
43
78
|
end
|
44
79
|
|
45
80
|
def pattern
|
46
|
-
@pattern ||= /^(-?\d+)d(\d+)
|
81
|
+
@pattern ||= /^(-?\d+)d(\d+)?([+-]\d+)?$/
|
47
82
|
end
|
48
83
|
|
49
84
|
def valid_denomination?
|
data/lib/mythal/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mythal
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- George Groh
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-
|
11
|
+
date: 2018-11-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -111,8 +111,10 @@ files:
|
|
111
111
|
- Rakefile
|
112
112
|
- bin/console
|
113
113
|
- bin/setup
|
114
|
+
- config.yml
|
114
115
|
- exe/mythal
|
115
116
|
- lib/mythal.rb
|
117
|
+
- lib/mythal/config.rb
|
116
118
|
- lib/mythal/npc.rb
|
117
119
|
- lib/mythal/roll.rb
|
118
120
|
- lib/mythal/version.rb
|
@@ -137,7 +139,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
137
139
|
version: '0'
|
138
140
|
requirements: []
|
139
141
|
rubyforge_project:
|
140
|
-
rubygems_version: 2.
|
142
|
+
rubygems_version: 2.7.8
|
141
143
|
signing_key:
|
142
144
|
specification_version: 4
|
143
145
|
summary: Roll D&D dice from the command line.
|