pfrpg_core 0.0.2 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (71) hide show
  1. checksums.yaml +4 -4
  2. data/LICENSE +23 -0
  3. data/Rakefile +1 -1
  4. data/lib/pfrpg_core/attack.rb +66 -0
  5. data/lib/pfrpg_core/attributes.rb +113 -0
  6. data/lib/pfrpg_core/avatar_url.rb +15 -0
  7. data/lib/pfrpg_core/bonus.rb +1 -1
  8. data/lib/pfrpg_core/character.rb +83 -0
  9. data/lib/pfrpg_core/class_feature.rb +31 -0
  10. data/lib/pfrpg_core/combat.rb +60 -0
  11. data/lib/pfrpg_core/demographics.rb +30 -0
  12. data/lib/pfrpg_core/derived/combat_bonuses.rb +78 -0
  13. data/lib/pfrpg_core/derived/defense.rb +29 -0
  14. data/lib/pfrpg_core/derived/magic.rb +145 -0
  15. data/lib/pfrpg_core/derived/misc.rb +114 -0
  16. data/lib/pfrpg_core/derived/offense.rb +49 -0
  17. data/lib/pfrpg_core/derived.rb +10 -0
  18. data/lib/pfrpg_core/effect_processor.rb +1 -1
  19. data/lib/pfrpg_core/effect_totaler.rb +29 -0
  20. data/lib/pfrpg_core/equipment_totaler.rb +14 -0
  21. data/lib/pfrpg_core/feat.rb +27 -0
  22. data/lib/pfrpg_core/feat_totaler.rb +61 -0
  23. data/lib/pfrpg_core/feature_duplicator.rb +26 -0
  24. data/lib/pfrpg_core/feature_totaler.rb +86 -0
  25. data/lib/pfrpg_core/filterable.rb +1 -1
  26. data/lib/pfrpg_core/filters/filter.rb +14 -0
  27. data/lib/pfrpg_core/filters/proficiency_mod.rb +34 -0
  28. data/lib/pfrpg_core/filters/prowess_mod.rb +20 -0
  29. data/lib/pfrpg_core/filters/ranged_attack_mod.rb +28 -0
  30. data/lib/pfrpg_core/filters/skill_focus_mod.rb +25 -0
  31. data/lib/pfrpg_core/filters/strength_mod.rb +21 -0
  32. data/lib/pfrpg_core/filters/weapon_finesse_mod.rb +24 -0
  33. data/lib/pfrpg_core/filters/weapon_focus_mod.rb +23 -0
  34. data/lib/pfrpg_core/filters/weapon_mastery_mod.rb +23 -0
  35. data/lib/pfrpg_core/filters/weapon_specialization_mod.rb +22 -0
  36. data/lib/pfrpg_core/filters/weapon_training_mod.rb +22 -0
  37. data/lib/pfrpg_core/inventory.rb +62 -0
  38. data/lib/pfrpg_core/item.rb +42 -0
  39. data/lib/pfrpg_core/level.rb +14 -0
  40. data/lib/pfrpg_core/level_parser.rb +9 -1
  41. data/lib/pfrpg_core/macros/macro.rb +62 -0
  42. data/lib/pfrpg_core/macros/manyshot_macro.rb +12 -0
  43. data/lib/pfrpg_core/macros/power_attack_macro.rb +12 -0
  44. data/lib/pfrpg_core/macros/rapid_shot_macro.rb +12 -0
  45. data/lib/pfrpg_core/macros/sneak_attack_macro.rb +33 -0
  46. data/lib/pfrpg_core/macros/vital_strike_macro.rb +12 -0
  47. data/lib/pfrpg_core/null_object.rb +31 -29
  48. data/lib/pfrpg_core/saving_throws.rb +43 -0
  49. data/lib/pfrpg_core/skills.rb +141 -0
  50. data/lib/pfrpg_core/specializer.rb +48 -0
  51. data/lib/pfrpg_core/spell.rb +37 -0
  52. data/lib/pfrpg_core/spell_books.rb +36 -0
  53. data/lib/pfrpg_core/spells_per_level.rb +53 -0
  54. data/lib/pfrpg_core/version.rb +1 -1
  55. data/lib/pfrpg_core/weapon_training_calculator.rb +36 -0
  56. data/lib/pfrpg_core.rb +13 -2
  57. data/test/alignment_test.rb +30 -0
  58. data/test/attributes_test.rb +50 -0
  59. data/test/bonus_test.rb +29 -0
  60. data/test/feat_totaler_test.rb +24 -7
  61. data/test/helper.rb +1 -1
  62. data/test/levels_test.rb +19 -0
  63. data/test/misc_test.rb +78 -0
  64. data/test/saves_test.rb +54 -0
  65. data/test/skills_test.rb +93 -0
  66. data/test/test_helper.rb +78 -0
  67. metadata +66 -35
  68. data/lib/pfrpg_core/affectable.rb +0 -7
  69. data/lib/pfrpg_core/effect.rb +0 -39
  70. data/lib/pfrpg_core/prerequisite.rb +0 -58
  71. data/lib/pfrpg_core/quick_classed.rb +0 -37
