traveller_rpg 0.0.0.4 → 0.0.1.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -36,8 +36,8 @@ module TravellerRPG
36
36
  end
37
37
  end
38
38
 
39
- def self.stats_dm(stat)
40
- case stat
39
+ def self.stats_dm(stat_val)
40
+ case stat_val
41
41
  when 0 then -3
42
42
  when 1..2 then -2
43
43
  when 3..5 then -1
@@ -46,23 +46,30 @@ module TravellerRPG
46
46
  when 12..14 then 2
47
47
  when 15..20 then 3
48
48
  else
49
- raise "unexpected stat: #{stat} (#{stat.class})"
49
+ raise "unexpected stat: #{stat_val} (#{stat_val.class})"
50
50
  end
51
51
  end
52
52
 
53
- attr_reader :desc, :stats, :homeworld, :skills, :stuff
53
+ attr_reader :desc, :stats, :homeworld, :skills,
54
+ :stuff, :credits, :cash_rolls
54
55
 
55
56
  def initialize(desc:, stats:, homeworld:,
56
- skills: {}, stuff: {}, log: [])
57
+ skills: {}, stuff: {}, log: [], credits: 0, cash_rolls: 0)
57
58
  @desc = desc
58
59
  @stats = stats
59
60
  @homeworld = homeworld
60
61
  @skills = skills
61
62
  @stuff = stuff
62
63
  @log = log
64
+ @cash_rolls = cash_rolls # max 3 lifetime
65
+ @credits = credits
63
66
  self.birth
64
67
  end
65
68
 
69
+ def stats_dm(stat_sym)
70
+ self.class.stats_dm(@stats[stat_sym])
71
+ end
72
+
66
73
  # gain background skills based on homeworld
67
74
  def birth
68
75
  return nil unless @log.empty?
@@ -70,7 +77,7 @@ module TravellerRPG
70
77
  @desc.name,
71
78
  @homeworld.name,
72
79
  @homeworld.traits.join(' '))
73
- skill_count = 3 + self.class.stats_dm(@stats.education)
80
+ skill_count = 3 + self.stats_dm(:education)
74
81
  self.log format("Education %i qualifies for %i skills",
75
82
  @stats.education, skill_count)
76
83
  skill_choices = []
@@ -87,9 +94,30 @@ module TravellerRPG
87
94
  }
88
95
  end
89
96
  skill_choices.each { |sym|
90
- self.log "Acquired background skill: #{sym} 0"
91
- @skills[sym] ||= 0
97
+ if TravellerRPG::SKILLS.key?(sym)
98
+ self.log "Acquired background skill: #{sym} 0"
99
+ @skills[sym] ||= 0
100
+ else
101
+ raise(KeyError, sym)
102
+ end
92
103
  }
104
+ self
105
+ end
106
+
107
+ def train(sym, level = nil)
108
+ target = TravellerRPG::SKILLS.key?(sym) ? @skills : @stats
109
+ target[sym] ||= 0
110
+ if level
111
+ if target[sym] < level
112
+ target[sym] = level
113
+ else
114
+ self.log "#{sym} #{level} is < current #{target[sym]}"
115
+ end
116
+ else
117
+ target[sym] += 1
118
+ level = target[sym]
119
+ end
120
+ self.log "#{sym} is trained to #{level}"
93
121
  end
94
122
 
95
123
  def add_stuff(benefits)
@@ -111,6 +139,7 @@ module TravellerRPG
111
139
  return @log unless msg
112
140
  puts msg
113
141
  @log << msg
142
+ self
114
143
  end
115
144
 
116
145
  def name
@@ -124,5 +153,83 @@ module TravellerRPG
124
153
  def skill_check?(skill, val = 0)
125
154
  @skills[skill] and @skills[skill] >= val
126
155
  end
156
+
157
+ def skill_level(sym)
158
+ @skills[sym] and @skills[sym].clamp(0, 4)
159
+ end
160
+
161
+ def cash_roll(amount)
162
+ @cash_rolls += 1
163
+ if @cash_rolls <= 3
164
+ @credits += amount
165
+ self.log "Acquired #{amount} credits from cash roll ##{@cash_rolls}"
166
+ else
167
+ self.log "Ignoring cash roll ##{@cash_rolls}"
168
+ end
169
+ self
170
+ end
171
+
172
+ def benefit(item)
173
+ if item.is_a?(Integer)
174
+ if item != 0
175
+ self.log "Acquired #{item} credits as a career benefit"
176
+ @credits += item
177
+ end
178
+ else
179
+ self.log "Acquired #{item} as a career benefit"
180
+ @stuff[item] ||= 0
181
+ @stuff[item] += 1
182
+ end
183
+ end
184
+
185
+ def report(desc: :short, stats: true, skills: true, stuff: true,
186
+ log: false, credits: true)
187
+ hsh = {}
188
+ if desc
189
+ hsh['Description'] = { 'Name' => @desc.name,
190
+ 'Gender' => @desc.gender,
191
+ 'Age' => @desc.age }
192
+ if desc == :long
193
+ hsh['Description'].merge! 'Appearance' => @desc.appearance,
194
+ 'Temperament' => @desc.temperament,
195
+ 'Plot' => @desc.plot
196
+ end
197
+ end
198
+ if stats
199
+ hsh['Characteristics'] = {
200
+ 'Strength' => @stats.strength,
201
+ 'Dexterity' => @stats.dexterity,
202
+ 'Endurance' => @stats.endurance,
203
+ 'Intelligence' => @stats.intelligence,
204
+ 'Education' => @stats.education,
205
+ 'Social Status' => @stats.social_status,
206
+ }
207
+ end
208
+ hsh['Skills'] = @skills if skills
209
+ hsh['Stuff'] = @stuff if stuff
210
+ hsh['Log'] = @log if log
211
+ if credits
212
+ hsh['Credits'] = {
213
+ 'Total' => @credits,
214
+ 'Cash Rolls' => @cash_rolls,
215
+ }
216
+ end
217
+ report = []
218
+ hsh.each { |section, tbl|
219
+ report << "#{section}\n==="
220
+ report << "(none)" if tbl.empty?
221
+ if tbl.is_a?(Hash)
222
+ tbl.each { |label, val|
223
+ report << format("%s: %s", label.to_s.rjust(20, ' '), val.to_s)
224
+ }
225
+ elsif tbl.is_a?(Array)
226
+ report += tbl
227
+ else
228
+ report << tbl
229
+ end
230
+ report << ' '
231
+ }
232
+ report.join("\n")
233
+ end
127
234
  end
