Class: Gemwarrior::World

Inherits:
Object
  • Object
show all
Defined in:
lib/gemwarrior/world.rb

Constant Summary collapse

ERROR_LIST_PARAM_INVALID =

CONSTANTS

'That is not something that can be listed.'
ERROR_DESCRIBE_ENTITY_INVALID =
'You do not see that here.'
WORLD_DIM_WIDTH =
10
WORLD_DIM_HEIGHT =
10

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#durationObject

Returns the value of attribute duration.



19
20
21
# File 'lib/gemwarrior/world.rb', line 19

def duration
  @duration
end

#emerald_beatenObject

Returns the value of attribute emerald_beaten.



19
20
21
# File 'lib/gemwarrior/world.rb', line 19

def emerald_beaten
  @emerald_beaten
end

#locationsObject

Returns the value of attribute locations.



19
20
21
# File 'lib/gemwarrior/world.rb', line 19

def locations
  @locations
end

#playerObject

Returns the value of attribute player.



19
20
21
# File 'lib/gemwarrior/world.rb', line 19

def player
  @player
end

#shifty_has_jeweledObject

Returns the value of attribute shifty_has_jeweled.



19
20
21
# File 'lib/gemwarrior/world.rb', line 19

def shifty_has_jeweled
  @shifty_has_jeweled
end

#shifty_to_jewelObject

Returns the value of attribute shifty_to_jewel.



19
20
21
# File 'lib/gemwarrior/world.rb', line 19

def shifty_to_jewel
  @shifty_to_jewel
end

Instance Method Details

#can_move?(direction) ⇒ Boolean

Returns:

  • (Boolean)


128
129
130
# File 'lib/gemwarrior/world.rb', line 128

def can_move?(direction)
  location_by_coords(player.cur_coords).has_loc_to_the?(direction)
end

#describe(point) ⇒ Object



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/gemwarrior/world.rb', line 26

def describe(point)
  desc_text = "[>>> #{point.name_display.upcase} <<<]".colorize(:cyan)

  if GameOptions.data['debug_mode']
    desc_text << " DL[#{point.danger_level.to_s}] MLR[#{point.monster_level_range.to_s}]".colorize(:yellow)
  end

  desc_text << "\n"

  point_desc = point.description.clone
  
  # specific location description changes
  if point.name.eql?('home')
    if point.contains_item?('tent')
      point_desc << ' Next to the bed, on the floor, is a folded-up tent.'
    end
    if point.contains_item?('letter')
      point_desc << ' Atop the chest you notice a curious letter, folded in three.'
    end
  end

  desc_text << point_desc

  point.populate_monsters(GameMonsters.data) unless point.checked_for_monsters?

  desc_text << "\n >> Monster(s):  #{point.list_monsters.join(', ')}".colorize(:yellow) unless point.list_monsters.empty?
  desc_text << "\n >> Boss(es):    #{point.list_bosses.join(', ')}".colorize(:red) unless point.list_bosses.empty?
  desc_text << "\n >> Thing(s):    #{point.list_items.join(', ')}".colorize(:white) unless point.list_items.empty?
  desc_text << "\n >> Path(s):     #{point.list_paths.join(', ')}".colorize(:white)

  if GameOptions.data['debug_mode']
    desc_text << "\n >>> Actionable: ".colorize(color: :yellow, background: :grey)
    desc_text << point.list_actionable_words.colorize(color: :white, background: :grey)
  end

  desc_text
end

#describe_entity(point, entity_name) ⇒ Object



64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
# File 'lib/gemwarrior/world.rb', line 64

def describe_entity(point, entity_name)
  entity_name.downcase!

  if point.contains_item?(entity_name)
    point.items.each do |i|
      if i.name.downcase.eql?(entity_name)
        if GameOptions.data['debug_mode']
          return i.describe_detailed(self)
        else
          return i.describe(self)
        end
      end
    end
  elsif point.has_monster?(entity_name)
    point.monsters_abounding.each do |m|
      if m.name.downcase.eql?(entity_name)
        if GameOptions.data['debug_mode']
          return m.describe_detailed(self)
        else
          return m.describe(self)
        end
      end
    end
  elsif point.has_boss?(entity_name)
    point.bosses_abounding.each do |b|
      if b.name.downcase.eql?(entity_name)
        if GameOptions.data['debug_mode']
          return b.describe_detailed(self)
        else
          return b.describe(self)
        end
      end
    end
  elsif player.inventory.contains_item?(entity_name)
    player.inventory.describe_item(entity_name, self)
  else
    ERROR_DESCRIBE_ENTITY_INVALID
  end
end

#has_monster_to_attack?(monster_name) ⇒ Boolean

Returns:

  • (Boolean)


132
133
134
135
136
137
138
139
# File 'lib/gemwarrior/world.rb', line 132

def has_monster_to_attack?(monster_name)
  possible_combatants = location_by_coords(player.cur_coords).monsters_abounding.map(&:name) | location_by_coords(player.cur_coords).bosses_abounding.map(&:name)

  possible_combatants.each do |combatant|
    return true if combatant.downcase.eql?(monster_name.downcase)
  end
  false
end

#list(param, details = false) ⇒ Object



141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
# File 'lib/gemwarrior/world.rb', line 141

