gemwarrior 0.8.6 → 0.8.7

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.
Files changed (51) hide show
  1. checksums.yaml +4 -4
  2. data/bin/gemwarrior +15 -9
  3. data/gemwarrior.gemspec +1 -0
  4. data/lib/gemwarrior/arena.rb +10 -10
  5. data/lib/gemwarrior/battle.rb +41 -36
  6. data/lib/gemwarrior/entities/item.rb +2 -2
  7. data/lib/gemwarrior/entities/items/arena_master.rb +4 -4
  8. data/lib/gemwarrior/entities/items/bed.rb +1 -1
  9. data/lib/gemwarrior/entities/items/couch.rb +1 -1
  10. data/lib/gemwarrior/entities/items/floor_tile.rb +3 -3
  11. data/lib/gemwarrior/entities/items/gun.rb +1 -1
  12. data/lib/gemwarrior/entities/items/herb.rb +1 -1
  13. data/lib/gemwarrior/entities/items/ladder.rb +2 -2
  14. data/lib/gemwarrior/entities/items/map.rb +2 -2
  15. data/lib/gemwarrior/entities/items/massive_door.rb +1 -1
  16. data/lib/gemwarrior/entities/items/opalaser.rb +1 -1
  17. data/lib/gemwarrior/entities/items/pond.rb +2 -2
  18. data/lib/gemwarrior/entities/items/rope.rb +2 -2
  19. data/lib/gemwarrior/entities/items/snowman.rb +1 -1
  20. data/lib/gemwarrior/entities/items/sparklything.rb +1 -1
  21. data/lib/gemwarrior/entities/items/tent.rb +1 -1
  22. data/lib/gemwarrior/entities/items/tower_switch.rb +1 -1
  23. data/lib/gemwarrior/entities/items/waterfall.rb +1 -1
  24. data/lib/gemwarrior/entities/location.rb +19 -19
  25. data/lib/gemwarrior/entities/monster.rb +2 -2
  26. data/lib/gemwarrior/entities/monsters/alexandrat.rb +3 -3
  27. data/lib/gemwarrior/entities/monsters/amberoo.rb +3 -3
  28. data/lib/gemwarrior/entities/monsters/amethystle.rb +3 -3
  29. data/lib/gemwarrior/entities/monsters/apatiger.rb +2 -2
  30. data/lib/gemwarrior/entities/monsters/aquamarine.rb +3 -3
  31. data/lib/gemwarrior/entities/monsters/bloodstorm.rb +3 -3
  32. data/lib/gemwarrior/entities/monsters/bosses/emerald.rb +4 -4
  33. data/lib/gemwarrior/entities/monsters/bosses/garynetty.rb +2 -2
  34. data/lib/gemwarrior/entities/monsters/citrinaga.rb +3 -3
  35. data/lib/gemwarrior/entities/monsters/coraliz.rb +3 -3
  36. data/lib/gemwarrior/entities/monsters/cubicat.rb +3 -3
  37. data/lib/gemwarrior/entities/monsters/diaman.rb +3 -3
  38. data/lib/gemwarrior/entities/player.rb +275 -263
  39. data/lib/gemwarrior/evaluator.rb +448 -448
  40. data/lib/gemwarrior/game.rb +5 -5
  41. data/lib/gemwarrior/inventory.rb +14 -10
  42. data/lib/gemwarrior/misc/animation.rb +1 -1
  43. data/lib/gemwarrior/misc/music.rb +1 -1
  44. data/lib/gemwarrior/misc/name_generator.rb +8 -8
  45. data/lib/gemwarrior/misc/player_levels.rb +1 -1
  46. data/lib/gemwarrior/misc/timer.rb +50 -0
  47. data/lib/gemwarrior/misc/wordlist.rb +7 -7
  48. data/lib/gemwarrior/repl.rb +55 -21
  49. data/lib/gemwarrior/version.rb +1 -1
  50. data/lib/gemwarrior/world.rb +21 -21
  51. metadata +17 -2
@@ -17,7 +17,7 @@ require_relative 'inventory'
17
17
  module Gemwarrior
