gemwarrior 0.9.39 → 0.10.0

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.
@@ -20,39 +20,23 @@ module Gemwarrior
20
20
  include Formatting
21
21
 
22
22
  attr_accessor :stam_cur, :stam_max, :cur_coords, :special_abilities,
23
- :monsters_killed, :items_taken, :movements_made, :rests_taken, :deaths
24
-
25
- def initialize(options)
26
- self.name = generate_name
27
- self.description = options.fetch(:description)
28
-
29
- self.face = generate_face
30
- self.hands = generate_hands
31
- self.mood = generate_mood
32
-
33
- self.level = options.fetch(:level)
34
- self.xp = options.fetch(:xp)
35
- self.hp_cur = options.fetch(:hp_cur)
36
- self.hp_max = options.fetch(:hp_max)
37
- self.atk_lo = options.fetch(:atk_lo)
38
- self.atk_hi = options.fetch(:atk_hi)
39
-
40
- self.defense = options.fetch(:defense)
41
- self.dexterity = options.fetch(:dexterity)
42
-
43
- self.inventory = options.fetch(:inventory)
44
- self.rox = options.fetch(:rox)
45
-
46
- self.stam_cur = options.fetch(:stam_cur)
47
- self.stam_max = options.fetch(:stam_max)
48
- self.cur_coords = options.fetch(:cur_coords)
49
- self.special_abilities = []
50
-
51
- self.monsters_killed = 0
52
- self.items_taken = 0
53
- self.movements_made = 0
54
- self.rests_taken = 0
55
- self.deaths = 0
23
+ :monsters_killed, :items_taken, :movements_made,
24
+ :rests_taken, :deaths
25
+
26
+ def generate_name
27
+ NameGenerator.new('fantasy').generate_name
28
+ end
29
+
30
+ def generate_face
31
+ WordList.new('adjective').get_random_value
32
+ end
33
+
34
+ def generate_hands
35
+ WordList.new('adjective').get_random_value
36
+ end
37
+
38
+ def generate_mood
39
+ WordList.new('adjective').get_random_value
56
40
  end
57
41
 
58
42
  def check_self(show_pic = true)
@@ -77,20 +61,21 @@ module Gemwarrior
77
61
  else
78
62
  abilities = Formatting::upstyle(special_abilities.collect { |x| x.to_s }).join(', ')
79
63
  end
64
+
80
65
  self_text = "NAME : #{self.name}\n"
81
- self_text << "POSITION : #{self.cur_coords.values.to_a}\n" if GameOptions.data['debug_mode']
82
- self_text << "WEAPON : #{weapon_slot}\n"
83
66
  self_text << "LEVEL : #{self.level}\n"
84
67
  self_text << "EXPERIENCE: #{self.xp}\n"
85
68
  self_text << "HIT POINTS: #{self.hp_cur}/#{self.hp_max}\n"
69
+ self_text << "WEAPON : #{weapon_slot}\n"
86
70
  self_text << "ATTACK : #{atk_lo}-#{atk_hi}\n"
87
71
  self_text << "DEXTERITY : #{self.dexterity}\n"
88
72
  self_text << "DEFENSE : #{self.defense}\n"
89
73
  self_text << "ABILITIES : #{abilities}\n"
90
74
 
91
75
  if GameOptions.data['debug_mode']
92
- self_text << "GOD_MODE : #{GameOptions.data['god_mode']}\n"
93
- self_text << "BEAST_MODE: #{GameOptions.data['beast_mode']}\n"
76
+ self_text << " POSITION : #{self.cur_coords.values.to_a}\n"
77
+ self_text << " GOD_MODE : #{GameOptions.data['god_mode']}\n"
78
+ self_text << " BEAST_MODE: #{GameOptions.data['beast_mode']}\n"
94
79
  end
95
80
 
96
81
  self_text << "\n"
@@ -99,7 +84,7 @@ module Gemwarrior
99
84
 
100
85
  self_text << "\n\n"
101
86
 
102
- self_text << "[Current Status]\nBreathing, non-naked, with a #{self.face.colorize(:yellow)} face, #{self.hands.colorize(:yellow)} hands, and feeling, generally, #{self.mood.colorize(:yellow)}."
87
+ self_text << "[Current Status]\nBreathing, non-naked, with a #{self.face.colorize(:yellow)} face, #{self.hands.colorize(:yellow)} hands, and\nfeeling, generally, #{self.mood.colorize(:yellow)}."
103
88
 
104
89
  self_text << "\n"
105
90
  end
@@ -225,10 +210,6 @@ module Gemwarrior
225
210
  # stats
226
211
  self.movements_made += 1
