dnd_treasure_calc 0.1

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.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: b31c166660564f09ac45ebcd3ca94bae78407f3b
4
+ data.tar.gz: 5f923b7303c635d99f90e8b18e275e873fa38482
5
+ SHA512:
6
+ metadata.gz: ed094668a797cf4a72381766b081c2799f44be49ef17a3ccc54df2faa58ebe956776e13cc25d1dca812e2e27543d79e125625aefa4c9ede5810f5c8bf979f466
7
+ data.tar.gz: 186960dc3cd7c50fdbd9ad49c68c795f150997fe6d0c1bbd2d042806c59ee7502d27562cea67d7318aed7ea2fbc754a09d5c3659f65ca5b64b4840773bfcf8ba
@@ -0,0 +1,12 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ *.gem
11
+ .byebug_history
12
+ reinstall
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in dnd_treasure_calc.gemspec
4
+ gemspec
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2017 Andre LaFleur
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
@@ -0,0 +1,46 @@
1
+ # DndTreasureCalc
2
+
3
+ A simple CLI to calculate treasure for Dungeons and Dragons 5e. I figured I could make a single tool that would do it for me,
4
+ and I'd never have to do it manually again.
5
+
6
+ ## Installation
7
+
8
+ Add this line to your application's Gemfile:
9
+
10
+ ```ruby
11
+ gem 'dnd_treasure_calc'
12
+ ```
13
+
14
+ And then execute:
15
+
16
+ $ bundle
17
+
18
+ Or install it yourself as:
19
+
20
+ $ gem install dnd_treasure_calc
21
+
22
+ ## Usage
23
+
24
+ Right now there is only one command to generate individual treasure, of the format `dnd_treasure_calc individual [challenge rating] [number of monsters]`. Examples below:
25
+
26
+ ```bash
27
+ individual 6 1 # Treasure held by one monster with a challenge rating of 6
28
+ individual 2 5 # Treasure held by five different monsters with a challenge rating of 2
29
+ individual 2 5 --show_each # Treasure held by five different monsters with a challenge rating of 2, displayed individually
30
+ ```
31
+
32
+ ## Development
33
+
34
+ After checking out the repo, run `bin/setup` to install dependencies. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
35
+
36
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
37
+
38
+ ## Contributing
39
+
40
+ Bug reports and pull requests are welcome on GitHub at https://github.com/cincospenguinos/dnd_treasure_calc.
41
+
42
+
43
+ ## License
44
+
45
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
46
+
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+ task :default => :spec
@@ -0,0 +1,18 @@
1
+ # For managing conversions between coin types.
2
+ #
3
+ # Works by breaking down, rather than building up
4
+ ---
5
+ :platinum:
6
+ :gold: 100
7
+ :electrum: 200
8
+ :silver: 10000
9
+ :copper: 1000000
10
+ :gold:
11
+ :electrum: 2
12
+ :silver: 10
13
+ :copper: 100
14
+ :electrum:
15
+ :silver: 5
16
+ :copper: 50
17
+ :silver:
18
+ :copper: 100
@@ -0,0 +1,60 @@
1
+ # This may never be done, because I can't justify spending tons of time encoding every horde table
2
+ # and magic items table into YAML, when I can just look up the tables and generate a treasure horde
3
+ # whenever I want.
4
+ ---
5
+ # Challenge Rating 0-4
6
+ - :coins:
7
+ - :multiplier: 100
8
+ :rolls: 2
9
+ :faces: 6
10
+ :type: :copper
11
+ - :multiplier: 1000
12
+ :rolls: 2
13
+ :faces: 6
14
+ :type: :silver
15
+ - :multiplier: 100
16
+ :rolls: 6
17
+ :faces: 6
18
+ :type: :gold
19
+ - :multiplier: 10
20
+ :rolls: 3
21
+ :faces: 6
22
+ :type: :platinum
23
+ :magic_table:
24
+ 6:
25
+ 16:
26
+ :gems:
27
+ :rolls: 2
28
+ :faces: 6
29
+ :value:
30
+ :amount: 10
31
+ :type: gold
32
+ 26:
33
+ :art:
34
+ :rolls: 2
35
+ :faces: 4
36
+ :value:
37
+ :amount: 25
38
+ :type: gold
39
+ 36:
40
+ 44:
41
+ 52:
42
+ 60:
43
+ 65:
44
+ 70:
45
+ 75:
46
+ 78:
47
+ 80:
48
+ 85:
49
+ 92:
50
+ 97:
51
+ 99:
52
+ 100:
53
+ # Challenge Rating 5-10
54
+ - :coins:
55
+
56
+ # Challenge Rating 11-16
57
+ - :coins:
58
+
59
+ # Challenge Rating 17+
60
+ - :coins:
@@ -0,0 +1,137 @@
1
+ ---
2
+ # Challenge 0-4
3
+ - 30:
4
+ - :multiplier: 1
5
+ :rolls: 5
6
+ :faces: 6
7
+ :type: :copper
8
+ 60:
9
+ - :multiplier: 1
10
+ :rolls: 5
11
+ :faces: 6
12
+ :type: :silver
13
+ 70:
14
+ - :multiplier: 1
15
+ :rolls: 5
16
+ :faces: 6
17
+ :type: :electrum
18
+ 95:
19
+ - :multiplier: 1
20
+ :rolls: 5
21
+ :faces: 6
22
+ :type: :gold
23
+ 100:
24
+ - :multiplier: 1
25
+ :rolls: 5
26
+ :faces: 6
27
+ :type: :platinum
28
+
29
+ # Challenge 5-10
30
+ - 30:
31
+ - :multiplier: 100
32
+ :rolls: 4
33
+ :faces: 6
34
+ :type: :copper
35
+ - :multiplier: 10
36
+ :rolls: 1
37
+ :faces: 6
38
+ :type: :electrum
39
+ 60:
40
+ - :multiplier: 10
41
+ :rolls: 6
42
+ :faces: 6
43
+ :type: :silver
44
+ - :multiplier: 10
45
+ :rolls: 2
46
+ :faces: 6
47
+ :type: :gold
48
+ 70:
49
+ - :multiplier: 10
50
+ :rolls: 3
51
+ :faces: 6
52
+ :type: :electrum
53
+ - :multiplier: 10
54
+ :rolls: 2
55
+ :faces: 6
56
+ :type: :gold
57
+ 95:
58
+ - :multiplier: 10
59
+ :rolls: 4
60
+ :faces: 6
61
+ :type: :gold
62
+ 100:
63
+ - :multiplier: 10
64
+ :rolls: 2
65
+ :faces: 6
66
+ :type: :gold
67
+ - :multiplier: 1
68
+ :rolls: 3
69
+ :faces: 6
70
+ :type: :platinum
71
+
72
+ # Challenge 11-16
73
+ - 20:
74
+ - :multiplier: 100
75
+ :rolls: 4
76
+ :faces: 6
77
+ :type: :silver
78
+ - :multiplier: 100
79
+ :rolls: 1
80
+ :faces: 6
81
+ :type: :gold
82
+ 35:
83
+ - :multiplier: 100
84
+ :rolls: 1
85
+ :faces: 6
86
+ :type: :electrum
87
+ - :multiplier: 100
88
+ :rolls: 1
89
+ :faces: 6
90
+ :type: :gold
91
+ 75:
92
+ - :multiplier: 100
93
+ :rolls: 2
94
+ :faces: 6
95
+ :type: :gold
96
+ - :multiplier: 10
97
+ :rolls: 1
98
+ :faces: 6
99
+ :type: :platinum
100
+ 100:
101
+ - :multiplier: 100
102
+ :rolls: 2
103
+ :faces: 6
104
+ :type: :gold
105
+ - :multiplier: 10
106
+ :rolls: 2
107
+ :faces: 6
108
+ :type: :platinum
109
+
110
+ # Challenge 17+
111
+ - 15:
112
+ - :multiplier: 1000
113
+ :rolls: 2
114
+ :faces: 6
115
+ :type: :electrum
116
+ - :multiplier: 100
117
+ :rolls: 8
118
+ :faces: 6
119
+ :type: :gold
120
+ 55:
121
+ - :multiplier: 1000
122
+ :rolls: 1
123
+ :faces: 6
124
+ :type: :gold
125
+ - :multiplier: 100
126
+ :rolls: 1
127
+ :faces: 6
128
+ :type: :platinum
129
+ 100:
130
+ - :multiplier: 1000
131
+ :rolls: 1
132
+ :faces: 6
133
+ :type: :gold
134
+ - :multiplier: 100
135
+ :rolls: 2
136
+ :faces: 6
137
+ :type: :platinum
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "dnd_treasure_calc"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start(__FILE__)
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,38 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'dnd_treasure_calc/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "dnd_treasure_calc"
8
+ spec.version = DndTreasureCalc::VERSION
9
+ spec.authors = ["Andre LaFleur"]
10
+ spec.email = ["andre.lafleur@utah.edu"]
11
+
12
+ spec.summary = %q{A simple CLI to calculate D&D treasure -- individual and horde}
13
+ spec.description = %q{A simple CLI to calculate D&D treasure -- individual and horde}
14
+ spec.homepage = "https://github.com/cincospenguinos/dnd_treasure_calc"
15
+ spec.license = "MIT"
16
+
17
+ # Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
18
+ # to allow pushing to a single host or delete this section to allow pushing to any host.
19
+ if spec.respond_to?(:metadata)
20
+ # spec.metadata['allowed_push_host'] = "http://"
21
+ else
22
+ raise "RubyGems 2.0 or newer is required to protect against " \
23
+ "public gem pushes."
24
+ end
25
+
26
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
27
+ f.match(%r{^(test|spec|features)/})
28
+ end
29
+ spec.bindir = "exe"
30
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
31
+ spec.require_paths = ["lib"]
32
+
33
+ spec.add_development_dependency "bundler", "~> 1.14"
34
+ spec.add_development_dependency "rake", "~> 10.0"
35
+ spec.add_development_dependency 'byebug', '~> 9.1'
36
+
37
+ spec.add_runtime_dependency 'thor', '~> 0.20.0'
38
+ end
@@ -0,0 +1,53 @@
1
+ #!/usr/bin/env ruby
2
+ require 'thor'
3
+ require 'dnd_treasure_calc'
4
+
5
+ class Calculator < Thor
6
+ desc 'individual CR AMOUNT', 'Calculate coins for AMOUNT monsters with a challenge rating of CR.'
7
+ option :show_each, :type => :boolean
8
+ def individual(challenge_rating, amount)
9
+ challenge_rating = challenge_rating.to_i
10
+ amount = amount.to_i
11
+
12
+ coins = []
13
+ amount.times { coins += DndTreasureCalc.individual(challenge_rating) }
14
+
15
+ coins = merge_coins(coins) unless options[:show_each]
16
+ print_coins(coins)
17
+ end
18
+
19
+ private
20
+
21
+ # Merge all the coins together into single sets
22
+ def merge_coins(coins_array)
23
+ buckets = {}
24
+ DndTreasureCalc::COINS.each { |c| buckets[c] = [] }
25
+ coins_array.each { |c| buckets[c.type] << c }
26
+
27
+ coins_array = []
28
+ current_coin = nil
29
+ buckets.each do |_, coins|
30
+ coins.each do |c|
31
+ if current_coin.nil?
32
+ current_coin = c
33
+ next
34
+ end
35
+
36
+ current_coin += c
37
+ end
38
+
39
+ coins_array << current_coin unless current_coin.nil?
40
+ current_coin = nil
41
+ end
42
+
43
+ coins_array
44
+ end
45
+
46
+ # Print the coins array out
47
+ def print_coins(coins_array)
48
+ puts 'COINS'
49
+ coins_array.each { |c| puts "\t#{c.amount}\t#{c.type}" }
50
+ end
51
+ end
52
+
53
+ Calculator.start(ARGV)
@@ -0,0 +1,55 @@
1
+ require 'yaml'
2
+
3
+ require 'dnd_treasure_calc/version'
4
+ require 'dnd_treasure_calc/dice'
5
+ require 'dnd_treasure_calc/coins'
6
+
7
+ module DndTreasureCalc
8
+
9
+ D_100 = Dice.new(1, 100).freeze
10
+ COINS = %i(copper silver electrum gold platinum).freeze
11
+ INDIVIDUAL_TABLES = YAML.load_file('assets/individual_tables.yml')
12
+ HORDE_TABLES = YAML.load_file('assets/horde_tables.yml')
13
+
14
+ # Calculate individual treasure at challenge rating provided
15
+ def DndTreasureCalc.individual(challenge_rating)
16
+ table = individual_table_for(challenge_rating)
17
+ roll = D_100.roll
18
+ table.each do |threshold, dice|
19
+ if roll <= threshold
20
+ coins = []
21
+
22
+ dice.each do |d|
23
+ die = Dice.new(d[:rolls], d[:faces])
24
+ amount = die.roll * d[:multiplier]
25
+ coins << Coins.new(amount, d[:type])
26
+ end
27
+
28
+ return coins
29
+ end
30
+ end
31
+
32
+ raise RuntimeError, "#{roll} did not meet any of the thresholds!"
33
+ end
34
+
35
+ # Calculate horde treasure at challenge rating provided
36
+ def DndTreasureCalc.horde(challenge_rating)
37
+ raise RuntimeError, 'Not yet implemented.'
38
+ end
39
+
40
+ def DndTreasureCalc.individual_table_for(challenge_rating)
41
+ idx = get_index(challenge_rating)
42
+ INDIVIDUAL_TABLES[idx]
43
+ end
44
+
45
+ def DndTreasureCalc.horde_table_for(challenge_rating)
46
+ idx = get_index(challenge_rating)
47
+ HORDE_TABLES[idx]
48
+ end
49
+
50
+ def DndTreasureCalc.get_index(challenge_rating)
51
+ idx = challenge_rating / 5
52
+ idx = 3 if idx > 3
53
+ idx
54
+ end
55
+ end
@@ -0,0 +1,30 @@
1
+ # coins.rb
2
+ module DndTreasureCalc
3
+ class Coins
4
+
5
+ attr_accessor :amount
6
+ attr_reader :type
7
+
8
+ @@conversions = YAML.load_file('assets/conversions.yml')
9
+
10
+ def initialize(amount, type)
11
+ raise RuntimeError, "#{type} is not a valid coin type" unless COINS.include?(type)
12
+ @amount = amount
13
+ @type = type
14
+ end
15
+
16
+ def +(coins)
17
+ raise RuntimeError, "#{coins} is not an instance of Coins" unless coins.is_a?(Coins)
18
+ coins.convert_to(@type) ? 0 : convert_to(coins.type)
19
+ Coins.new(@amount + coins.amount, @type)
20
+ end
21
+
22
+ # Converts this coin to the type provided
23
+ def convert_to(type)
24
+ return false if @@conversions[@type].nil? || @@conversions[@type][type].nil?
25
+ return true if @type == type
26
+ @amount *= @@conversions[@type][type]
27
+ @type = type
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,25 @@
1
+ # dice.rb
2
+
3
+ module DndTreasureCalc
4
+ class Dice
5
+
6
+ @@rand = Random.new
7
+
8
+ def initialize(rolls, faces, modifier=0)
9
+ @rolls = rolls
10
+ @faces = faces
11
+ @modifier = modifier
12
+ end
13
+
14
+ def roll
15
+ total = 0
16
+ @rolls.times { total += @@rand.rand(@faces) + 1 }
17
+ total += @modifier
18
+ total
19
+ end
20
+
21
+ def self.seed=(seed)
22
+ @@rand = Random.new(seed)
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,3 @@
1
+ module DndTreasureCalc
2
+ VERSION = "0.1"
3
+ end
metadata ADDED
@@ -0,0 +1,117 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: dnd_treasure_calc
3
+ version: !ruby/object:Gem::Version
4
+ version: '0.1'
5
+ platform: ruby
6
+ authors:
7
+ - Andre LaFleur
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2017-12-20 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.14'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.14'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: byebug
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '9.1'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '9.1'
55
+ - !ruby/object:Gem::Dependency
56
+ name: thor
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: 0.20.0
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: 0.20.0
69
+ description: A simple CLI to calculate D&D treasure -- individual and horde
70
+ email:
71
+ - andre.lafleur@utah.edu
72
+ executables:
73
+ - dnd_treasure_calc
74
+ extensions: []
75
+ extra_rdoc_files: []
76
+ files:
77
+ - ".gitignore"
78
+ - Gemfile
79
+ - LICENSE.txt
80
+ - README.md
81
+ - Rakefile
82
+ - assets/conversions.yml
83
+ - assets/horde_tables.yml
84
+ - assets/individual_tables.yml
85
+ - bin/console
86
+ - bin/setup
87
+ - dnd_treasure_calc.gemspec
88
+ - exe/dnd_treasure_calc
89
+ - lib/dnd_treasure_calc.rb
90
+ - lib/dnd_treasure_calc/coins.rb
91
+ - lib/dnd_treasure_calc/dice.rb
92
+ - lib/dnd_treasure_calc/version.rb
93
+ homepage: https://github.com/cincospenguinos/dnd_treasure_calc
94
+ licenses:
95
+ - MIT
96
+ metadata: {}
97
+ post_install_message:
98
+ rdoc_options: []
99
+ require_paths:
100
+ - lib
101
+ required_ruby_version: !ruby/object:Gem::Requirement
102
+ requirements:
103
+ - - ">="
104
+ - !ruby/object:Gem::Version
105
+ version: '0'
106
+ required_rubygems_version: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ requirements: []
112
+ rubyforge_project:
113
+ rubygems_version: 2.6.8
114
+ signing_key:
115
+ specification_version: 4
116
+ summary: A simple CLI to calculate D&D treasure -- individual and horde
117
+ test_files: []