18
18
  class Game
19
19
  include PlayerLevels
20
-
20
+
21
21
  # CONSTANTS
22
22
  ## PLAYER DEFAULTS
23
23
  PLAYER_DESC_DEFAULT = 'Picked to do battle against a wizened madman for a shiny something or other for world-saving purposes.'
@@ -25,13 +25,13 @@ module Gemwarrior
25
25
  PLAYER_ROX_DEFAULT = 0
26
26
 
27
27
  attr_accessor :world, :eval, :repl
28
-
28
+
29
29
  def initialize(options)
30
30
  # create new world and player
31
31
  self.world = World.new
32
-
32
+
33
33
  start_stats = PlayerLevels::get_level_stats(1)
34
-
34
+
35
35
  world.debug_mode = options.fetch(:debug_mode)
36
36
  world.use_wordnik = options.fetch(:use_wordnik)
37
37
  world.sound = options.fetch(:sound)
@@ -51,7 +51,7 @@ module Gemwarrior
51
51
  :inventory => PLAYER_INVENTORY_DEFAULT,
52
52
  :rox => world.debug_mode ? 300 : PLAYER_ROX_DEFAULT,
53
53
  :cur_coords => world.location_coords_by_name('Home'),
54
-
54
+
55
55
  :god_mode => options.fetch(:god_mode),
56
56
  :beast_mode => options.fetch(:beast_mode),
57
57
  :use_wordnik => options.fetch(:use_wordnik)
@@ -13,14 +13,14 @@ module Gemwarrior
13
13
  ERROR_ITEM_EQUIP_NONWEAPON = 'That cannot be equipped as a weapon.'
14
14
  ERROR_ITEM_UNEQUIP_INVALID = 'You do not have anything called that to unequip.'
15
15
  ERROR_ITEM_UNEQUIP_NONWEAPON = 'That cannot be unequipped.'
16
-
16
+
17
17
  attr_accessor :items, :weapon
18
-
18
+
19
19
  def initialize(items = [], weapon = nil)
20
20
  self.items = items
21
21
  self.weapon = weapon
22
22
  end
23
-
23
+
24
24
  def list_contents
25
25
  if items.nil? || items.empty?
26
26
  return contents_text = '[empty]'
@@ -28,11 +28,11 @@ module Gemwarrior
28
28
  return contents_text = "#{items.map(&:name).join ', '}"
29
29
  end
30
30
  end
31
-
31
+
32
32
  def has_item?(item_name)
33
33
  items.map(&:name).include?(item_name)
34
34
  end
35
-
35
+
36
36
  def describe_item(item_name)
37
37
  if has_item?(item_name)
38
38
  items.each do |i|
@@ -44,7 +44,7 @@ module Gemwarrior
44
44
  ERROR_ITEM_DESCRIBE_INVALID
45
45
  end
46
46
  end
47
-
47
+
48
48
  def equip_item(item_name)
49
49
  if has_item?(item_name)
50
50
  items.each do |i|
@@ -62,7 +62,7 @@ module Gemwarrior
62
62
  ERROR_ITEM_EQUIP_INVALID
63
63
  end
64
64
  end
65
-
65
+
66
66
  def unequip_item(item_name)
67
67
  if has_item?(item_name)
68
68
  items.each do |i|
@@ -80,13 +80,17 @@ module Gemwarrior
80
80
  ERROR_ITEM_UNEQUIP_INVALID
81
81
  end
82
82
  end
83
-
84
- def add_item(cur_loc, item_name)
83
+
84
+ def add_item(cur_loc, item_name, player)
85
85
  cur_loc.items.each do |i|
86
86
  if i.name.eql?(item_name)
87
87
  if i.takeable
88
88
  items.push(i)
89
89
  cur_loc.remove_item(item_name)
90
+
91
+ # stats
92
+ player.items_taken += 1
93
+
90
94
  return "Added #{item_name} to your increasing collection of bits of tid."
91
95
  else
92
96
  return ERROR_ITEM_ADD_UNTAKEABLE
@@ -95,7 +99,7 @@ module Gemwarrior
95
99
  end