@@ -0,0 +1,93 @@
1
+ require 'minitest/autorun'
2
+ require 'pfrpg_core'
3
+ require 'pfrpg_classes'
4
+ require_relative './test_helper'
5
+
6
+ class SkillsTest < Minitest::Test
7
+ include TestHelper
8
+ def skill_list
9
+ [
10
+ 'Acrobatics',
11
+ 'Appraise',
12
+ 'Bluff',
13
+ 'Disguise',
14
+ 'Fly',
15
+ 'Stealth'
16
+ ]
17
+ end
18
+
19
+ def setup
20
+ @c = plain_character
21
+ @c.base_skills = skill_list.map do |skill|
22
+ return {
23
+ char_skill: { 'trained_rank'=> 0, name: skill },
24
+ skill: skill
25
+ }
26
+ end
27
+ end
28
+
29
+ class MockRace
30
+ attr_reader :name
31
+ def initialize(name)
32
+ @name = name
33
+ end
34
+ end
35
+
36
+ class MockAttributes
37
+ attr_reader :int_mod
38
+ def initialize(int_mod)
39
+ @int_mod =int_mod
40
+ end
41
+
42
+ def method_missing(m, *args, &block)
43
+ 0
44
+ end
45
+ end
46
+
47
+ class MockLevel
48
+ attr_reader :total, :skill_count, :favored_bonus
49
+ def initialize(total, skill_count, favored)
50
+ @total = total
51
+ @skill_count = skill_count
52
+ @favored_bonus = favored
53
+ end
54
+ end
55
+
56
+ def basic_level
57
+ MockLevel.new(10, 5, 'hp')
58
+ end
59
+
60
+ def test_basic_skills
61
+ skills = PfrpgCore::Skills.new(@c)
62
+
63
+ assert skills.current_trained_ranks('Acrobatics') == 0
64
+ end
65
+
66
+ def test_skills_per_level
67
+ @c.race = MockRace.new('elf)')
68
+ skills = PfrpgCore::Skills.new(@c)
69
+
70
+ assert skills.skills_per_level(PfrpgClasses::Fighter.new(1), false) == 2
71
+ end
72
+
73
+ def test_skills_per_level_human
74
+ @c.race = MockRace.new('Human')
75
+ skills = PfrpgCore::Skills.new(@c)
76
+
77
+ assert skills.skills_per_level(PfrpgClasses::Fighter.new(1), false) == 3
78
+ end
79
+
80
+ def test_skills_per_level_int_mod
81
+ @c.attributes = MockAttributes.new(1)
82
+ skills = PfrpgCore::Skills.new(@c)
83
+ assert skills.skills_per_level(PfrpgClasses::Fighter.new(1), false) == 4
84
+ end
85
+
86
+ def test_skills_per_level_int_mod_negative
87
+ @c.attributes = MockAttributes.new(-1)
88
+ skills = PfrpgCore::Skills.new(@c)
89
+ assert skills.skills_per_level(PfrpgClasses::Fighter.new(1), false) == 2
90
+ end
91
+
92
+
93
+ end
@@ -0,0 +1,78 @@
1
+ require 'pfrpg_races'
2
+ require 'pfrpg_utility'
3
+
4
+ module TestHelper
5
+ class MockCharacter
6
+
7
+ attr_accessor :alignent, :race, :attributes, :levels, :bonuses, :saves,
8
+ :inventory, :character, :feats, :class_features, :skills,
9
+ :base_skills
10
+
11
+ def initialize(alignment,
12
+ race,
13
+ attributes,
14
+ levels,
15
+ bonuses,
16
+ saves,
17
+ skills = [],
18
+ inventory = PfrpgCore::Inventory.new([],[]),
19
+ feats = [],
20
+ class_features = [],
21
+ base_skills = {},
22
+ character = nil)
23
+ @alignment = alignment
24
+ @race = race
25
+ @attributes = attributes
26
+ @levels = levels
27
+ @bonuses = bonuses
28
+ @saves = saves
29
+ @inventory = inventory
30
+ @skills = skills
31
+ @feats = feats
32
+ @class_features = class_features
33
+ @base_skills = base_skills
34
+ @character = character
35
+ end
36
+ include PfrpgCore::Derived::CombatBonuses
37
+ include PfrpgCore::Derived::Misc
38
+ include PfrpgCore::Bonus
39
+ end
40
+
41
+ def basic_attributes
42
+ {
43
+ raw_int: 10,
44
+ raw_wis: 10,
45
+ raw_dex: 10,
46
+ raw_con: 10,
47
+ raw_cha: 10,
48
+ raw_str: 10
49
+ }
50
+ end
51
+
52
+ def basic_saves
53
+ {
54
+ fort: 5,
55
+ ref: 5,
56
+ will: 5
57
+ }
58
+ end
59
+
60
+ Le = Struct.new(:class_name, :class_number, :favored)
61
+ def basic_levels
62
+ [ PfrpgCore::Level.new(Le.new('Fighter', 10, true))]
63
+ end
64
+
65
+ def plain_character
66
+ @bonuses = PfrpgCore::Bonuses.new
67
+ @attributes = PfrpgCore::Attributes.new(basic_attributes, @bonuses)
68
+ @saves = PfrpgCore::SavingThrows.new(basic_saves, @bonuses, @attributes)
69
+ @levels = basic_levels
70
+
71
+ return MockCharacter.new(PfrpgUtility::Alignment.new("CN"),
72
+ PfrpgRaces::Race.fetch('Human'),
73
+ @attributes,
74
+ @levels,
75
+ @bonuses,
76
+ @saves)
77
+ end
78
+ end
metadata CHANGED
@@ -1,43 +1,15 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pfrpg_core
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jordan OMara
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-11-11 00:00:00.000000000 Z
12
- dependencies:
13
- - !ruby/object:Gem::Dependency
14
- name: rails
15
- requirement: !ruby/object:Gem::Requirement
16
- requirements:
17
- - - ~>
18
- - !ruby/object:Gem::Version
19
- version: 4.1.1
20
- type: :runtime
21
- prerelease: false
22
- version_requirements: !ruby/object:Gem::Requirement
23
- requirements:
24
- - - ~>
25
- - !ruby/object:Gem::Version
26
- version: 4.1.1
27
- - !ruby/object:Gem::Dependency
28
- name: sqlite3
29
- requirement: !ruby/object:Gem::Requirement
30
- requirements:
31
- - - '>='
32
- - !ruby/object:Gem::Version
33
- version: '0'
34
- type: :development
35
- prerelease: false
36
- version_requirements: !ruby/object:Gem::Requirement
37
- requirements:
38
- - - '>='
39
- - !ruby/object:Gem::Version
40
- version: '0'
11
+ date: 2014-12-23 00:00:00.000000000 Z
12
+ dependencies: []
41
13
  description: core
