Skip to content

Commit cdae94c

Browse files
talk (to) command added; made y/n prompts consistent across game; arena_master and ware_hawker made talkable
1 parent 840d82f commit cdae94c

File tree

10 files changed

+112
-30
lines changed

10 files changed

+112
-30
lines changed

data/default_world.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1556,6 +1556,7 @@ locations:
15561556
consumable: false
15571557
used: false
15581558
number_of_uses:
1559+
talkable: true
15591560
name: arena_master
15601561
description: She wears simple clothing, but carries herself with an air of authority.
15611562
You think she may be the person to talk with if you want to engage in battle.
@@ -1761,6 +1762,7 @@ locations:
17611762
consumable: false
17621763
used: false
17631764
number_of_uses:
1765+
talkable: true
17641766
name: ware_hawker
17651767
description: A literal anthropomorphic hawk has set up shop behind a crudely-made
17661768
table. Some wares are scattered atop its surface, seemingly within anyone's

lib/gemwarrior/arena.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,11 @@ def start
3030
arena_monsters_vanquished += 1
3131

3232
puts
33-
puts 'Do you wish to continue fighting in the Arena? (Y/N)'
33+
print 'Do you wish to continue fighting in the Arena? (y/n) '
3434
answer = gets.chomp.downcase
3535

3636
case answer
37-
when 'yes', 'y'
37+
when 'y', 'yes'
3838
next
3939
else
4040
bonus_rox = arena_monsters_vanquished * 25

lib/gemwarrior/entities/item.rb

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,14 @@
66
module Gemwarrior
77
class Item < Entity
88
attr_accessor :atk_lo, :atk_hi, :takeable, :useable, :equippable, :equipped,
9-
:consumable, :use, :used, :number_of_uses
9+
:consumable, :use, :used, :number_of_uses, :talkable
1010

1111
def initialize
1212
self.equipped = false
1313
self.consumable = false
1414
self.used = false
1515
self.number_of_uses = nil
16+
self.talkable = false
1617
end
1718

1819
def use(inventory = nil)
@@ -28,6 +29,7 @@ def describe
2829
status_text << "EQUIPPABLE? #{equippable}\n".colorize(:white)
2930
status_text << "CONSUMABLE? #{consumable}\n".colorize(:white)
3031
status_text << "NUMBER OF USES? #{number_of_uses}\n".colorize(:white) unless number_of_uses.nil?
32+
status_text << "TALKABLE? #{talkable}\n".colorize(:white)
3133
status_text << "\n"
3234
end
3335
end

lib/gemwarrior/entities/items/arena_master.rb

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,24 +19,28 @@ def initialize
1919
self.takeable = false
2020
self.useable = true
2121
self.equippable = false
22+
self.talkable = true
2223
end
2324

2425
def use(player = nil)
2526
puts "You approach #{ARENA_MASTER_NAME.colorize(color: :white, background: :black)}, the Arena Master, and ask to prove your mettle in the arena. She snickers to herself, but sees you have a good spirit about you."
2627
puts
2728

2829
if player.rox >= 50
29-
puts "She asks for the requisite payment: #{ARENA_FEE} rox. Do you pay up? (Y/N)"
30+
print "She asks for the requisite payment: #{ARENA_FEE} rox. Do you pay up? (y/n) "
3031
answer = gets.chomp.downcase
32+
3133
case answer
3234
when 'y', 'yes'
3335
player.rox -= 50
36+
puts
3437
puts 'She pockets the money and motions toward the center of the arena. She reminds you that you will be facing an ever-worsening onslaught of monsters. Each one you dispatch nets you a bonus cache of rox in addition to whatever the monster gives you. You will also become more experienced the longer you last. Finally, you can give up at any time between battles.'
3538
puts
3639
puts 'She finishes by wishing you good luck!'
3740

3841
return { type: 'arena', data: nil }
3942
else
43+
puts
4044
puts 'She gives you a dirty look, as you have obviously wasted her time. You are told not to mess around with her anymore, and she turns away from you.'
4145
return { type: nil, data: nil }
4246
end

lib/gemwarrior/entities/items/letter.rb

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,11 @@ def initialize
1919

2020
def use(player = nil)
2121
if self.used
22-
puts 'Do you want to read the letter again? (Y/N)'
23-
print '> '
22+
print 'Do you want to read the letter again? (y/n) '
23+
answer = gets.chomp.downcase
2424

25-
choice = STDIN.getch
26-
27-
case choice
28-
when 'y'
25+
case answer
26+
when 'y', 'yes'
2927
print "\n"
3028
print_letter(player)
3129
else

lib/gemwarrior/entities/items/ware_hawker.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ def initialize
2424
self.takeable = false
2525
self.useable = true
2626
self.equippable = false
27+
self.talkable = true
2728
end
2829

2930
def use(player = nil)
@@ -54,7 +55,7 @@ def hawk_shop(player)
5455
puts ' 2 - Spear'
5556
puts ' x - leave'
5657
print '[HAWK]> '
57-
choice = gets.chomp!
58+
choice = gets.chomp.downcase
5859

