wayfinder 0.0.4 → 0.0.5

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.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/lib/wayfinder.rb +17 -3
  3. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: e79fa064d4cb9ac71b713c26f5861b4708c1de8b
4
- data.tar.gz: 8ceb7131687cb6eb167435d3060842b4d72005f1
3
+ metadata.gz: 7f4ae19a061f6b7caa1502c21c1a03bc914116ef
4
+ data.tar.gz: c68e89030487cecd9cd16f8be4ebe8c8c9bb2521
5
5
  SHA512:
6
- metadata.gz: 56a97597af28f2efb5f0c904b4226552193fbb13f379e985604cb37d328dcb61c46739dd075acb60a2a8af13aa5ceaa11bbcbd73e43cc07b25dbc86ff57e7367
7
- data.tar.gz: 5efb1eef1ad3fb85a1165ba287b27e77f7e06197168e12e671bc047d1beb8e8629488ecbd3267d41f194938ac898032efd467c5b2f338f35aa13e3f9ce2dab98
6
+ metadata.gz: 0b372f56c23fb34e78019eb2d63d3e1188a1f32aaf139eb06c0c03cafb066aa12ea31610948d24c6d8730e0ada426357d8c12f0038fc94ebf024a2c8f7329883
7
+ data.tar.gz: e0166635e52514241f0b11643ea1e930e0d26d243a7232de248d055e55476ce698aac11e7875a5419a10f1d28dffaad379deb66e9b85738a78d11ab0e1223e96
@@ -44,7 +44,6 @@ module Wayfinder
44
44
  end
45
45
  end
46
46
 
47
-
48
47
  ## Returns an array of items in the modifier stack marked with 'active: true'
49
48
  def active_stack
50
49
  self.modifier_stack.map(&:values).flatten.keep_if { |item| item['active'] }
@@ -52,14 +51,29 @@ module Wayfinder
52
51
 
53
52
  ## Returns an array of object who affect the specified attribute
54
53
  def stack_for(attribute)
55
- self.active_stack.each do |item|
54
+ # Bonuses of the same type do not stack, we need to pick the biggest one and use that one.
55
+ applicable_stack = []
56
+
57
+ self.active_stack.keep_if { |item|
58
+ # We care about the attributes each modifier affects.
56
59
  item.fetch('modifiers', {}).keys.include?(attribute)
60
+ }.group_by { |mod| mod['type'] }.each do |type, mods|
61
+ if type
62
+ # We take the highest modifier of each type
63
+ applicable_stack << mods.sort_by { |mod| mod.fetch('modifiers', {}).fetch(attribute, 0) }.reverse.first
64
+ else
65
+ # Modifiers without a type are simply added to the stack.
66
+ applicable_stack += mods
67
+ end
57
68
  end
69
+
70
+ applicable_stack
58
71
  end
59
72
 
60
73
  ## Outputs the final modifier for the specified attribute.
61
74
  def modifier_for(attribute)
62
75
  modifier = 0
76
+
63
77
  stack_for(attribute).each do |mod|
64
78
  modifier += mod.fetch('modifiers', {}).fetch(attribute, 0)
65
79
  end
@@ -159,7 +173,7 @@ module Wayfinder
159
173
 
160
174
  def skill(skill_name)
161
175
  skill = self.source[:skills].fetch(skill_name, {})
162
- computed_score = skill.fetch('ranks', 0) + self.send("#{ skill['stat'] }_modifier") + modifier_for(skill_name)
176
+ computed_score = skill.fetch('ranks', 0) + self.send("#{ skill['stat'] }_modifier") + modifier_for(skill_name) + modifier_for('all_skills')
163
177
 
164
178
  if skill['class']
165
179
  computed_score += 3
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: wayfinder
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.4
4
+ version: 0.0.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - PoTe
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-10-21 00:00:00.000000000 Z
11
+ date: 2013-10-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: box