42
14
  email:
43
15
  - jordan@herosheets.com
@@ -45,23 +17,74 @@ executables: []
45
17
  extensions: []
46
18
  extra_rdoc_files: []
47
19
  files:
48
- - lib/pfrpg_core/affectable.rb
20
+ - lib/pfrpg_core/attack.rb
21
+ - lib/pfrpg_core/attributes.rb
22
+ - lib/pfrpg_core/avatar_url.rb
49
23
  - lib/pfrpg_core/bonus.rb
50
24
  - lib/pfrpg_core/bonuses.rb
51
- - lib/pfrpg_core/effect.rb
25
+ - lib/pfrpg_core/character.rb
26
+ - lib/pfrpg_core/class_feature.rb
27
+ - lib/pfrpg_core/combat.rb
28
+ - lib/pfrpg_core/demographics.rb
29
+ - lib/pfrpg_core/derived/combat_bonuses.rb
30
+ - lib/pfrpg_core/derived/defense.rb
31
+ - lib/pfrpg_core/derived/magic.rb
32
+ - lib/pfrpg_core/derived/misc.rb
33
+ - lib/pfrpg_core/derived/offense.rb
34
+ - lib/pfrpg_core/derived.rb
52
35
  - lib/pfrpg_core/effect_processor.rb