def list(param, details = false)
  case param
  when 'players'
    puts '[PLAYERS]'.colorize(:yellow)
    if details
      player.check_self(false)
    else
      ">> players: #{player.name}"
    end
  when 'creatures'
    puts "[CREATURES](#{GameCreatures.data.length})".colorize(:yellow)
    if details
      GameCreatures.data.map { |c| print c.describe_detailed }
      return
    else
      ">> creatures: #{GameCreatures.data.map(&:name).join(', ')}"
    end
  when 'items'
    puts "[ITEMS](#{GameItems.data.length})".colorize(:yellow)
    if details
      GameItems.data.map { |i| print i.describe_detailed }
      return
    else
      ">> items: #{GameItems.data.map(&:name).join(', ')}"
    end
  when 'locations'
    puts "[LOCATIONS](#{locations.length})".colorize(:yellow)
    if details
      locations.map { |l| print l.describe_detailed }
      return
    else
      ">> locations: #{locations.map(&:name).join(', ')}"
    end
  when 'monsters'
    puts "[MONSTERS](#{GameMonsters.data.length})".colorize(:yellow)
    if details
      GameMonsters.data.map { |m| print m.describe_detailed }
      return
    else
      ">> monsters: #{GameMonsters.data.map(&:name).join(', ')}"
    end
  when 'people'
    puts "[PEOPLE](#{GamePeople.data.length})".colorize(:yellow)
    if details
      GamePeople.data.map { |p| print p.describe_detailed }
      return
    else
      ">> people: #{GamePeople.data.map(&:name).join(', ')}"
    end
  when 'weapons'
    puts "[WEAPONS](#{GameWeapons.data.length})".colorize(:yellow)
    if details
      GameWeapons.data.map { |w| print w.describe_detailed }
      return
    else
      ">> weapons: #{GameWeapons.data.map(&:name).join(', ')}"
    end
  when 'armor'
    puts "[ARMOR](#{GameArmor.data.length})".colorize(:yellow)
    if details
      GameArmor.data.map { |w| print w.describe_detailed }
      return
    else
      ">> armor: #{GameArmor.data.map(&:name).join(', ')}"
    end
  else
    ERROR_LIST_PARAM_INVALID
  end
end

#location_by_coords(coords) ⇒ Object



104
105
106
107
108
109
# File 'lib/gemwarrior/world.rb', line 104

def location_by_coords(coords)
  locations.each do |l|
    return l if l.coords.eql?(coords)
  end
  nil
end

#location_by_name(location_name) ⇒ Object



120
121
122
123
124
125
126
# File 'lib/gemwarrior/world.rb', line 120

def location_by_name(location_name)
  loc = locations[locations.map(&:name).index(location_name)]
  if loc.nil?
    loc = locations[locations.map(&:name_display).index(location_name)]
  end
  loc.nil? ? nil : loc
end

#location_coords_by_name(name) ⇒ Object



111
112
113
114
115
116
117
118
# File 'lib/gemwarrior/world.rb', line 111

def location_coords_by_name(name)
  locations.each do |l|
    if l.name.downcase.eql?(name.downcase) or l.name_display.downcase.eql?(name.downcase)
      return l.coords
    end
  end
  nil
end


225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
# File 'lib/gemwarrior/world.rb', line 225

def print_map(floor)
  0.upto(WORLD_DIM_HEIGHT - 1) do |count_y|
    print '  '
    0.upto(WORLD_DIM_WIDTH - 1) do
      print '---'
    end
    print "\n"
    if GameOptions.data['debug_mode']
      print "#{(WORLD_DIM_HEIGHT - 1) - count_y} "
    else
      print ' '
    end
    0.upto(WORLD_DIM_WIDTH - 1) do |count_x|
      cur_map_coords = {
        x: count_x,
        y: (WORLD_DIM_HEIGHT - 1) - count_y,
        z: floor.nil? ? self.player.cur_coords[:z] : floor.to_i
      }
      if self.player.cur_coords.eql?(cur_map_coords)
        print "|#{'O'.colorize(:cyan)}|"
      elsif location_by_coords(cur_map_coords)
        if GameOptions.data['debug_mode'] || location_by_coords(cur_map_coords).visited || self.player.special_abilities.include?(:gleam)
          print '|X|'
        else
          print '| |'
        end
      else
        print '| |'
      end
    end
    print "\n"
  end
  print '  '
  0.upto(WORLD_DIM_WIDTH - 1) do
    print '---'
  end
  puts
  print '   '
  0.upto(WORLD_DIM_WIDTH - 1) do |count_x|
    if GameOptions.data['debug_mode']
      print "#{count_x}  "
    else
      print ' '
    end
  end
  if GameOptions.data['debug_mode']
    puts
    puts
    puts "Current level: #{player.cur_coords[:z]}"
    puts '| | = invalid location'
    puts '|X| = valid location'
    puts '|O| = player'
  end
end


211
212
213
214
215
216
217
218
219
220
221
222
223
# File 'lib/gemwarrior/world.rb', line 211

def print_vars(show_details = false)
  puts "======================\n"
  puts "All Variables in World\n"
  puts "======================\n"
  puts "#{list('players', show_details)}\n\n"
  puts "#{list('creatures', show_details)}\n\n"
  puts "#{list('monsters', show_details)}\n\n"
  puts "#{list('items', show_details)}\n\n"
  puts "#{list('armor', show_details)}\n\n"
  puts "#{list('weapons', show_details)}\n\n"
  puts "#{list('locations', show_details)}\n"
  puts
end