Skip to content

Commit

Permalink
'no implicit conversion from nil to integer' rest crash fixed, hopefu…
Browse files Browse the repository at this point in the history
…lly; sound system now selectable in main menu; sub-menu prompts now more descriptive; checkupdate command added to check for new version; new version checking improved yet again
  • Loading branch information
michaelchadwick committed Aug 17, 2015
1 parent 295dcfa commit 840d82f
Show file tree
Hide file tree
Showing 10 changed files with 89 additions and 27 deletions.
15 changes: 11 additions & 4 deletions bin/gemwarrior
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#!/usr/bin/env ruby

require 'optparse'
require 'os'

require_relative '../lib/gemwarrior/game'
require_relative '../lib/gemwarrior/game_options'
Expand All @@ -25,6 +26,7 @@ def parse_options_cli
new_skip: false,
resume_skip: false,
sound_enabled: false,
sound_system: nil,
sound_volume: 0.3,
use_wordnik: false,
extra_command: nil
Expand All @@ -34,10 +36,12 @@ def parse_options_cli

unless options_file.nil?
sound_enabled_option = options_file[0][1].eql?('false') ? false : true
sound_volume_option = options_file[1][1].to_f
use_wordnik_option = options_file[2][1].eql?('false') ? false : true

sound_system_selected = options_file[1][1]
sound_volume_option = options_file[2][1].to_f
use_wordnik_option = options_file[3][1].eql?('false') ? false : true

options[:sound_enabled] = sound_enabled_option
options[:sound_system] = sound_system_selected
options[:sound_volume] = sound_volume_option
options[:use_wordnik] = use_wordnik_option
end
Expand Down Expand Up @@ -110,7 +114,10 @@ end
def init_config
Dir.mkdir(GW_HOME) unless Dir.exist?(GW_HOME)

GameOptions.add 'save_file_mode', 'Y'
sound_system_default = OS.windows? ? 'win32-sound' : 'feep'

GameOptions.add 'sound_system', sound_system_default
GameOptions.add 'save_file_mode', 'Y'
GameOptions.add 'default_world_path_yaml', GW_DEFAULT_WORLD_YAML
GameOptions.add 'default_world_path_bin', GW_DEFAULT_WORLD_BIN
GameOptions.add 'save_file_yaml_path', GW_SAVE_FILE_YAML
Expand Down
2 changes: 1 addition & 1 deletion lib/gemwarrior/entities/items/small_hole.rb
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ def rat_shop(player)
puts ' 1 - Herb'
puts ' 2 - Dagger'
puts ' x - leave'
print 'Option? '
print '[ROCKNEY]>? '

choice = gets.chomp!

Expand Down
2 changes: 1 addition & 1 deletion lib/gemwarrior/entities/items/ware_hawker.rb
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ def hawk_shop(player)
puts ' 1 - Mace'
puts ' 2 - Spear'
puts ' x - leave'
print 'Option? '
print '[HAWK]> '
choice = gets.chomp!

case choice
Expand Down
4 changes: 4 additions & 0 deletions lib/gemwarrior/entities/location.rb
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,10 @@ def should_spawn_monster?
trigger_values = 0..max
actual_value = rand(1..100)

if GameOptions.data['debug_mode']
puts "should_spawn_monster? #{trigger_values} : #{actual_value}"
end

if trigger_values.include?(actual_value)
found = true
end
Expand Down
14 changes: 8 additions & 6 deletions lib/gemwarrior/entities/player.rb
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ def check_self(show_pic = true)
self_text << "\n"
end

def rest(world, tent_uses = nil, ensure_fight = false)
def rest(world, tent_uses = 0, ensure_fight = false)
if ensure_fight
battle = Battle.new(world: world, player: self, monster: world.monsters[rand(0..world.monsters.length-1)].clone)
result = battle.start(is_arena = false, is_event = true)
Expand All @@ -99,12 +99,14 @@ def rest(world, tent_uses = nil, ensure_fight = false)
return
end
end

cur_loc = world.location_by_coords(cur_coords)

if cur_loc.should_spawn_monster?
chance_of_ambush = rand(0..100)

puts "chance_of_ambush: #{chance_of_ambush}" if GameOptions.data['debug_mode']