36
+ - lib/pfrpg_core/effect_totaler.rb
37
+ - lib/pfrpg_core/equipment_totaler.rb
38
+ - lib/pfrpg_core/feat.rb
53
39
  - lib/pfrpg_core/feat_finder.rb
40
+ - lib/pfrpg_core/feat_totaler.rb
41
+ - lib/pfrpg_core/feature_duplicator.rb
42
+ - lib/pfrpg_core/feature_totaler.rb
54
43
  - lib/pfrpg_core/filterable.rb
44
+ - lib/pfrpg_core/filters/filter.rb
45
+ - lib/pfrpg_core/filters/proficiency_mod.rb
46
+ - lib/pfrpg_core/filters/prowess_mod.rb
47
+ - lib/pfrpg_core/filters/ranged_attack_mod.rb
48
+ - lib/pfrpg_core/filters/skill_focus_mod.rb
49
+ - lib/pfrpg_core/filters/strength_mod.rb
50
+ - lib/pfrpg_core/filters/weapon_finesse_mod.rb
51
+ - lib/pfrpg_core/filters/weapon_focus_mod.rb
52
+ - lib/pfrpg_core/filters/weapon_mastery_mod.rb
53
+ - lib/pfrpg_core/filters/weapon_specialization_mod.rb
54
+ - lib/pfrpg_core/filters/weapon_training_mod.rb
55
+ - lib/pfrpg_core/inventory.rb
56
+ - lib/pfrpg_core/item.rb
57
+ - lib/pfrpg_core/level.rb
55
58
  - lib/pfrpg_core/level_parser.rb
59
+ - lib/pfrpg_core/macros/macro.rb
60
+ - lib/pfrpg_core/macros/manyshot_macro.rb
61
+ - lib/pfrpg_core/macros/power_attack_macro.rb
62
+ - lib/pfrpg_core/macros/rapid_shot_macro.rb
63
+ - lib/pfrpg_core/macros/sneak_attack_macro.rb
64
+ - lib/pfrpg_core/macros/vital_strike_macro.rb
56
65
  - lib/pfrpg_core/math_helper.rb
57
66
  - lib/pfrpg_core/null_object.rb
58
- - lib/pfrpg_core/prerequisite.rb
59
- - lib/pfrpg_core/quick_classed.rb
67
+ - lib/pfrpg_core/saving_throws.rb
68
+ - lib/pfrpg_core/skills.rb
69
+ - lib/pfrpg_core/specializer.rb
70
+ - lib/pfrpg_core/spell.rb
71
+ - lib/pfrpg_core/spell_books.rb
72
+ - lib/pfrpg_core/spells_per_level.rb
60
73
  - lib/pfrpg_core/version.rb
74
+ - lib/pfrpg_core/weapon_training_calculator.rb
61
75
  - lib/pfrpg_core.rb
76
+ - LICENSE
62
77
  - Rakefile
78
+ - test/alignment_test.rb
79
+ - test/attributes_test.rb
80
+ - test/bonus_test.rb
63
81
  - test/feat_totaler_test.rb
64
82
  - test/helper.rb
83
+ - test/levels_test.rb
84
+ - test/misc_test.rb
85
+ - test/saves_test.rb
86
+ - test/skills_test.rb
87
+ - test/test_helper.rb
65
88
  homepage: http://herosheets.com
66
89
  licenses: []
67
90
  metadata: {}
@@ -86,5 +109,13 @@ signing_key:
86
109
  specification_version: 4
87
110
  summary: PFRPG core
88
111
  test_files:
112
+ - test/alignment_test.rb
113
+ - test/attributes_test.rb
114
+ - test/bonus_test.rb
89
115
  - test/feat_totaler_test.rb
90
116
  - test/helper.rb