5960
case choice
6061
when '1'

lib/gemwarrior/evaluator.rb

Lines changed: 87 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,13 @@ class Evaluator
1414
GO_PARAMS = 'Options: north, east, south, west'
1515
CHANGE_PARAMS = 'Options: name'
1616
DEBUG_LIST_PARAMS = 'Options: monsters, items, locations'
17-
DEBUG_STAT_PARAMS = 'Options: atk_lo, atk_hi, strength, dexterity'
17+
DEBUG_STAT_PARAMS = 'Options: hp_cur, atk_lo, atk_hi, experience, rox, strength, dexterity, defense, inventory'
1818

1919
ERROR_COMMAND_INVALID = 'That is not something the game yet understands.'
2020
ERROR_LOOK_AT_PARAM_MISSING = 'You cannot just "look at". You gotta choose something to look at.'
21+
ERROR_TALK_PARAM_INVALID = 'Are you talking to yourself? That person is not here.'
22+
ERROR_TALK_PARAM_UNTALKABLE = 'That cannnot be conversed with.'
23+
ERROR_TALK_TO_PARAM_MISSING = 'You cannot just "talk to". You gotta choose someone to talk to.'
2124
ERROR_GO_PARAM_MISSING = 'Just wander aimlessly? A direction would be nice.'
2225
ERROR_GO_PARAM_INVALID = 'The place in that direction is far, far, FAR too dangerous. You should try a different way.'
2326
ERROR_DIRECTION_PARAM_INVALID = 'You cannot go to that place.'
@@ -57,21 +60,22 @@ def initialize(world)
5760
'List all the variables in the world',
5861
'Show a map of the world',
5962
'Change player stat',
60-
'Teleport to coordinates (5 0 0) or location name (\'Home\')',
63+
'Teleport to coordinates (5 0 0) or name (\'Home\')',
6164
'Spawn random monster',
62-
'Bump your character to the next experience level',
65+
'Bump your character to the next level',
6366
'Rest, but ensure battle for testing'
6467
]
6568

66-
self.commands = %w(character inventory rest look take use drop equip unequip go north east south west attack change version checkupdate help quit quit!)
67-
self.aliases = %w(c i r l t u d eq ue g n e s w a ch v cu h q qq)
69+
self.commands = %w(character inventory rest look take talk use drop equip unequip go north east south west attack change version checkupdate help quit quit!)
70+
self.aliases = %w(c i r l t tk u d eq ue g n e s w a ch v cu h q qq)
6871
self.extras = %w(exit exit! x xx fight f ? ?? ???)
6972
self.cmd_descriptions = [
7073
'Display character information',
7174
'Look in your inventory',
7275
'Take a load off and regain HP',
7376
'Look around your current location',
7477
'Take item',
78+
'Talk to person',
7579
'Use item (in inventory or environment)',
7680
'Drop item',
7781
'Equip item',
@@ -81,11 +85,11 @@ def initialize(world)
8185
'Go east (shortcut)',
8286
'Go south (shortcut)',
8387
'Go west (shortcut)',
84-
'Attack a monster',
88+
'Attack a monster (also fight)',
8589
'Change something',
8690
'Display game version',
8791
'Check for newer game releases',
88-
'This help menu',
92+
'This help menu (also ?)',
8993
'Quit w/ confirmation (also exit/x)',
9094
'Quit w/o confirmation (also exit!/xx)'
9195
]
@@ -172,7 +176,7 @@ def evaluate(input)
172176
end
173177
end
174178
end
175-
when 'dexterity', 'dex', 'd'
179+
when 'dexterity', 'dex'
176180
unless param2.nil?
177181
param2 = param2.to_i
178182
if param2.is_a? Numeric
@@ -181,6 +185,15 @@ def evaluate(input)
181185
end
182186
end
183187
end
188+
when 'defense', 'def'
189+
unless param2.nil?
190+
param2 = param2.to_i
191+
if param2.is_a? Numeric
192+
if param2 >= 0
193+
world.player.defense = param2
194+
end
195+
end
196+
end
184197
when 'rox', 'r', '$'
185198
unless param2.nil?
186199
param2 = param2.to_i
@@ -333,6 +346,62 @@ def evaluate(input)
333346
else
334347
world.player.inventory.add_item(world.location_by_coords(world.player.cur_coords), param1, world.player)
335348
end
349+
when 'talk', 'tk'
350+
if param1.nil?
351+
return ERROR_USE_PARAM_MISSING
352+
elsif param1.eql?('to')
353+
if param2
354+
param1 = param2
355+
else
356+
return ERROR_TALK_TO_PARAM_MISSING
357+
end
358+
end
359+
360+
person_name = param1
361+
result = nil
362+
363+
player_inventory = world.player.inventory.items
364+
location = world.location_by_coords(world.player.cur_coords)
365+
location_inventory = location.items
366+
367+
if player_inventory.map(&:name).include?(person_name)
368+
player_inventory.each do |person|
369+
if person.name.eql?(person_name)
370+
if person.talkable
371+
result = person.use(world.player)
372+
else
373+
return ERROR_TALK_PARAM_UNTALKABLE
374+
end
375+
end
376+
end
377+
elsif location_inventory.map(&:name).include?(person_name)
378+
location_inventory.each do |person|
379+
if person.name.eql?(person_name)
380+
if person.talkable
381+
result = person.use(world.player)
382+
else
383+
return ERROR_TALK_PARAM_UNTALKABLE
384+
end
385+
end
386+
end
387+
end
388+
389+
return ERROR_TALK_PARAM_INVALID if result.nil?
390+
391+
case result[:type]
392+
when 'arena'
393+
arena_result = Arena.new(world: world, player: world.player)
394+
arena_result = arena.start
395+
396+
if arena_result.eql?('death')
397+
player_death_resurrection
398+
end
399+
when 'purchase'
400+
result[:data].each do |i|
401+
world.player.inventory.items.push(i)
402+
end
403+
return
404+
end
336405
when 'use', 'u'
337406
if param1.nil?
338407
ERROR_USE_PARAM_MISSING
@@ -341,7 +410,8 @@ def evaluate(input)
341410
result = nil
342411