128
235
  end
@@ -3,24 +3,24 @@ require 'traveller_rpg'
3
3
  module TravellerRPG
4
4
  class Homeworld
5
5
  TRAITS = {
6
- agricultural: :animals,
6
+ agricultural: :animals_group,
7
7
  asteroid: :zero_g,
8
8
  desert: :survival,
9
- fluid_oceans: :seafarer,
10
- garden: :animals,
9
+ fluid_oceans: :seafarer_group,
10
+ garden: [:animals_riding, :animals_veterinary],
11
11
  high_technology: :computers,
12
12
  high_population: :streetwise,
13
13
  ice_capped: :vacc_suit,
14
- industrial: :trade,
14
+ industrial: :trade_group,
15
15
  low_technology: :survival,
16
- poor: :animals,
16
+ poor: :animals_group,
17
17
  rich: :carouse,
18
- water_world: :seafarer,
18
+ water_world: :seafarer_group,
19
19
  vacuum: :vacc_suit,
20
- education: [:admin, :advocate, :art, :carouse, :comms,
21
- :computer, :drive, :engineer, :language, :medic,
22
- :physical_science, :life_science, :social_science,
23
- :space_science, :trade],
20
+ education: [:admin, :advocate, :art_group, :carouse, :comms,
21
+ :computers, :drive_group, :engineer_group, :language_group,
22
+ :medic, :physical_sciences_group, :life_sciences_group,
23
+ :social_sciences_group, :space_sciences_group, :trade_group],
24
24
  }
25
25
  TRAIT_MIN = 3
26
26
  TRAIT_MAX = 6
data/lib/traveller_rpg.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  module TravellerRPG
2
- PLAYER_CHOICE = ENV['PLAYER_CHOICE']
2
+ PLAYER_CHOOSE = ENV['HUMAN']
3
3
 
4
4
  ROLL_RGX = %r{
5
5
  \A # starts with
@@ -22,8 +22,9 @@ module TravellerRPG
22
22
  end
23
23
 
24
24
  def self.choose(msg, *args)
25
- return self.player_choose(msg, *args) if PLAYER_CHOICE
26
- puts msg + ' (' + args.join(' ') + ')'
25
+ puts msg + ' (' + args.join(' ') + ')'
26
+ raise "no choices" if args.empty?
27
+ return self.player_choose(msg, *args) if PLAYER_CHOOSE
27
28
  choice = args.sample
28
29
  puts "> #{choice}"
29
30
  choice
@@ -32,10 +33,11 @@ module TravellerRPG
32
33
  def self.player_choose(msg, *args)
33
34
  chosen = false
34
35
  while !chosen
35
- puts msg + ' (' + args.join(' ') + ')'
36
- choice = self.prompt.to_s.downcase.to_sym
36
+ choice = self.player_prompt
37
37
  if args.include?(choice)
38
38
  chosen = choice
39
+ elsif args.include?(choice.to_sym)
40
+ chosen = choice.to_sym
39
41
  else
40
42
  puts "Try again.\n"
41
43
  end
@@ -49,10 +51,6 @@ module TravellerRPG
49
51
  $stdin.gets(chomp: true)
50
52
  end
51
53
 
52
- def self.career_class(str)
53
- Object.const_get("TravellerRPG::#{str.split('::').last}")
54
- end
55
-
56
54
  # per http://www.traveller-srd.com/core-rules/skills/
57
55
  SKILLS = {
58
56
  admin: nil,
@@ -198,6 +196,7 @@ module TravellerRPG
198
196
  tactics_group: nil,
199
197
  tactics_military: nil,
200
198
  tactics_ground: nil,
199
+ tactics_naval: nil,
201
200
 
202
201
  trade_group: nil,
203
202
  trade_biologicals: nil,
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: traveller_rpg
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.0.4
4
+ version: 0.0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Rick Hull
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-12-03 00:00:00.000000000 Z
11
+ date: 2017-12-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: buildar