117
+ - test/levels_test.rb
118
+ - test/misc_test.rb
119
+ - test/saves_test.rb
120
+ - test/skills_test.rb
121
+ - test/test_helper.rb
@@ -1,7 +0,0 @@
1
- module PfrpgCore
2
- module Affectable
3
- def get_effects
4
- Effect.load(effects)
5
- end
6
- end
7
- end
@@ -1,39 +0,0 @@
1
- class PfrpgCore::Effect
2
- attr_accessor :type, :key, :value, :affect
3
- def initialize(type, key, value, affect=nil)
4
- # standard effect proc; add a value
5
- basic = Proc.new do |character, attribute, value|
6
- character.bonuses.plus(attribute, value)
7
- end
8
- affect ||= basic
9
- @type = type
10
- @key = key
11
- @value = value
12
- @affect = affect
13
- end
14
-
15
- def self.load(effects_string)
16
- return effects_string if effects_string.instance_of? Array
17
- return [ effects_string ] if effects_string.instance_of? PfrpgCore::Effect
18
- return [] if effects_string.nil? || effects_string.empty?
19
- unless effects_string.instance_of? String
20
- ap "Error effect: "
21
- ap effects_string
22
- end
23
- raise Exception unless effects_string.instance_of? String
24
- effects_string.split(";").map { |effect| parse_effect(effect) }
25
- end
26
-
27
- def self.parse_effect(string)
28
- p = string.split(":")
29
- type = p[0]
30
- key = p[1]
31
- value = p[2]
32
- PfrpgCore::Effect.new(type, key, value)
33
- end
34
-
35
- def apply(character)
36
- @affect.call(character, @key, @value)
37
- end
38
-
39
- end
@@ -1,58 +0,0 @@
1
- module PfrpgCore
2
- class Prerequisite
3
-
4
- def initialize(attribute, value, matcher=nil)
5
- default_matcher = Proc.new do |character, attribute, value|
6
- true
7
- end
8
- @attribute = attribute
9
- @value = value
10
- @matcher = matcher || default_matcher
11
- end
12
-
13
- def self.load(prereq_string)
14
- begin
15
- prereqs = []
16
- p = prereq_string.split(";")
17
- p.each { |x| prereqs << parse_prereq(x) }
18
- prereqs
19
- rescue Exception
20
- []
21
- end
22
- end
23
-
24
- def self.parse_prereq(string)
25
- p = string.split(":")
26
- type = p[0]
27
- attribute = p[1]
28
- value = p[2]
29
- case type
30
- when "class"
31
- Prerequisite::ClassPrereq.new(attribute, value)
32
- when "attribute"
33
- Prerequisite::AttributePrereq.new(attribute, value)
34
- when "alignment"
35
- Prerequisite::AlignmentPrereq.new(attribute, value)
36
- when "feat"
37
- Prerequisite::FeatPrereq.new(attribute, value)
38
- when "skill"
39
- Prerequisite::SkillPrereq.new(attribute, value)
40
- when "class_feature"
41
- Prerequisite::HeroclassFeaturePrereq.new(attribute, value)
42
- when "combat"
43
- Prerequisite::BabPrereq.new(attribute, value)
44
- when "language"
45
- Prerequisite::LanguagePrereq.new(attribute, value)
46
- when "misc"
47
- Prerequisite::MiscPrereq.new(attribute, value)
48
- else
49
- Prerequisite.new(attribute, value)
50
- end
51
- end
52
-
53
- def match(character)
54
- @matcher.call(character, @attribute, @value)
55
- end
56
-
57
- end
58
- end
@@ -1,37 +0,0 @@
1
- # basic class math. classes must provide latest_levels method
2
- # with a map of heroclass name & level
3
- module PfrpgCore
4
- module QuickClassed
5
- def get_class_level(heroclass)
6
- l = latest_levels[heroclass.name]
7
- l ||= 0
8
- return l
9
- end
10
-
11
- def explode_levels
12
- # TODO: implement me
13
- []
14
- end
15
-
16
- def get_total_level
17
- latest_levels.keys.inject(0) do |key, sum|
18
- sum = sum + latest_levels[key]
19
- end
20
- end
21
-
22
- def hit_dice
23
- get_total_level
24
- end
25
-
26
- def get_caster_level
27
- # TODO constantize somewhere better
28
- caster_classes = ['Bard', 'Cleric', 'Druid', 'Paladin', 'Ranger', 'Sorcerer', 'Wizard']
29
- caster_levels = []
30
- latest_levels.keys.each do |key|
31
- caster_levels << latest_levels[key] if caster_classes.include? key
32
- end
33
- ek_level = get_class_level(Heroclass.by_name('Eldritch Knight'))
34
- return (caster_levels.max + ek_level) || 0
35
- end
36
- end
37
- end