rpg-prompt 1.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.
- checksums.yaml +7 -0
- data/bin/rpg-prompt +45 -0
- data/data/rpg-prompt/example.txt +190 -0
- data/data/rpg-prompt/help.txt +108 -0
- data/data/rpg-prompt/rules_default.rb +314 -0
- data/data/rpg-prompt/rules_default_hashes.rb +91 -0
- data/data/rpg-prompt/texts_default.rb +313 -0
- data/lib/rpg-prompt/commands.rb +76 -0
- data/lib/rpg-prompt/keypress.rb +66 -0
- data/lib/rpg-prompt/manage_command.rb +594 -0
- data/lib/rpg-prompt/message.rb +294 -0
- data/lib/rpg-prompt/parse_line.rb +123 -0
- data/lib/rpg-prompt/rules_default.rb +226 -0
- data/lib/rpg-prompt/rules_default_hashes.rb +68 -0
- data/lib/rpg-prompt/rules_sheet.rb +326 -0
- data/lib/rpg-prompt/save.rb +141 -0
- data/lib/rpg-prompt/texts_default.rb +346 -0
- data/lib/rpg-prompt/texts_prompt.rb +259 -0
- data/tests/test_rpg-prompt.rb +10 -0
- metadata +67 -0
|
@@ -0,0 +1,294 @@
|
|
|
1
|
+
module Message
|
|
2
|
+
class Language
|
|
3
|
+
@@language = nil
|
|
4
|
+
|
|
5
|
+
def initialize(valid_languages)
|
|
6
|
+
@@Valid_Languages = valid_languages.clone
|
|
7
|
+
if @@language.nil?
|
|
8
|
+
@@language = @@Valid_Languages[0]
|
|
9
|
+
end
|
|
10
|
+
end
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
class Dictionary < Language
|
|
14
|
+
@@language = nil
|
|
15
|
+
|
|
16
|
+
def initialize(valid_languages)
|
|
17
|
+
@dict_hash = Hash.new("no lang")
|
|
18
|
+
super(valid_languages)
|
|
19
|
+
@@Valid_Languages.each do |l|
|
|
20
|
+
@dict_hash[l] = Hash.new("no word")
|
|
21
|
+
end
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
def self.language=(l)
|
|
25
|
+
unless @@Valid_Languages.nil?
|
|
26
|
+
if @@Valid_Languages.include?(l)
|
|
27
|
+
@@language = l
|
|
28
|
+
Questionnaire.set_option(l, Questionnaire.type)
|
|
29
|
+
end
|
|
30
|
+
end
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
def add_word(s, w)
|
|
34
|
+
@dict_hash[@@language][s] = w
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
def word(s)
|
|
38
|
+
@dict_hash[@@language][s]
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
def symbol(w)
|
|
42
|
+
@dict_hash[@@language].key(w)
|
|
43
|
+
end
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
valid_languages = [:english, :spanish]
|
|
47
|
+
|
|
48
|
+
@@message_dict = Message::Dictionary.new(valid_languages)
|
|
49
|
+
@@help_dict = Message::Dictionary.new(valid_languages)
|
|
50
|
+
@@weapon_dict = Message::Dictionary.new(valid_languages)
|
|
51
|
+
@@armor_dict = Message::Dictionary.new(valid_languages)
|
|
52
|
+
@@skill_dict = Message::Dictionary.new(valid_languages)
|
|
53
|
+
@@skill_help_hash = Message::Dictionary.new(valid_languages)
|
|
54
|
+
|
|
55
|
+
class Option < Language
|
|
56
|
+
@@option = nil
|
|
57
|
+
@@valid_options = nil
|
|
58
|
+
|
|
59
|
+
def initialize(valid_languages, valid_types)
|
|
60
|
+
super(valid_languages)
|
|
61
|
+
@@Valid_Types = valid_types.clone
|
|
62
|
+
if @@valid_options.nil?
|
|
63
|
+
@@valid_options = Array.new
|
|
64
|
+
end
|
|
65
|
+
@@Valid_Languages.each do |l|
|
|
66
|
+
@@Valid_Types.each do |t|
|
|
67
|
+
@@valid_options.push([l, t])
|
|
68
|
+
end
|
|
69
|
+
end
|
|
70
|
+
if @@option.nil?
|
|
71
|
+
@@option = @@valid_options[0]
|
|
72
|
+
end
|
|
73
|
+
end
|
|
74
|
+
end
|
|
75
|
+
|
|
76
|
+
class Questionnaire < Option
|
|
77
|
+
def initialize(valid_languages, valid_types)
|
|
78
|
+
@dict_hash = Hash.new("no lang")
|
|
79
|
+
super(valid_languages, valid_types)
|
|
80
|
+
@@valid_options.each do |l|
|
|
81
|
+
@dict_hash[l] = Hash.new("no word")
|
|
82
|
+
end
|
|
83
|
+
end
|
|
84
|
+
|
|
85
|
+
def self.set_option(l, t)
|
|
86
|
+
unless @@valid_options.nil?
|
|
87
|
+
if @@valid_options.include?([l,t])
|
|
88
|
+
@@option = [l, t]
|
|
89
|
+
@@language = l
|
|
90
|
+
end
|
|
91
|
+
end
|
|
92
|
+
end
|
|
93
|
+
|
|
94
|
+
def self.set_type(t)
|
|
95
|
+
unless @@valid_options.nil?
|
|
96
|
+
if @@valid_options.include?([@@language,t])
|
|
97
|
+
@@option = [@@language, t]
|
|
98
|
+
end
|
|
99
|
+
end
|
|
100
|
+
end
|
|
101
|
+
|
|
102
|
+
def add_word(s, w)
|
|
103
|
+
@dict_hash[@@option][s] = w
|
|
104
|
+
end
|
|
105
|
+
|
|
106
|
+
def word(s)
|
|
107
|
+
@dict_hash[@@option][s]
|
|
108
|
+
end
|
|
109
|
+
|
|
110
|
+
def self.type
|
|
111
|
+
unless @@option.nil?
|
|
112
|
+
@@option[1]
|
|
113
|
+
else
|
|
114
|
+
nil
|
|
115
|
+
end
|
|
116
|
+
end
|
|
117
|
+
end
|
|
118
|
+
|
|
119
|
+
valid_languages = [:english, :spanish]
|
|
120
|
+
valid_types = [:character, :foe, :spawn]
|
|
121
|
+
|
|
122
|
+
@@questionnaire_dict = Message::Questionnaire.new(valid_languages, valid_types)
|
|
123
|
+
@@load_prompt_dict = Message::Questionnaire.new(valid_languages, valid_types)
|
|
124
|
+
|
|
125
|
+
# ***************** message_dict ***************** #
|
|
126
|
+
def self.add_message(s, m)
|
|
127
|
+
@@message_dict.add_word(s, m)
|
|
128
|
+
end
|
|
129
|
+
|
|
130
|
+
def self.message(s)
|
|
131
|
+
puts @@message_dict.word(s)
|
|
132
|
+
end
|
|
133
|
+
|
|
134
|
+
# ***************** help_dict ***************** #
|
|
135
|
+
def self.add_help(s, h)
|
|
136
|
+
@@help_dict.add_word(s, h)
|
|
137
|
+
end
|
|
138
|
+
|
|
139
|
+
def self.help(s, arg)
|
|
140
|
+
puts @@help_dict.word(s) % arg
|
|
141
|
+
end
|
|
142
|
+
|
|
143
|
+
def self.help_string(s, arg)
|
|
144
|
+
@@help_dict.word(s) % arg
|
|
145
|
+
end
|
|
146
|
+
|
|
147
|
+
def self.print_help
|
|
148
|
+
data_dir = Gem.datadir("rpg-prompt")
|
|
149
|
+
data_dir = data_dir ? data_dir : ""
|
|
150
|
+
@@Help_file_name = data_dir + "/help.txt"
|
|
151
|
+
puts open(@@Help_file_name).read
|
|
152
|
+
end
|
|
153
|
+
|
|
154
|
+
def self.print_example
|
|
155
|
+
data_dir = Gem.datadir("rpg-prompt")
|
|
156
|
+
data_dir = data_dir ? data_dir : ""
|
|
157
|
+
@@Example_file_name = data_dir + "/example.txt"
|
|
158
|
+
puts open(@@Example_file_name).read
|
|
159
|
+
end
|
|
160
|
+
|
|
161
|
+
# ***************** weapon_dict ***************** #
|
|
162
|
+
def self.add_weapon(s, w)
|
|
163
|
+
@@weapon_dict.add_word(s, w)
|
|
164
|
+
end
|
|
165
|
+
|
|
166
|
+
def self.weapon_word(s)
|
|
167
|
+
@@weapon_dict.word(s)
|
|
168
|
+
end
|
|
169
|
+
|
|
170
|
+
def self.weapon_symbol(w)
|
|
171
|
+
@@weapon_dict.symbol(w)
|
|
172
|
+
end
|
|
173
|
+
|
|
174
|
+
# ***************** armor_dict ***************** #
|
|
175
|
+
def self.add_armor(s, w)
|
|
176
|
+
@@armor_dict.add_word(s, w)
|
|
177
|
+
end
|
|
178
|
+
|
|
179
|
+
def self.armor_word(s)
|
|
180
|
+
@@armor_dict.word(s)
|
|
181
|
+
end
|
|
182
|
+
|
|
183
|
+
def self.armor_symbol(w)
|
|
184
|
+
@@armor_dict.symbol(w)
|
|
185
|
+
end
|
|
186
|
+
|
|
187
|
+
# ***************** skill_dict ***************** #
|
|
188
|
+
def self.add_skill(s, w)
|
|
189
|
+
@@skill_dict.add_word(s, w)
|
|
190
|
+
end
|
|
191
|
+
|
|
192
|
+
def self.skill_word(s)
|
|
193
|
+
@@skill_dict.word(s)
|
|
194
|
+
end
|
|
195
|
+
|
|
196
|
+
def self.skill_symbol(w)
|
|
197
|
+
@@skill_dict.symbol(w)
|
|
198
|
+
end
|
|
199
|
+
|
|
200
|
+
def self.skill_help(s)
|
|
201
|
+
@@skill_help_hash.word(s)
|
|
202
|
+
end
|
|
203
|
+
|
|
204
|
+
# ***************** questionnaire_dict ***************** #
|
|
205
|
+
def self.add_question(s, q)
|
|
206
|
+
@@questionnaire_dict.add_word(s, w)
|
|
207
|
+
end
|
|
208
|
+
|
|
209
|
+
def self.question(s)
|
|
210
|
+
puts @@questionnaire_dict.word(s)
|
|
211
|
+
end
|
|
212
|
+
|
|
213
|
+
def self.question_symbol(w)
|
|
214
|
+
@@questionnaire_dict.symbol(w)
|
|
215
|
+
end
|
|
216
|
+
|
|
217
|
+
# ***************** load_prompt_dict ***************** #
|
|
218
|
+
def self.add_load_prompt(s, q)
|
|
219
|
+
@@load_prompt_dict.add_word(s, w)
|
|
220
|
+
end
|
|
221
|
+
|
|
222
|
+
def self.load_prompt(s, arg)
|
|
223
|
+
puts @@load_prompt_dict.word(s) % arg
|
|
224
|
+
end
|
|
225
|
+
|
|
226
|
+
# ***************** lists ***************** #
|
|
227
|
+
def self.puts_weapons_list(weapons_available)
|
|
228
|
+
s = ""
|
|
229
|
+
(0...weapons_available.length).each do |i|
|
|
230
|
+
s += Message.weapon_word(weapons_available[i]) + " / "
|
|
231
|
+
if (((i+1)%5) == 0) || (i == (weapons_available.length-1))
|
|
232
|
+
puts s
|
|
233
|
+
s = ""
|
|
234
|
+
end
|
|
235
|
+
end
|
|
236
|
+
end
|
|
237
|
+
|
|
238
|
+
def self.puts_armors_list(armors_available)
|
|
239
|
+
s = ""
|
|
240
|
+
(0...armors_available.length).each do |i|
|
|
241
|
+
s += Message.armor_word(armors_available[i]) + " / "
|
|
242
|
+
end
|
|
243
|
+
puts s
|
|
244
|
+
end
|
|
245
|
+
|
|
246
|
+
# ***************** status and readable ***************** #
|
|
247
|
+
def self.pool_status(pool)
|
|
248
|
+
pool.each do |name, sheet|
|
|
249
|
+
if not(sheet.spawned?)
|
|
250
|
+
if sheet[:type] != :spawn
|
|
251
|
+
Message.help(:warrior_in_one_line, sheet)
|
|
252
|
+
else
|
|
253
|
+
Message.help(:spawn_in_one_line, sheet)
|
|
254
|
+
end
|
|
255
|
+
end
|
|
256
|
+
end
|
|
257
|
+
end
|
|
258
|
+
|
|
259
|
+
def self.combat_status(combat, pool)
|
|
260
|
+
combat.each do |name, ep|
|
|
261
|
+
sheet = pool[name]
|
|
262
|
+
Message.short_readable(sheet)
|
|
263
|
+
end
|
|
264
|
+
end
|
|
265
|
+
|
|
266
|
+
def self.combat_status_verbose(combat, pool)
|
|
267
|
+
combat.each do |name, ep|
|
|
268
|
+
sheet = pool[name]
|
|
269
|
+
if (sheet.unique?) || (sheet.spawned?)
|
|
270
|
+
Message.help(:full_name, sheet)
|
|
271
|
+
Message.readable(sheet)
|
|
272
|
+
end
|
|
273
|
+
end
|
|
274
|
+
end
|
|
275
|
+
|
|
276
|
+
def self.short_readable(sheet)
|
|
277
|
+
puts Message.help_string(:warrior_in_one_line_hp, sheet)
|
|
278
|
+
end
|
|
279
|
+
|
|
280
|
+
def self.readable(sheet)
|
|
281
|
+
s = sheet.to_s
|
|
282
|
+
s = s.gsub(", ","\n")
|
|
283
|
+
s = s.gsub("=>\"","=>")
|
|
284
|
+
s = s.gsub("=>","=> ")
|
|
285
|
+
s = s.gsub("\""," ")
|
|
286
|
+
s = s.gsub("{","")
|
|
287
|
+
s = s.gsub("}","")
|
|
288
|
+
puts s + "\n\n"
|
|
289
|
+
end
|
|
290
|
+
|
|
291
|
+
def self.load_language(lang)
|
|
292
|
+
file_name = ".#{lang}.csv"
|
|
293
|
+
end
|
|
294
|
+
end
|
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
# require "rpg-prompt/manage_command.rb" # required at the en of the file
|
|
2
|
+
# require "rpg-prompt/commands.rb" # required at the en of the file
|
|
3
|
+
|
|
4
|
+
module ParseLine
|
|
5
|
+
class Line
|
|
6
|
+
@@line_regexp_hash = nil
|
|
7
|
+
@help = false
|
|
8
|
+
|
|
9
|
+
def self.line_regexp_hash
|
|
10
|
+
@@line_regexp_hash
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
def remove_extra_separators
|
|
14
|
+
ret_line = @line.clone
|
|
15
|
+
ret_line = ret_line.gsub(/\s+/, " ")
|
|
16
|
+
ret_line = ret_line.gsub(/^\s*/, "")
|
|
17
|
+
ret_line = ret_line.gsub(/\s*$/, "")
|
|
18
|
+
ret_line = ret_line.gsub(/,/, "")
|
|
19
|
+
@line = ret_line.clone
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
def initialize(line)
|
|
23
|
+
if @@line_regexp_hash.nil?
|
|
24
|
+
@@line_regexp_hash = Hash.new([/^$/,/^$/])
|
|
25
|
+
end
|
|
26
|
+
@line = line
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
def Line.add_command(symbol, command, options)
|
|
30
|
+
if @@line_regexp_hash.nil?
|
|
31
|
+
@@line_regexp_hash = Hash.new([/^$/,[]])
|
|
32
|
+
end
|
|
33
|
+
unless (symbol.class != Symbol) || (command.class != Regexp)
|
|
34
|
+
o = "(?<options> [-"
|
|
35
|
+
r = []
|
|
36
|
+
options.each do |t|
|
|
37
|
+
o += t
|
|
38
|
+
r.push(Regexp.new("^" + t + "$"))
|
|
39
|
+
end
|
|
40
|
+
o += "]+)?"
|
|
41
|
+
c = Regexp.new("^" + command.source + o + "$")
|
|
42
|
+
@@line_regexp_hash[symbol] = [c, r]
|
|
43
|
+
end
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
def parse
|
|
47
|
+
c = ManageCommand::Command.new(:unkown_command, Hash.new, Hash.new)
|
|
48
|
+
|
|
49
|
+
self.remove_extra_separators
|
|
50
|
+
@@line_regexp_hash.each do |symbol, regex_constant|
|
|
51
|
+
command_regex = regex_constant[0]
|
|
52
|
+
options_array = regex_constant[1]
|
|
53
|
+
|
|
54
|
+
if (@line.match(command_regex))
|
|
55
|
+
line_array = @line.gsub(":", " : ").gsub(" "," ").split(" ")
|
|
56
|
+
options = @line.match(command_regex)[:options]
|
|
57
|
+
|
|
58
|
+
unless options.nil?
|
|
59
|
+
is_known, options = process_line_options(options, options_array)
|
|
60
|
+
if is_known == :known_options
|
|
61
|
+
line_array.pop
|
|
62
|
+
c = ManageCommand::Command.new(symbol, line_array, options)
|
|
63
|
+
elsif is_known == :unknown_options
|
|
64
|
+
line_array.pop
|
|
65
|
+
c = ManageCommand::Command.new(symbol, line_array, Hash.new())
|
|
66
|
+
elsif is_known == :no_options
|
|
67
|
+
c = ManageCommand::Command.new(symbol, line_array, Hash.new())
|
|
68
|
+
end
|
|
69
|
+
else
|
|
70
|
+
c = ManageCommand::Command.new(symbol, line_array, Hash.new())
|
|
71
|
+
end
|
|
72
|
+
elsif @line.length == 0
|
|
73
|
+
c = ManageCommand::Command.new(:empty, Hash.new, Hash.new)
|
|
74
|
+
end
|
|
75
|
+
end
|
|
76
|
+
|
|
77
|
+
c
|
|
78
|
+
end
|
|
79
|
+
|
|
80
|
+
def process_line_options(options, regex)
|
|
81
|
+
# there are options
|
|
82
|
+
if (options.length > 1) && (options[1] == '-')
|
|
83
|
+
l = options.length-1
|
|
84
|
+
o = Array.new
|
|
85
|
+
(0..l).each do |i|
|
|
86
|
+
unless options[i].match(/^[- ]$/)
|
|
87
|
+
o.push(options[i])
|
|
88
|
+
end
|
|
89
|
+
end
|
|
90
|
+
|
|
91
|
+
valid_options = Hash.new(false) # default, all are invalid
|
|
92
|
+
o.each do |opt|
|
|
93
|
+
regex.each do |reg|
|
|
94
|
+
if opt.match(reg)
|
|
95
|
+
valid_options[opt] = true #only if they are valid
|
|
96
|
+
end
|
|
97
|
+
end
|
|
98
|
+
end
|
|
99
|
+
|
|
100
|
+
valid = (valid_options.length >= 1) #tentatively
|
|
101
|
+
o.each do |opt|
|
|
102
|
+
# Only if all are valid, options are in fact known
|
|
103
|
+
valid &&= valid_options[opt]
|
|
104
|
+
end
|
|
105
|
+
|
|
106
|
+
if valid
|
|
107
|
+
return :known_options, o
|
|
108
|
+
else
|
|
109
|
+
# this should never occur, if the Regexp are well written
|
|
110
|
+
return :unknown_options, Hash.new
|
|
111
|
+
end
|
|
112
|
+
|
|
113
|
+
# there are no options
|
|
114
|
+
else
|
|
115
|
+
return :no_options, Hash.new
|
|
116
|
+
end
|
|
117
|
+
|
|
118
|
+
end
|
|
119
|
+
end
|
|
120
|
+
end
|
|
121
|
+
|
|
122
|
+
require "rpg-prompt/manage_command.rb"
|
|
123
|
+
require "rpg-prompt/commands.rb"
|
|
@@ -0,0 +1,226 @@
|
|
|
1
|
+
require "rpg-prompt/rules_default_hashes.rb"
|
|
2
|
+
require "rpg-prompt/message.rb"
|
|
3
|
+
require "rpg-prompt/texts_default.rb"
|
|
4
|
+
require "rpg-prompt/keypress.rb"
|
|
5
|
+
|
|
6
|
+
ParseLine::Line.add_command(:hits,
|
|
7
|
+
/(?<atk>\w+) hits (?<def>\w+)/, ["c", "f", "r", "h", "s", "u", "d"])
|
|
8
|
+
ParseLine::Line.add_command(:hits_short,
|
|
9
|
+
/(?<atk>\w+) h (?<def>\w+)/, ["c", "f", "r", "h", "s", "u", "d"])
|
|
10
|
+
|
|
11
|
+
ParseLine::Line.add_command(:skill,
|
|
12
|
+
/skill (?<ch>\w+) (?<skill>\w+)( [+-]\d+)?/,
|
|
13
|
+
["c", "r", "e", "l", "m", "h", "v", "e", "s", "a", "c", "u", "i", "d", "p"])
|
|
14
|
+
ParseLine::Line.add_command(:skill_short,
|
|
15
|
+
/(?<ch>\w+)( )?:( )?(?<skill>\w+)( [+-]\d+)?/,
|
|
16
|
+
["c", "r", "e", "l", "m", "h", "v", "e", "s", "a", "c", "u", "i", "d", "p"])
|
|
17
|
+
|
|
18
|
+
module Rules
|
|
19
|
+
module Dice
|
|
20
|
+
def self.roll(type_of_roll)
|
|
21
|
+
case type_of_roll
|
|
22
|
+
when :d6
|
|
23
|
+
1+rand(6)
|
|
24
|
+
when :d10
|
|
25
|
+
1+rand(10)
|
|
26
|
+
end
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
def self.prompt_roll(type_of_roll)
|
|
30
|
+
case type_of_roll
|
|
31
|
+
when :d6
|
|
32
|
+
roll_prompt = :ask_for_d6
|
|
33
|
+
roll_limit = 6
|
|
34
|
+
else
|
|
35
|
+
roll_prompt = :ask_for_d10
|
|
36
|
+
roll_limit = 10
|
|
37
|
+
end
|
|
38
|
+
roll = 0
|
|
39
|
+
Message.message(:preset_roll_prompt)
|
|
40
|
+
case Keypress.read_char
|
|
41
|
+
when "r"
|
|
42
|
+
Message.message(roll_prompt)
|
|
43
|
+
loop do
|
|
44
|
+
roll = $stdin.gets.to_i
|
|
45
|
+
if (roll > roll_limit) || (roll <= 0)
|
|
46
|
+
Message.message(:bad_range)
|
|
47
|
+
redo
|
|
48
|
+
else
|
|
49
|
+
Message.help(:rolling, {roll: roll})
|
|
50
|
+
end
|
|
51
|
+
break
|
|
52
|
+
end
|
|
53
|
+
else
|
|
54
|
+
roll = Dice.roll(type_of_roll)
|
|
55
|
+
Message.help(:rolling, {roll: roll})
|
|
56
|
+
end
|
|
57
|
+
roll
|
|
58
|
+
end
|
|
59
|
+
end
|
|
60
|
+
|
|
61
|
+
class Turn
|
|
62
|
+
def resolve
|
|
63
|
+
end
|
|
64
|
+
end
|
|
65
|
+
|
|
66
|
+
class AttackTurn
|
|
67
|
+
@no_damage = nil
|
|
68
|
+
@modifier = nil
|
|
69
|
+
|
|
70
|
+
def initialize(attacker_sheet, defender_sheet)
|
|
71
|
+
@attacker_sheet = attacker_sheet
|
|
72
|
+
@defender_sheet = defender_sheet
|
|
73
|
+
@weapon = Weapon.new(@attacker_sheet)
|
|
74
|
+
@armor = Armor.new(@defender_sheet)
|
|
75
|
+
if @no_damage == nil
|
|
76
|
+
@no_damage = false
|
|
77
|
+
@modifier = 0
|
|
78
|
+
end
|
|
79
|
+
end
|
|
80
|
+
|
|
81
|
+
def process_options(options)
|
|
82
|
+
@no_damage = false
|
|
83
|
+
@modifier = 0
|
|
84
|
+
distance = 0
|
|
85
|
+
options.each do |option|
|
|
86
|
+
c = option[0]
|
|
87
|
+
option[0] = ' '
|
|
88
|
+
case c
|
|
89
|
+
when 'c' #check
|
|
90
|
+
@no_damage = true
|
|
91
|
+
when 'f' #flank
|
|
92
|
+
@modifier += 1
|
|
93
|
+
when 'b' #back
|
|
94
|
+
@modifier += 2
|
|
95
|
+
when 'h' #higher ground
|
|
96
|
+
@modifier += 1
|
|
97
|
+
when 's' #surprise
|
|
98
|
+
@modifier += 2
|
|
99
|
+
when 'u' #unsheathing
|
|
100
|
+
@modifier -= -1
|
|
101
|
+
when 'd' #distance
|
|
102
|
+
distance += 1
|
|
103
|
+
end
|
|
104
|
+
end
|
|
105
|
+
if (distance > 0) && (distance < @weapon.weapon[:distance_mod].length)
|
|
106
|
+
@modifier += @weapon.weapon[:distance_mod][distance][1]
|
|
107
|
+
elsif (distance > 0) && (distance >= @weapon.weapon[:distance_mod].length)
|
|
108
|
+
@no_damage = true
|
|
109
|
+
end
|
|
110
|
+
return @no_damage, @modifier
|
|
111
|
+
end
|
|
112
|
+
|
|
113
|
+
def resolve
|
|
114
|
+
roll = Dice.prompt_roll(:d10)
|
|
115
|
+
mod_roll = roll + @modifier
|
|
116
|
+
|
|
117
|
+
damage = @weapon.damage_roll(@armor, mod_roll)
|
|
118
|
+
|
|
119
|
+
unless @no_damage then @defender_sheet.reduce_health(damage) end
|
|
120
|
+
|
|
121
|
+
if damage > 0
|
|
122
|
+
Message.help(:hits_lose_hp,
|
|
123
|
+
{full_name: @defender_sheet.full_name, damage: damage})
|
|
124
|
+
end
|
|
125
|
+
end
|
|
126
|
+
end
|
|
127
|
+
|
|
128
|
+
class ActionTurn < Turn
|
|
129
|
+
@@skill_hash = nil
|
|
130
|
+
@skill_sym = nil
|
|
131
|
+
|
|
132
|
+
def initialize(sheet, skill)
|
|
133
|
+
@sheet = sheet
|
|
134
|
+
unless @skill_sym
|
|
135
|
+
@skill_sym = Message.skill_symbol(skill)
|
|
136
|
+
@@skill_hash = RulesHashes::SkillHash.new
|
|
137
|
+
end
|
|
138
|
+
@skill_bonus = @sheet[@skill_sym] ? @sheet[@skill_sym] : 0
|
|
139
|
+
end
|
|
140
|
+
|
|
141
|
+
def self.skill?(skill)
|
|
142
|
+
unless @skill_sym
|
|
143
|
+
@skill_sym = Message.skill_symbol(skill)
|
|
144
|
+
@@skill_hash = RulesHashes::SkillHash.new
|
|
145
|
+
end
|
|
146
|
+
@@skill_hash.key?(@skill_sym)
|
|
147
|
+
end
|
|
148
|
+
|
|
149
|
+
|
|
150
|
+
def process_options(options, command_mod)
|
|
151
|
+
@modifier = command_mod
|
|
152
|
+
@no_action = false
|
|
153
|
+
options.each do |option|
|
|
154
|
+
c = option[0]
|
|
155
|
+
option[0] = ' '
|
|
156
|
+
case c
|
|
157
|
+
when 'c' #check
|
|
158
|
+
@no_action = true
|
|
159
|
+
when 'e' #easy
|
|
160
|
+
@modifier += 3
|
|
161
|
+
when 'm' #medium
|
|
162
|
+
@modifier += 0
|
|
163
|
+
when 'h' #hard
|
|
164
|
+
@modifier -= 3
|
|
165
|
+
end
|
|
166
|
+
end
|
|
167
|
+
@modifier += @skill_bonus
|
|
168
|
+
return @no_action, @modifier
|
|
169
|
+
end
|
|
170
|
+
|
|
171
|
+
def truncate_val(v)
|
|
172
|
+
v = (v > 500) ? 500 : v
|
|
173
|
+
v = (v < -500) ? -500 : v
|
|
174
|
+
end
|
|
175
|
+
|
|
176
|
+
def action_table_result(roll)
|
|
177
|
+
r = truncate_val(roll)
|
|
178
|
+
@@action_table = RulesHashes::ActionTable.new
|
|
179
|
+
action_result = :failure
|
|
180
|
+
@@action_table.each do |ar, l|
|
|
181
|
+
if (r >= l[0]) && (r < l[1])
|
|
182
|
+
action_result = ar
|
|
183
|
+
end
|
|
184
|
+
end
|
|
185
|
+
action_result
|
|
186
|
+
end
|
|
187
|
+
|
|
188
|
+
def mod_roll(roll)
|
|
189
|
+
r = roll + @modifier
|
|
190
|
+
Message.help(:skill_roll, {r: r, roll: roll, modifier: @modifier})
|
|
191
|
+
r
|
|
192
|
+
end
|
|
193
|
+
|
|
194
|
+
def resolve
|
|
195
|
+
roll = Dice.prompt_roll(:d10)
|
|
196
|
+
action_result = action_table_result(mod_roll(roll))
|
|
197
|
+
Message.skill_word(action_result)
|
|
198
|
+
end
|
|
199
|
+
end
|
|
200
|
+
|
|
201
|
+
class Weapon
|
|
202
|
+
attr_accessor :weapon
|
|
203
|
+
|
|
204
|
+
def initialize(sheet)
|
|
205
|
+
@@weapon_hash = RulesHashes::WeaponHash.new()
|
|
206
|
+
@weapon = @@weapon_hash[sheet[:weapon]]
|
|
207
|
+
end
|
|
208
|
+
|
|
209
|
+
def damage_roll(armor, mod_roll)
|
|
210
|
+
if (mod_roll >= armor[:armor])
|
|
211
|
+
Message.message(:hits_success)
|
|
212
|
+
Dice.prompt_roll(:d6)
|
|
213
|
+
else
|
|
214
|
+
Message.message(:hits_fail)
|
|
215
|
+
0
|
|
216
|
+
end
|
|
217
|
+
end
|
|
218
|
+
end
|
|
219
|
+
|
|
220
|
+
class Armor < Hash
|
|
221
|
+
def initialize(sheet)
|
|
222
|
+
@@weapon_hash = RulesHashes::ArmorHash.new()
|
|
223
|
+
self[:armor] = @@weapon_hash[sheet[:armor]]
|
|
224
|
+
end
|
|
225
|
+
end
|
|
226
|
+
end
|