227
212
  end
228
-
229
- def at_full_hp?
230
- self.hp_cur == self.hp_max
231
- end
232
213
 
233
214
  def attack(world, monster)
234
215
  battle = Battle.new(world: world, player: self, monster: monster)
@@ -317,6 +298,10 @@ module Gemwarrior
317
298
  end
318
299
  end
319
300
 
301
+ def at_full_hp?
302
+ self.hp_cur == self.hp_max
303
+ end
304
+
320
305
  private
321
306
 
322
307
  def player_death
@@ -325,7 +310,6 @@ module Gemwarrior
325
310
  return 'death'
326
311
  end
327
312
 
328
- # TRAVEL
329
313
  def print_traveling_text(direction_text)
330
314
  Music::cue([
331
315
  { frequencies: 'C4', duration: 75 },
@@ -335,7 +319,6 @@ module Gemwarrior
335
319
  Animation::run(phrase: "* #{direction_text} *", oneline: false)
336
320
  end
337
321
 
338
- # CHARACTER
339
322
  def print_char_pic
340
323
  char_pic = ''
341
324
  char_pic << "************\n"
@@ -351,25 +334,5 @@ module Gemwarrior
351
334
  def print_battle_line
352
335
  puts '**************************************'
353
336
  end
354
-
355
- # INIT
356
- def generate_name
357
- NameGenerator.new('fantasy').generate_name
358
- end
359
-
360
- def generate_face
361
- face_descriptors = WordList.new('adjective')
362
- face_descriptors.get_random_value
363
- end
364
-
365
- def generate_hands
366
- hand_descriptors = WordList.new('adjective')
367
- hand_descriptors.get_random_value
368
- end
369
-
370
- def generate_mood
371
- mood_descriptors = WordList.new('adjective')
372
- mood_descriptors.get_random_value
373
- end
374
337
  end
375
338
  end
@@ -112,9 +112,11 @@ module Gemwarrior
112
112
  if GameOptions.data['debug_mode']
113
113
  case command
114
114
  when 'god', 'gd'
115
- return GameOptions.data['god_mode'] = !GameOptions.data['god_mode']
115
+ GameOptions.data['god_mode'] = !GameOptions.data['god_mode']
116
+ return "God mode set to #{GameOptions.data['god_mode']}"
116
117
  when 'beast', 'bs'
117
- return GameOptions.data['beast_mode'] = !GameOptions.data['beast_mode']
118
+ GameOptions.data['beast_mode'] = !GameOptions.data['beast_mode']
119
+ return "Beast mode set to #{GameOptions.data['beast_mode']}"
118
120
  when 'vars', 'vs'
119
121
  world.print_vars
120
122
  when 'list', 'ls'
@@ -522,7 +524,7 @@ module Gemwarrior
522
524
  when 'version', 'v'
523
525
  Gemwarrior::VERSION
524
526
  when 'quit', 'exit', 'q', 'x'
525
- puts 'You sure you want to quit? (y/n): '
527
+ print 'You sure you want to quit? (y/n) '
526
528
  response = gets.chomp.downcase
527
529
  if (response.eql?('y') || response.eql?('yes'))
528
530
  puts QUIT_MESSAGE
@@ -4,9 +4,6 @@
4
4
  require 'colorize'
5
5
  require 'matrext'
6
6
 
7
- require_relative 'entities/player'
8
- require_relative 'entities/items/herb'
9
- require_relative 'misc/player_levels'
10
7
  require_relative 'misc/animation'
11
8
  require_relative 'misc/music'
12
9
  require_relative 'world'
@@ -17,16 +14,14 @@ require_relative 'game_options'
17
14
 
18
15
  module Gemwarrior
19
16
  class Game
20
- include PlayerLevels
21
-
22
17
  # CONSTANTS
23
- PLAYER_DESC_DEFAULT = "Picked to do battle against a wizened madman for a shiny something\nor other for world-saving purposes."
24
- PLAYER_INVENTORY_DEFAULT = Inventory.new
25
- PLAYER_INVENTORY_DEBUG = Inventory.new([Herb.new])
26
- PLAYER_ROX_DEFAULT = 0
27
- PLAYER_ROX_DEBUG = 300
18
+ INVENTORY_DEFAULT = Inventory.new
19
+ INVENTORY_DEBUG = Inventory.new([Herb.new])
20
+ ROX_DEFAULT = 0
21
+ ROX_DEBUG = 300
28
22
 
29
- attr_accessor :world, :evaluator, :repl
23
+ attr_accessor :world, :evaluator, :repl,
24
+ :monsters, :items
30
25
 
31
26
  def initialize(options)
32
27
  # set game options
@@ -36,38 +31,33 @@ module Gemwarrior
36
31
  GameOptions.add 'sound_enabled', options.fetch(:sound_enabled)
37
32
  GameOptions.add 'sound_volume', options.fetch(:sound_volume)
38
33
  GameOptions.add 'use_wordnik', options.fetch(:use_wordnik)
34
+
35
+ # add classes for monsters and items to game
36
+ init_monsters
37
+ init_items
38
+
39
+ # create new world based on default template
40
+ self.world = init_world
39
41
 
40
- # create new world and player
41
- start_stats = PlayerLevels::get_level_stats(1)
42
-
43
- self.world = World.new
44
-
45
- world.player = Player.new({
46
- description: PLAYER_DESC_DEFAULT,
47
- level: start_stats[:level],
48
- xp: start_stats[:xp_start],
49
- hp_cur: start_stats[:hp_max],
50
- hp_max: start_stats[:hp_max],
51
- stam_cur: start_stats[:stam_max],
52
- stam_max: start_stats[:stam_max],
53
- atk_lo: start_stats[:atk_lo],
54
- atk_hi: start_stats[:atk_hi],
55
- defense: start_stats[:defense],
56
- dexterity: start_stats[:dexterity],
57
- inventory: GameOptions.data['debug_mode'] ? PLAYER_INVENTORY_DEBUG : PLAYER_INVENTORY_DEFAULT,
58
- rox: GameOptions.data['debug_mode'] ? PLAYER_ROX_DEBUG : PLAYER_ROX_DEFAULT,
59
- cur_coords: world.location_coords_by_name('Home')
60
- })
42
+ # update some player aspects to make more dynamic
43
+ world.player.name = world.player.generate_name
44
+ world.player.face = world.player.generate_face
45
+ world.player.hands = world.player.generate_hands
46
+ world.player.mood = world.player.generate_mood
47
+ world.player.inventory = GameOptions.data['debug_mode'] ? INVENTORY_DEBUG : INVENTORY_DEFAULT
48
+ world.player.rox = GameOptions.data['debug_mode'] ? ROX_DEBUG : ROX_DEFAULT
49
+
50
+ world.duration = { mins: 0, secs: 0, ms: 0 }
61
51
 
62
52
  # create options file if not existing
63
53
  update_options_file
64
-
54
+
65
55
  # create the console
66
56
  self.evaluator = Evaluator.new(world)
67
57
  self.repl = Repl.new(self, world, evaluator)
68
58
 
69
59
  # enter Jool!
70
- repl.start('look', options.fetch(:extra_command), options.fetch(:new_game))
60
+ repl.start('look', options.fetch(:extra_command), options.fetch(:new_skip), options.fetch(:resume_skip))
71
61
  end
72
62
 
73
63
  def update_options_file
@@ -77,5 +67,59 @@ module Gemwarrior
77
67
  f.puts "use_wordnik:#{GameOptions.data['use_wordnik']}"
78
68
  end
79
69
  end
70
+
71
+ private
72
+
73
+ def init_monsters
74
+ Dir.glob(File.expand_path('../entities/monsters/*.rb', __FILE__)).each do |item|
75
+ require_relative item
76
+ end
77
+ Dir.glob(File.expand_path('../entities/monsters/bosses/*.rb', __FILE__)).each do |item|
78
+ require_relative item
79
+ end
80
+
81
+ self.monsters = [
82
+ Alexandrat.new,
83
+ Amberoo.new,
84
+ Amethystle.new,
85
+ Apatiger.new,
86
+ Aquamarine.new,
87
+ Bloodstorm.new,
88
+ Citrinaga.new,
89
+ Coraliz.new,
90
+ Cubicat.new,
91
+ Diaman.new,
92
+ Emerald.new,
93
+ Garynetty.new
94
+ ]
95
+ end
96
+
97
+ def init_items
98
+ Dir.glob(File.expand_path('../entities/items/*.rb', __FILE__)).each do |item|
99
+ require_relative item
100
+ end
101
+ end
102
+
103
+ def init_world
104
+ mode = GameOptions.data['save_file_mode']
105
+
106
+ if mode.eql?('Y')
107
+ if File.exist?(GameOptions.data['default_world_path_yaml'])
108
+ File.open(GameOptions.data['default_world_path_yaml'], 'r') do |f|
109
+ return YAML::load(f)
110
+ end
111
+ else
112
+ puts "Error: cannot load #{GameOptions.data['default_world_path_yaml']}."
113
+ end
114
+ else
115
+ if File.exist?(GameOptions.data['default_world_path_bin'])
116
+ File.open(GameOptions.data['default_world_path_bin'], 'r') do |f|
117
+ return Marshal::load(f)
118
+ end
119
+ else
120
+ puts "Error: cannot load #{GameOptions.data['default_world_path_bin']}."
121
+ end
122
+ end
123
+ end
80
124
  end
81
125
  end
@@ -17,7 +17,7 @@ class NameGenerator
17
17
  # load sample names
18
18
  def get_name_set(type)
19
19
  names = []
20
- names_data = YAML.load_file(File.expand_path("../../../../data/#{type}_names.yml", __FILE__))
20
+ names_data = YAML.load_file(File.expand_path("../../../../data/#{type}_names.yaml", __FILE__))
21
21
  names_data.each do |n|
22
22
  names.push(n)
23
23
  end
@@ -31,16 +31,16 @@ module Gemwarrior
31
31
  self.evaluator = evaluator
32
32
  end
33
33
 
34
- def start(initial_command, extra_command, new_game)
35
- setup_screen(initial_command, extra_command, new_game)
34
+ def start(initial_command, extra_command, new_skip, resume_skip)
35
+ setup_screen(initial_command, extra_command, new_skip, resume_skip)
36
36
 
37
37
  clocker = Clocker.new
38
38
 
39
39
  at_exit do
40
- world.duration = clocker.stop
40
+ update_duration(clocker.stop)
41
41
  game.update_options_file
42
42
  log_stats(world.duration, world.player)
43
- #save_game(world)
43
+ save_game(world)
44
44
  end
45
45
 
46
46
  clocker.clock do
@@ -167,7 +167,7 @@ module Gemwarrior
167
167
  print "#{line}"
168
168
  end
169
169
  if GameOptions.data['debug_mode']
170
- print 'Clear log of attempts (y/n)? '
170
+ print 'Clear log of attempts? (y/n) '
171
171
  answer = gets.chomp.downcase
172
172
 
173
173
  case answer
@@ -204,7 +204,7 @@ module Gemwarrior
204
204
  puts " GW v#{Gemwarrior::VERSION}"
205
205
  puts '======================='
206
206
  puts ' (N)ew Game'
207
- #puts ' (R)esume Game' if save_file_exist?
207
+ puts ' (R)esume Game' if save_file_exist?
208
208
  puts ' (A)bout'
209
209
  puts ' (H)elp'
210
210
  puts ' (O)ptions'
@@ -227,16 +227,15 @@ module Gemwarrior
227
227
 
228
228
  case choice
229
229
  when 'n'
230
- #if overwrite_save?
230
+ if overwrite_save?
231
231
  clear_screen
232
232
  play_intro_tune
233
233
  print_splash_message
234
234
  print_fortune
235
235
  return
236
- #else
237
- # run_main_menu
238
- #end
239
- =begin
236
+ else
237
+ run_main_menu
238
+ end
240
239
  when 'r'
241
240
  if save_file_exist?
242
241
  result = resume_game
@@ -244,9 +243,10 @@ module Gemwarrior
244
243
  run_main_menu
245
244
  elsif
246
245
  self.world = result
246
+ self.evaluator = Evaluator.new(self.world)
247
+ return
247
248
  end
248
249
  end
249
- =end
250
250
  when 'a'
251
251
  puts choice
252
252
  print_about_text
@@ -286,14 +286,14 @@ module Gemwarrior
286
286
  print " #{duration[:secs].to_s.colorize(color: :white, background: :black)} sec(s),"
287
287
  print " and #{duration[:ms].to_s.colorize(color: :white, background: :black)} ms\n"
288
288
  puts '----------------------------------------------------------------------'
289
- print "Player killed #{pl.monsters_killed.to_s.colorize(color: :white, background: :black)} monster(s)"
290
- print "\n".ljust(8)
289
+ print "#{pl.name.ljust(10)} killed #{pl.monsters_killed.to_s.colorize(color: :white, background: :black)} monster(s)"
290
+ print "\n".ljust(12)
291
291
  print "picked up #{pl.items_taken.to_s.colorize(color: :white, background: :black)} item(s)"
292
- print "\n".ljust(8)
292
+ print "\n".ljust(12)
293
293
  print "traveled #{pl.movements_made.to_s.colorize(color: :white, background: :black)} time(s)"
294
- print "\n".ljust(8)
294
+ print "\n".ljust(12)
295
295
  print "rested #{pl.rests_taken.to_s.colorize(color: :white, background: :black)} time(s)"
296
- print "\n".ljust(8)
296
+ print "\n".ljust(12)
297
297
  print "died #{pl.deaths.to_s.colorize(color: :white, background: :black)} time(s)"
298
298
  print "\n"
299
299
  puts '######################################################################'
@@ -307,13 +307,13 @@ module Gemwarrior
307
307
  def save_game(world)
308
308
  mode = GameOptions.data['save_file_mode']
309
309
  puts 'Saving game...'
310
-
310
+
311
311
  if mode.eql? 'Y'
312
- File.open(GameOptions.data['save_file_yaml_path'], 'w+') do |f|
312
+ File.open(GameOptions.data['save_file_yaml_path'], 'w') do |f|
313
313
  f.write YAML::dump(world)
314
314
  end
315
315
  elsif mode.eql? 'M'
316
- File.open(GameOptions.data['save_file_bin_path'], 'w+') do |f|
316
+ File.open(GameOptions.data['save_file_bin_path'], 'w') do |f|
317
317
  f.write Marshal::dump(world)
318
318
  end
319
319
  else
@@ -338,29 +338,27 @@ module Gemwarrior
338
338
  mode = GameOptions.data['save_file_mode']
339
339
  puts 'Resuming game...'
340
340
 
341
- if save_file_exist?
342
- if mode.eql? 'Y'
343
- if File.exist?(GameOptions.data['save_file_yaml_path'])
344
- File.open(GameOptions.data['save_file_yaml_path'], 'r') do |f|
345
- return YAML::load(f)
346
- end
347
- else
348
- puts 'No save file exists.'
349
- nil
341
+ if mode.eql? 'Y'
342
+ if File.exist?(GameOptions.data['save_file_yaml_path'])
343
+ File.open(GameOptions.data['save_file_yaml_path'], 'r') do |f|
344
+ return YAML::load(f)
350
345
  end
351
- elsif mode.eql? 'M'
352
- if File.exist?(GameOptions.data['save_file_marshal_path'])
353
- File.open(GameOptions.data['save_file_marshal_path'], 'r') do |f|
354
- return Marshal::load(f)
355
- end
356
- else
357
- puts 'No save file exists.'
358
- nil
346
+ else
347
+ puts 'No save file exists.'
348
+ nil
349
+ end
350
+ elsif mode.eql? 'M'
351
+ if File.exist?(GameOptions.data['save_file_marshal_path'])
352
+ File.open(GameOptions.data['save_file_marshal_path'], 'r') do |f|
353
+ return Marshal::load(f)
359
354
  end
355
+ else
356
+ puts 'No save file exists.'
357
+ nil
360
358
  end
361
359
  end
362
360
  end
363
-
361
+
364
362
  def overwrite_save?
365
363
  mode = GameOptions.data['save_file_mode']
366
364
  save_file_path = ''
@@ -388,6 +386,26 @@ module Gemwarrior
388
386
  true
389
387
  end
390
388
 
389
+ def update_duration(new_duration)
390
+ new_mins = new_duration[:mins]
391
+ new_secs = new_duration[:secs]
392
+ new_ms = new_duration[:ms]
393
+
394
+ world.duration[:mins] += new_mins
395
+ world.duration[:secs] += new_secs
396
+ world.duration[:ms] += new_ms
397
+
398
+ if world.duration[:ms] > 1000
399
+ world.duration[:secs] += world.duration[:ms] / 1000
400
+ world.duration[:ms] = world.duration[:ms] % 1000
401
+ end
402
+
403
+ if world.duration[:secs] > 60
404
+ world.duration[:mins] += world.duration[:secs] / 60
405
+ world.duration[:secs] = world.duration[:secs] % 60
406
+ end
407
+ end
408
+
391
409
  def play_intro_tune
392
410
  Music::cue([
393
411
  { frequencies: 'A3,E4,C#5,E5', duration: 300 },
@@ -395,16 +413,24 @@ module Gemwarrior
395
413
  ])
396
414
  end
397
415
 
398
- def setup_screen(initial_command = nil, extra_command = nil, new_game = false)
416
+ def setup_screen(initial_command = nil, extra_command = nil, new_skip = false, resume_skip = false)
399
417
  # welcome player to game
400
418
  clear_screen
401
419
  print_logo
402
420
 
403
421
  # main menu loop until new game or exit
404
- if new_game
422
+ if new_skip
405
423
  play_intro_tune
406
424
  print_splash_message
407
425
  print_fortune
426
+ elsif resume_skip
427
+ result = resume_game
428
+ if result.nil?
429
+ run_main_menu
430
+ elsif
431
+ self.world = result
432
+ self.evaluator = Evaluator.new(self.world)
433
+ end
408
434
  else
409
435
  run_main_menu
410
436
  end