96
100
  ERROR_ITEM_ADD_INVALID
97
101
  end
98
-
102
+
99
103
  def remove_item(item_name)
100
104
  if has_item?(item_name)
101
105
  items.reject! { |item| item.name == item_name }
@@ -22,7 +22,7 @@ module Gemwarrior
22
22
  :random => options.fetch(:random)
23
23
  })
24
24
  end
25
-
25
+
26
26
  return th.join
27
27
  end
28
28
  end
@@ -19,7 +19,7 @@ module Gemwarrior
19
19
  volume = note[:volume].nil? ? defaults[:volume] : note[:volume]
20
20
  duration = note[:duration].nil? ? defaults[:duration] : note[:duration]
21
21
  notext = note[:notext].nil? ? defaults[:notext] : note[:notext]
22
-
22
+
23
23
  Feep::Base.new({
24
24
  :freq_or_note => note_to_play,
25
25
  :waveform => waveform,
@@ -23,7 +23,7 @@ class NameGenerator
23
23
  end
24
24
  return names
25
25
  end
26
-
26
+
27
27
  # generator function
28
28
  def generate_name
29
29
  chain = nil
@@ -31,7 +31,7 @@ class NameGenerator
31
31
  if (chain = markov_chain(self.type))
32
32
  return markov_name(chain)
33
33
  end
34
-
34
+
35
35
  return ''
36
36
  end
37
37
 
@@ -42,7 +42,7 @@ class NameGenerator
42
42
  for i in 1..count
43
43
  list.push(generate_name)
44
44
  end
45
-
45
+
46
46
  return list
47
47
  end
48
48
 
@@ -61,7 +61,7 @@ class NameGenerator
61
61
  end
62
62
  end
63
63
  end
64
-
64
+
65
65
  return false
66
66
  end
67
67
 
@@ -92,7 +92,7 @@ class NameGenerator
92
92
  end
93
93
  end
94
94
  end
95
-
95
+
96
96
  return scale_chain(chain)
97
97
  end
98
98
 
@@ -107,7 +107,7 @@ class NameGenerator
107
107
  chain[key] = {}
108
108
  chain[key][token] = 1
109
109
  end
110
-
110
+
111
111
  return chain
112
112
  end
113
113
 
@@ -125,7 +125,7 @@ class NameGenerator
125
125
  table_len[key] += weighted
126
126
  end
127
127
  end
128
-
128
+
129
129
  chain['table_len'] = table_len
130
130
 
131
131
  return chain
@@ -162,7 +162,7 @@ class NameGenerator
162
162
  t += chain_value
163
163
  return chain_key if (idx < t)
164
164
  end
165
-
165
+
166
166
  return '-'
167
167
  end
168
168
  end
@@ -63,7 +63,7 @@ module Gemwarrior
63
63
  }
64
64
  end
65
65
  end
66
-
66
+
67
67
  def self.check_level(xp)
68
68
  if xp < 50
69
69
  1
@@ -0,0 +1,50 @@
1
+ # lib/gemwarrior/misc/timer.rb
2
+ # Timer
3
+
4
+ module Gemwarrior
5
+ class Timer
6
+ attr_accessor :duration_in_s, :timer_name, :background, :progress, :verbose
7
+
8
+ DEFAULTS = {
9
+ duration_in_s: 1,
10
+ timer_name: 'Timer',
11
+ background: false,
12
+ progress: false,
13
+ verbose: true
14
+ }
15
+
16
+ def initialize(options = {})
17
+ options = DEFAULTS.merge(options)
18
+
19
+ self.duration_in_s = options[:duration_in_s]
20
+ self.timer_name = options[:timer_name]
21
+ self.background = options[:background]
22
+ self.progress = options[:progress]
23
+ self.verbose = options[:verbose]
24
+ end
25
+
26
+ def start
27
+ if background
28
+ Thread.start { self.run }
29
+ else
30
+ self.run
31
+ end
32
+ end
33
+
34
+ def run
35
+ puts "#{timer_name} began at #{Time.now} for #{duration_in_s} seconds" if verbose
36
+
37
+ end_time = Time.now + duration_in_s
38
+
39
+ loop do
40
+ sleep 1
41
+ print '.' if progress
42
+ if Time.now >= end_time
43
+ print "\n"
44
+ puts "#{timer_name} ended at #{Time.now}" if verbose
45
+ return
46
+ end
47
+ end
48
+ end
49
+ end
50
+ end
@@ -18,9 +18,9 @@ module Gemwarrior
18
18
  STATIC_VERB_VALUES = [
19
19
  'accentuate', 'accompany', 'blatter', 'bully', 'collide', 'crusade', 'disallow', 'entitle', 'infest', 'lateral', 'micturate', 'mourn', 'munge', 'numb', 'outdraw', 'overstep', 'plummet', 'refill', 'refurnish', 'reroute', 'rumple', 'scupper', 'smoosh', 'spifflicate', 'straighten', 'synthesize', 'terrorize', 'unshift', 'vociferate'
20
20
  ]
21
-
21
+
22
22
  attr_accessor :use_wordnik, :type, :limit, :words, :error
23
-
23
+
24
24
  def initialize(use_wordnik = false, type = 'noun', limit = 10)
25
25
  self.use_wordnik = use_wordnik
26
26
  self.type = type
@@ -34,7 +34,7 @@ module Gemwarrior
34
34
 
35
35
  return random_value.nil? ? get_random_value : random_value
36
36
  end
37
-
37
+
38
38
  def list_words
39
39
  words.join(',')
40
40
  end
@@ -52,7 +52,7 @@ module Gemwarrior
52
52
  error = 'invalid wordlist type'
53
53
  return
54
54
  end
55
-
55
+
56
56
  json_return = HTTP.get(
57
57
  url,
58
58
  :params => {
@@ -70,7 +70,7 @@ module Gemwarrior
70
70
  :api_key => api_key
71
71
  }
72
72
  )
73
-
73
+
74
74
  json_data = JSON.parse(json_return.to_s)
75
75
 
76
76
  if json_data.include?('type') && json_data.include?('message')
@@ -87,10 +87,10 @@ module Gemwarrior
87
87
  end
88
88
  end
89
89
  end
90
-
90
+
91
91
  return get_static_values(type)
92
92
  end
93
-
93
+
94
94
  def get_static_values(type = nil)
95
95
  static_values = []
96
96
  0.upto(10) do
@@ -3,7 +3,9 @@
3
3
 
4
4
  require 'readline'
5
5
  require 'os'
6
+ require 'clocker'
6
7
 
8
+ require_relative 'misc/timer'
7
9
  require_relative 'misc/wordlist'
8
10
  require_relative 'evaluator'
9
11
  require_relative 'version'
@@ -14,9 +16,9 @@ module Gemwarrior
14
16
  ## MESSAGES
15
17
  QUIT_MESSAGE = 'Temporal flux detected. Shutting down...'.colorize(:red)
16
18
  SPLASH_MESSAGE = 'Welcome to the land of *Jool*, where randomized fortune is just as likely as mayhem.'
17
-
19
+
18
20
  attr_accessor :world, :eval
19
-
21
+
20
22
  def initialize(world, evaluator)
21
23
  self.world = world
22
24
  self.eval = evaluator
@@ -25,26 +27,41 @@ module Gemwarrior
25
27
  def start(initialCommand = nil)
26
28
  setup_screen(initialCommand)
27
29
 
28
- # main loop
29
- loop do
30
- prompt
31
- begin
32
- input = read_line
33
- puts eval.evaluate(input)
34
- rescue Interrupt
35
- puts
36
- puts QUIT_MESSAGE
37
- exit(0)
38
- end
30
+ clocker = Clocker.new
31
+
32
+ at_exit do
33
+ pl = world.player
34
+ duration = clocker.stop
35
+ print_stats(duration, pl)
39
36
  end
37
+
38
+ clocker.clock {
39
+ # main loop
40
+ loop do
41
+ prompt
42
+ begin
43
+ input = read_line
44
+ result = eval.evaluate(input)
45
+ if result.eql?("exit")
46
+ exit
47
+ else
48
+ puts result
49
+ end
50
+ rescue Interrupt
51
+ puts
52
+ puts QUIT_MESSAGE
53
+ exit
54
+ end
55
+ end
56
+ }
40
57
  end
41
-
58
+
42
59
  private
43
-
60
+
44
61
  def clear_screen
45
62
  OS.windows? ? system('cls') : system('clear')
46
63
  end
47
-
64
+
48
65
  def print_logo
49
66
  if world.sound
50
67
  Music::cue([
@@ -57,7 +74,7 @@ module Gemwarrior
57
74
  puts "\\-+-+-+ +-+-+-+-+-+-+-/".colorize(:yellow)
58
75
  puts '[[[[[[[DEBUGGING]]]]]]]'.colorize(:white) if world.debug_mode
59
76
  end
60
-
77
+
61
78
  def print_splash_message
62
79
  SPLASH_MESSAGE.length.times do print '=' end
63
80
  puts
@@ -65,7 +82,7 @@ module Gemwarrior
65
82
  SPLASH_MESSAGE.length.times do print '=' end
66
83
  puts
67
84
  end
68
-
85
+
69
86
  def print_fortune
70
87
  noun1_values = WordList.new(world.use_wordnik, 'noun-plural')
71
88
  noun2_values = WordList.new(world.use_wordnik, 'noun-plural')
@@ -73,7 +90,7 @@ module Gemwarrior
73
90
 
74
91
  puts "* Remember: #{noun1_values.get_random_value} and #{noun2_values.get_random_value} are the key to #{noun3_values.get_random_value} *\n\n"
75
92
  end
76
-
93
+
77
94
  def print_help
78
95
  puts '* Basic functions: look, go, character, inventory, attack *'
79
96
  puts '* Type \'help\' for complete command list'
@@ -81,6 +98,23 @@ module Gemwarrior
81
98
  puts
82
99
  end
83
100
 
101
+ def print_stats(duration, pl)
102
+ puts '######################################################################'
103
+ puts
104
+ print 'Gem Warrior'.colorize(:color => :white, :background => :black)
105
+ print " played for #{duration[:mins].to_s.colorize(:color => :white, :background => :black)} minutes, #{duration[:secs].to_s.colorize(:color => :white, :background => :black)} seconds, and #{duration[:ms].to_s.colorize(:color => :white, :background => :black)} milliseconds\n"
106
+ puts '----------------------------------------------------------------------'
107
+ print "Player killed #{pl.monsters_killed.to_s.colorize(:color => :white, :background => :black)} monster(s)"
108
+ print "\n".ljust(8)
109
+ print "picked up #{pl.items_taken.to_s.colorize(:color => :white, :background => :black)} item(s)"
110
+ print "\n".ljust(8)
111
+ print "traveled #{pl.movements_made.to_s.colorize(:color => :white, :background => :black)} time(s)"
112
+ print "\n".ljust(8)
113
+ print "rested #{pl.rests_taken.to_s.colorize(:color => :white, :background => :black)} time(s)"
114
+ puts
115
+ puts '######################################################################'
116
+ end
117
+
84
118
  def setup_screen(initialCommand = nil)
85
119
  # welcome player to game
86
120
  clear_screen
@@ -92,7 +126,7 @@ module Gemwarrior
92
126
  # hook to do something right off the bat
93
127
  puts eval.evaluate(initialCommand) unless initialCommand.nil?
94
128
  end
95
-
129
+
96
130
  def prompt
97
131
  prompt_template = "\n[LV:%3s][XP:%3s][ROX:%3s] -- [HP:%3s/%-3s][STM:%2s/%-2s] -- [%s @ %s]"
98
132
  if world.debug_mode
@@ -114,7 +148,7 @@ module Gemwarrior
114
148
  end
115
149
  puts (prompt_template % prompt_vars_arr).colorize(:yellow)
116
150
  end
117
-
151
+
118
152
  def read_line
119
153
  prompt_text = world.debug_mode ? ' GW[D]> ' : ' GW> '
120
154
  Readline.readline(prompt_text, true).to_s