if chance_of_ambush < 25
battle = Battle.new(world: world, player: self, monster: cur_loc.monsters_abounding[rand(0..cur_loc.monsters_abounding.length-1)].clone)
return battle.start(is_arena = false, is_event = true)
Expand All @@ -114,13 +116,13 @@ def rest(world, tent_uses = nil, ensure_fight = false)
# stats
self.rests_taken += 1

hours = rand(1..23)
hours = rand(1..23)
minutes = rand(1..59)
seconds = rand(1..59)

hours_text = hours == 1 ? 'hour' : 'hours'
mins_text = minutes == 1 ? 'minute' : 'minutes'
secs_text = seconds == 1 ? 'second' : 'seconds'
hours_text = hours == 1 ? 'hour' : 'hours'
mins_text = minutes == 1 ? 'minute' : 'minutes'
secs_text = seconds == 1 ? 'second' : 'seconds'

if tent_uses > 0
if self.at_full_hp?
Expand Down
11 changes: 6 additions & 5 deletions lib/gemwarrior/evaluator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,8 @@ def initialize(world)
'Rest, but ensure battle for testing'
]

self.commands = %w(character inventory rest look take use drop equip unequip go north east south west attack change version help quit quit!)
self.aliases = %w(c i r l t u d eq ue g n e s w a ch v h q qq)
self.commands = %w(character inventory rest look take use drop equip unequip go north east south west attack change version checkupdate help quit quit!)
self.aliases = %w(c i r l t u d eq ue g n e s w a ch v cu h q qq)
self.extras = %w(exit exit! x xx fight f ? ?? ???)
self.cmd_descriptions = [
'Display character information',
Expand All @@ -84,6 +84,7 @@ def initialize(world)
'Attack a monster',
'Change something',
'Display game version',
'Check for newer game releases',
'This help menu',
'Quit w/ confirmation (also exit/x)',
'Quit w/o confirmation (also exit!/xx)'
Expand Down Expand Up @@ -256,7 +257,7 @@ def evaluate(input)
when 'levelbump', 'lb'
world.player.update_stats(reason: :level_bump, value: 1)
when 'restfight', 'rf'
result = world.player.rest(world, nil, true)
result = world.player.rest(world, 0, true)

if result.eql?('death')
player_death_resurrection
Expand Down Expand Up @@ -414,8 +415,6 @@ def evaluate(input)
world.player.rest(world, result[:data])
when 'action'
case result[:data]
when 'rest'
world.player.rest(world)
when 'map'
world.print_map(world.player.cur_coords[:z])
end
Expand Down Expand Up @@ -523,6 +522,8 @@ def evaluate(input)
list_commands
when 'version', 'v'
Gemwarrior::VERSION
when 'checkupdate', 'cu'
'checkupdate'
when 'quit', 'exit', 'q', 'x'
print 'You sure you want to quit? (y/n) '
response = gets.chomp.downcase
Expand Down
2 changes: 2 additions & 0 deletions lib/gemwarrior/game.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ def initialize(options)
GameOptions.add 'debug_mode', options.fetch(:debug_mode)
GameOptions.add 'god_mode', options.fetch(:god_mode)
GameOptions.add 'sound_enabled', options.fetch(:sound_enabled)
GameOptions.add 'sound_system', options.fetch(:sound_system)
GameOptions.add 'sound_volume', options.fetch(:sound_volume)
GameOptions.add 'use_wordnik', options.fetch(:use_wordnik)

Expand Down Expand Up @@ -63,6 +64,7 @@ def initialize(options)
def update_options_file
File.open(GameOptions.data['options_file_path'], 'w') do |f|
f.puts "sound_enabled:#{GameOptions.data['sound_enabled']}"
f.puts "sound_system:#{GameOptions.data['sound_system']}"
f.puts "sound_volume:#{GameOptions.data['sound_volume']}"
f.puts "use_wordnik:#{GameOptions.data['use_wordnik']}"
end
Expand Down
4 changes: 2 additions & 2 deletions lib/gemwarrior/misc/music.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ module Music
def self.cue(sequence)
if GameOptions.data['sound_enabled']
# if Windows, use superior win32-sound library
if OS.windows?
if GameOptions.data['sound_system'].eql?('win32-sound')
require 'win32/sound'
require_relative 'musical_notes'

Expand All @@ -24,7 +24,7 @@ def self.cue(sequence)
end
end
# otherwise, use inferior feep library
else
elsif GameOptions.data['sound_system'].eql?('feep')
require 'feep'

feep_defaults = {
Expand Down
60 changes: 53 additions & 7 deletions lib/gemwarrior/repl.rb
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ def start(initial_command, extra_command, new_skip, resume_skip)
result = evaluator.evaluate(input)
if result.eql?('exit')
exit
elsif result.eql?('checkupdate')
check_for_new_release
else
puts result
end
Expand Down Expand Up @@ -123,16 +125,18 @@ def print_options
puts
puts 'Gem Warrior Options'.colorize(:yellow)
puts '======================='.colorize(:yellow)
puts 'Toggle whether sound is played, what the game\'s volume is, or whether Wordnik is used to generate more dynamic descriptors of entities (valid WORDNIK_API_KEY environment variable must be set)'
puts 'Change whether sound is played, which sound system to use, what game volume is, or whether Wordnik is used to generate more dynamic descriptors of entities (valid WORDNIK_API_KEY environment variable must be set)'
puts
puts " (1) SOUND ENABLED : #{GameOptions.data['sound_enabled']}"
puts " (2) SOUND VOLUME : #{GameOptions.data['sound_volume']}"
puts " (3) USE WORDNIK : #{GameOptions.data['use_wordnik']}"
puts " (2) SOUND SYSTEM : #{GameOptions.data['sound_system']}"
puts " (3) SOUND VOLUME : #{GameOptions.data['sound_volume']}"
puts " (4) USE WORDNIK : #{GameOptions.data['use_wordnik']}"
puts
puts '======================='
puts
puts 'Enter option number to change value, or any other key to return to main menu.'
print 'Option? '
print '[GAME_OPTIONS]> '

answer = STDIN.getch

case answer
Expand All @@ -141,6 +145,11 @@ def print_options
GameOptions.data['sound_enabled'] = !GameOptions.data['sound_enabled']
print_options
when '2'
print answer
print "\n"
print_sound_system_selection
print_options
when '3'
print answer
print "\n"
print 'Enter a volume from 0.0 to 1.0: '
Expand All @@ -151,7 +160,7 @@ def print_options
puts 'Not a valid volume.'
end
print_options
when '3'
when '4'
print answer
GameOptions.data['use_wordnik']= !GameOptions.data['use_wordnik']
print_options
Expand All @@ -161,6 +170,36 @@ def print_options
end
end

def print_sound_system_selection
puts
puts 'Sound System Selection'.colorize(:yellow)
puts '========================'.colorize(:yellow)
puts
print ' (1) WIN32-SOUND '
print '(SELECTED)'.colorize(:yellow) if GameOptions.data['sound_system'].eql?('win32-sound')
print "\n"
print ' (2) FEEP '
print '(SELECTED)'.colorize(:yellow) if GameOptions.data['sound_system'].eql?('feep')
print "\n"
puts
puts 'Enter option number to select sound system, or any other key to exit.'
puts 'Note: win32-sound only works on Windows and will break the game is sound is enabled on non-Windows machines. Feep is cross-platform, but very slow and buggy, so use at your discretion!'
puts
print '[SOUND_SYSTEM]> '
answer = STDIN.getch.chomp.downcase

case answer
when '1'
GameOptions.add 'sound_system', 'win32-sound'
print_sound_system_selection
when '2'
GameOptions.add 'sound_system', 'feep'
print_sound_system_selection
else
return
end
end

def display_log_of_attempts
if File.exist?(GameOptions.data['log_file_path']) and !File.zero?(GameOptions.data['log_file_path'])
File.open(GameOptions.data['log_file_path']).readlines.each do |line|
Expand All @@ -184,12 +223,19 @@ def display_log_of_attempts
end

def check_for_new_release
new_release_available = false
puts 'Checking releases...'
remote_release = Gems.versions('gemwarrior').first['number']
local_release = Gemwarrior::VERSION

if remote_release != local_release
puts "GW v#{remote_release} available! Please (E)xit and run 'gem update' before continuing."
0.upto(2) do |i|
if remote_release.split('.')[i].to_i > local_release.split('.')[i].to_i
new_release_available = true
end
end

if new_release_available
puts "GW v#{remote_release} available! Please exit and run 'gem update' before continuing."
puts
else
puts 'You have the latest version. Fantastic!'
Expand Down
2 changes: 1 addition & 1 deletion lib/gemwarrior/version.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@
# Version of Gem Warrior

module Gemwarrior
VERSION = '0.10.2'
VERSION = '0.10.4'
end

0 comments on commit 840d82f

Please sign in to comment.