343412
player_inventory = world.player.inventory.items
344-
location_inventory = world.location_by_coords(world.player.cur_coords).items
413+
location = world.location_by_coords(world.player.cur_coords)
414+
location_inventory = location.items
345415

346416
if player_inventory.map(&:name).include?(item_name)
347417
player_inventory.each do |i|
@@ -380,7 +450,7 @@ def evaluate(input)
380450
end
381451
elsif i.consumable
382452
result = i.use(world.player)
383-
world.player.inventory.remove_item(i.name)
453+
location.remove_item(i.name)
384454
else
385455
result = i.use(world.player)
386456
end
@@ -527,7 +597,9 @@ def evaluate(input)
527597
when 'quit', 'exit', 'q', 'x'
528598
print 'You sure you want to quit? (y/n) '
529599
response = gets.chomp.downcase
530-
if (response.eql?('y') || response.eql?('yes'))
600+
601+
case answer
602+
when 'y', 'yes'
531603
puts QUIT_MESSAGE
532604
return 'exit'
533605
else
@@ -582,8 +654,10 @@ def print_separator
582654
def list_commands
583655
i = 0
584656
print_separator
657+
puts ' COMMAND | ALIAS | DESCRIPTION '
658+
print_separator
585659
commands.each do |cmd|
586-
puts " #{cmd.ljust(9)}, #{aliases[i].ljust(2)} -- #{cmd_descriptions[i]}"
660+
puts " #{cmd.ljust(11)} | #{aliases[i].ljust(5)} | #{cmd_descriptions[i]}"
587661
i += 1
588662
end
589663
print_separator
@@ -593,7 +667,7 @@ def list_commands
593667
print_separator
594668
i = 0
595669
devcommands.each do |cmd|
596-
puts " #{cmd.ljust(9)}, #{devaliases[i].ljust(2)} -- #{devcmd_descriptions[i]}"
670+
puts " #{cmd.ljust(11)} | #{devaliases[i].ljust(5)} | #{devcmd_descriptions[i]}"
597671
i += 1
598672
end
599673
print_separator

lib/gemwarrior/inventory.rb

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -113,10 +113,11 @@ def remove_item(item_name)
113113

114114
def drop_item(item_name)
115115
if contains_item?(item_name)
116-
puts "Are you sure you want to permanently throw away #{item_name}? (Y/N)"
117-
answer = gets.downcase.chomp!
116+
print "Are you sure you want to permanently throw away #{item_name}? (y/n) "
117+
answer = gets.chomp.downcase
118118

119-
if answer.eql?('y')
119+
case answer
120+
when 'y', 'yes'
120121
remove_item(item_name)
121122

122123
return "The #{item_name} has been thrown on the ground, but far out of reach, and you're much too lazy to go get it now, so it's as good as gone."

lib/gemwarrior/repl.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,7 @@ def display_log_of_attempts
210210
answer = gets.chomp.downcase
211211

212212
case answer
213-
when 'y'
213+
when 'y', 'yes'
214214
File.truncate(GameOptions.data['log_file_path'], 0)
215215
puts 'Log of attempts: erased!'
216216
end
@@ -418,7 +418,7 @@ def overwrite_save?
418418
answer = gets.chomp.downcase
419419

420420
case answer
421-
when 'y'
421+
when 'y', 'yes'
422422
puts 'New game started! Press any key to continue.'
423423
gets
424424
return true

lib/gemwarrior/version.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,5 @@
22
# Version of Gem Warrior
33

44
module Gemwarrior
5-
VERSION = '0.10.4'
5+
VERSION = '0.10.5'
66
end

0 commit comments

Comments
 (0)