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,68 @@
|
|
|
1
|
+
require "rpg-prompt/message.rb"
|
|
2
|
+
|
|
3
|
+
module RulesHashes
|
|
4
|
+
class ArmorHash < Hash
|
|
5
|
+
@@armors = nil
|
|
6
|
+
|
|
7
|
+
def initialize
|
|
8
|
+
self[:no_armor] = 0
|
|
9
|
+
self[:hardened_leather] = 3
|
|
10
|
+
self[:chainmail] = 5
|
|
11
|
+
self[:plate] = 8
|
|
12
|
+
|
|
13
|
+
@@armors = self.keys
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
def armors
|
|
17
|
+
@@armors
|
|
18
|
+
end
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
class WeaponHash < Hash
|
|
22
|
+
@@weapons = nil
|
|
23
|
+
|
|
24
|
+
def initialize
|
|
25
|
+
self[:broad_sword] = {:distance_mod => []}
|
|
26
|
+
self[:dagger] = {:distance_mod => []}
|
|
27
|
+
self[:scimitar] = {:distance_mod => []}
|
|
28
|
+
self[:hand_axe] = {:distance_mod => []}
|
|
29
|
+
self[:composite_bow] = {:distance_mod => [[0,0], [30,0], [60,-3], [90,-6]]}
|
|
30
|
+
self[:mace] = {:distance_mod => []}
|
|
31
|
+
self[:warhammer] = {:distance_mod => []}
|
|
32
|
+
self[:battle_axe] = {:distance_mod => []}
|
|
33
|
+
self[:claw_and_bite] = {:distance_mod => []}
|
|
34
|
+
|
|
35
|
+
@@weapons = self.keys
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
def weapons
|
|
39
|
+
@@weapons
|
|
40
|
+
end
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
class CreationArray < Hash
|
|
44
|
+
def initialize
|
|
45
|
+
self[:full_name] = [:question_full_name, :string, nil]
|
|
46
|
+
self[:nickname] = [:question_nickname, :string, nil]
|
|
47
|
+
self[:race] = [:question_race, :string, ""]
|
|
48
|
+
self[:hp] = [:question_hp, :integer, 10]
|
|
49
|
+
self[:weapon] = [:question_weapon, :weapon, :broad_sword]
|
|
50
|
+
self[:armor] = [:question_armor, :armor, :no_armor]
|
|
51
|
+
self[:move_capacity] = [:question_move_capacity, :integer, 10]
|
|
52
|
+
end
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
class SkillHash < Hash
|
|
56
|
+
def initialize
|
|
57
|
+
self[:sing] = [:artistic, :active]
|
|
58
|
+
self[:stalk] = [:subterfuge, :stealth]
|
|
59
|
+
self[:pick_locks] = [:subterfuge, :mechanics]
|
|
60
|
+
end
|
|
61
|
+
end
|
|
62
|
+
class ActionTable < Hash
|
|
63
|
+
def initialize
|
|
64
|
+
self[:failure] = [-1000, 3]
|
|
65
|
+
self[:success] = [4, 1000]
|
|
66
|
+
end
|
|
67
|
+
end
|
|
68
|
+
end
|
|
@@ -0,0 +1,326 @@
|
|
|
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
|
+
module Rules
|
|
7
|
+
class Sheet < Hash
|
|
8
|
+
def initialize(short_name)
|
|
9
|
+
self[:short_name] = short_name
|
|
10
|
+
super(false)
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
def load_attribute(attribute, value)
|
|
14
|
+
self[attribute] = value
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
def read_attribute(attribute)
|
|
18
|
+
self[attribute]
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
def set_attribute(attribute, value)
|
|
22
|
+
c_a = self.creation_array
|
|
23
|
+
if c_a.key?(attribute)
|
|
24
|
+
type = c_a[attribute][1]
|
|
25
|
+
el = case type
|
|
26
|
+
when :integer
|
|
27
|
+
Integer(value)
|
|
28
|
+
when :float
|
|
29
|
+
Float(value)
|
|
30
|
+
when :bool
|
|
31
|
+
case value
|
|
32
|
+
when "true"
|
|
33
|
+
true
|
|
34
|
+
when "false"
|
|
35
|
+
false
|
|
36
|
+
else
|
|
37
|
+
puts 747390
|
|
38
|
+
false
|
|
39
|
+
end
|
|
40
|
+
when :weapon
|
|
41
|
+
value = value.gsub("_", " ")
|
|
42
|
+
if Message.weapon_symbol(value)
|
|
43
|
+
Message.weapon_symbol(value)
|
|
44
|
+
else
|
|
45
|
+
return_symbol = :set_fail
|
|
46
|
+
self[attribute]
|
|
47
|
+
end
|
|
48
|
+
else
|
|
49
|
+
value
|
|
50
|
+
end
|
|
51
|
+
self[attribute] = el.clone
|
|
52
|
+
end
|
|
53
|
+
unless (return_symbol == :set_fail)
|
|
54
|
+
return_symbol = :set_attribute
|
|
55
|
+
end
|
|
56
|
+
return_symbol
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
def clone_sheet(sheet)
|
|
60
|
+
sheet.each { |key, val|
|
|
61
|
+
self[key] = val
|
|
62
|
+
}
|
|
63
|
+
end
|
|
64
|
+
|
|
65
|
+
def remove_extra_separators(line)
|
|
66
|
+
ret_line = String.new(line)
|
|
67
|
+
ret_line = ret_line.gsub(/\s+/, " ")
|
|
68
|
+
ret_line = ret_line.gsub(/^\s*/, "")
|
|
69
|
+
ret_line = ret_line.gsub(/\s*$/, "")
|
|
70
|
+
ret_line = ret_line.gsub(/,/, "")
|
|
71
|
+
end
|
|
72
|
+
|
|
73
|
+
def create_new_w_questions
|
|
74
|
+
creation_array = self.creation_array
|
|
75
|
+
creation_array.each do |key, question|
|
|
76
|
+
unless question[0] == :no_question
|
|
77
|
+
Message.question(question[0])
|
|
78
|
+
|
|
79
|
+
if question[1] == :string
|
|
80
|
+
val = $stdin.gets.chomp
|
|
81
|
+
val = remove_extra_separators(val)
|
|
82
|
+
if val.length == 0
|
|
83
|
+
val = question[2]
|
|
84
|
+
end
|
|
85
|
+
|
|
86
|
+
elsif question[1] == :integer
|
|
87
|
+
i = $stdin.gets.chomp
|
|
88
|
+
if i.length == 0
|
|
89
|
+
val = question[2]
|
|
90
|
+
else
|
|
91
|
+
begin
|
|
92
|
+
val = Integer(i)
|
|
93
|
+
rescue ArgumentError
|
|
94
|
+
redo
|
|
95
|
+
end
|
|
96
|
+
end
|
|
97
|
+
|
|
98
|
+
elsif question[1] == :float
|
|
99
|
+
i = $stdin.gets.chomp
|
|
100
|
+
if i.length == 0
|
|
101
|
+
val = question[2]
|
|
102
|
+
else
|
|
103
|
+
begin
|
|
104
|
+
val = Float(i)
|
|
105
|
+
rescue ArgumentError
|
|
106
|
+
redo
|
|
107
|
+
end
|
|
108
|
+
end
|
|
109
|
+
|
|
110
|
+
elsif question[1] == :bool
|
|
111
|
+
b = $stdin.gets.chomp
|
|
112
|
+
b = remove_extra_separators(b)
|
|
113
|
+
if b.length == 0
|
|
114
|
+
val = question[2]
|
|
115
|
+
elsif (b == "s") || (b == "si")
|
|
116
|
+
val = true
|
|
117
|
+
elsif (b == "n") || (b == "no")
|
|
118
|
+
val = false
|
|
119
|
+
else
|
|
120
|
+
redo
|
|
121
|
+
end
|
|
122
|
+
|
|
123
|
+
elsif question[1] == :multiple
|
|
124
|
+
val = Array.new
|
|
125
|
+
loop do
|
|
126
|
+
name = $stdin.gets.chomp
|
|
127
|
+
name = remove_extra_separators(name)
|
|
128
|
+
if name == "q"
|
|
129
|
+
break
|
|
130
|
+
else
|
|
131
|
+
val.push(name)
|
|
132
|
+
end
|
|
133
|
+
end
|
|
134
|
+
|
|
135
|
+
elsif question[1] == :weapon
|
|
136
|
+
weapon_hash = RulesHashes::WeaponHash.new
|
|
137
|
+
available = weapon_hash.weapons
|
|
138
|
+
translated = Array.new
|
|
139
|
+
available.each do |e|
|
|
140
|
+
translated.push(Message.weapon_word(e))
|
|
141
|
+
end
|
|
142
|
+
Message.puts_weapons_list(available)
|
|
143
|
+
s = $stdin.gets.chomp
|
|
144
|
+
s = remove_extra_separators(s)
|
|
145
|
+
unless translated.include?(s)
|
|
146
|
+
redo
|
|
147
|
+
end
|
|
148
|
+
val = Message.weapon_symbol(s)
|
|
149
|
+
|
|
150
|
+
elsif question[1] == :armor
|
|
151
|
+
armor_hash = RulesHashes::ArmorHash.new
|
|
152
|
+
available = armor_hash.armors
|
|
153
|
+
translated = Array.new
|
|
154
|
+
available.each do |e|
|
|
155
|
+
translated.push(Message.armor_word(e))
|
|
156
|
+
end
|
|
157
|
+
Message.puts_armors_list(available)
|
|
158
|
+
s = $stdin.gets.chomp
|
|
159
|
+
s = remove_extra_separators(s)
|
|
160
|
+
unless translated.include?(s)
|
|
161
|
+
redo
|
|
162
|
+
end
|
|
163
|
+
val = Message.armor_symbol(s)
|
|
164
|
+
|
|
165
|
+
else
|
|
166
|
+
puts 367223
|
|
167
|
+
end
|
|
168
|
+
load_attribute(key, val)
|
|
169
|
+
else
|
|
170
|
+
load_attribute(key, question[2])
|
|
171
|
+
end
|
|
172
|
+
end
|
|
173
|
+
end
|
|
174
|
+
|
|
175
|
+
def full_name
|
|
176
|
+
String.new(self[:full_name] + " " + self[:nickname])
|
|
177
|
+
end
|
|
178
|
+
|
|
179
|
+
def add_ability(ability)
|
|
180
|
+
case ability
|
|
181
|
+
when :sing
|
|
182
|
+
@abilities[:sing] = true
|
|
183
|
+
when :dance
|
|
184
|
+
@abilities[:dance] = true
|
|
185
|
+
end
|
|
186
|
+
end
|
|
187
|
+
|
|
188
|
+
def remove_ability(ability)
|
|
189
|
+
@abilities[ability] = false
|
|
190
|
+
end
|
|
191
|
+
|
|
192
|
+
def []=(key, el)
|
|
193
|
+
if (key == :hp) || (key == :dead_in)
|
|
194
|
+
if el <= 0
|
|
195
|
+
super(key, el)
|
|
196
|
+
if key == :hp
|
|
197
|
+
Message.message(:mortal_wound_hp)
|
|
198
|
+
elsif key == :dead_in
|
|
199
|
+
Message.message(:mortal_wound_dead_in)
|
|
200
|
+
end
|
|
201
|
+
end
|
|
202
|
+
end
|
|
203
|
+
super(key, el)
|
|
204
|
+
end
|
|
205
|
+
|
|
206
|
+
def dead?
|
|
207
|
+
if self[:dead_in] != false
|
|
208
|
+
(self[:hp] <= 0) || (self[:dead_in] <= 0)
|
|
209
|
+
else
|
|
210
|
+
(self[:hp] <= 0)
|
|
211
|
+
end
|
|
212
|
+
end
|
|
213
|
+
|
|
214
|
+
def health?
|
|
215
|
+
self[:hp]
|
|
216
|
+
end
|
|
217
|
+
|
|
218
|
+
def spawned?
|
|
219
|
+
self[:spawned]
|
|
220
|
+
end
|
|
221
|
+
|
|
222
|
+
def reduce_health(damage)
|
|
223
|
+
self[:hp] -= damage
|
|
224
|
+
end
|
|
225
|
+
|
|
226
|
+
def move_capacity?
|
|
227
|
+
@move_capacity
|
|
228
|
+
end
|
|
229
|
+
|
|
230
|
+
def pass_round
|
|
231
|
+
self.each do |key, el|
|
|
232
|
+
case key
|
|
233
|
+
when :dead_in
|
|
234
|
+
self[key] -= 1
|
|
235
|
+
end
|
|
236
|
+
end
|
|
237
|
+
end
|
|
238
|
+
end
|
|
239
|
+
|
|
240
|
+
class Character < Sheet
|
|
241
|
+
def initialize(short_name)
|
|
242
|
+
super(short_name)
|
|
243
|
+
@creation_array = RulesHashes::CreationArray.new()
|
|
244
|
+
end
|
|
245
|
+
def creation_array
|
|
246
|
+
@creation_array
|
|
247
|
+
end
|
|
248
|
+
def unique?
|
|
249
|
+
true
|
|
250
|
+
end
|
|
251
|
+
def good?
|
|
252
|
+
true
|
|
253
|
+
end
|
|
254
|
+
end
|
|
255
|
+
|
|
256
|
+
class Foe < Sheet
|
|
257
|
+
def initialize(short_name)
|
|
258
|
+
super(short_name)
|
|
259
|
+
@creation_array = RulesHashes::CreationArray.new()
|
|
260
|
+
end
|
|
261
|
+
def creation_array
|
|
262
|
+
@creation_array
|
|
263
|
+
end
|
|
264
|
+
def unique?
|
|
265
|
+
true
|
|
266
|
+
end
|
|
267
|
+
def good?
|
|
268
|
+
false
|
|
269
|
+
end
|
|
270
|
+
end
|
|
271
|
+
|
|
272
|
+
class Spawn < Foe
|
|
273
|
+
def initialize(short_name)
|
|
274
|
+
super(short_name)
|
|
275
|
+
@creation_array = RulesHashes::CreationArray.new()
|
|
276
|
+
@creation_array[:full_name] = [:question_full_name, :multiple, nil]
|
|
277
|
+
@creation_array[:nickname] = [:question_nickname, :multiple, nil]
|
|
278
|
+
end
|
|
279
|
+
def creation_array
|
|
280
|
+
@creation_array
|
|
281
|
+
end
|
|
282
|
+
def unique?
|
|
283
|
+
false
|
|
284
|
+
end
|
|
285
|
+
def good?
|
|
286
|
+
false
|
|
287
|
+
end
|
|
288
|
+
|
|
289
|
+
def create_new_w_questions
|
|
290
|
+
super
|
|
291
|
+
@short_name = read_attribute(:short_name)
|
|
292
|
+
@hp = read_attribute(:hp)
|
|
293
|
+
@full_name = read_attribute(:full_name)
|
|
294
|
+
@nickname = read_attribute(:nickname)
|
|
295
|
+
end
|
|
296
|
+
|
|
297
|
+
def get_random_full_name(short_name, name_list)
|
|
298
|
+
get_random(short_name, name_list, :full_name)
|
|
299
|
+
end
|
|
300
|
+
|
|
301
|
+
def get_random_nickname(short_name, name_list)
|
|
302
|
+
get_random(short_name, name_list, :nickname)
|
|
303
|
+
end
|
|
304
|
+
|
|
305
|
+
def full_name
|
|
306
|
+
String.new("enemy of kind " + self[:short_name])
|
|
307
|
+
end
|
|
308
|
+
|
|
309
|
+
def get_random(name_list)
|
|
310
|
+
r = rand(name_list.length)
|
|
311
|
+
name_list[r]
|
|
312
|
+
end
|
|
313
|
+
|
|
314
|
+
def clone_sheet(sheet, short_name)
|
|
315
|
+
sheet.each do |key, val|
|
|
316
|
+
if key == :short_name
|
|
317
|
+
self.load_attribute(:short_name, short_name)
|
|
318
|
+
elsif (key == :full_name) || (key == :nickname)
|
|
319
|
+
self.load_attribute(key, get_random(sheet[key]))
|
|
320
|
+
else
|
|
321
|
+
self.load_attribute(key, val)
|
|
322
|
+
end
|
|
323
|
+
end
|
|
324
|
+
end
|
|
325
|
+
end
|
|
326
|
+
end
|
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
module Save
|
|
2
|
+
def self.file_name_format(short_name)
|
|
3
|
+
"sw." + short_name + ".marshal"
|
|
4
|
+
end
|
|
5
|
+
|
|
6
|
+
def self.file_scene_format(short_name)
|
|
7
|
+
"ss." + short_name + ".marshal"
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
def self.save_exist?(short_name)
|
|
11
|
+
File.exist?(Save.file_name_format(short_name))
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
def self.save_sheet(short_name, sheet)
|
|
15
|
+
file_name = Save.file_name_format(short_name)
|
|
16
|
+
file_handler = File.open(file_name, "w") {|to_file| Marshal.dump(sheet, to_file)}
|
|
17
|
+
file_handler.close
|
|
18
|
+
if File.exist?(file_name)
|
|
19
|
+
return 0
|
|
20
|
+
else
|
|
21
|
+
return -1
|
|
22
|
+
end
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
def self.load_sheet(short_name)
|
|
26
|
+
file_name = Save.file_name_format(short_name)
|
|
27
|
+
Save.load(file_name)
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
def self.delete_sheet(short_name)
|
|
31
|
+
file_name = Save.file_name_format(short_name)
|
|
32
|
+
Save.delete(file_name)
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
def self.list_warriors
|
|
36
|
+
ls = Dir.entries(".")
|
|
37
|
+
ls.each do |f|
|
|
38
|
+
m = f.match(/^sw\.(?<name>\w+)\.marshal$/)
|
|
39
|
+
if m
|
|
40
|
+
puts m[:name]
|
|
41
|
+
end
|
|
42
|
+
end
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
@pool_file_name = "pool.marshal"
|
|
46
|
+
|
|
47
|
+
def self.save_pool(pool)
|
|
48
|
+
file_handler = File.open(@pool_file_name, "w") {|to_file| Marshal.dump(pool, to_file)}
|
|
49
|
+
file_handler.close
|
|
50
|
+
if File.exist?(@pool_file_name)
|
|
51
|
+
return 0
|
|
52
|
+
else
|
|
53
|
+
return -1
|
|
54
|
+
end
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
def self.load_pool
|
|
58
|
+
if File.exist?(@pool_file_name)
|
|
59
|
+
Save.load(@pool_file_name)
|
|
60
|
+
end
|
|
61
|
+
end
|
|
62
|
+
|
|
63
|
+
def self.delete_pool
|
|
64
|
+
if File.exist?(@pool_file_name)
|
|
65
|
+
File.delete(@pool_file_name)
|
|
66
|
+
end
|
|
67
|
+
end
|
|
68
|
+
|
|
69
|
+
@backup_file_name = ".backup.marshal"
|
|
70
|
+
|
|
71
|
+
def self.save_backup(pool)
|
|
72
|
+
file_handler = File.open(@backup_file_name, "w") {|to_file| Marshal.dump(pool, to_file)}
|
|
73
|
+
file_handler.close
|
|
74
|
+
if File.exist?(@backup_file_name)
|
|
75
|
+
return 0
|
|
76
|
+
else
|
|
77
|
+
return -1
|
|
78
|
+
end
|
|
79
|
+
end
|
|
80
|
+
|
|
81
|
+
def self.load_backup
|
|
82
|
+
Save.load(@backup_file_name)
|
|
83
|
+
end
|
|
84
|
+
|
|
85
|
+
def self.delete_scene(short_name)
|
|
86
|
+
file_name = Save.file_scene_format(short_name)
|
|
87
|
+
Save.delete(file_name)
|
|
88
|
+
end
|
|
89
|
+
|
|
90
|
+
def self.delete_backup
|
|
91
|
+
File.delete(@backup_file_name)
|
|
92
|
+
end
|
|
93
|
+
|
|
94
|
+
def self.save_scene(pool, name)
|
|
95
|
+
file_name = file_scene_format(name)
|
|
96
|
+
file_handler = File.open(file_name, "w") {|to_file| Marshal.dump(pool, to_file)}
|
|
97
|
+
file_handler.close
|
|
98
|
+
if File.exist?(file_name)
|
|
99
|
+
return 0
|
|
100
|
+
else
|
|
101
|
+
return -1
|
|
102
|
+
end
|
|
103
|
+
end
|
|
104
|
+
|
|
105
|
+
def self.load_scene(name)
|
|
106
|
+
Save.load(file_scene_format(name))
|
|
107
|
+
end
|
|
108
|
+
|
|
109
|
+
def self.list_scenes
|
|
110
|
+
ls = Dir.entries(".")
|
|
111
|
+
ls.each do |f|
|
|
112
|
+
m = f.match(/^ss\.(?<name>\w+)\.marshal$/)
|
|
113
|
+
if m
|
|
114
|
+
puts m[:name]
|
|
115
|
+
end
|
|
116
|
+
end
|
|
117
|
+
end
|
|
118
|
+
|
|
119
|
+
def self.load(file_name)
|
|
120
|
+
if File.exist?(file_name)
|
|
121
|
+
begin
|
|
122
|
+
file_handler = File.open(file_name, "r")
|
|
123
|
+
sheet = Marshal.load(file_handler)
|
|
124
|
+
file_handler.close
|
|
125
|
+
rescue
|
|
126
|
+
sheet = false
|
|
127
|
+
end
|
|
128
|
+
else
|
|
129
|
+
sheet = nil
|
|
130
|
+
end
|
|
131
|
+
sheet
|
|
132
|
+
end
|
|
133
|
+
|
|
134
|
+
def self.delete(file_name)
|
|
135
|
+
if File.exist?(file_name)
|
|
136
|
+
File.delete(file_name)
|
|
137
|
+
else
|
|
138
|
+
-1
|
|
139
|
+
end
|
|
140
|
+
end
|
|
141
|
+
end
|