pathfinder-dnd-tools 0.1.2 → 0.1.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.
@@ -34,8 +34,8 @@ class Fixnum
34
34
  end
35
35
 
36
36
  # all skills & most stats included
37
- puts '--- Pathfinder Character Tools 2: Revenge of Google Docs ---
38
- version 0.1.2 "Gold and Gems"
37
+ puts %Q[--- Pathfinder Character Tools 2: Revenge of Google Docs ---
38
+ version #{Pathfinder::VERSION}
39
39
 
40
40
  You are in a fully-interactive ruby console.
41
41
  You can `ls` to see methods.
@@ -47,7 +47,7 @@ puts '--- Pathfinder Character Tools 2: Revenge of Google Docs ---
47
47
 
48
48
  type `help` for an overview of console usage
49
49
  type `show-doc <method>` to view help for that specific method
50
+ ]
50
51
 
51
- '
52
52
 
53
53
  character.pry
@@ -1,3 +1,8 @@
1
+ # A simple D&D runtime that connects to Google Docs for your character data
2
+ # Also loads personal functions from ~/.config/pathfinder/rc.rb
3
+ module Pathfinder
4
+ VERSION = '0.1.3 - "User Functions"'
5
+ end
1
6
  require 'pathfinder_dnd/character_sheet'
2
7
  require 'pathfinder_dnd/state_manager'
3
8
 
@@ -17,6 +17,11 @@ module Pathfinder
17
17
 
18
18
  # include standard D&D tools
19
19
  include Pathfinder::Tools
20
+
21
+ # Include user RC if possible
22
+ if load '~/.config/pathfinder/rc.rb'
23
+ include Pathfinder::RC
24
+ end
20
25
 
21
26
  # What sheet title to pull stats from?
22
27
  STATS_SHEET = 'Stats, Skills, Weapons'
@@ -1,6 +1,7 @@
1
1
  module Pathfinder
2
2
 
3
3
  # This is where all the in-game functions are defined, like rolling dice.
4
+ # Also includes some analytics, like an `average` function.
4
5
  module Tools
5
6
 
6
7
  # Deep sum arrays of integers and arrays.
@@ -8,6 +9,10 @@ module Pathfinder
8
9
  # @return [Integer] the total
9
10
  def sum(array)
10
11
  res = 0
12
+
13
+ # numbers sum to themselves
14
+ return array if array.is_a? Fixnum
15
+
11
16
  array.each do |i|
12
17
  if i.respond_to? :each
13
18
  res += sum(i)
@@ -27,14 +32,14 @@ module Pathfinder
27
32
  # @param failure_level [integer] alert the user to dice rolls
28
33
  # at or below this level when rolling 20-sided dice. Default 1.
29
34
  # @return [Integer] result of the dice roll
30
- def single_roll(sides, crit_level = 19, failure_level = 1)
35
+ def single_roll(sides, crit_level = 0, failure_level = 1)
31
36
  res = 1 + rand(sides)
32
- if sides == 20 and res >= crit_level
33
- puts "Crit: rolled #{res}"
37
+ if res >= crit_level + sides and @verbose
38
+ puts "High roll: rolled #{res} on a d#{sides}"
34
39
  end
35
40
 
36
- if sides == 20 and res <= failure_level
37
- puts "Low roll: rolled #{res}"
41
+ if res <= failure_level and @verbose
42
+ puts "Low roll: rolled #{res} on a d#{sides}"
38
43
  end
39
44
 
40
45
  res
@@ -46,43 +51,48 @@ module Pathfinder
46
51
  # @param sides [Integer] number of sides on each die. Default 6.
47
52
  # @see #single_roll
48
53
  # @return [Array<Integer>] list of dice roll results
49
- def roll(dice = 1, sides = 6, crit_level = 19, failure_level = 1)
54
+ def roll(dice = 1, sides = 6, crit_level = 0, failure_level = 1)
50
55
  (1..dice).to_a.map{ |_| single_roll(sides, crit_level, failure_level) }
51
56
  end
52
57
 
53
58
  # Roll a 20-sided dice and add an optional skill bonus
59
+ # Alerts the user on 19-20 rolls
54
60
  # @param skill [Integer] your skill-check or saving-throw bonus. Default 0.
55
61
  # @return [Integer]
56
62
  def check(skill = 0)
57
- sum(roll(1, 20)) + skill
63
+ verbose do
64
+ single_roll(20, -1) + skill
65
+ end
58
66
  end
59
67
 
60
- # roll to hit
61
- # Rolls a basic check with an additional bonus
62
- # @param bonus [Integer] added bonus, usually from Anne's blung-ing or haste
63
- # @param base [Integer] your usual attack bonus. Character-specific default 14.
64
- # @see #check
65
- def atk_roll(bonus = 0, base = 14)
66
- check(base) + bonus
67
- end
68
+ # Average the many runs of a function.
69
+ # Intended to benchmark your damage.
70
+ #
71
+ # @param runs [Integer] how many samples to take
72
+ # @param fn_name [String, Symbol] name of the method to call
73
+ # @param block [Proc] a block to use instead of calling a defined method
74
+ # @return [Integer] the average
75
+ def average(runs = 100, fn_name = nil, &block)
76
+ res = 0
77
+
78
+ if fn_name
79
+ b = method(fn_name.to_sym)
80
+ else
81
+ b = block
82
+ end
68
83
 
69
- # roll for damage
70
- # Character-specific to Shalizara
71
- # @return [Array<Integer>] magic and normal components of the attack
72
- def normal_damage(magic_damage_dice = 2)
73
- magic = sum(roll(magic_damage_dice, 6)) + 2
74
- dagger = sum(roll(1, 4)) + 2
75
- [magic, dagger]
84
+ runs.times { res += sum(b.call()) }
85
+ res / runs
76
86
  end
77
87
 
78
- # Roll for sneak-attack damage
79
- # Character-specific to Shalizara
80
- # @see #normal_damage
81
- def sneak_damage(magic_damage_dice = 2)
82
- sneak = sum(roll(5, 6))
83
- reg = normal_damage(magic_damage_dice)
84
- reg << sneak
85
- reg
88
+ # roll verbosely
89
+ def verbose(&block)
90
+ old_v = @verbose
91
+ @verbose = true
92
+ res = block.call()
93
+ @verbose = old_v
94
+
95
+ res
86
96
  end
87
97
  end
88
98
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pathfinder-dnd-tools
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.1.3
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -97,3 +97,4 @@ signing_key:
97
97
  specification_version: 3
98
98
  summary: D&D Tools
99
99
  test_files: []
100
+ has_rdoc: