Class: Gemwarrior::Location
- Inherits:
-
Entity
- Object
- Entity
- Gemwarrior::Location
show all
- Defined in:
- lib/gemwarrior/entities/location.rb
Constant Summary
collapse
- DANGER_LEVEL =
{ none: 0, low: 15, moderate: 30, high: 55, assured: 100 }
- ERROR_ITEM_ADD_INVALID =
'That item cannot be added to the location\'s inventory.'
- ERROR_ITEM_REMOVE_INVALID =
'That item cannot be removed as it does not exist here.'
- ERROR_SPAWN_NAME_INVALID =
'That monster does not exist in the game, and cannot be spawned.'
Instance Attribute Summary collapse
Attributes inherited from Entity
#consumable, #description, #display_shopping_cart, #equippable, #equipped, #name, #name_display, #number_of_uses, #takeable, #talkable, #useable, #useable_battle, #used, #used_again
Instance Method Summary
collapse
Methods inherited from Entity
#puts, #use
Constructor Details
#initialize(options) ⇒ Location
Returns a new instance of Location.
26
27
28
29
30
31
32
33
34
35
36
37
38
|
# File 'lib/gemwarrior/entities/location.rb', line 26
def initialize(options)
self.name = options.fetch(:name)
self.description = options.fetch(:description)
self.coords = options.fetch(:coords)
self.paths = options.fetch(:paths)
self.danger_level = options.fetch(:danger_level)
self.monster_level_range = options.fetch(:monster_level_range)
self.items = options.fetch(:items)
self.monsters_abounding = options.fetch(:monsters_abounding)
self.bosses_abounding = options.fetch(:bosses_abounding)
self.checked_for_monsters = false
self.visited = false
end
|
Instance Attribute Details
#bosses_abounding ⇒ Object
Returns the value of attribute bosses_abounding.
16
17
18
|
# File 'lib/gemwarrior/entities/location.rb', line 16
def bosses_abounding
@bosses_abounding
end
|
#checked_for_monsters ⇒ Object
Returns the value of attribute checked_for_monsters.
16
17
18
|
# File 'lib/gemwarrior/entities/location.rb', line 16
def checked_for_monsters
@checked_for_monsters
end
|
#coords ⇒ Object
Returns the value of attribute coords.
16
17
18
|
# File 'lib/gemwarrior/entities/location.rb', line 16
def coords
@coords
end
|
#danger_level ⇒ Object
Returns the value of attribute danger_level.
16
17
18
|
# File 'lib/gemwarrior/entities/location.rb', line 16
def danger_level
@danger_level
end
|
#items ⇒ Object
Returns the value of attribute items.
16
17
18
|
# File 'lib/gemwarrior/entities/location.rb', line 16
def items
@items
end
|
#monster_level_range ⇒ Object
Returns the value of attribute monster_level_range.
16
17
18
|
# File 'lib/gemwarrior/entities/location.rb', line 16
def monster_level_range
@monster_level_range
end
|
#monsters_abounding ⇒ Object
Returns the value of attribute monsters_abounding.
16
17
18
|
# File 'lib/gemwarrior/entities/location.rb', line 16
def monsters_abounding
@monsters_abounding
end
|
#paths ⇒ Object
Returns the value of attribute paths.
16
17
18
|
# File 'lib/gemwarrior/entities/location.rb', line 16
def paths
@paths
end
|
#visited ⇒ Object
Returns the value of attribute visited.
16
17
18
|
# File 'lib/gemwarrior/entities/location.rb', line 16
def visited
@visited
end
|
Instance Method Details
#add_item(item_name_to_add) ⇒ Object
75
76
77
78
79
80
81
82
83
84
|
# File 'lib/gemwarrior/entities/location.rb', line 75
def add_item(item_name_to_add)
all_items = GameItems.data | GameWeapons.data | GameArmor.data
all_items.each do |game_item|
if game_item.name.eql?(item_name_to_add)
self.items.push(game_item)
return
end
end
return LOCATION_INVENTORY_ADD_ITEM_INVALID
end
|
#checked_for_monsters? ⇒ Boolean
123
124
125
|
# File 'lib/gemwarrior/entities/location.rb', line 123
def checked_for_monsters?
checked_for_monsters
end
|
#contains_item?(item_name) ⇒ Boolean
59
60
61
|
# File 'lib/gemwarrior/entities/location.rb', line 59
def contains_item?(item_name)
self.items.map{|i| i.name.downcase}.include?(item_name.downcase)
end
|
#describe ⇒ Object
40
41
42
43
44
45
46
47
48
|
# File 'lib/gemwarrior/entities/location.rb', line 40
def describe
desc_text = name.ljust(30).upcase.colorize(:green)
desc_text << coords.values.to_a.to_s.colorize(:white)
desc_text << " DL[#{danger_level.to_s.ljust(8)}] ".colorize(:white) if GameOptions.data['debug_mode']
desc_text << " MLR[#{monster_level_range.to_s.ljust(6)}] ".colorize(:white) if GameOptions.data['debug_mode']
desc_text << "\n"
desc_text << "#{description}".colorize(:white)
desc_text
end
|
#describe_detailed ⇒ Object
50
51
52
53
54
55
56
57
|
# File 'lib/gemwarrior/entities/location.rb', line 50
def describe_detailed
desc_text = "#{name_display.ljust(36).colorize(:yellow)} #{coords.values.to_a.to_s.colorize(:white)}\n"
desc_text << "(#{name})\n".colorize(:green)
desc_text << "#{description}\n".colorize(:white)
desc_text << "DANGER_LEVEL : #{danger_level}\n".colorize(:white)
desc_text << "MONSTER_LEVEL_RANGE: #{monster_level_range}\n".colorize(:white)
desc_text
end
|
#has_any_monsters? ⇒ Boolean
63
64
65
|
# File 'lib/gemwarrior/entities/location.rb', line 63
def has_any_monsters?
monsters_abounding.length > 0
end
|
#has_boss?(boss_name) ⇒ Boolean
71
72
73
|
# File 'lib/gemwarrior/entities/location.rb', line 71
def has_boss?(boss_name)
bosses_abounding.map{|b| b.name.downcase}.include?(boss_name.downcase)
end
|
#has_loc_to_the?(direction) ⇒ Boolean
99
100
101
102
103
104
105
106
107
108
109
110
111
|
# File 'lib/gemwarrior/entities/location.rb', line 99
def has_loc_to_the?(direction)
case direction
when 'n'
direction = 'north'
when 'e'
direction = 'east'
when 's'
direction = 'south'
when 'w'
direction = 'west'
end
paths[direction.to_sym]
end
|
#has_monster?(monster_name) ⇒ Boolean
67
68
69
|
# File 'lib/gemwarrior/entities/location.rb', line 67
def has_monster?(monster_name)
monsters_abounding.map{|m| m.name.downcase}.include?(monster_name.downcase)
end
|
#list_actionable_words ⇒ Object
195
196
197
198
199
200
201
|
# File 'lib/gemwarrior/entities/location.rb', line 195
def list_actionable_words
actionable_words = []
actionable_words.push(monsters_abounding.map(&:name)) unless monsters_abounding.empty?
actionable_words.push(bosses_abounding.map(&:name)) unless bosses_abounding.empty?
actionable_words.push(items.map(&:name)) unless items.empty?
actionable_words.join(', ')
end
|
#list_bosses ⇒ Object
181
182
183
|
# File 'lib/gemwarrior/entities/location.rb', line 181
def list_bosses
bosses_abounding.length > 0 ? bosses_abounding.map(&:name_display) : []
end
|
#list_items ⇒ 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
|
# File 'lib/gemwarrior/entities/location.rb', line 141
def list_items
if items.empty?
[]
else
item_hash = {}
self.items.map(&:name).each do |i|
i_sym = i.to_sym
if item_hash.keys.include? i_sym
item_hash[i_sym] += 1
else
item_hash[i_sym] = 1
end
end
if item_hash.length == 1
i = item_hash.keys
q = item_hash.values.join.to_i
return q > 1 ? ["#{q} #{i}s"] : i
else
item_arr = []
item_hash.each do |i, q|
if q > 1
item_arr.push("#{i.to_s.colorize(:yellow)}#{'s'.colorize(:yellow)} x#{q}")
else
item_arr.push(i)
end
end
return item_arr
end
end
end
|
#list_monsters ⇒ Object
177
178
179
|
# File 'lib/gemwarrior/entities/location.rb', line 177
def list_monsters
monsters_abounding.length > 0 ? monsters_abounding.map(&:name) : []
end
|
#list_paths ⇒ Object
185
186
187
188
189
190
191
192
193
|
# File 'lib/gemwarrior/entities/location.rb', line 185
def list_paths
valid_paths = []
self.paths.each do |key, value|
if value
valid_paths.push(key.to_s)
end
end
return valid_paths
end
|
#monster_by_name(monster_name) ⇒ Object
113
114
115
116
117
118
119
120
121
|
# File 'lib/gemwarrior/entities/location.rb', line 113
def monster_by_name(monster_name)
monsters_list = monsters_abounding | bosses_abounding
monsters_list.each do |m|
if m.name.downcase.eql?(monster_name.downcase)
return m.clone
end
end
end
|
#populate_monsters(monsters_available = nil, spawn = false, monster_type = nil) ⇒ Object
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
|
# File 'lib/gemwarrior/entities/location.rb', line 203
def populate_monsters(monsters_available = nil, spawn = false, monster_type = nil)
if spawn
random_monster = nil
if monster_type.nil?
loop do
random_monster = monsters_available[rand(0..monsters_available.length-1)].clone
monsters_abounding.push(random_monster)
break
end
else
monster_type_to_spawn = monsters_available.find { |m| m.name.downcase == monster_type.downcase }
if monster_type_to_spawn.nil?
puts ERROR_SPAWN_NAME_INVALID.colorize(:red)
puts
else
monsters_abounding.push(monster_type_to_spawn)
end
end
elsif should_spawn_monster?
self.checked_for_monsters = true
self.monsters_abounding = []
random_monster = nil
loop do
random_monster = monsters_available[rand(0..monsters_available.length-1)].clone
if !random_monster.is_boss && self.monster_level_range.include?(random_monster.level)
monsters_abounding.push(random_monster)
break
end
end
else
return nil
end
end
|
#remove_item(item_name) ⇒ Object
86
87
88
89
90
91
92
|
# File 'lib/gemwarrior/entities/location.rb', line 86
def remove_item(item_name)
if contains_item?(item_name)
self.items.delete_at(items.index(items.find { |i| i.name.downcase == item_name.downcase }))
else
ERROR_ITEM_REMOVE_INVALID
end
end
|
#remove_monster(name) ⇒ Object
94
95
96
97
|
# File 'lib/gemwarrior/entities/location.rb', line 94
def remove_monster(name)
monsters_abounding.reject! { |monster| monster.name == name }
bosses_abounding.reject! { |boss| boss.name == name }
end
|
#should_spawn_monster? ⇒ Boolean
127
128
129
130
131
132
133
134
135
136
137
138
139
|
# File 'lib/gemwarrior/entities/location.rb', line 127
def should_spawn_monster?
found = false
unless danger_level.eql?(:none)
max = DANGER_LEVEL[danger_level]
trigger_values = 0..max
actual_value = rand(1..100)
if trigger_values.include?(actual_value)
found = true
end
end
return found
end
|